get_calendar#
- rateslib.scheduling.get_calendar(calendar, named=False)#
Returns a calendar object from base implementation or user-defined and/or combinations of such.
- Parameters:
calendar (str, Cal, UnionCal, NamedCal, required) – If str, then the calendar is returned from pre-calculated values. If a specific user defined calendar this is returned without modification.
named (bool, optional (set as False)) – If True, will pass any string input directly to Rust and attempt to return a
NamedCalobject. These will always only use the base implementation calendars and ignore any user-implemented calendars.
- Return type:
Notes
Please see the defaults section of the documentation to discover which named calendars are base implemented to rateslib.
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") In [2]: print(tgt_cal.print(2023, 5)) May 2023 Su Mo Tu We Th Fr Sa * 2 3 4 5 . . 8 9 10 11 12 . . 15 16 17 18 19 . . 22 23 24 25 26 . . 29 30 31 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.NamedCal
Calendars can be combined from the pre-existing names using comma separation.
In [5]: tgt_and_nyc_cal = get_calendar("tgt,nyc", named=False) In [6]: print(tgt_and_nyc_cal.print(2023, 5)) May 2023 Su Mo Tu We Th Fr Sa * 2 3 4 5 . . 8 9 10 11 12 . . 15 16 17 18 19 . . 22 23 24 25 26 . . * 30 31 In [7]: type(tgt_and_nyc_cal) Out[7]: rateslib.rs.UnionCal