def __call__(self, trade_calendar: TradeCalendarManager) -> Tuple[int, int]: if trade_calendar is None: raise NotImplementedError("trade_calendar is necessary for getting TradeRangeByTime.") start_date = trade_calendar.start_time.date() val_start, val_end = concat_date_time(start_date, self.start_time), concat_date_time(start_date, self.end_time) return trade_calendar.get_range_idx(val_start, val_end)
def clip_time_range( self, start_time: pd.Timestamp, end_time: pd.Timestamp) -> Tuple[pd.Timestamp, pd.Timestamp]: start_date = start_time.date() val_start, val_end = concat_date_time( start_date, self.start_time), concat_date_time(start_date, self.end_time) # NOTE: `end_date` should not be used. Because the `end_date` is for slicing. It may be in the next day # Assumption: start_time and end_time is for intraday trading. So it is OK for only using start_date return max(val_start, start_time), min(val_end, end_time)