MAINT: Move ZiplineAPI context so that it always wraps main loop.

Move the responsibility of wrapping the main simulation loop in the
ZiplineAPI context from the algorithm modules generator setup to the
main trade simulation loop, so that different methods of invoking loop
do not need to duplicate how the context is set.

To make it easier for internal implementation of handle_data to
transition off of calling the ZiplineAPI every bar, to only invoking the
context once per simulation.
This commit is contained in:
Eddie Hebert
2015-07-01 10:58:47 -04:00
parent 62ab540fa2
commit 9bf4855b8c
3 changed files with 18 additions and 9 deletions
+7 -8
View File
@@ -510,15 +510,14 @@ class TradingAlgorithm(object):
self.sim_params.data_frequency,
)
with ZiplineAPI(self):
# loop through simulated_trading, each iteration returns a
# perf dictionary
perfs = []
for perf in self.gen:
perfs.append(perf)
# loop through simulated_trading, each iteration returns a
# perf dictionary
perfs = []
for perf in self.gen:
perfs.append(perf)
# convert perf dict to pandas dataframe
daily_stats = self._create_daily_stats(perfs)
# convert perf dict to pandas dataframe
daily_stats = self._create_daily_stats(perfs)
self.analyze(daily_stats)