Merge pull request #29 from quantopian/fawce_sprint1

added transactions to the daily update objects.
This commit is contained in:
fawce
2012-04-10 11:17:37 -07:00
3 changed files with 34 additions and 4 deletions
+8 -2
View File
@@ -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 |
+-----------------+----------------------------------------------------+
@@ -389,7 +392,7 @@ class Position():
'cost_basis' : self.cost_basis,
'last_sale_price' : self.last_sale_price,
'last_sale_date' : self.last_sale_date,
'timestamp' : datetime.datetime.now(),
'timestamp' : datetime.datetime.now()
}
@@ -405,6 +408,7 @@ class PerformancePeriod():
#cash balance at start of period
self.starting_cash = starting_cash
self.ending_cash = starting_cash
self.processed_transactions = []
self.calculate_performance()
@@ -426,6 +430,7 @@ class PerformancePeriod():
self.positions[txn.sid] = Position(txn.sid)
self.positions[txn.sid].update(txn)
self.period_capital_used += -1 * txn.price * txn.amount
self.processed_transactions.append(txn)
def calculate_positions_value(self):
mktValue = 0.0
@@ -456,7 +461,8 @@ class PerformancePeriod():
'positions' : positions,
'timestamp' : datetime.datetime.now(),
'pnl' : self.pnl,
'returns' : self.returns
'returns' : self.returns,
'transactions' : self.processed_transactions,
}
def to_namedict(self):
+25 -1
View File
@@ -631,6 +631,28 @@ 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 txn in tp['transactions']:
cur = {
'date':EPOCH(txn.dt),
'amount': txn.amount,
'price': txn.price,
'sid':txn.sid
}
transactions.append(cur)
positions = []
for sid, pos in tp['positions'].iteritems():
cur = {
'cost_basis':pos['cost_basis'],
'sid' :pos['sid'],
'last_sale' :pos['last_sale_price'],
'amount' :pos['amount']
}
positions.append(cur)
daily_perf = {
'date' : EPOCH(date),
@@ -640,7 +662,9 @@ 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,
'positions' : positions
}
cumulative_perf = {
+1 -1
View File
@@ -60,7 +60,7 @@ class namedict(object):
def __getitem__(self, key):
return self.__dict__[key]
def keys(self):
return self.__dict__.keys()