mirror of
https://github.com/wassname/catalyst.git
synced 2026-07-15 11:22:18 +08:00
MAINT: Removes the ability to reference a global TradingEnvironment
This commit removes the ability to reference a shared TradingEnvironment through the zipline.finance.trading module. In place, the classes that require a TradingEnvironment, or its child AssetFinder, contain their own references to those objects. This commit also adds serialization utilities that allow for the pickling/unpickling of objects without unintentionally their TradingEnvironments or AssetFinders.
This commit is contained in:
+16
-16
@@ -135,18 +135,17 @@ class AlgorithmGeneratorTestCase(TestCase):
|
||||
Ensure the pipeline of generators are in sync, at least as far as
|
||||
their current dates.
|
||||
"""
|
||||
# Ensure we are pointing to the TradingEnvironment for this class
|
||||
trading.environment = AlgorithmGeneratorTestCase.env
|
||||
|
||||
sim_params = factory.create_simulation_parameters(
|
||||
start=datetime(2011, 7, 30, tzinfo=pytz.utc),
|
||||
end=datetime(2012, 7, 30, tzinfo=pytz.utc)
|
||||
end=datetime(2012, 7, 30, tzinfo=pytz.utc),
|
||||
env=self.env,
|
||||
)
|
||||
algo = TestAlgo(self, sim_params=sim_params,
|
||||
env=AlgorithmGeneratorTestCase.env)
|
||||
algo = TestAlgo(self, sim_params=sim_params, env=self.env)
|
||||
trade_source = factory.create_daily_trade_source(
|
||||
[8229],
|
||||
sim_params
|
||||
sim_params,
|
||||
env=self.env,
|
||||
)
|
||||
algo.set_sources([trade_source])
|
||||
|
||||
@@ -168,10 +167,10 @@ class AlgorithmGeneratorTestCase(TestCase):
|
||||
sim_params = SimulationParameters(
|
||||
period_start=datetime(2012, 7, 30, tzinfo=pytz.utc),
|
||||
period_end=datetime(2012, 7, 30, tzinfo=pytz.utc),
|
||||
data_frequency='minute'
|
||||
data_frequency='minute',
|
||||
env=self.env,
|
||||
)
|
||||
algo = TestAlgo(self, sim_params=sim_params,
|
||||
env=AlgorithmGeneratorTestCase.env)
|
||||
algo = TestAlgo(self, sim_params=sim_params, env=self.env)
|
||||
|
||||
midnight_custom_source = [Event({
|
||||
'custom_field': 42.0,
|
||||
@@ -214,13 +213,14 @@ class AlgorithmGeneratorTestCase(TestCase):
|
||||
|
||||
sim_params = factory.create_simulation_parameters(
|
||||
start=datetime(2008, 1, 1, tzinfo=pytz.utc),
|
||||
end=datetime(2008, 1, 5, tzinfo=pytz.utc)
|
||||
end=datetime(2008, 1, 5, tzinfo=pytz.utc),
|
||||
env=self.env,
|
||||
)
|
||||
algo = TestAlgo(self, sim_params=sim_params,
|
||||
env=AlgorithmGeneratorTestCase.env)
|
||||
algo = TestAlgo(self, sim_params=sim_params, env=self.env)
|
||||
trade_source = factory.create_daily_trade_source(
|
||||
[8229],
|
||||
sim_params
|
||||
sim_params,
|
||||
env=self.env,
|
||||
)
|
||||
algo.set_sources([trade_source])
|
||||
|
||||
@@ -238,8 +238,8 @@ class AlgorithmGeneratorTestCase(TestCase):
|
||||
See https://github.com/quantopian/zipline/issues/241
|
||||
"""
|
||||
sim_params = create_simulation_parameters(num_days=1,
|
||||
data_frequency='minute')
|
||||
algo = TestAlgo(self, sim_params=sim_params,
|
||||
env=AlgorithmGeneratorTestCase.env)
|
||||
data_frequency='minute',
|
||||
env=self.env)
|
||||
algo = TestAlgo(self, sim_params=sim_params, env=self.env)
|
||||
algo.run(source=[], overwrite_sim_params=False)
|
||||
self.assertEqual(algo.datetime, sim_params.last_close)
|
||||
|
||||
Reference in New Issue
Block a user