Calendar-Related Functions
About 3 min
Calendar-Related Functions
Visit the Mathema Option Pricing System for foreign exchange options and structured product valuation!
Constructor Functions
Excel: =McpCalendar(code, dates)
Python: McpCalendar(*args)
- Function: Constructs a holiday object.
- Parameters:
code
: Currency code (currently supports single currency only, not currency pairs).dates
: Holiday data for the currency.*args
: It is a dictionary with key/value pairs, similar to the parameters in Excel.
- Returns: A holiday object for subsequent calculations.
Excel: =McpNCalendar(ccys, holidays)
- Function: Constructs a Calendar using currency and holiday data.
- Parameters:
ccys
: One or more currency codes.holidays
: Corresponding holiday data.
- Returns: A holiday object for subsequent calculations.
Excel: =McpFCalendar(ccys, path=None)
- Function: Constructs a Calendar using currency and a holiday file.
- Parameters:
ccys
: One or more currency codes.path
: Path to the holiday file (default iscontrol/Holidays.txt
).
- Returns: A holiday object for subsequent calculations.
Usage Functions
Excel: =CalendarAddBusinessDays(cal, date, count, calendarCodes="")
Python: AddBusinessDays(*args)
- Function: Adds a specified number of business days to a given date.
- Parameters:
cal
: Holiday object.date
: Start date.count
: Number of business days to add.calendarCodes
: Specifies the currency or currency pair holidays to use (default is empty, using the entirecal
).*args
:is a dictionary, does not require the cal parameter, other parameters are the same as those in Excel.
- Returns: Adjusted date.
- Example:Returns
=CalendarAddBusinessDays(McpCalendar("USD", "USD", "2023-01-01,2023-12-25"), "2023-01-01", 5)
2023-01-09
(assuming 2023-01-01 and 2023-01-07 are holidays).
Excel: =CalendarAddPeriod(cal, date, tenor, dateAdjustRule=DateAdjusterRule.Actual, endOfMonthRule=False, lastOpenDay=False, calendarCodes='')
Python: AddPeriod(*args)
- Function: Adds a tenor (period) to a given date.
- Parameters:
cal
: Holiday object.date
: Start date.tenor
: Period (e.g.,1M
,3M
, etc.).dateAdjustRule
: Date adjustment rule (default isActual
).endOfMonthRule
: Whether to enable the end-of-month rule (default isFalse
).lastOpenDay
: Whether to consider the last open trading day (default isFalse
).calendarCodes
: Specifies the currency or currency pair holidays to use (default is empty, using the entirecal
).*args
:is a dictionary, does not require the cal parameter, other parameters are the same as those in Excel.
- Returns: Adjusted date.
- Example:Returns
=CalendarAddPeriod(McpCalendar("USD", "USD", "2023-01-01,2023-12-25"), "2023-01-01", "1M")
2023-02-01
(assuming 2023-01-01 is a holiday).
Excel: =CalendarValueDate(cal, date, isFollowing=True, calendarCodes='')
Python: ValueDate(*args)
- Function: Calculates the value date based on a given date.
- Parameters:
cal
: Holiday object.date
: Start date.isFollowing
: Whether to adjust using theFollowing
rule (default isTrue
).calendarCodes
: Specifies the currency or currency pair holidays to use (default is empty, using the entirecal
).*args
:is a dictionary, does not require the cal parameter, other parameters are the same as those in Excel.
- Returns: Adjusted value date.
- Example:Returns
=CalendarValueDate(McpCalendar("USD", "USD", "2023-01-01,2023-12-25"), "2023-01-01")
2023-01-03
(assuming 2023-01-01 is a holiday).
Excel: =CalendarAdjust(cal, date, rule, calendarCodes="")
Python: Adjust(*args)
- Function: Adjusts a date based on a specified rule.
- Parameters:
cal
: Holiday object.date
: Start date.rule
: Adjustment rule (enumeration value).calendarCodes
: Specifies the currency or currency pair holidays to use (default is empty, using the entirecal
).*args
:is a dictionary, does not require the cal parameter, other parameters are the same as those in Excel.
- Returns: Adjusted date.
Excel: =CalendarFXOExpiryDate(cal, date, calendarCodes='')
Python: FXOExpiryDate(*args)
- Function: Calculates the expiry date based on the delivery date.
- Parameters:
cal
: Holiday object.date
: Delivery date.calendarCodes
: Specifies the currency or currency pair holidays to use (default is empty, using the entirecal
).*args
:is a dictionary, does not require the cal parameter, other parameters are the same as those in Excel.
- Returns: Expiry date.
Excel: =CalendarFXODeliveryDateFromTenor(cal, referenceDate, tenor, spotDate, calendarCodes='')
Python: FXODeliveryDateFromTenor(*args)
- Function: Calculates the delivery date based on a tenor.
- Parameters:
cal
: Holiday object.referenceDate
: Trade date or valuation date.tenor
: Period.spotDate
: Value date.calendarCodes
: Specifies the currency or currency pair holidays to use (default is empty, using the entirecal
).*args
:is a dictionary, does not require the cal parameter, other parameters are the same as those in Excel.
- Returns: Delivery date.
Excel: =CalendarFXOExpiryDateFromTenor(cal, referenceDate, tenor, spotDate, calendarCodes='')
Python: FXOExpiryDateFromTenor(*args)
- Function: Calculates the expiry date based on a tenor.
- Parameters:
cal
: Holiday object.referenceDate
: Trade date or valuation date.tenor
: Period.spotDate
: Value date.calendarCodes
: Specifies the currency or currency pair holidays to use (default is empty, using the entirecal
).*args
:is a dictionary, does not require the cal parameter, other parameters are the same as those in Excel.
- Returns: Expiry date.
Excel: =CalendarIsBusinessDay(cal, date, calendarCodes='')
Python: IsBusinessDay(date, calendarCodes)
- Function: Checks if a given date is a business day.
- Parameters:
cal
: Holiday object.date
: Date to check.calendarCodes
: Specifies the currency or currency pair holidays to use (default is empty, using the entirecal
).
- Returns:
True
if it is a business day, otherwiseFalse
. - Example:Returns
=CalendarIsBusinessDay(McpCalendar("USD", "USD", "2023-01-01,2023-12-25"), "2023-01-01")
False
(assuming 2023-01-01 is a holiday).
Excel: =CalendarValueDateTenor(cal, date, tenor, calendarCodes="", isFarLeg=True)
- Function: Calculates the near or far value date based on a trade date or valuation date and a tenor.
- Parameters:
cal
: Holiday object.date
: Start date.tenor
: Period.calendarCodes
: Specifies the currency or currency pair holidays to use (default is empty, using the entirecal
).isFarLeg
: Whether to calculate the far value date (default isTrue
; ifFalse
, calculates the near value date).
- Returns: Near or far value date.
DayCounter-Related Functions
Excel: =McpDayCounter(dayCounter)
- Function: Constructs a DayCounter object.
- Parameters:
dayCounter
: Day count convention (enumeration value).
- Returns: A DayCounter object for subsequent calculations.
Excel: =DayCounterYearFraction(dayCounter, startDate, endDate)
- Function: Calculates the year fraction between two dates.
- Parameters:
dayCounter
: Day count convention (enumeration value).startDate
: Start date.endDate
: End date.
- Returns: Year fraction.
- Example:Returns
=DayCounterYearFraction(McpDayCounter("Actual/360"), "2023-01-01", "2023-12-31")
1.0
(assuming theActual/360
convention is used).