year_fraction
Evaluates the fraction of a year represented by the number of whole days between two dates.
Synopsis
#include <imsl.h>
float imsl_f_year_fraction (struct tm start, struct tm end, int basis)
The type double function is imsl_d_year_fraction.
Required Arguments
struct tm start (Input)
Initial date. For a more detailed discussion on dates see the Usage Notes section of this chapter.
struct tm end (Input)
Ending date. For a more detailed discussion on dates see the Usage Notes section of this chapter.
int basis (Input)
The method for computing the number of days between two dates. It should be one of IMSL_DAY_CNT_BASIS_ACTUALACTUAL, IMSL_DAY_CNT_BASIS_NASD, IMSL_DAY_CNT_BASIS_ACTUAL360, IMSL_DAY_CNT_BASIS_ACTUAL365, or IMSL_DAY_CNT_BASIS_30E360. For a more detailed discussion on basis see the Usage Notes section of this chapter.
Return Value
The fraction of a year represented by the number of whole days between two dates. If no result can be computed, NaN is returned.
Description
Function imsl_f_year_fraction computes the fraction of the year.
It is computed using the following:
where A =the number of days from start to end, D =annual basis.
Example
In this example, imsl_f_year_fraction computes the year fraction between August 1, 2000, and July 1, 2001, using the NASD day count method.
#include <stdio.h>
#include <imsl.h>
int main()
{
struct tm start, end;
int basis = IMSL_DAY_CNT_BASIS_NASD;
float yearfrac;
start.tm_year = 100;
start.tm_mon = 7;
start.tm_mday = 1;
end.tm_year = 101;
end.tm_mon = 6;
end.tm_mday = 1;
yearfrac = imsl_f_year_fraction (start, end, basis);
printf ("The year fraction of the 30/360 period is %f.\n", yearfrac);
}
Output
The year fraction of the 30/360 period is 0.916667.