diff --git a/tests/history_cases.py b/tests/history_cases.py index 0496ed5d..cd2c42d8 100644 --- a/tests/history_cases.py +++ b/tests/history_cases.py @@ -44,6 +44,9 @@ def mixed_frequency_expected_data(count, frequency): MIXED_FREQUENCY_MINUTES = TradingEnvironment.instance().market_minute_window( to_utc('2013-07-03 9:31AM'), 600, ) +ONE_MINUTE_PRICE_ONLY_SPECS = [ + HistorySpec(1, '1m', 'price', True), +] DAILY_OPEN_CLOSE_SPECS = [ HistorySpec(3, '1d', 'open_price', False), HistorySpec(3, '1d', 'close_price', False), @@ -77,6 +80,55 @@ HISTORY_CONTAINER_TEST_CASES = { # 23 24 25 26 27 28 29 # 30 + 'test one minute price only': { + # A list of HistorySpec objects. + 'specs': ONE_MINUTE_PRICE_ONLY_SPECS, + # Sids for the test. + 'sids': [1], + # Start date for test. + 'dt': to_utc('2013-06-21 9:31AM'), + # Sequency of updates to the container + 'updates': [ + BarData( + { + 1: { + 'price': 5, + 'dt': to_utc('2013-06-21 9:31AM'), + }, + }, + ), + BarData( + { + 1: { + 'price': 6, + 'dt': to_utc('2013-06-21 9:32AM'), + }, + }, + ), + ], + # Expected results + 'expected': { + ONE_MINUTE_PRICE_ONLY_SPECS[0].key_str: [ + pd.DataFrame( + data={ + 1: [5], + }, + index=[ + to_utc('2013-06-21 9:31AM'), + ], + ), + pd.DataFrame( + data={ + 1: [6], + }, + index=[ + to_utc('2013-06-21 9:32AM'), + ], + ), + ], + }, + }, + 'test daily open close': { # A list of HistorySpec objects. 'specs': DAILY_OPEN_CLOSE_SPECS, diff --git a/zipline/history/history_container.py b/zipline/history/history_container.py index 49cc9a49..4c77a343 100644 --- a/zipline/history/history_container.py +++ b/zipline/history/history_container.py @@ -23,7 +23,6 @@ from . history import ( index_at_dt, ) -from zipline.finance import trading from zipline.utils.data import RollingPanel @@ -206,13 +205,14 @@ class HistoryContainer(object): # requiring the largest number of bars. largest_spec = specs[-1] if largest_spec.bar_count == 1: + # No need to allocate a digest panel; this frequency will only # ever use data drawn from self.buffer_panel. - env = trading.environment - first_window_closes[freq] = \ - env.get_open_and_close(initial_dt)[1] - first_window_starts[freq] = \ - freq.window_open(first_window_closes[freq]) + first_window_starts[freq] = freq.window_open(initial_dt) + first_window_closes[freq] = freq.window_close( + first_window_starts[freq] + ) + continue initial_dates = index_at_dt(largest_spec, initial_dt)