Why does the YEARFRAC function in the Financial Toolbox, produce different results between MATLAB version 6.5 (R13) and version 7.0 (R14)?

2 views (last 30 days)
The YEARFRAC function produces different results for 360 day year convention between MATLAB versions 6.5.x and 7.0.x for the same input values.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 27 Jun 2009
This is expected behavior. The discrepancy in the output of the YEARFRAC function between MATLAB 6.5.x and MATLAB 7.0.x is the result of a bug fix.
The YEARFRAC function determines the fraction of years between two dates. Assume the following dates as an example:
datedisp([Date1 Date2])
07-Jun-2005 01-Dec-2005
07-Jun-2005 01-Jun-2006
07-Jun-2005 01-Dec-2006
07-Jun-2005 01-Jun-2007
07-Jun-2005 01-Dec-2007
07-Jun-2005 01-Jun-2008
07-Jun-2005 01-Dec-2008
07-Jun-2005 01-Jun-2009
07-Jun-2005 01-Dec-2009
07-Jun-2005 01-Jun-2010
07-Jun-2005 01-Dec-2010
07-Jun-2005 01-Jun-2011
These dates occur at a regular interval of almost a 6 month cycle.
Logically, the fraction of years should increase consistently without any variation due to having 360 days in every year. On a perfect 6 month cycle, it should be 0.5 years, 1 year, 1.5 years, 2 years, etc. Since the example does not run on a perfect 6 month cycle, the fractions are slightly less than exact multiples of 0.5.
In MATLAB 6.5 (R13), the fractions between each set of dates are:
0.49166666666667
0.99722222222222
1.50555555555556
2.01111111111111
2.51944444444444
3.02777777777778
3.53611111111111
4.04166666666667
4.55000000000000
5.05555555555556
5.56388888888889
6.06944444444444
Note these fractions are fairly regular, but increase a tiny bit for each additional 6 month cycle. For large time spans the slight increase can become very dramatic.
The YEARFRAC function has been fixed for MATLAB 7.0.x (R14), producing the correct results:
0.49166666666667
0.99722222222222
1.49166666666667
1.99722222222222
2.49166666666667
3.00000000000000
3.49166666666667
3.99722222222222
4.49166666666667
4.99722222222222
5.49166666666667
5.99722222222222
Note the fraction is consistent from year to year. Also if you look at the big picture, from 07-Jun-2005 to 01-Jun-2011, is not exactly 6 years as MATLAB 6.5.x (R13) calculates. It is actually slightly less than 6 years, and this is what MATLAB 7.0.x (R14) reports.
To have the correct output in either version of MATLAB, I suggest using the YEARFRAC function associated with MATLAB 7.0.x. This produces the correct results for year fractions of the 360 days/year convention.

More Answers (0)

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!