duration

Evaluates the annual duration of a security where the security has periodic interest payments.

Synopsis

duration (settlement, maturity, couponRate, yield, frequency, basis)

Required Arguments

date settlement (Input)
The date on which payment is made to settle a trade. For a more detailed discussion on dates see the Usage Notes section of this chapter.
date maturity (Input)
The date on which the bond comes due, and principal and accrued interest are paid. For a more detailed discussion on dates see the Usage Notes section of this chapter.
float couponRate (Input)
Annual interest rate set forth on the face of the security; the coupon rate.
float yield (Input)
Annual yield of the security.
Int frequency (Input)
Frequency of the interest payments. It should be one of ANNUAL, SEMIANNUAL or QUARTERLY. For a more detailed discussion on frequency 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, or DAY_CNT_BASIS_30E360. For a more detailed discussion see the Usage Notes section of this chapter.

Return Value

The annual duration of a security with periodic interest payments. If no result can be computed, NaN is returned.

Description

Function duration computes the Maccaluey’s duration of a security with periodic interest payments. The Maccaluey’s duration is the weighted-average time to the payments, where the weights are the present value of the payments.

It is computed using the following:

\[\frac { \frac {\frac{DSC}{E} * 100} {\left(1 + \frac{\textit{yield}}{\textit{freq}}\right)^{\left(N-1+\frac{DSC}{E}\right)}} + \sum_{k=1}^{N}\left(\left(\frac{100 * \textit{couponRate}}{\textit{freq} * \left(1 + \frac{\textit{yield}}{\textit{freq}}\right)^{\left(k - 1 + \frac{DSC}{E}\right)}}\right) * \left(k - 1 + \frac{DSC}{E}\right)\right) } { \frac{100}{\left(1 + \frac{\textit{yield}}{\textit{freq}}\right)^{N - 1 + \frac{DSC}{E}}} + \sum_{k=1}^{N}\left(\frac{100 * \textit{couponRate}}{\textit{freq} * \left(1 + \frac{\textit{yield}}{\textit{freq}}\right)^{k-1+\frac{DSC}{E}}}\right) } * \frac{1}{\textit{freq}}\]

In the equation above, DSC represents the number of days starting with the settlement date and ending with the next coupon date. E represents the number of days within the coupon period. N represents the number of coupons payable from the settlement date to the maturity date. freq represents the frequency of the coupon payments annually.

Example

In this example, duration computes the annual duration of a security with the settlement date of July 1, 1995, and maturity date of July 1, 2005, using the Actual/365 day count method.

from __future__ import print_function
from numpy import *
from datetime import date
from pyimsl.math.duration import duration, DAY_CNT_BASIS_ACTUAL365, SEMIANNUAL

coupon = .075
yield_amt = .09
frequency = SEMIANNUAL
basis = DAY_CNT_BASIS_ACTUAL365

settlement = date(1995, 7, 1)
maturity = date(2005, 7, 1)
duration_amt = duration(settlement, maturity, coupon,
                        yield_amt, frequency, basis)
print("The annual duration of the bond with")
print("semiannual interest payments is %.4f." % (duration_amt))

Output

The annual duration of the bond with
semiannual interest payments is 7.0420.