mirror of
https://github.com/wassname/catalyst.git
synced 2026-07-29 11:18:20 +08:00
BUG: Generate sim_params within run_algorithm, fix it for raw data
Previously, run_algorithm caused an error if run on raw (non-bundle) data, because of uninitialized variables. Initializing those variables to None to allow run_algorithm to work with Panel data, etc. Also, run_algorithm did not create sim_params for the TradingAlgorithm instance it created; this kicked the can to TradingAlgorithm, which gets default sim_params with data_frequency 'daily'. To support minute bars, changing run_algorithm to create its own sim_params with the data_frequency specified in its arguments.
This commit is contained in:
@@ -21,6 +21,7 @@ from zipline.finance.trading import TradingEnvironment
|
||||
from zipline.pipeline.data import USEquityPricing
|
||||
from zipline.pipeline.loaders import USEquityPricingLoader
|
||||
from zipline.utils.calendars import get_calendar
|
||||
from zipline.utils.factory import create_simulation_parameters
|
||||
import zipline.utils.paths as pth
|
||||
|
||||
|
||||
@@ -150,14 +151,21 @@ def _run(handle_data,
|
||||
raise ValueError(
|
||||
"No PipelineLoader registered for column %s." % column
|
||||
)
|
||||
else:
|
||||
env = None
|
||||
choose_loader = None
|
||||
|
||||
perf = TradingAlgorithm(
|
||||
namespace=namespace,
|
||||
capital_base=capital_base,
|
||||
start=start,
|
||||
end=end,
|
||||
env=env,
|
||||
get_pipeline_loader=choose_loader,
|
||||
sim_params=create_simulation_parameters(
|
||||
start=start,
|
||||
end=end,
|
||||
capital_base=capital_base,
|
||||
data_frequency=data_frequency,
|
||||
),
|
||||
**{
|
||||
'initialize': initialize,
|
||||
'handle_data': handle_data,
|
||||
@@ -314,8 +322,8 @@ def run_algorithm(start,
|
||||
load_extensions(default_extension, extensions, strict_extensions, environ)
|
||||
|
||||
non_none_data = valfilter(bool, {
|
||||
'data': data,
|
||||
'bundle': bundle,
|
||||
'data': data is not None,
|
||||
'bundle': bundle is not None,
|
||||
})
|
||||
if not non_none_data:
|
||||
# if neither data nor bundle are passed use 'quantopian-quandl'
|
||||
|
||||
Reference in New Issue
Block a user