#========================================================# # Quantitative ALM, Financial Econometrics & Derivatives # ML/DL using R, Python, Tensorflow by Sang-Heon Lee # # https://kiandlee.blogspot.com #——————————————————–# # Adams and Deventer Maximum Smoothness Forward Curve # Robustness Check using a user-defined function #========================================================# graphics.off() # clear all graphs rm(list = ls()) # remove all files from your workspace # function for Maximum Smoothness Forward Curve func_msfc – function(df.mkt) { # maturity strings for figure v.str.mat – paste0(as.character(df.mkt$mat), “Y”) # number of maturity n – length(df.mkt$mat) # add 0-maturity zero rate (assumption) df – rbind(c(0, df.mkt$zrc[1]), df.mkt) #df – rbind(c(0, 0.04), df.mkt) # discount factor df$DF – with(df, exp(–zrc*mat)) # -ln(P(t(i)/t(i-1))) df$mln – c(NA,–log(df$DF[1:n+1]/df$DF[1:n])) # ti^n df$t5 – df$mat^5 df$t4 – df$mat^4 df$t3 – df$mat^3 df$t2 – df$mat^2 df$t1 – df$mat^1 df$t0 – 1 # dti = ti^n-(ti-1)^n df$dt5 – c(NA,df$t5[1:n+1] – df$t5[1:n]) df$dt4 – c(NA,df$t4[1:n+1] – df$t4[1:n]) df$dt3 – c(NA,df$t3[1:n+1] – df$t3[1:n]) df$dt2 – c(NA,df$t2[1:n+1] – df$t2[1:n]) df$dt1 – c(NA,df$t1[1:n+1] – df$t1[1:n]) #———————————————— # construction linear system #———————————————— mQ – mA – matrix(0, nrow = 5*n, ncol = 5*n) vC – vB – rep(0,5*n) # Objective function for(r in 1:n) { mQ[((r–1)*5+1):((r–1)*5+3),((r–1)*5+1):((r–1)*5+3)] – matrix(with(df[r+1,], … Read more