Replicating Matlab YEARFRAC function in excel or vice versa

I am wondering why the following code in matlab generate
yearfrac(datenum('31/05/2015','dd/mm/yyyy'),datenum('07/02/2025','dd/mm/yyyy')) = 9.672131147540984
yearfrac(datenum('31/05/2015','dd/mm/yyyy'),datenum('07/02/2025','dd/mm/yyyy'),12) = 9.690410958904067
However, in excel, using actual/actual, it gives a slightly different answer?
YEARFRAC(31/05/2015,07/02/2025,1) = 9.69138875062
Thanks

 Accepted Answer

It appears that Excel's YEARFRAC uses the following rule to compute the year fraction
(Number of days between day1 and day2)/(Average number of days per year between day1 and day2)
which is different from the standard day count conventions that MATLAB's YEARFRAC tries to follow:
In MATLAB, you can reproduce the results from Excel's YEARFRAC as follows:
>> d1 = datenum('31-May-2015');
>> d2 = datenum('7-Feb-2025');
>> daysact(d1,d2)/mean(yeardays(year(d1):year(d2)))
ans =
9.691388750622201
For more information about day count conventions, you could also refer to the following:
Krgin, Dragomir, Handbook of Global Fixed Income Calculations, John Wiley & Sons, 2002.
Mayle, Jan, "Standard Securities Calculations Methods: Fixed Income Securities Formulas for Analytic Measures", SIA, Vol 2, Jan 1994.
Stigum, Marcia, and Franklin Robinson, Money Market and Bond Calculations, McGraw-Hill, 1996.
Hope this helps.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!