mirror of
https://github.com/wassname/catalyst.git
synced 2026-07-21 12:30:16 +08:00
ENH: Add fast "vectorized" minute_to_session_label for DatetimeIndex
The new TradingCalendar method is called `minute_index_to_session_labels`. It takes a DatetimeIndex of in-order market minutes and returns a DatetimeIndex of the corresponding sessions. The new method is approximately 100x faster than mapping `minute_to_session_label` over a large DatetimeIndex.
This commit is contained in:
@@ -432,6 +432,22 @@ class ExchangeCalendarTestBase(object):
|
||||
direction="none"
|
||||
)
|
||||
|
||||
@parameterized.expand([
|
||||
(1, 0),
|
||||
(2, 0),
|
||||
(2, 1),
|
||||
])
|
||||
def test_minute_index_to_session_labels(self, interval, offset):
|
||||
minutes = self.calendar.minutes_for_sessions_in_range('2011-01-04',
|
||||
'2011-04-04')
|
||||
minutes = minutes[range(offset, len(minutes), interval)]
|
||||
|
||||
np.testing.assert_array_equal(
|
||||
np.array(minutes.map(self.calendar.minute_to_session_label),
|
||||
dtype='datetime64[ns]'),
|
||||
self.calendar.minute_index_to_session_labels(minutes)
|
||||
)
|
||||
|
||||
def test_next_prev_session(self):
|
||||
session_labels = self.answers.index[1:-2]
|
||||
max_idx = len(session_labels) - 1
|
||||
|
||||
Reference in New Issue
Block a user