Delta Sensitivity of Interest Rate Swap
[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.
This post explains how to calculate delta sensitivities or delta vector of interest rate swap, especially delta. delta can be calculated by either 1) zero delta or 2) market delta. To the best of our knowledge, FRTB can use these two methods but SIMM use the market Greeks. We implement R code for two approaches Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
Delta Sensitivity of LIBOR Interest Rate Swap
For detailed information about the Libor IRS swap pricing and zero curve bootstrapping, refer to the following posts.
In previous posts, we have priced a 5Y Libor IRS swap and generated a zero curve from market swap rates by using bootstrapping. Based on these works, we calculate Greeks of IRS. Since IRS does not have any option characteristics, our focus is to calculate the delta sensitivity. And for convenience, swap value is defined as (floating leg – fixed leg).
Delta Sensitivity
ISDA SIMM uses the following definitions of interest rate risk delta (\(x\) is a risk factor). There are, of course, several versions of it but they are all essentially the same.
\[\begin{align} \text{delta} &= V(x+0.5bp) – V(x-0.5bp) \\ \\ \text{delta} &= \frac{V(x+1bp) – V(x-1bp)}{2} \end{align}\]
For ease of notation, let \(z(t)\) and \(s(t)\) denote the (bootstrapped) zero rate and (market observed) swap rate at time t respectively.
There are two approaches for the calculation of delta: 1) zero delta, 2) market delta.
Zero Delta
Zero delta approach calculates delta sensitivities by bumping up or down zero rates one by one in order.
Once the zero curve (\(z(t)\)) is generated from market swap rates (\(s(t)\)), \[\begin{align} s(t) &= \{s(t_1), …, s(t_i), …, s(t_{ni})\} \\ z(t) &= Bootstrap(s(t)) \\ &= \{z(t_1), …, z(t_i), …, z(t_{ni})\} \end{align}\] Bumping up (\(z(t;t_i+0.5bp)\)) or down (\(z(t;t_i-0.5bp)\)), \(\text{delta}(t_i)\) is calculated and this process is applied for all \(t_i\). \[\begin{align} z(t;t_i+0.5bp) &= \{z(t_1), …, z(t_i)+0.5bp, …, z(t_{ni})\} \\ z(t;t_i-0.5bp) &= \{z(t_1), …, z(t_i)-0.5bp, …, z(t_{ni})\} \\ \text{delta}(t_i) &= V(z(t;t_i+0.5bp)) – V(z(t;t_i-0.5bp)) \end{align}\] Here, \(t_i\), \(i=1,2,…,n_i\) are maturities or dates of market swap rates at which the corresponding zero rates are bootstrapped.
Market Delta
Market delta approach calculates delta sensitivities by bumping up or down market swap rates one by one in order. Unlike the zero delta, every time we bump one market swap rate of a selected maturity, we should run a bootstrapping for finding new zero curve. Using this zero curve, we can calculate delta sensitivity at time \(t_i\) as follows. \[\begin{align} s(t;t_i+0.5bp) &= \{s(t_1), …, s(t_i)+0.5bp, …, s(t_{ni})\} \\ s(t;t_i-0.5bp) &= \{s(t_1), …, s(t_i)-0.5bp, …, s(t_{ni})\} \\ \\ z(t)^{up} &= Bootstrap(s(t;t_i+0.5bp)) \\ &= \{z(t_1)^{up}, …, z(t_i)^{up}, …, z(t_{ni})^{up}\} \\ z(t)^{down} &= Bootstrap(s(t;t_i-0.5bp)) \\ &= \{z(t_1)^{down}, …, z(t_i)^{down}, …, z(t_{ni})^{down}\} \\ \\ \text{delta}(t_i) &= V(z(t)^{up}) – V(z(t)^{down}) \end{align}\]
R code
The following R code calculates delta sensitivities of IRS using these two approaches.
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 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 | #=========================================================================# # Financial Econometrics & Derivatives, ML/DL using R, Python, Tensorflow # by Sang-Heon Lee # # https://kiandlee.blogspot.com #————————————————————————-# # Calculate Delta Sensitivities of Libor IRS #=========================================================================# graphics.off() # clear all graphs rm(list = ls()) # remove all files from your workspace #========================================================================= # Functions – Definition #========================================================================= #————————————————————– # Calculation of IRS swap price #————————————————————– f_zero_prr_IRS <– function( fixed_rate, # fixed rate vd.fixed_date, vd.float_date, # date for two legs vd.zero_date, v.zero_rate, # zero curve (dates, rates) d.spot_date, no_amt, # spot date, nominal amt save_cf_yn) { # “y” : CF save #———————————————————- # 0) Preprocessing #———————————————————- # convert spot date from date(d) to numeric(n) n.spot_date <– as.numeric(d.spot_date) # Interpolation of zero curve vn.zero_date <– as.numeric(vd.zero_date) f_linear <– approxfun(vn.zero_date, v.zero_rate, method=“linear”) vn.zero_date.inter <– n.spot_date:max(vn.zero_date) v.zero_rate.inter <– f_linear(vn.zero_date) # number of CFs ni <– length(vd.fixed_date) nj <– length(vd.float_date) # output data.frame with CF dates and its interpolated zero df.fixed = data.frame(d.date = vd.fixed_date, n.date = as.numeric(vd.fixed_date)) df.float = data.frame(d.date = vd.float_date, n.date = as.numeric(vd.float_date)) #———————————————————- # 1) Fixed Leg #———————————————————- # zero rate for discounting df.fixed$zero_DC = f_linear(as.numeric(df.fixed$d.date)) # discount factor df.fixed$DF <– exp(–df.fixed$zero_DC* (df.fixed$n.date–n.spot_date)/365) # tau, CF for(i in 1:ni) { ymd <– df.fixed$d.date[i] ymd_prev <– df.fixed$d.date[i–1] if(i==1) ymd_prev <– d.spot_date d <– as.numeric(strftime(ymd, format = “%d”)) m <– as.numeric(strftime(ymd, format = “%m”)) y <– as.numeric(strftime(ymd, format = “%Y”)) d_prev <– as.numeric(strftime(ymd_prev, format = “%d”)) m_prev <– as.numeric(strftime(ymd_prev, format = “%m”)) y_prev <– as.numeric(strftime(ymd_prev, format = “%Y”)) # 30I/360 tau <– (360*(y–y_prev) + 30*(m–m_prev) + (d–d_prev))/360 # cash flow rate df.fixed$rate[i] <– fixed_rate # Cash flow at time ti df.fixed$CF[i] <– fixed_rate*tau*no_amt # day fraction } # Present value of CF df.fixed$PV = df.fixed$CF*df.fixed$DF #———————————————————- # 2) Floating Leg #———————————————————- # zero rate for discounting df.float$zero_DC = f_linear(as.numeric(df.float$d.date)) # discount factor df.float$DF <– exp(–df.float$zero_DC* (df.float$n.date–n.spot_date)/365) # tau, forward rate, CF for(i in 1:nj) { date <– df.float$n.date[i] date_prev <– df.float$n.date[i–1] DF <– df.float$DF[i] DF_prev <– df.float$DF[i–1] if(i==1) { date_prev <– n.spot_date DF_prev <– 1 } # ACT/360 tau <– (date – date_prev)/360 # forward rate fwd_rate <– (1/tau)*(DF_prev/DF–1) # cash flow rate df.float$rate[i] <– fwd_rate # Cash flow amount at time ti df.float$CF[i] <– fwd_rate*tau*no_amt # day fraction } # Present value of CF df.float$PV = df.float$CF*df.float$DF # check for cash flows if (save_cf_yn == “y”) { # print(df.float); print(df.fixed) write.csv(df.float, “CF_float.csv”) write.csv(df.fixed, “CF_fixed.csv”) } return(sum(df.float$PV) – sum(df.fixed$PV)) } #————————————————————– # IRS swap zero curve generator #————————————————————– f_zero_maker_IRS <– function( df.mt, # market information data.frame # [d.date, swap_rate, source]] v.unknown_swap_maty_all, # all unknown swap maturity vd.fixed_date, # date for fixed leg vd.float_date, # date for float leg d.spot_date, # spot date no_amt) { # nominal principal amount # convert spot date from date(d) to numeric(n) n.spot_date <– as.numeric(d.spot_date) # for bootstrapped zero curve df.zr <– data.frame( d.date = df.mt$d.date, n.date = as.numeric(df.mt$d.date), tau = as.numeric(df.mt$d.date) – n.spot_date, taui = as.numeric(df.mt$d.date) – n.spot_date, swap_rate = df.mt$swap_rate, zero_rate = rep(0,length(df.mt$d.date)), DF = rep(0,length(df.mt$d.date))) # tau(i) = t(i) – t(i-1) df.zr$taui[2:nrow(df.zr)] <– df.zr$n.date[2:nrow(df.zr)] – df.zr$n.date[1:(nrow(df.zr)–1)] # divide rows according to its source or instrument type rows_deposit <– which(df.mt$source==“deposit”) rows_futures <– which(df.mt$source==“futures”) rows_swap <– which(df.mt$source==“swap”) #————————————————————– # 3. Bootstrapping – Deposit #————————————————————– for(i in rows_deposit) { # 1) calculate discount factor for deposit df.zr$DF[i] <– 1/(1+df.zr$swap_rate[i]*df.zr$tau[i]/360) # 2) convert DF to spot rate df.zr$zero_rate[i] <– 365/df.zr$tau[i]*log(1/df.zr$DF[i]) } #————————————————————– # 4. Bootstrapping – Futures #————————————————————– # No convexity adjustment is made for(i in rows_futures) { # 1) discount factor from t(i-1) to t(i) df.zr$DF[i] <– 1/(1+df.zr$swap_rate[i]*df.zr$taui[i]/360) # 2) discount factor from spot date to t(i) df.zr$DF[i] <– df.zr$DF[i–1]*df.zr$DF[i] # 3) zero rate from discount factor df.zr$zero_rate[i] <– 365/df.zr$tau[i]*log(1/df.zr$DF[i]) } #————————————————————– # 5. Bootstrapping – Swaps #————————————————————– k <– 1 for(i in rows_swap) { # unknown swap maturity in year swap_maty <– v.unknown_swap_maty_all[k] # 1) find one unknown zero rate for one swap maturity m<–optim(0.01, objf, control = list(abstol=10^(–20), reltol=10^(–20), maxit=50000, trace=2), method = c(“Brent”), lower = 0, upper = 0.1, # for Brent v.unknown_swap_maty = swap_maty, # unknown zero maturity v.swap_rate = df.zr$swap_rate[i], # observed swap rate vd.fixed_date = vd.fixed_date, # date for fixed leg vd.float_date = vd.float_date, # date for float leg vd.zero_date_all = df.zr$d.date[1:i], # all dates for zero curve v.zero_rate_known = df.zr$zero_rate[1:(i–1)], # known zero rates d.spot_date = d.spot_date, no_amt = no_amt) # 2) update this zero curve with the newly found zero rate df.zr$zero_rate[i] <– m$par # 3) convert this new zero rate to discount factor df.zr$DF[i] <– exp(–df.zr$zero_rate[i]*df.zr$tau[i]/365) k <– k + 1 } return(df.zr) } #————————————————————– # objective function to be minimized #————————————————————– objf <– function( v.unknown_swap_zero_rate, # unknown zero curve (rates) v.unknown_swap_maty, # unknown swap maturity v.swap_rate, # fixed rate vd.fixed_date, # date for fixed leg vd.float_date, # date for float leg vd.zero_date_all, # all dates for zero curve v.zero_rate_known, # known zero curve (rates) d.spot_date, # spot date no_amt) { # nominal principal amount # zero curve augmented with zero rates for swaps v.zero_rate_all <– c(v.zero_rate_known, v.unknown_swap_zero_rate) v.swap_pr <– NULL # vector of swap prices k <– 1 for(i in v.unknown_swap_maty) { # calculate IRS swap price swap_pr <– f_zero_prr_IRS( v.swap_rate[k], # fixed rate, vd.fixed_date[1🙁2*i)], # semi-annual date vd.float_date[1🙁4*i)], # quarterly date vd.zero_date_all, # zero curve (dates) v.zero_rate_all, # zero curve (rates) d.spot_date, no_amt, “n”) # concatenate swap prices v.swap_pr <– c(v.swap_pr, swap_pr) k <– k + 1 } return(sum(v.swap_pr^2)) } #========================================================================= # Main #========================================================================= #————————————————————– # 1. Market Information #————————————————————– # Zero curve from Bloomberg as of 2021-06-30 until 5-year maturity df.mt <– data.frame( d.date = as.Date(c(“2021-10-04”,“2021-12-15”, “2022-03-16”,“2022-06-15”, “2022-09-21”,“2022-12-21”, “2023-03-15”,“2023-07-03”, “2024-07-02”,“2025-07-02”, “2026-07-02”)), # we use swap rate not zero rate. swap_rate= c(0.00145750000000000, 0.00139609870272047, 0.00203838571440434, 0.00197747863867587, 0.00266249271921742, 0.00359490949297661, 0.00512603194652204, 0.00328354999423027, 0.00571049988269806, 0.00793000012636185, 0.00964949995279312 ), source = c(“deposit”, rep(“futures”,6), rep(“swap”, 4)) ) #————————————————————– # 2. Libor Swap Specification #————————————————————– d.spot_date <– as.Date(“2021-07-02”) # spot date (date type) n.spot_date <– as.numeric(d.spot_date) # spot date (numeric type) no_amt <– 10000000 # notional principal amount # swap cash flow schedule from Bloomberg lt.cf_date <– list( fixed = as.Date(c(“2022-01-04”,“2022-07-05”, “2023-01-03”,“2023-07-03”, “2024-01-02”,“2024-07-02”, “2025-01-02”,“2025-07-02”, “2026-01-02”,“2026-07-02”)), float = as.Date(c(“2021-10-04”,“2022-01-04”, “2022-04-04”,“2022-07-05”, “2022-10-03”,“2023-01-03”, “2023-04-03”,“2023-07-03”, “2023-10-02”,“2024-01-02”, “2024-04-02”,“2024-07-02”, “2024-10-02”,“2025-01-02”, “2025-04-02”,“2025-07-02”, “2025-10-02”,“2026-01-02”, “2026-04-02”,“2026-07-02”)) ) #————————————————————– # 3. 5-year swap price : base #————————————————————– i = 5 # 5-year swap # zero pricing df.zr <– f_zero_maker_IRS( df.mt, c(2,3,4,5), lt.cf_date$fixed, lt.cf_date$float, d.spot_date, no_amt) pr <– f_zero_prr_IRS( df.mt$swap_rate[i+6], lt.cf_date$fixed[1🙁2*i)], lt.cf_date$float[1🙁4*i)], df.zr$d.date, df.zr$zero_rate, d.spot_date,no_amt, save_cf_yn = “y”) print(paste0(i,“-year Swap price at spot date = “, pr)) df.zr_delta <– df.mt_delta <– df.zr[,–c(2,3,4)] df.zr_delta$pr <– df.mt_delta$pr <– pr #————————————————————– # 3. Bump and Reprice for Market Greeks #————————————————————– df.mt_delta$delta <– df.mt_delta$pr_up <– df.mt_delta$pr_dn <– NA # iteration for all market maturities for(r in 1:11) { #——————— # bump up (1bp up) #——————— df.mt_bump <– df.mt # initialization df.mt_bump$swap_rate[r] <– df.mt_bump$swap_rate[r] + 0.0001 # zero pricing df.zr <– f_zero_maker_IRS(df.mt_bump, c(2,3,4,5), lt.cf_date$fixed, lt.cf_date$float, d.spot_date, no_amt) pr <– f_zero_prr_IRS(df.mt$swap_rate[i+6], lt.cf_date$fixed[1🙁2*i)], lt.cf_date$float[1🙁4*i)], df.zr$d.date, df.zr$zero_rate, d.spot_date, no_amt, “n”) # save price with bumping up df.mt_delta$pr_up[r] <– pr # check whether swap prices at spot date is at par pr <– f_zero_prr_IRS(df.mt_bump$swap_rate[i+6], lt.cf_date$fixed[1🙁2*i)], lt.cf_date$float[1🙁4*i)], df.zr$d.date, df.zr$zero_rate, d.spot_date,no_amt, “n”) print(paste0(i,“-year Swap price at spot date = “, pr)) #——————— # bump down (1bp down) #——————— df.mt_bump <– df.mt # initialization df.mt_bump$swap_rate[r] <– df.mt_bump$swap_rate[r] – 0.0001 # zero pricing df.zr <– f_zero_maker_IRS(df.mt_bump, c(2,3,4,5), lt.cf_date$fixed, lt.cf_date$float, d.spot_date, no_amt) pr <– f_zero_prr_IRS(df.mt$swap_rate[i+6], lt.cf_date$fixed[1🙁2*i)], lt.cf_date$float[1🙁4*i)], df.zr$d.date, df.zr$zero_rate, d.spot_date,no_amt, “n”) # save price with bumping down df.mt_delta$pr_dn[r] <– pr # check whether swap prict at spot date is at par pr <– f_zero_prr_IRS(df.mt_bump$swap_rate[i+6], lt.cf_date$fixed[1🙁2*i)], lt.cf_date$float[1🙁4*i)], df.zr$d.date, df.zr$zero_rate, d.spot_date,no_amt, “n”) print(paste0(i,“-year Swap price at spot date = “, pr)) } # Market Greeks : Delta calculation df.mt_delta$delta <– (df.mt_delta$pr_up – df.mt_delta$pr_dn)/2 df.mt_delta x11(width = 5, height = 3.5) barplot(delta ~ substr(d.date,1,7), data = df.mt_delta, width = 0.5, col = “blue”) x11(width = 5, height = 3.5) barplot(delta ~ substr(d.date,1,7), data = df.mt_delta[1:10,], width = 0.5, col = “green”) #————————————————————– # 4. Bump and Reprice for Zero Greeks #————————————————————– df.zr_delta$delta <– df.zr_delta$pr_up <– df.zr_delta$pr_dn <– NA # zero pricing df.zr <– f_zero_maker_IRS(df.mt, c(2,3,4,5), lt.cf_date$fixed, lt.cf_date$float, d.spot_date, no_amt) for(r in 1:11) { #——————— # bump up (1bp up) #——————— df.zr_bump <– df.zr # initialization df.zr_bump$zero_rate[r] <– df.zr_bump$zero_rate[r] + 0.0001 # zero pricing pr <– f_zero_prr_IRS(df.mt$swap_rate[i+6], lt.cf_date$fixed[1🙁2*i)], lt.cf_date$float[1🙁4*i)], df.zr_bump$d.date, df.zr_bump$zero_rate, d.spot_date, no_amt, “n”) # save price with bumping up df.zr_delta$pr_up[r] <– pr #——————— # bump down (1bp down) #——————— df.zr_bump <– df.zr # initialization df.zr_bump$zero_rate[r] <– df.zr_bump$zero_rate[r] – 0.0001 # zero pricing pr <– f_zero_prr_IRS(df.mt$swap_rate[i+6], lt.cf_date$fixed[1🙁2*i)], lt.cf_date$float[1🙁4*i)], df.zr_bump$d.date, df.zr_bump$zero_rate, d.spot_date,no_amt, “n”) # save price with bumping down df.zr_delta$pr_dn[r] <– pr } # Market Greeks : Delta calculation df.zr_delta$delta <– (df.zr_delta$pr_up – df.zr_delta$pr_dn)/2 df.zr_delta x11(width = 5, height = 3.5) barplot(delta ~ substr(d.date,1,7), data = df.zr_delta, width = 0.5, col = “blue”) x11(width = 5, height = 3.5) barplot(delta ~ substr(d.date,1,7), data = df.zr_delta[1:10,], width = 0.5, col = “green”) | cs |
Results
Zero Delta
The following figure and table show zero delta vector along the maturities. A meaningful value of delta is only observed at maturity since delta at maturities less than IRS maturity (3-year) is so small(10~30). But this pattern is not absolute and is subject to the change of market environment because these days shows ultra lower interest rates.
Market Delta
The following figure and table show market delta vector along the maturities. Like zero delta, a meaningful value of delta is only observed at maturity since delta at maturities less than IRS maturity (3-year) is considered a zero. Like zero delta, this pattern is also not absolute and is subject to the change of market environment from the same reason.
Intuition behind IRS delta
In both case of zero and market delta of IRS, we can observe the peak of delta at the IRS maturity. Increase in the interest rate has two effects. Firstly a higher interest rate decreases a discount factor and increases variable cash flows. These two effects have a trade-off.
Secondly, forward rates, which determine future cash flows show the following up and down pattern (we use 25bp up for the clear visual inspection and illustration) because the next swap rate is determined at market value, of which maturity is beyond the bumping maturity. Therefore there are positive and negative effects on future cash flows at the bumping time and the next time.
But at maturity, there is only positive effect on future cashflows because the successive negative effect takes place beyond the maturity of this IRS.
To be more specific, let’s compare the Aqua and Yellow colored line, which represent the forward rate curve with 2-year and 3-year swap rate bumping up respectively. We can observe that as the 2-year swap rate is bumped up, a downward movement of 2-year forward rate at time 2.25-year is following the upward movement of it at time 2-year. But in case of 3-year bumping, there is only upward movement of forward rate at time 3-year.
Conclusion
From this post, we have calculated delta sensitivities of IRS. In this example, two methods do not show some significant differences. But this result is not general because market Greeks permit interactions between market variables but zero Greeks does not (or little).
For example, in case of a Libor 3×6 basis swap, when Libor3M swap rates are changed, Libor6M zero curve is also changed. But there is little or no interaction effect in the case of zero Greeks. Therefore, it is advised for you to investigate the full effect of Greeks calculation in many cases. \(\blacksquare\)
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.