diff --git a/tests/test_history.py b/tests/test_history.py index 9a2f21cb..ab242661 100644 --- a/tests/test_history.py +++ b/tests/test_history.py @@ -874,7 +874,11 @@ def handle_data(context, data): np.testing.assert_almost_equal(recorded_ma, 159.76304468946876) - def test_history_container_constructed_at_runtime(self): + @parameterized.expand([ + ('daily',), + ('minute',), + ]) + def test_history_container_constructed_at_runtime(self, data_freq): algo_text = dedent( """\ from zipline.api import history @@ -889,17 +893,17 @@ def handle_data(context, data): period_start=start, period_end=end, capital_base=float("1.0e5"), - data_frequency='minute', - emission_rate='daily' + data_frequency=data_freq, + emission_rate=data_freq ) test_algo = TradingAlgorithm( script=algo_text, - data_frequency='minute', + data_frequency=data_freq, sim_params=sim_params ) - source = RandomWalkSource(start=start, end=end) + source = RandomWalkSource(start=start, end=end, freq=data_freq) self.assertIsNone(test_algo.history_container) test_algo.run(source) @@ -909,13 +913,6 @@ def handle_data(context, data): ) container = test_algo.history_container - self.assertEqual( - container.buffer_panel.window_length, - Frequency.MAX_MINUTES['d'], - msg='HistoryContainer.buffer_panel was not large enough to service' - ' the given HistorySpec', - ) - self.assertEqual( len(container.digest_panels), 1, diff --git a/tests/test_sources.py b/tests/test_sources.py index a3590cfa..8e9bc24b 100644 --- a/tests/test_sources.py +++ b/tests/test_sources.py @@ -125,6 +125,4 @@ class TestRandomWalkSource(TestCase): self.assertLess(event.dt, end) self.assertGreater(event.price, 0, "price should never go negative.") - self.assertTrue(13 <= event.dt.hour <= 21, - "event.dt.hour == %i, not during market \ - hours." % event.dt.hour) + self.assertEqual(event.dt.hour, 0) diff --git a/zipline/sources/simulated.py b/zipline/sources/simulated.py index f7b6ec49..c580184b 100644 --- a/zipline/sources/simulated.py +++ b/zipline/sources/simulated.py @@ -18,6 +18,7 @@ import six import numpy as np from datetime import timedelta +import pandas as pd from zipline.sources.data_source import DataSource from zipline.utils import tradingcalendar as calendar_nyse @@ -141,7 +142,8 @@ class RandomWalkSource(DataSource): current_dt += timedelta(minutes=1) elif self.freq == 'daily': # Emit one signal per day at close - for event in self._gen_events(cur_prices, close_dt): + for event in self._gen_events( + cur_prices, pd.tslib.normalize_date(close_dt)): yield event @property