termstrc (version 1.3.7)

duration: Duration, modified Duration and Duration based Weights

Description

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

Usage

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.

Value

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

Details

The duration vector is calculated using the following formula:

$$\bm{d}= \frac{\bm{\iota}'(\bm{C}\cdot\bm{M}\cdot\bm{D})}{\bm{\iota}'(\bm{C}\cdot\bm{D})},$$ whereas $\bm{C}$ is the cashflow matrix and $\bm{M}$ is the maturity matrix. $\bm{\iota}$ is a column vector filled with ones. $(\cdot)$ denotes a elementwise matrix mulitplication and $" ' "$ the transpose of a vector (matrix).

The weight $\omega_j$ for one bond $j$ is defined as $$\omega_j=\frac{\frac{1}{d_j}}{\sum_{i=1}^m\frac{1}{d_i}},$$ where $d_j$ is the duration of the j-th bond.

Examples

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])