mirror of
https://github.com/wassname/catalyst.git
synced 2026-09-12 12:12:04 +08:00
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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user