From 4420e370ffd2e08ab43ed6c390ea8c91c762e19d Mon Sep 17 00:00:00 2001 From: Scott Sanderson Date: Mon, 28 Jul 2014 22:20:41 -0400 Subject: [PATCH] MAINT: Move call to `updated_portfolio` in `AlgorithmSimulator`. We guarantee that `TradingAlgorithm.updated_portfolio` is called at least once between each perf message emission. This change moves that guaranteed call into `AlgorithmSimulator.get_message` and adds a comment to make it clear why updated_portfolio is being called. --- zipline/gens/tradesimulation.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/zipline/gens/tradesimulation.py b/zipline/gens/tradesimulation.py index 27b6303a..c465d5b8 100644 --- a/zipline/gens/tradesimulation.py +++ b/zipline/gens/tradesimulation.py @@ -223,7 +223,6 @@ class AlgorithmSimulator(object): self.process_event(event) if benchmark_event_occurred: - self.algo.updated_portfolio() return self.get_message(dt) else: return None @@ -242,6 +241,11 @@ class AlgorithmSimulator(object): """ Get a perf message for the given datetime. """ + # Ensure that updated_portfolio has been called at least once for this + # dt before we emit a perf message. This is a no-op if + # updated_portfolio has already been called this dt. + self.algo.updated_portfolio() + rvars = self.algo.recorded_vars if self.algo.perf_tracker.emission_rate == 'daily': perf_message = \