I am translating a code from MATLAB to Python and I need to find equivalent setting to MATLAB’s day-count basis of 0 = actual / actual. My MATLAB code uses date2time
function to determine the length of period (measured in years) between two dates, with the default setting for the Basis parameter set to “0”.
MATLAB documentation for the day-count bases is here (and I’m using default first option ‘actual/actual’):
https://uk.mathworks.com/help/fininst/day-count-basis.html
The most appropriate Python library I could find for this sort of task is ‘QuantLib’, which has several day-count basis options as described here:
https://quantlib-python-docs.readthedocs.io/en/latest/dates.html#daycounter
However, having tried all the ql.ActualActual
options (ISMA, Bond, ISDA, … ) it seems none of them replicates the result of the default MATLAB actual/actual basis precisely.
Does anyone know how to get an identical result? I could obviously dive deep into the MATLAB function implementation and write it in python from scratch, but I would have hoped that there is already an existing solution out there.
As a reproducible example, Matlab gives a period length of 30.0302 years between 20-Mar-2006 and 31-Mar-2031 as follows:
period = date2time(datetime(2006,3,20), datetime(2036,3,31), 1, 0)
period = 30.0302
I’m trying to find a function in python that would replicate the 30.0302 figure. However, I’m seeing the following:
import QuantLib as ql
dateS = ql.Date(20,3,2006)
dateE = ql.Date(31,3,2036)
ql.ActualActual(ql.ActualActual.ISDA).yearFraction(dateS, dateE) = 30.032203009207276
ql.ActualActual(ql.ActualActual.Bond).yearFraction(dateS, dateE) = 30.083333333333332
ql.ActualActual(ql.ActualActual.AFB).yearFraction(dateS, dateE) = 30.03013698630137
Martin Kabelka is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.