mirror of
https://github.com/wassname/catalyst.git
synced 2026-06-30 03:11:14 +08:00
ENH: Add direct methods for session start/end.
Rather than having to do 'start, _ = cal.open_and_close_for_session(dt)' to get just the start, we can now do 'start = cal.session_start(dt)'.
This commit is contained in:
@@ -670,6 +670,14 @@ class ExchangeCalendarTestBase(object):
|
||||
found_open, found_close = \
|
||||
self.calendar.open_and_close_for_session(session_label)
|
||||
|
||||
# Test that the methods for just session open and close produce the
|
||||
# same values as the method for getting both.
|
||||
alt_open = self.calendar.session_open(session_label)
|
||||
self.assertEqual(alt_open, found_open)
|
||||
|
||||
alt_close = self.calendar.session_close(session_label)
|
||||
self.assertEqual(alt_close, found_close)
|
||||
|
||||
self.assertEqual(open_answer, found_open)
|
||||
self.assertEqual(close_answer, found_close)
|
||||
|
||||
|
||||
@@ -643,6 +643,18 @@ class TradingCalendar(with_metaclass(ABCMeta)):
|
||||
return (o_and_c['market_open'].tz_localize('UTC'),
|
||||
o_and_c['market_close'].tz_localize('UTC'))
|
||||
|
||||
def session_open(self, session_label):
|
||||
return self.schedule.loc[
|
||||
session_label,
|
||||
'market_open'
|
||||
].tz_localize('UTC')
|
||||
|
||||
def session_close(self, session_label):
|
||||
return self.schedule.loc[
|
||||
session_label,
|
||||
'market_close'
|
||||
].tz_localize('UTC')
|
||||
|
||||
@property
|
||||
def all_sessions(self):
|
||||
return self.schedule.index
|
||||
|
||||
Reference in New Issue
Block a user