#=========================================================================# # Financial Econometrics & Derivatives, ML/DL using R, Python, Tensorflow # by Sang-Heon Lee # # https://kiandlee.blogspot.com #————————————————————————-# # Generate Libor 3M IRS zero curve by using Bootstrapping #=========================================================================# graphics.off() # clear all graphs rm(list = ls()) # remove all files from your workspace #————————————————————————– # Functions – Definition – Start #————————————————————————– # IRS swap pricer f_zero_pricer_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, # spot date no_amt) { # nominal principal amount #———————————————————- # 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 dataframe 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) … Read more