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

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

 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509 #=========================================================================## 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 graphsrm(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 maturitydf.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 pricingdf.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 maturitiesfor(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 calculationdf.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 pricingdf.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 calculationdf.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”) Colored by Color Scripter 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$$