MCPcopy
hub / github.com/quantopian/zipline / run

Method run

zipline/algorithm.py:621–654  ·  view source on GitHub ↗

Run the algorithm.

(self, data_portal=None)

Source from the content-addressed store, hash-verified

619 return self._create_generator(self.sim_params)
620
621 def run(self, data_portal=None):
622 """Run the algorithm.
623 """
624 # HACK: I don't think we really want to support passing a data portal
625 # this late in the long term, but this is needed for now for backwards
626 # compat downstream.
627 if data_portal is not None:
628 self.data_portal = data_portal
629 self.asset_finder = data_portal.asset_finder
630 elif self.data_portal is None:
631 raise RuntimeError(
632 "No data portal in TradingAlgorithm.run().\n"
633 "Either pass a DataPortal to TradingAlgorithm() or to run()."
634 )
635 else:
636 assert self.asset_finder is not None, \
637 "Have data portal without asset_finder."
638
639 # Create zipline and loop through simulated_trading.
640 # Each iteration returns a perf dictionary
641 try:
642 perfs = []
643 for perf in self.get_generator():
644 perfs.append(perf)
645
646 # convert perf dict to pandas dataframe
647 daily_stats = self._create_daily_stats(perfs)
648
649 self.analyze(daily_stats)
650 finally:
651 self.data_portal = None
652 self.metrics_tracker = None
653
654 return daily_stats
655
656 def _create_daily_stats(self, perfs):
657 # create daily and cumulative stats dataframe

Callers 2

_runFunction · 0.45
run_algorithmMethod · 0.45

Calls 3

get_generatorMethod · 0.95
_create_daily_statsMethod · 0.95
analyzeMethod · 0.95

Tested by

no test coverage detected