add_tenor#
- rateslib.calendars.add_tenor(start, tenor, modifier, calendar=NoInput.blank, roll=NoInput.blank, settlement=False, mod_days=False)#
Add a tenor to a given date under specific modification rules and holiday calendar.
Warning
Note this function does not validate the
roll
input, but expects it to be correct. This can be used to correctly replicate a schedule under a given roll day. For example a modified 29th May +3M will default to 29th Aug, but can be made to match 31 Aug with ‘eom’ roll, or 30th Aug with 30 roll.- Parameters:
start (datetime) – The initial date to which to add the tenor.
tenor (str) – The tenor to add, identified by calendar days, “D”, months, “M”, years, “Y” or business days, “B”, for example “10Y” or “5B”.
modifier (str, optional in {"NONE", "MF", "F", "MP", "P"}) – The modification rule to apply if the tenor is calendar days, months or years.
calendar (CustomBusinessDay or str, optional) – The calendar for use with business day adjustment and modification.
roll (str, int, optional) – This is only required if the tenor is given in months or years. Ensures the tenor period associates with a schedule’s roll day.
settlement (bool, optional) – Whether to enforce the settlement with an associated settlement calendar. If there is no associated settlement calendar this will have no effect.
mod_days (bool, optional) – If True will apply modified rules to day type tenors as well as month and year tenors. If False will convert “MF” to “F” and “MP” to “P” for day type tenors.
- Return type:
datetime
Notes
Read more about the
settlement
argument in the calendar user guide.The
mod_days
argument is provided to avoid having to reconfigure Instrument specifications when a termination may differ between months or years, and days or weeks. Most Instruments will be defined by the typical modified following (“MF”)modifier
, but this would prefer not to always apply.In [1]: add_tenor(dt(2021, 1, 29), "1M", "MF", "bus") Out[1]: datetime.datetime(2021, 2, 26, 0, 0)
while, the following will by default roll into a new month,
In [2]: add_tenor(dt(2021, 1, 22), "8d", "MF", "bus") Out[2]: datetime.datetime(2021, 2, 1, 0, 0)
unless,
In [3]: add_tenor(dt(2021, 1, 22), "8d", "MF", "bus", mod_days=True) Out[3]: datetime.datetime(2021, 1, 29, 0, 0)
Examples
In [4]: add_tenor(dt(2022, 2, 28), "3M", "NONE") Out[4]: datetime.datetime(2022, 5, 28, 0, 0) In [5]: add_tenor(dt(2022, 12, 28), "4b", "F", get_calendar("ldn")) Out[5]: datetime.datetime(2023, 1, 4, 0, 0) In [6]: add_tenor(dt(2022, 12, 28), "4d", "F", get_calendar("ldn")) Out[6]: datetime.datetime(2023, 1, 3, 0, 0)