duration: Duration, modified Duration and Duration based Weights

Description Usage Arguments Details Value Examples

Description

The function calculates the Macauly duration, modified duration and duration based weights.

Usage

1
duration(cf_p, m_p, y)

Arguments

cf_p

cashflows matrix including the current dirty prices of the bonds.

m_p

maturity matrix, the first row is filled with zeros.

y

yields of the bonds.

Details

The duration vector is calculated using the following formula:

\bm{d}= \frac{\bm{ι}'(\bm{C}\cdot\bm{M}\cdot\bm{D})}{\bm{ι}'(\bm{C}\cdot\bm{D})},

whereas \bm{C} is the cashflow matrix and \bm{M} is the maturity matrix. \bm{ι} is a column vector filled with ones. (\cdot) denotes a elementwise matrix mulitplication and " ' " the transpose of a vector (matrix).

The weight ω_j for one bond j is defined as

ω_j=\frac{\frac{1}{d_j}}{∑_{i=1}^m\frac{1}{d_i}},

where d_j is the duration of the j-th bond.

Value

The function returns a matrix with three columns, i.e,. duration, modified duration and duration based weights.

Examples

1
2
3
4
5
6
 
data(govbonds)
cf_p <- create_cashflows_matrix(govbonds[[1]],include_price=TRUE)
m_p <- create_maturities_matrix(govbonds[[1]],include_price=TRUE)
y <- bond_yields(cf_p,m_p)
duration(cf_p,m_p,y[,2])

changshun/termstrc documentation built on May 13, 2019, 3:24 p.m.