def test_next_event_indexer(self): events = self.events event_sids = events['sid'].values event_dates = events['event_date'] event_timestamps = events['timestamp'] all_dates = pd.date_range('2014', '2014-01-31', tz='UTC') all_sids = np.unique(event_sids) domain = EquitySessionDomain( all_dates, 'US', time(8, 45, tzinfo=pytz.timezone('US/Eastern')), ) indexer = next_event_indexer( all_dates, domain.data_query_cutoff_for_sessions(all_dates), all_sids, event_dates, event_timestamps, event_sids, ) # Compute expected results without knowledge of null events. for i, sid in enumerate(all_sids): self.check_next_event_indexer( events, all_dates, sid, indexer[:, i], )
def test_previous_event_indexer(self): events = self.events event_sids = events['sid'].values event_dates = events['event_date'].values event_timestamps = events['timestamp'].values all_dates = pd.date_range('2014', '2014-01-31', tz='UTC') all_sids = np.unique(event_sids) domain = EquitySessionDomain( all_dates, 'CN', time(8, 45, tzinfo=pytz.timezone('Asia/Shanghai')), ) indexer = previous_event_indexer( # -> ndarray[datetime64[ns], ndim=1] domain.data_query_cutoff_for_sessions(all_dates).values, all_sids, event_dates, event_timestamps, event_sids, ) # Compute expected results without knowledge of null events. for i, sid in enumerate(all_sids): self.check_previous_event_indexer( events, all_dates, sid, indexer[:, i], )
def test_next_event_indexer(self): events = self.events event_sids = events['sid'].values event_dates = events['event_date'].values event_timestamps = events['timestamp'].values all_dates = pd.date_range('2014', '2014-01-31', tz='UTC') all_sids = np.unique(event_sids) domain = EquitySessionDomain( all_dates, 'US', time(8, 45, tzinfo=pytz.timezone('US/Eastern')), ) indexer = next_event_indexer( all_dates, domain.data_query_cutoff_for_sessions(all_dates), all_sids, event_dates, event_timestamps, event_sids, ) # Compute expected results without knowledge of null events. for i, sid in enumerate(all_sids): self.check_next_event_indexer( events, all_dates, sid, indexer[:, i], )
def test_next_event_indexer(self): events = self.events event_sids = events["sid"].to_numpy() event_dates = events["event_date"].to_numpy() event_timestamps = events["timestamp"].to_numpy() all_dates = pd.date_range("2014", "2014-01-31", tz="UTC") all_sids = np.unique(event_sids) domain = EquitySessionDomain( all_dates, "US", time(8, 45, tzinfo=pytz.timezone("US/Eastern")), ) indexer = next_event_indexer( all_dates, domain.data_query_cutoff_for_sessions(all_dates), all_sids, event_dates, event_timestamps, event_sids, ) # Compute expected results without knowledge of null events. for i, sid in enumerate(all_sids): self.check_next_event_indexer( events, all_dates, sid, indexer[:, i], )
def test_equity_session_domain(self, parameters): time, date_offset, expected_timedelta = parameters naive_sessions = pd.date_range('2000-01-01', '2000-06-01') utc_sessions = naive_sessions.tz_localize('UTC') domain = EquitySessionDomain( utc_sessions, CountryCode.UNITED_STATES, data_query_time=time, data_query_date_offset=date_offset, ) # Adding and localizing the naive_sessions here because pandas 18 # crashes when adding a tz-aware DatetimeIndex and a # TimedeltaIndex. :sadpanda:. expected = (naive_sessions + expected_timedelta).tz_localize('utc') actual = domain.data_query_cutoff_for_sessions(utc_sessions) assert_equal(expected, actual)
def test_equity_session_domain(self, parameters): time, date_offset, expected_timedelta = parameters naive_sessions = pd.date_range('2000-01-01', '2000-06-01') utc_sessions = naive_sessions.tz_localize('UTC') domain = EquitySessionDomain( utc_sessions, CountryCode.UNITED_STATES, data_query_time=time, data_query_date_offset=date_offset, ) # Adding and localizing the naive_sessions here because pandas 18 # crashes when adding a tz-aware DatetimeIndex and a # TimedeltaIndex. :sadpanda:. expected = (naive_sessions + expected_timedelta).tz_localize('utc') actual = domain.data_query_cutoff_for_sessions(utc_sessions) assert_equal(expected, actual)