tf_quant_finance.datetime.create_holiday_calendar

Contents

Last updated: 2023-03-16.

tf_quant_finance.datetime.create_holiday_calendar#

View source

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: Boolean Tensor of 7 elements one for each day of the week starting with Monday at index 0. A True value indicates the day is considered a weekend day and a False value implies a week day. Default value: None which means no weekends are applied.

  • holidays: Defines the holidays that are added to the weekends defined by weekend_mask. An instance of dates.DateTensor or an object convertible to DateTensor. 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. If holidays is specified, then start_year and end_year are ignored, and the boundaries are derived from holidays. Default value: None which means start year is inferred from holidays, if present.

  • end_year: Integer giving the latest year this calendar includes. If holidays is specified, then start_year and end_year are ignored, and the boundaries are derived from holidays. Default value: None which means start year is inferred from holidays, if present.

Returns:#

A HolidayCalendar instance.