mirror of
https://github.com/wassname/catalyst.git
synced 2026-07-03 08:51:59 +08:00
MAINT: Remove environment as an argument to benchmark source. (#1816)
MAINT: Remove environment as an argument to benchmark source. To allow the BenchmarkSource class to be more easily used in contexts other than a TradingAlgorithm, remove the TradingEnvironment as an argument to the benchmark source. Instead: - Pass a benchmark Asset, instead of a bencmark sid; so that the asset_finder does not need to be passed to the benchmark source. - Pass the pre-calculated benchmark_returns instead of an env, which contains the benchmark_returns; a consumer can let the benchmark_returns stay as the default of `None` when using an asset. We may want to further refactor and make two different classes, instead of relying on a combination of existence/non-existence of benchmark_asset and benchmark_returns. That refactoring should be easier to do with this change.
This commit is contained in:
+11
-2
@@ -541,13 +541,22 @@ class TradingAlgorithm(object):
|
||||
)
|
||||
|
||||
def _create_benchmark_source(self):
|
||||
if self.benchmark_sid is not None:
|
||||
benchmark_asset = self.asset_finder.retrieve_asset(
|
||||
self.benchmark_sid)
|
||||
benchmark_returns = None
|
||||
else:
|
||||
benchmark_asset = None
|
||||
# get benchmark info from trading environment, which defaults to
|
||||
# downloading data from Yahoo.
|
||||
benchmark_returns = self.trading_environment.benchmark_returns
|
||||
return BenchmarkSource(
|
||||
benchmark_sid=self.benchmark_sid,
|
||||
env=self.trading_environment,
|
||||
benchmark_asset=benchmark_asset,
|
||||
trading_calendar=self.trading_calendar,
|
||||
sessions=self.sim_params.sessions,
|
||||
data_portal=self.data_portal,
|
||||
emission_rate=self.sim_params.emission_rate,
|
||||
benchmark_returns=benchmark_returns,
|
||||
)
|
||||
|
||||
def _create_generator(self, sim_params):
|
||||
|
||||
Reference in New Issue
Block a user