<!--
This file is generated by a tool. Do not edit directly.
For open-source contributions the docs will be updated automatically.
-->

*Last updated: 2023-03-16.*

<div itemscope itemtype="http://developers.google.com/ReferenceObject">
<meta itemprop="name" content="tf_quant_finance.datetime.create_holiday_calendar" />
<meta itemprop="path" content="Stable" />
</div>

# tf_quant_finance.datetime.create_holiday_calendar

<!-- Insert buttons and diff -->

<table class="tfo-notebook-buttons tfo-api" align="left">
</table>

<a target="_blank" href="https://github.com/paolodelia99/tf-quant-finance/blob/main/tf_quant_finance/datetime/holiday_calendar_factory.py">View source</a>



Creates a holiday calendar.

```python
tf_quant_finance.datetime.create_holiday_calendar(
    weekend_mask=None, holidays=None, start_year=None, end_year=None
)
```



<!-- Placeholder for "Used in" -->

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:


* <b>`weekend_mask`</b>: 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.
* <b>`holidays`</b>: 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:

  ```python
  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]")
  ```

* <b>`start_year`</b>: 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.
* <b>`end_year`</b>: 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.
