Description Usage Arguments Details Value Examples
The function calculates the Macauly duration, modified duration and duration based weights.
1 | duration(cf_p, m_p, y)
|
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. |
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.
The function returns a matrix with three columns, i.e,. duration, modified duration and duration based weights.
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])
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.