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. \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.

 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 #========================================================## 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 graphsrm(list = ls()) # remove all files from your workspace library(derivmkts) # price, yield, duration, convexity #——————————————————-# Input#——————————————————-C   <– 0.05       # coupon ratey   <– 0.03       # YTMm   <– 5          # maturityfreq   <– 1       # payment frequencyPA  <– 1          # principal amountcpn <– 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”))    Colored by Color Scripter 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.

 123456789101112131415161718 > > # initial price(P0), duration and convexity> P0        = 1.09159414374389Duration  = 4.43501016442331Convexity = 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% Colored by Color Scripter 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. $$\blacksquare$$