PERF: Optimize session close lookups in resample bar reader (#1749)

Optimize session close lookups in MinuteResampleSessionBarReader:

- Adds `session_closes_in_range` method (along with
  `session_opens_in_range`) to TradingCalendar to allow vectorized
  retrieval of all values in a range of sessions.
- Improves code path for resampling a single session's worth of data (as
  is the case when calling `get_value`), since we don't actually need to
  look up the close minute.
This commit is contained in:
Andrew Daniels
2017-04-11 16:35:04 -04:00
committed by GitHub
parent 26ffda9ca1
commit acf345e1d3
3 changed files with 63 additions and 18 deletions
+17
View File
@@ -34,6 +34,7 @@ from zipline.errors import (
InvalidCalendarName,
)
from zipline.testing.predicates import assert_equal
from zipline.utils.calendars import(
register_calendar,
deregister_calendar,
@@ -683,6 +684,22 @@ class ExchangeCalendarTestBase(object):
self.assertEqual(open_answer, found_open)
self.assertEqual(close_answer, found_close)
def test_session_opens_in_range(self):
found_opens = self.calendar.session_opens_in_range(
self.answers.index[0],
self.answers.index[-1],
)
assert_equal(found_opens, self.answers['market_open'])
def test_session_closes_in_range(self):
found_closes = self.calendar.session_closes_in_range(
self.answers.index[0],
self.answers.index[-1],
)
assert_equal(found_closes, self.answers['market_close'])
def test_daylight_savings(self):
# 2004 daylight savings switches:
# Sunday 2004-04-04 and Sunday 2004-10-31