Last updated: 2023-03-16.
tf_quant_finance.datetime.create_holiday_calendar#
Creates a holiday calendar.
tf_quant_finance.datetime.create_holiday_calendar(
weekend_mask=None, holidays=None, start_year=None, end_year=None
)
Each instance should be used in the context of only one graph. E.g. one can’t create a HolidayCalendar in one tf.function and reuse it in another.
Note: providing bounds for the calendar, i.e. holidays and/or start_year,
end_year yields a better-performing calendar.
Args:#
weekend_mask: BooleanTensorof 7 elements one for each day of the week starting with Monday at index 0. ATruevalue indicates the day is considered a weekend day and aFalsevalue implies a week day. Default value: None which means no weekends are applied.holidays: Defines the holidays that are added to the weekends defined byweekend_mask. An instance ofdates.DateTensoror an object convertible toDateTensor. Default value: None which means no holidays other than those implied by the weekends (if any). Note that it is necessary to provide holidays for each year, and also adjust the holidays that fall on the weekends if required, e.g. 2021-12-25 to 2021-12-24. To avoid doing this manually one can use AbstractHolidayCalendar from Pandas:from pandas.tseries.holiday import AbstractHolidayCalendar from pandas.tseries.holiday import Holiday from pandas.tseries.holiday import nearest_workday class MyCalendar(AbstractHolidayCalendar): rules = [ Holiday('NewYear', month=1, day=1, observance=nearest_workday), Holiday('Christmas', month=12, day=25, observance=nearest_workday) ] calendar = MyCalendar() holidays_index = calendar.holidays( start=datetime.date(2020, 1, 1), end=datetime.date(2030, 12, 31)) holidays = np.array(holidays_index.to_pydatetime(), dtype="<M8[D]")
start_year: Integer giving the earliest year this calendar includes. Ifholidaysis specified, thenstart_yearandend_yearare ignored, and the boundaries are derived fromholidays. Default value: None which means start year is inferred fromholidays, if present.end_year: Integer giving the latest year this calendar includes. Ifholidaysis specified, thenstart_yearandend_yearare ignored, and the boundaries are derived fromholidays. Default value: None which means start year is inferred fromholidays, if present.
Returns:#
A HolidayCalendar instance.