Skip to content

Commit

Permalink
Merge 48a66ce into 32c0747
Browse files Browse the repository at this point in the history
  • Loading branch information
richafrank authored Jan 22, 2018
2 parents 32c0747 + 48a66ce commit 363c203
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
32 changes: 28 additions & 4 deletions tests/test_history.py
Original file line number Diff line number Diff line change
Expand Up @@ -1599,8 +1599,16 @@ def test_daily_history_minute_gaps_price_ffill(self, test_name, bar_count):

# January 5 2015 is the first day, and there is volume only every
# 10 minutes.

# January 6 has the same volume pattern and is used here to ensure we
# ffill correctly from the previous day when there is no volume yet
# today.

# January 12 is a Monday, ensuring we ffill correctly when the previous
# day is not a trading day.
for day_idx, day in enumerate([pd.Timestamp('2015-01-05', tz='UTC'),
pd.Timestamp('2015-01-06', tz='UTC')]):
pd.Timestamp('2015-01-06', tz='UTC'),
pd.Timestamp('2015-01-12', tz='UTC')]):

session_minutes = self.trading_calendar.minutes_for_session(day)

Expand All @@ -1620,7 +1628,7 @@ def test_daily_history_minute_gaps_price_ffill(self, test_name, bar_count):
(equity_minutes[-1], 391.0), # Last minute of exchange
(session_minutes[-1], 391.0), # Last minute of day
])
else:
elif day_idx == 1:
minutes_to_test = OrderedDict([
(session_minutes[0], 391.0), # ffill from yesterday
(equity_minutes[0], 391.0), # ...
Expand All @@ -1629,6 +1637,13 @@ def test_daily_history_minute_gaps_price_ffill(self, test_name, bar_count):
(equity_minutes[-1], 781.0), # Last minute of exchange
(session_minutes[-1], 781.0), # Last minute of day
])
else:
minutes_to_test = OrderedDict([
(session_minutes[0], 1951.0), # ffill from previous week
(equity_minutes[0], 1951.0), # ...
(equity_minutes[8], 1951.0), # ...
(equity_minutes[9], 1961.0), # New price today
])

for minute, expected in minutes_to_test.items():

Expand All @@ -1641,8 +1656,17 @@ def test_daily_history_minute_gaps_price_ffill(self, test_name, bar_count):
'minute',
)[self.ASSET3]

self.assertEqual(len(window), bar_count)
np.testing.assert_allclose(window[-1], expected)
self.assertEqual(
len(window),
bar_count,
"Unexpected window length at {}. Expected {}, but was {}."
.format(minute, bar_count, len(window))
)
np.testing.assert_allclose(
window[-1],
expected,
err_msg="at minute {}".format(minute),
)


class NoPrefetchMinuteEquityHistoryTestCase(MinuteEquityHistoryTestCase):
Expand Down
2 changes: 1 addition & 1 deletion zipline/data/data_portal.py
Original file line number Diff line number Diff line change
Expand Up @@ -939,7 +939,7 @@ def get_history_window(self,
# volume in today's minute bars yet, we need to use the
# previous day's ffilled daily price. Using today's daily price
# could yield a value from later today.
history_start -= pd.Timedelta(days=1)
history_start -= self.trading_calendar.day

initial_values = []
for asset in df.columns[assets_with_leading_nan]:
Expand Down

0 comments on commit 363c203

Please sign in to comment.