Skip to content

Commit

Permalink
BUG: Fix an issue where history fails during forward-filling on the f…
Browse files Browse the repository at this point in the history
…irst

minute when the only supplied HistorySpec is a 1m price history.
  • Loading branch information
ssanderson committed Jun 25, 2014
1 parent 1b571a5 commit e68b87d
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 7 deletions.
53 changes: 52 additions & 1 deletion tests/history_cases.py
Expand Up @@ -40,10 +40,12 @@ def mixed_frequency_expected_data(count, frequency):
else:
return [count - 1, count]


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),
Expand Down Expand Up @@ -77,6 +79,55 @@ def mixed_frequency_expected_data(count, frequency):
# 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,
Expand Down
12 changes: 6 additions & 6 deletions zipline/history/history_container.py
Expand Up @@ -23,7 +23,6 @@
index_at_dt,
)

from zipline.finance import trading
from zipline.utils.data import RollingPanel


Expand Down Expand Up @@ -206,13 +205,14 @@ def create_digest_panels(self, initial_sids, initial_dt):
# 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)
Expand Down

0 comments on commit e68b87d

Please sign in to comment.