yearFraction¶
Evaluates the fraction of a year represented by the number of whole days between two dates.
Synopsis¶
yearFraction (start, end, basis)
Required Arguments¶
- date
start
(Input) - Initial date. For a more detailed discussion on dates see the Usage Notes section of this chapter.
- date
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
DAY_CNT_BASIS_ACTUALACTUAL
,DAY_CNT_BASIS_NASD
,DAY_CNT_BASIS_ACTUAL360
,DAY_CNT_BASIS_ACTUAL365
, orDAY_CNT_BASIS_30E360
. For a more detailed discussion onbasis
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 yearFraction
computes the fraction of the year.
It is computed using the following:
\[A / D\]
where A =the number of days from start
to end
, D =annual basis.
Example¶
In this example, yearFraction
computes the year fraction between August
1, 2000, and July 1, 2001, using the NASD day count method.
from __future__ import print_function
from numpy import *
from datetime import date
from pyimsl.math.yearFraction import yearFraction, DAY_CNT_BASIS_NASD
basis = DAY_CNT_BASIS_NASD
start_date = date(2000, 8, 1)
end_date = date(2001, 7, 1)
yearfrac = yearFraction(start_date, end_date, basis)
print("The year fraction of the 30/360 period is %f." % (yearfrac))
Output¶
The year fraction of the 30/360 period is 0.916667.