ENH: Makes breakpoints work in algoscripts started with the run_algo.py

script.

Adds an option kwarg to TradingAlgorithm named 'algo_filename' that
represents the file where the algoscript came from (if any). The
run_algo.py script will pass this argument with the value passed to the
'-f' flag. The default name is '<string>' to represent that the script
is coming from a string in python and not a file. This matches the
behavior of exec and the python convention for compiling code objects.
This commit is contained in:
Joe Jevnik
2014-11-10 10:14:56 -05:00
parent ca59abcc43
commit e56457c671
2 changed files with 5 additions and 2 deletions
+3 -1
View File
@@ -197,7 +197,9 @@ class TradingAlgorithm(object):
self.event_manager = EventManager()
if self.algoscript is not None:
exec_(self.algoscript, self.namespace)
filename = kwargs.pop('algo_filename', '<string>')
code = compile(self.algoscript, filename, 'exec')
exec_(code, self.namespace)
self._initialize = self.namespace.get('initialize')
if 'handle_data' not in self.namespace:
raise ValueError('You must define a handle_data function.')
+2 -1
View File
@@ -187,7 +187,8 @@ def run_pipeline(print_algo=True, **kwargs):
algo = zipline.TradingAlgorithm(script=algo_text,
namespace=kwargs.get('namespace', {}),
capital_base=float(kwargs['capital_base']))
capital_base=float(kwargs['capital_base']),
algo_filename=kwargs.get('algofile'))
perf = algo.run(source)