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.
Best Answer