Percent Change of Bond Price using Duration and Convexity in R

[This article was first published on K & L Fintech Modeling, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

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. f(x)f(a)+f(a)(xa)
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. f(x)f(a)+f(a)(xa)+12f(a)(xa)2
When we set x=a+Δa, the following approximation is obtained. f(a+Δa)f(a)+f(a)Δa+12f(a)(Δa)2


% change in bond price


Bond price with unit notional amount, coupon C, YTM y, annual frequency is as follows. P=P(y)=Tt=1CFt(1+y)t
Expanding the price of the bond in a Taylor series around y results in P(y+Δy)P(y)+PyΔy+12d2Pdy2(Δy)2
Dividing both sides by P(y) gives P(y+Δy)1P(y)P(y)1P(y)+PyΔy1P(y)+12d2Pdy2(Δy)21P(y)
Moving P(y)1P(y) from the right hand side to the left one, P(y+Δy)P(y)P(y)PyΔy1P(y)+12d2Pdy2(Δy)21P(y)
Using the definitions of duration and convexity, we get ΔPPDΔy+12C(Δy)2D=dPdy1P,C=d2Pdy21P

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.
ΔPP=DΔy+12C(Δy)2

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 results have some 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 duration and convexity.

To leave a comment for the author, please follow the link and comment on their blog: K & L Fintech Modeling.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)