Cal#

class rateslib.scheduling.Cal(holidays, week_mask)#

Bases: object

A business day calendar defined by weekends and a holiday list.

Parameters:
  • holidays (list[datetime]) – A list of specific non-business days.

  • week_mask (list[int]) – A list of days defined as weekends, e.g. [5,6] for Saturday and Sunday.

Attributes Summary

holidays

A list of specifically provided non-business days.

week_mask

A list of days in the week defined as weekends.

Methods Summary

add_bus_days(date, days, settlement)

Return a business date separated by days from an input business date.

add_cal_days(date, days, adjuster)

Return a date separated by calendar days from input date, and rolled with a modifier.

add_months(date, months, adjuster, roll)

Return a date separated by months from an input date, and rolled with a modifier.

adjust(date, adjuster)

Adjust a date under a date adjustment rule.

adjusts(dates, adjuster)

Adjust a list of dates under a date adjustment rule.

bus_date_range(start, end)

Return a list of business dates in a range.

cal_date_range(start, end)

Return a list of calendar dates within a range.

from_name()

Create a new Cal object from simple string name.

is_bus_day(date)

Return whether the date is a business day.

is_non_bus_day(date)

Return whether the date is not a business day.

is_settlement(date)

Return whether the date is a business day of an associated settlement calendar.

lag_bus_days(date, days, settlement)

Adjust a date by a number of business days, under lag rules.

roll(date, modifier, settlement)

Roll a date under a simplified adjustment rule.

to_json()

Return a JSON representation of the object.

Attributes Documentation

holidays#

A list of specifically provided non-business days.

week_mask#

A list of days in the week defined as weekends.

Methods Documentation

add_bus_days(date, days, settlement)#

Return a business date separated by days from an input business date.

Parameters:
  • date (datetime) – The original business date. Raises if a non-business date is given.

  • days (int) – Number of business days to add.

  • settlement (bool) – Enforce an associated settlement calendar, if True and if one exists.

Return type:

datetime

Notes

If adding negative number of business days a failing settlement will be rolled backwards, whilst adding a positive number of days will roll a failing settlement day forwards, if settlement is True.

See also

lag_bus_days(): Add business days to inputs which are potentially non-business dates.

add_cal_days(date, days, adjuster)#

Return a date separated by calendar days from input date, and rolled with a modifier.

Parameters:
  • date (datetime) – The original business date. Raise if a non-business date is given.

  • days (int) – The number of calendar days to add.

  • adjuster (Adjuster) – The date adjustment rule to use on the unadjusted result.

Return type:

datetime

add_months(date, months, adjuster, roll)#

Return a date separated by months from an input date, and rolled with a modifier.

Parameters:
  • date (datetime) – The original date to adjust.

  • months (int) – The number of months to add.

  • adjuster (Adjuster) – The date adjustment rule to apply to the unadjusted result.

  • roll (RollDay, optional) – The day of the month to adjust to. If not given adopts the calendar day of date.

Return type:

datetime

adjust(date, adjuster)#

Adjust a date under a date adjustment rule.

Parameters:
  • date (datetime) – The date to adjust.

  • adjuster (Adjuster) – The date adjustment rule to apply.

Return type:

datetime

adjusts(dates, adjuster)#

Adjust a list of dates under a date adjustment rule.

Parameters:
  • dates (list[datetime]) – The dates to adjust.

  • adjuster (Adjuster) – The date adjustment rule to apply.

Return type:

list[datetime]

bus_date_range(start, end)#

Return a list of business dates in a range.

Parameters:
  • start (datetime) – The start date of the range, inclusive.

  • end (datetime) – The end date of the range, inclusive.

Return type:

list[datetime]

cal_date_range(start, end)#

Return a list of calendar dates within a range.

Parameters:
  • start (datetime) – The start date of the range, inclusive.

  • end (datetime) – The end date of the range, inclusive,

Return type:

list[datetime]

from_name()#

Create a new Cal object from simple string name. :param name: The 3-digit name of the calendar to load. Must be pre-defined in the Rust core code. :type name: str

Return type:

Cal

is_bus_day(date)#

Return whether the date is a business day.

Parameters:

date (datetime) – Date to test

Return type:

bool

is_non_bus_day(date)#

Return whether the date is not a business day.

Parameters:

date (datetime) – Date to test

Return type:

bool

is_settlement(date)#

Return whether the date is a business day of an associated settlement calendar.

Note

Cal objects will always return True, since they do not contain any associated settlement calendars. This method is provided only for API consistency.

Parameters:

date (datetime) – Date to test

Return type:

bool

lag_bus_days(date, days, settlement)#

Adjust a date by a number of business days, under lag rules.

Parameters:
  • date (datetime) – The date to adjust.

  • days (int) – Number of business days to add.

  • settlement (bool) – Whether to enforce settlement against an associated settlement calendar.

Return type:

datetime

Notes

lag_bus_days and add_bus_days will return the same value if the input date is a business date. If not a business date, add_bus_days will raise, while lag_bus_days will follow lag rules. lag_bus_days should be used when the input date cannot be guaranteed to be a business date.

Lag rules define the addition of business days to a date that is a non-business date:

  • Adding zero days will roll the date forwards to the next available business day.

  • Adding one day will roll the date forwards to the next available business day.

  • Subtracting one day will roll the date backwards to the previous available business day.

Adding (or subtracting) further business days adopts the add_bus_days() approach with a valid result.

roll(date, modifier, settlement)#

Roll a date under a simplified adjustment rule.

Parameters:
  • date (datetime) – The date to adjust.

  • modifier (str in {"F", "P", "MF", "MP", "Act"}) – The simplified date adjustment rule to apply

  • settlement (bool) – Whether to adhere to an additional settlement calendar.

Return type:

datetime

to_json()#

Return a JSON representation of the object.

Return type:

str