mirror of
https://github.com/wassname/catalyst.git
synced 2026-09-10 11:50:32 +08:00
Refactoring of TradingEnvironment to isolate the global state: index symbol and exchange timezone. Parameters that define the simulation (start, end, and capital base) were put in a new class, SimulationParameters.
Global state for the financial simulation environment is accessed through the
zipline.finance.trading module, which now contains a module variable:
environment.
Parameters are passed into an algorithm as a keyword argument, sim_params.
SimulationParameters creates a trading day index for the test period that
can be used to find trading days, calculate distance between trading days,
and other common operations. The sim params index is just selected from the
global state.
================
Details:
- adding delorean to the requirements.
- made index symbol a parameter for loading the benchmark data. changed
messagepack storage to be symbol specific.
- ported risk, performance, algorithm, transforms, batch transforms
and associated tests to use simulation parameters and global environment
- factory and sim factory use global state and sim params
- factory method parameter names now reflect the class expected
This commit is contained in:
@@ -61,6 +61,8 @@ class NoopEventWindow(EventWindow):
|
||||
|
||||
class TestEventWindow(TestCase):
|
||||
def setUp(self):
|
||||
self.sim_params = factory.create_simulation_parameters()
|
||||
|
||||
setup_logger(self)
|
||||
|
||||
self.monday = datetime(2012, 7, 9, 16, tzinfo=pytz.utc)
|
||||
@@ -126,7 +128,7 @@ class TestEventWindow(TestCase):
|
||||
class TestFinanceTransforms(TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.trading_environment = factory.create_trading_environment()
|
||||
self.sim_params = factory.create_simulation_parameters()
|
||||
setup_logger(self)
|
||||
|
||||
trade_history = factory.create_trade_history(
|
||||
@@ -134,7 +136,7 @@ class TestFinanceTransforms(TestCase):
|
||||
[10.0, 10.0, 11.0, 11.0],
|
||||
[100, 100, 100, 300],
|
||||
timedelta(days=1),
|
||||
self.trading_environment
|
||||
self.sim_params
|
||||
)
|
||||
self.source = SpecificEquityTrades(event_list=trade_history)
|
||||
|
||||
@@ -142,7 +144,6 @@ class TestFinanceTransforms(TestCase):
|
||||
self.log_handler.pop_application()
|
||||
|
||||
def test_vwap(self):
|
||||
|
||||
vwap = MovingVWAP(
|
||||
market_aware=True,
|
||||
window_length=2
|
||||
@@ -186,7 +187,7 @@ class TestFinanceTransforms(TestCase):
|
||||
[10.0, 15.0, 13.0, 12.0, 13.0],
|
||||
[100, 100, 100, 300, 100],
|
||||
timedelta(days=1),
|
||||
self.trading_environment
|
||||
self.sim_params
|
||||
)
|
||||
self.source = SpecificEquityTrades(event_list=trade_history)
|
||||
|
||||
@@ -247,7 +248,7 @@ class TestFinanceTransforms(TestCase):
|
||||
[10.0, 15.0, 13.0, 12.0],
|
||||
[100, 100, 100, 100],
|
||||
timedelta(days=1),
|
||||
self.trading_environment
|
||||
self.sim_params
|
||||
)
|
||||
|
||||
stddev = MovingStandardDev(
|
||||
@@ -283,8 +284,13 @@ class TestFinanceTransforms(TestCase):
|
||||
|
||||
class TestBatchTransform(TestCase):
|
||||
def setUp(self):
|
||||
self.sim_params = factory.create_simulation_parameters(
|
||||
start=datetime(1990, 1, 1, tzinfo=pytz.utc),
|
||||
end=datetime(1990, 1, 8, tzinfo=pytz.utc)
|
||||
)
|
||||
setup_logger(self)
|
||||
self.source, self.df = factory.create_test_df_source()
|
||||
self.source, self.df = \
|
||||
factory.create_test_df_source(self.sim_params)
|
||||
|
||||
def test_event_window(self):
|
||||
algo = BatchTransformAlgorithm()
|
||||
@@ -361,12 +367,15 @@ class TestBatchTransform(TestCase):
|
||||
self.assertEqual(
|
||||
algo.history_return_args,
|
||||
[
|
||||
# 1990-01-01 - market holiday, no event
|
||||
# 1990-01-02 - window not full
|
||||
None,
|
||||
# 1990-01-03 - window not full
|
||||
None,
|
||||
# 1990-01-04 - window not full
|
||||
None,
|
||||
# 1990-01-05 - window not full, 3rd event
|
||||
# 1990-01-04 - window not full, 3rd event
|
||||
None,
|
||||
# 1990-01-05 - window now full
|
||||
expected_item,
|
||||
# 1990-01-08 - window now full
|
||||
expected_item
|
||||
])
|
||||
|
||||
Reference in New Issue
Block a user