diff --git a/zipline/finance/performance.py b/zipline/finance/performance.py index 4c96ecce..9fee208b 100644 --- a/zipline/finance/performance.py +++ b/zipline/finance/performance.py @@ -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): diff --git a/zipline/gens/tradesimulation.py b/zipline/gens/tradesimulation.py index 5e56b4f0..a049a5b8 100644 --- a/zipline/gens/tradesimulation.py +++ b/zipline/gens/tradesimulation.py @@ -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