Cal#
- class rateslib.calendars.Cal(holidays, week_mask)#
A calendar object for making date roll adjustment calculations.
- Parameters:
holidays (list of datetime) – A list of dates that defines holidays.
week_mask – A list of days defined as non-working days of the week. Most common is [5, 6] for Sat and Sun.
Attributes
- Variables:
holidays – list of datetime
week_mask – list of int
See also
UnionCal: Calendar object designed to merge calendars under financial date rules.Methods Summary
add_bus_days(date, days, settlement)Return a business date separated by days from an input business date.
add_days(date, days, modifier, settlement)Return a date separated by calendar days from input date, and rolled with a modifier.
add_months(date, months, modifier, roll, ...)Return a date separated by months from an input date, and rolled with a modifier.
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.
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(date, days, settlement)Adjust a date by a number of business days, under lag rules.
roll(date, modifier, settlement)Adjust a non-business date to a business date under a specific modification rule.
to_json()Return a JSON representation of the object.
Attributes Documentation
- holidays#
- week_mask#
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
settlementis True.See also
lag(): Add business days to inputs which are potentially non-business dates.
- add_days(date, days, modifier, settlement)#
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.
modifier (Modifier) – The rule to use to roll resultant non-business days.
settlement (bool) – Enforce an associated settlement calendar, if True and if one exists.
- Return type:
datetime
- add_months(date, months, modifier, roll, settlement)#
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.
modifier (Modifier) – The rule to use to roll a resultant non-business day.
roll (RollDay) – The day of the month to adjust to.
settlement (bool) – Enforce an associated settlement calendar, if True and if one exists.
- 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]
- 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(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
lagandadd_bus_dayswill return the same value if the input date is a business date. If not a business date,add_bus_dayswill raise, whilelagwill follow lag rules.lagshould 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)#
Adjust a non-business date to a business date under a specific modification rule.
- Parameters:
date (datetime) – The date to adjust.
modifier (Modifier) – The modification rule
settlement (bool) – Whether to enforce settlement against an associated settlement calendar.
- Return type:
datetime
Notes
An input date which is already a settleable, business date will be returned unchanged.
- to_json()#
Return a JSON representation of the object.
- Return type:
str