made distinction between cumulative behavior and daily behavior a bit more clear.

This commit is contained in:
fawce
2012-04-20 15:08:39 -04:00
parent bc14e7e3b7
commit bab0e2bd19
3 changed files with 16 additions and 10 deletions
+10 -5
View File
@@ -56,9 +56,6 @@ Position Tracking
+-----------------+----------------------------------------------------+
| last_sale_price | price at last sale of the security on the exchange |
+-----------------+----------------------------------------------------+
| transactions | all the transactions that were acrued into this |
| | position. |
+-----------------+----------------------------------------------------+
Performance Period
@@ -104,7 +101,9 @@ Performance Period
| period_open | The first open of the market in period. datetime in |
| | pytz.utc timezone. |
+---------------+------------------------------------------------------+
| transactions | all the transactions that were acrued during this |
| | period. Unset/missing for cumulative periods. |
+---------------+------------------------------------------------------+
"""
@@ -471,7 +470,7 @@ class PerformancePeriod():
positions = self.get_positions_list()
transactions = [x.as_dict() for x in self.processed_transactions]
return {
rval = {
'ending_value' : self.ending_value,
'capital_used' : self.period_capital_used,
'starting_value' : self.starting_value,
@@ -489,6 +488,12 @@ class PerformancePeriod():
'period_close' : self.period_close
}
# we want the key to be absent, not just empty
if not self.keep_transactions:
del(rval['transactions'])
return rval
def to_namedict(self):
"""
Creates a namedict representing the state of this perfomance period.
+1 -1
View File
@@ -292,7 +292,7 @@ class RiskMetrics():
curve = None
# in case end date is not a trading day, search for the next market
# day for an interest rate
for i in range(7):
for i in xrange(7):
if(self.treasury_curves.has_key(self.end_date + i * one_day)):
curve = self.treasury_curves[self.end_date + i * one_day]
break
+5 -4
View File
@@ -636,7 +636,9 @@ def PERF_FRAME(perf):
cp = perf['cumulative_perf']
assert isinstance(tp['transactions'], list)
assert isinstance(cp['transactions'], list)
# we never want to send transactions for the cumulative period.
# performance.py should never send them, but just to be safe:
assert not cp.has_key('transactions')
assert isinstance(tp['positions'], list)
assert isinstance(cp['positions'], list)
assert isinstance(tp['period_close'], datetime.datetime)
@@ -652,9 +654,8 @@ def PERF_FRAME(perf):
cp['period_close'] = EPOCH(cp['period_close'])
cp['period_open'] = EPOCH(cp['period_open'])
tp['transactions'] = convert_transactions(tp['transactions'])
cp['transactions'] = convert_transactions(cp['transactions'])
tp['transactions'] = convert_transactions(tp['transactions'])
return BT_UPDATE_FRAME('PERF', perf)
def convert_transactions(transactions):