mirror of
https://github.com/wassname/catalyst.git
synced 2026-07-16 11:18:11 +08:00
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:
@@ -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.')
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user