Sep 15, 2021

Percent Change of Bond Price using Duration and Convexity in R

A percentage (%) change in a bond price with respect to a change in interest rate is approximated by using duration and convexity, which is based on the Talor approximation with the first and second order terms.




We have calculated a bond duration and convexity in the previous posts



Taylor Approximation


When a function \(f(x)\) is given, at some point, the first order or linear approximation is as follows. \[\begin{align} f(x) \approx f(a) + f^{'}(a)(x-a) \end{align}\] To get more precise function value, we use the second order or quadratic approximation with the previous first order one, which is a well-known result. \[\begin{align} f(x) \approx f(a) + f^{'}(a)(x-a) + \frac{1}{2} f^{''}(a) (x-a)^2 \end{align}\] When we set \(x = a + \Delta a\), the following approximation is obtained. \[\begin{align} f(a + \Delta a) \approx f(a) + f^{'}(a)\Delta a + \frac{1}{2} f^{''}(a) (\Delta a)^2 \end{align}\]

% change in bond price


Bond price with unit notional amount, coupon C, YTM y, annual frequency is as follows. \[\begin{align} P = P(y) = \sum_{t=1}^{T} \frac{CF_t}{(1+y)^t} \end{align}\] Expanding the price of the bond in a Taylor series around \(y\) results in \[\begin{align} P(y + \Delta y) \approx P(y) + \frac{\partial P}{\partial y}\Delta y + \frac{1}{2} \frac{d^2P}{d y^2} (\Delta y)^2 \\ \end{align}\] Dividing both sides by \(P(y)\) gives \[\begin{align} P(y + \Delta y)\frac{1}{P(y)} &\approx P(y)\frac{1}{P(y)} + \frac{\partial P}{\partial y}\Delta y \frac{1}{P(y)} \\ &+ \frac{1}{2} \frac{d^2P}{d y^2} (\Delta y)^2 \frac{1}{P(y)} \end{align}\] Moving \(P(y)\frac{1}{P(y)}\) from the right hand side to the left one, \[\begin{align} \frac{P(y + \Delta y) - P(y)}{P(y)} \approx \frac{\partial P}{\partial y}\Delta y \frac{1}{P(y)} + \frac{1}{2} \frac{d^2P}{d y^2} (\Delta y)^2 \frac{1}{P(y)} \end{align}\] Using the definitions of duration and convexity, we get \[\begin{align} \frac{\Delta P}{P} \approx -D \Delta y + \frac{1}{2} C (\Delta y)^2 \\ \\ D = -\frac{d P}{d y}\frac{1}{P}, \quad C = \frac{d^2P}{d y^2} \frac{1}{P} \end{align}\]
Finally, the % change in a bond price w.r.t a small interest rate change using duration and convexity (without higher order terms) is as follows.
\[\begin{align} \frac{\Delta P}{P} = -D \Delta y + \frac{1}{2} C (\Delta y)^2 \end{align}\]

R code


The following R code calculates the % change of a bond price w.r.t a interest rate change by using three methods : 1) full pricing, 2) approximation with duration, 3) approximation with duration and convexity.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#========================================================#
# Quantitative ALM, Financial Econometrics & Derivatives 
# ML/DL using R, Python, Tensorflow by Sang-Heon Lee 
#
# https://kiandlee.blogspot.com
#--------------------------------------------------------#
# Bond Modified Duration Calculation
#========================================================#
 
graphics.off()  # clear all graphs
rm(list = ls()) # remove all files from your workspace
 
library(derivmkts) # price, yield, duration, convexity
 
#-------------------------------------------------------
# Input
#-------------------------------------------------------
C   <- 0.05       # coupon rate
y   <- 0.03       # YTM
m   <- 5          # maturity
freq   <- 1       # payment frequency
PA  <- 1          # principal amount
cpn <- C*PA       # annual coupon amount
 
 
# P0 : initial price(P0), 
# D and C : duration and convexity
 
    P0 <- bondpv(cpn, m, y, PA, freq)
    D  <- duration(P0, cpn, m, PA, freq, modified = TRUE)
    C  <- convexity(P0, cpn, m, PA, freq)
    
    cat(paste0(
        "P0        = ", P0, "\n"
        "Duration  = ", D,  "\n",
        "Convexity = ", C,  "\n"))
 
# % price change using
# 1) full calculation 
# 2) approximation with D 
# 3) approximation with D and C
    
    Pd <- bondpv(cpn, m, y+0.0001, PA, freq)
    per_ch_P_full   <- (Pd - P0)/P0 
    per_ch_P_app_D  <- -D*0.0001
    per_ch_P_app_DC <- -D*0.0001 + 0.5*C*(0.0001)^2
    
    cat(paste0(
        "% bond price change \n"
        "full                        = "
        round(per_ch_P_full*100,8), "%\n"
        "with duration               = "
        round(per_ch_P_app_D*100,8), "%\n",
        "with duration and convexity = "
        round(per_ch_P_app_DC*100,8), "%\n"))
    
cs


From the folloiwng output which is the results of the above R code, we can find that the first and third rounded % change in bond prices to the nearest eighth have the same value while the second result has a little difference with full valuation. This means that when a convexity is considered, we can make this approximation more precise.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
> 
> # initial price(P0), duration and convexity
> 
P0        = 1.09159414374389
Duration  = 4.43501016442331
Convexity = 25.0326484167849
> 
> 
> # % bond price change using
> # 1) full calculation 
> # 2) approximation with D 
> # 3) approximation with D and C
>     
% bond price change 
full                        = -0.04433759%
with duration               = -0.0443501%
with duration and convexity = -0.04433759%
 
cs


Concluding Remarks


From this post, using derivmkt R package, we can easily calculate a percent(%) change of a bond price with duration and convexity. Using this approximation, A % change in a bond portfolio is also calculated by using the same approximation with the present value weighted durations and convexities. \(\blacksquare\)


No comments:

Post a Comment