mirror of
https://github.com/wassname/catalyst.git
synced 2026-06-29 20:33:46 +08:00
added transactions to the daily update objects.
This commit is contained in:
@@ -81,6 +81,9 @@ Position Tracking
|
||||
| last_sale_date | datetime of the last trade of the position's |
|
||||
| | security on the exchange |
|
||||
+-----------------+----------------------------------------------------+
|
||||
| transactions | all the transactions that were acrued into this |
|
||||
| | position. |
|
||||
+-----------------+----------------------------------------------------+
|
||||
| timestamp | System time event occurs in zipilne |
|
||||
+-----------------+----------------------------------------------------+
|
||||
|
||||
@@ -344,11 +347,13 @@ class Position():
|
||||
self.cost_basis = 0.0 ##per share
|
||||
self.last_sale_price = None
|
||||
self.last_sale_date = None
|
||||
self.transactions = []
|
||||
|
||||
def update(self, txn):
|
||||
if(self.sid != txn.sid):
|
||||
raise NameError('updating position with txn for a different sid')
|
||||
|
||||
self.transactions.append(txn)
|
||||
#we're covering a short or closing a position
|
||||
if(self.amount + txn.amount == 0):
|
||||
self.cost_basis = 0.0
|
||||
@@ -387,6 +392,7 @@ class Position():
|
||||
'last_sale_price' : self.last_sale_price,
|
||||
'last_sale_date' : self.last_sale_date,
|
||||
'timestamp' : datetime.datetime.now(),
|
||||
'transactions' : self.transactions
|
||||
}
|
||||
|
||||
|
||||
|
||||
+15
-1
@@ -631,6 +631,19 @@ def PERF_FRAME(perf):
|
||||
tp = perf['todays_perf']
|
||||
cp = perf['cumulative_perf']
|
||||
risk = perf['cumulative_risk_metrics']
|
||||
|
||||
# aggregate the day's transactions, which are nested in their
|
||||
# respsective positions.
|
||||
transactions = []
|
||||
for sid, position in tp['positions'].iteritems():
|
||||
for txn in position['transactions']:
|
||||
cur = {
|
||||
'date':EPOCH(txn.dt),
|
||||
'amount': txn.amount,
|
||||
'price': txn.price,
|
||||
'sid':txn.sid
|
||||
}
|
||||
transactions.append(cur)
|
||||
|
||||
daily_perf = {
|
||||
'date' : EPOCH(date),
|
||||
@@ -640,7 +653,8 @@ def PERF_FRAME(perf):
|
||||
'portfolio_value' : tp['portfolio_value'],
|
||||
'starting_cash' : tp['starting_cash'],
|
||||
'ending_cash' : tp['ending_cash'],
|
||||
'capital_used' : tp['capital_used']
|
||||
'capital_used' : tp['capital_used'],
|
||||
'transactions' : transactions
|
||||
}
|
||||
|
||||
cumulative_perf = {
|
||||
|
||||
@@ -60,7 +60,7 @@ class namedict(object):
|
||||
|
||||
def __getitem__(self, key):
|
||||
return self.__dict__[key]
|
||||
|
||||
|
||||
def keys(self):
|
||||
return self.__dict__.keys()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user