fixes for max drawdown

This commit is contained in:
fawce
2012-08-09 21:43:26 -04:00
parent 1ddd52334c
commit 196c681d4b
2 changed files with 14 additions and 7 deletions
+12 -5
View File
@@ -197,7 +197,7 @@ class PerformanceTracker(object):
# save the transactions for the daily periods
keep_transactions = True
)
for sid in sid_list:
self.cumulative_performance.positions[sid] = Position(sid)
self.todays_performance.positions[sid] = Position(sid)
@@ -207,6 +207,13 @@ class PerformanceTracker(object):
event.perf_message = self.handle_simulation_end()
del event['TRANSACTION']
return event
elif self.exceeded_max_loss:
# in case of max_loss, signal to downstream
# generators that we are done.
event.dt = "DONE"
event.perf_message = self.handle_simulation_end()
del event['TRANSACTION']
return event
else:
event.perf_message = self.process_event(event)
event.portfolio = self.get_portfolio()
@@ -251,7 +258,7 @@ class PerformanceTracker(object):
def process_event(self, event):
message = None
if self.exceeded_max_loss:
@@ -275,12 +282,12 @@ class PerformanceTracker(object):
#calculate performance as of last trade
self.cumulative_performance.calculate_performance()
self.todays_performance.calculate_performance()
return message
def handle_market_close(self):
# add the return results from today to the list of DailyReturn objects.
todays_date = self.market_close.replace(hour=0, minute=0, second=0)
todays_return_obj = risk.DailyReturn(
@@ -338,7 +345,7 @@ class PerformanceTracker(object):
self.market_close,
keep_transactions = True
)
return daily_update
def handle_simulation_end(self):
+2 -2
View File
@@ -87,7 +87,7 @@ class TradeSimulationClient(object):
self.sids
)
with_portfolio = perf_tracker.transform(with_filled_orders)
# Pass the messages from perf along with the trading client's
# state into the algorithm for simulation. We provide the
# trading client so that the algorithm can place new orders
@@ -97,7 +97,7 @@ class TradeSimulationClient(object):
ordering_client.state,
self.algo,
)
# The algorithm will yield a daily_results message (as
# calculated by the performance tracker) at the end of each
# day. It will also yield a risk report at the end of the