get_calendar#

rateslib.calendars.get_calendar(calendar, kind=False, named=True)#

Returns a calendar object either from an available set or a user defined input.

Parameters:
  • calendar (str, Cal, UnionCal, NamedCal) – If str, then the calendar is returned from pre-calculated values. If a specific user defined calendar this is returned without modification.

  • kind (bool) – If True will also return the kind of calculation from “null”, “named”, “custom”.

  • named (bool) – If True will return a NamedCal object, which is more compactly serialized, otherwise will parse an input string and return a Cal or UnionCal directly.

Return type:

NamedCal, Cal, UnionCal or tuple

Notes

The following named calendars are available and have been back tested against the publication of RFR indexes in the relevant geography.

  • “all”: Every day is defined as business day including weekends.

  • “bus”: Regular weekdays are defined as business days. Saturdays and Sunday are non-business days.

  • “tgt”: Target for Europe’s ESTR.

  • “osl”: Oslo for Norway’s NOWA.

  • “zur”: Zurich for Switzerland’s SARON.

  • “nyc”: New York City for US’s SOFR.

  • “fed”: Similar to “nyc” but omitting Good Friday.

  • “ldn”: London for UK’s SONIA.

  • “stk”: Stockholm for Sweden’s SWESTR.

  • “tro”: Toronto for Canada’s CORRA.

  • “tyo”: Tokyo for Japan’s TONA.

  • “syd”: Sydney for Australia’s AONIA.

  • “wlg”: Wellington for New Zealand’s OCR and BKBM.

Combined calendars can be created with comma separated input, e.g. “tgt,nyc”. This would be the typical calendar assigned to a cross-currency derivative such as a EUR/USD cross-currency swap.

For short-dated, FX instrument date calculations a concept known as an associated settlement calendars is introduced. This uses a secondary calendar to determine if a calculated date is a valid settlement day, but it is not used in the determination of tenor dates. For a EURUSD FX instrument the appropriate calendar combination is “tgt|nyc”. For a GBPEUR FX instrument the appropriate calendar combination is “ldn,tgt|nyc”.

Examples

In [1]: tgt_cal = get_calendar("tgt", named=False)

In [2]: tgt_cal.holidays[300:312]
Out[2]: 
[datetime.datetime(2020, 1, 1, 0, 0),
 datetime.datetime(2020, 4, 10, 0, 0),
 datetime.datetime(2020, 4, 13, 0, 0),
 datetime.datetime(2020, 5, 1, 0, 0),
 datetime.datetime(2020, 12, 25, 0, 0),
 datetime.datetime(2020, 12, 26, 0, 0),
 datetime.datetime(2021, 1, 1, 0, 0),
 datetime.datetime(2021, 4, 2, 0, 0),
 datetime.datetime(2021, 4, 5, 0, 0),
 datetime.datetime(2021, 5, 1, 0, 0),
 datetime.datetime(2021, 12, 25, 0, 0),
 datetime.datetime(2021, 12, 26, 0, 0)]

In [3]: tgt_cal.add_bus_days(dt(2023, 1, 3), 5, True)
Out[3]: datetime.datetime(2023, 1, 10, 0, 0)

In [4]: type(tgt_cal)
Out[4]: rateslib.rs.Cal

Calendars can be combined from the pre-existing names using comma separation.

In [5]: tgt_and_nyc_cal = get_calendar("tgt,nyc")

In [6]: tgt_and_nyc_cal.holidays[300:312]
Out[6]: 
[datetime.datetime(1992, 2, 17, 0, 0),
 datetime.datetime(1992, 4, 17, 0, 0),
 datetime.datetime(1992, 4, 20, 0, 0),
 datetime.datetime(1992, 5, 1, 0, 0),
 datetime.datetime(1992, 5, 25, 0, 0),
 datetime.datetime(1992, 7, 3, 0, 0),
 datetime.datetime(1992, 9, 7, 0, 0),
 datetime.datetime(1992, 10, 12, 0, 0),
 datetime.datetime(1992, 11, 11, 0, 0),
 datetime.datetime(1992, 11, 26, 0, 0),
 datetime.datetime(1992, 12, 25, 0, 0),
 datetime.datetime(1992, 12, 26, 0, 0)]