I have forgotten

• https://me.yahoo.com
COST (GBP)
1.87
5.88
0

# year Fraction

viewed 2905 times and licensed 56 times
Computes the fraction of the year between two serial dates, Excel: YEARFRAC
Controller: CodeCogs

C++
HTML

## YearFraction

 doubleyearFraction( int startDate int endDate YearBasis basis = yb_USA )
Returns a number between 0 and 1 (normally), which represents the fraction of the year between two serial Julian dates:

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 1

#include <stdio.h>

#include <codecogs/units/date/date.h>
#include <codecogs/units/date/isleapyear.h>
#include <codecogs/finance/banking/yearfraction.h>

using namespace Units::Date;
using namespace 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",
}
return 0;
}
Output:
StartDate    EndDate   Basis: 0 (USA)  1        2        3       4 (European)
25-12-2003  25-12-2003       0.000    0.000    0.000    0.000   0.000
25-12-2003  14- 1-2004       0.053    0.055    0.056    0.055   0.053
25-12-2003   3- 2-2004       0.106    0.110    0.111    0.110   0.106
25-12-2003  23- 2-2004       0.161    0.164    0.167    0.164   0.161
25-12-2003  14- 3-2004       0.219    0.219    0.222    0.219   0.219
25-12-2003   3- 4-2004       0.272    0.273    0.278    0.274   0.272
25-12-2003  23- 4-2004       0.328    0.328    0.333    0.329   0.328
25-12-2003  13- 5-2004       0.383    0.383    0.389    0.384   0.383
25-12-2003   2- 6-2004       0.436    0.437    0.444    0.438   0.436
25-12-2003  22- 6-2004       0.492    0.492    0.500    0.493   0.492

<div align="center"> <table border="0"> <tr align="center"><td width="100"> <strong>Type</strong></td><td><strong>Value</strong></td><td><strong>Description</strong></td></tr> <tr><td align="center" valign="top"><em>yb_US</em></td><td valign="top">0</td><td>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.</td></tr> <tr><td align="center" valign="top"><em>yb_Act</em></td><td valign="top">1</td><td>Uses the exact number of elapsed days between the two dates, as well as the exact length of the year.</td></tr> <tr><td align="center" valign="top"><em>yb_Act360</em></td><td valign="top">2</td><td>Uses the exact number of elapsed days between two dates but assumes the year only have 360 days</td></tr> <tr><td align="center" valign="top"><em>yb_Act365</em></td><td valign="top">3</td><td>Uses the exact number of elapsed days between two dates but assumes the year always has 365 days</td></tr> <tr><td align="center" valign="top"><em>yb_EU</em></td><td valign="top">4</td><td>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.</td></tr> </table> </div>

### Parameters

 startDate and... endDate 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:
##### Source Code

Source code is available when you agree to a GP Licence or buy a Commercial Licence.

Not a member, then Register with CodeCogs. Already a Member, then Login.