BUG: Fix start and end dates of simulation parameters used in tests.

The start and end of the simulation parameters should be 'normalized'
i.e. midnight timestamped.
However, the algorithm tests were using the timestamp of the
first and last trade, which were in market times,
i.e. 9:30 AM and 4:00 PM EST.

Fix passing the sim_params that is used to create the trade_history,
instead of having the sim_params inferred from the source.

(Also may want to consider fixing the logic that infers the date
range from the sources provided.)

Also, add a `num_days` option to `factory.create_simulation_parameters`
so that the a date range that covers the desired number of days is covered.
Since the default sim_params were covering a year, while the test only
supplies 4 values, causing an alignment issue with the record test,
since a years worth of results were returned, but there were only 4 events.
This commit is contained in:
Eddie Hebert
2013-04-09 15:11:43 -04:00
parent 23ff65ad32
commit 57db5bc17c
2 changed files with 17 additions and 7 deletions
+8 -4
View File
@@ -30,7 +30,7 @@ from zipline.finance.trading import SimulationParameters
class TestRecordAlgorithm(TestCase):
def setUp(self):
self.sim_params = factory.create_simulation_parameters()
self.sim_params = factory.create_simulation_parameters(num_days=4)
trade_history = factory.create_trade_history(
133,
[10.0, 10.0, 11.0, 11.0],
@@ -38,13 +38,15 @@ class TestRecordAlgorithm(TestCase):
timedelta(days=1),
self.sim_params
)
self.source = SpecificEquityTrades(event_list=trade_history)
self.df_source, self.df = \
factory.create_test_df_source(self.sim_params)
def test_record_incr(self):
algo = RecordAlgorithm()
algo = RecordAlgorithm(sim_params=self.sim_params)
output = algo.run(self.source)
np.testing.assert_array_equal(output['incr'].values,
range(1, len(output) + 1))
@@ -52,7 +54,7 @@ class TestRecordAlgorithm(TestCase):
class TestTransformAlgorithm(TestCase):
def setUp(self):
setup_logger(self)
self.sim_params = factory.create_simulation_parameters()
self.sim_params = factory.create_simulation_parameters(num_days=4)
setup_logger(self)
trade_history = factory.create_trade_history(
@@ -109,7 +111,9 @@ class TestTransformAlgorithm(TestCase):
assert isinstance(algo.sources[0], DataFrameSource)
def test_panel_as_input(self):
algo = TestRegisterTransformAlgorithm(sids=[0, 1])
algo = TestRegisterTransformAlgorithm(
self.sim_params,
sids=[0, 1])
algo.run(self.panel)
assert isinstance(algo.sources[0], DataPanelSource)