Returns a number between 0 and 1 (normally), which represents the fraction of the year between two serial Julian dates:
(1)
If there is more than 1 year between the dates, then this value will be greater than 1.
The European or USA 360-day accounting system (with 30 days months - see dateDiff360), applies the following transformation to the start and end dates.
Type
Description
dd_Europe
Start or end dates that occur on the 31st of a month become equal to the 30th of the same month.
dd_USA
This is identical to the European system with one exception that applies only to end dates: If the end date occurs on the 31st of a month it is moved to the 1st of the next month if the start date is earlier than the 30th. This method is sometime also called the 'NASD' method.
Example:
#include <stdio.h>#include <codecogs/units/date/date.h>#include <codecogs/units/date/isleapyear.h>#include <codecogs/finance/banking/yearfraction.h>usingnamespace Units::Date;
usingnamespace Finance::Banking;
int main(){printf("\n StartDate EndDate Basis: 0 (USA) 1 2 3 4 (European)");
int adate=date("25 Dec 2003");
for(int i=0;i<200;i+=20){int d,m,y;
dateYMD(adate, y, m, d);
printf("\n %2d-%2d-%d", d,m,y);
dateYMD(adate+i, y, m, d);
printf(" %2d-%2d-%d", d,m,y);
printf(" %5.3lf %5.3lf %5.3lf %5.3lf %5.3lf",
yearFraction(adate, adate+i, yb_USA), // USA
yearFraction(adate, adate+i, yb_Act), // Actual/Actual
yearFraction(adate, adate+i, yb_Act360), // Actual/360
yearFraction(adate, adate+i, yb_Act365), // Actual/365
yearFraction(adate, adate+i, yb_EU)); // European}return0;
}
are serial Julian dates (see date). Note the return value is not signed, so the two dates can be swapped.
basis
is the day counting system to use:
Type
Value
Description
yb_US
0
US (NASD) 30/360 - As with the European 30/360 (yb_EU, with the additional provision that if the end date occurs on the 31st of a month it is moved to the 1st of the next month if the start date is earlier than the 30th.
yb_Act
1
Uses the exact number of elapsed days between the two dates, as well as the exact length of the year.
yb_Act360
2
Uses the exact number of elapsed days between two dates but assumes the year only have 360 days
yb_Act365
3
Uses the exact number of elapsed days between two dates but assumes the year always has 365 days
yb_EU
4
European 30/360 - Each month is assumed to have 30 days, such that the year has only 360 days. Start and end dates that occur on the 31st of a month become equal to the 30th of the same month.