################################################################ #### Example 1.1: Bootstrapping zero rates ################################################################ # Defining cash flow of the bonds T <- 241+3*365 bond.A <- 0*c(1:T) bond.A[190] <- 100 bond.B <- 0*c(1:T) bond.B[32] <- 5.5 bond.B[32+365] <- 5.5 bond.B[32+2*365] <- 105.5 bond.C <- 0*c(1:T) bond.C[241] <- 6.75 bond.C[241+365] <- 6.75 bond.C[241+2*365] <- 6.75 bond.C[241+3*365] <- 106.75 # Plotting the cash flow of the three bonds tvec <- c(1:T)/365 plot(tvec,bond.A,type="h", ylim=c(0,110), lty="solid", xlab="",ylab="") par(new = TRUE) plot(tvec,bond.B,type="h", lty="longdash",ylim=c(0,110), xlab="",ylab="") par(new = TRUE) plot(tvec,bond.C,type="h", lty="dotted",ylim=c(0,110), xlab="",ylab="") points(tvec[190],bond.A[190],pch=21) points(tvec[32],bond.B[32],pch=22) points(tvec[32+365],bond.B[32+365],pch=22) points(tvec[32+2*365],bond.B[32+2*365],pch=22) points(tvec[241],bond.C[241],pch=24) points(tvec[241+365],bond.C[241+365],pch=24) points(tvec[241+2*365],bond.C[241+2*365],pch=24) points(tvec[241+3*365],bond.C[241+3*365],pch=24) ### # Bootstrapping ### # Define the time vector (numbers in book are rounded) tvec<-c((24+8)/365,(24+31+30+31+31+28+15)/365,(24+31+30+31+31+28+31+30+5)/365,(24+8+365)/365,(24+31+30+31+31+28+31+30+5+365)/365,(24+8+365+365)/365,(24+31+30+31+31+28+31+30+5+365+365)/365,(24+31+30+31+31+28+31+30+5+365+365+365)/365) # Perform bootstrapping discvec<-tvec # Start with d2 discvec[2]<-99.65/100 # Find d1 by linear interpolation discvec[1]<-1+(discvec[2]-1)/(tvec[2]-0)*(tvec[1]-0) # Find d6 and using linear interpolation for d4 discvec[6]<-(113.43-5.5*discvec[1]-5.5*discvec[2]*(1-(tvec[4]-tvec[2])/(tvec[6]-tvec[2])))/(5.5*(tvec[4]-tvec[2])/(tvec[6]-tvec[2])+105.5) # Find d3,d4, and d5 by linear interpolation discvec[3]<-discvec[2]+(discvec[6]-discvec[2])/(tvec[6]-tvec[2])*(tvec[3]-tvec[2]) discvec[4]<-discvec[2]+(discvec[6]-discvec[2])/(tvec[6]-tvec[2])*(tvec[4]-tvec[2]) discvec[5]<-discvec[2]+(discvec[6]-discvec[2])/(tvec[6]-tvec[2])*(tvec[5]-tvec[2]) # Find d8 using linear interpolation for d7 discvec[8]<-(121.3-6.75*discvec[3]-6.75*discvec[5]-6.75*discvec[6]*(1-(tvec[7]-tvec[6])/(tvec[8]-tvec[6])))/(6.75*(tvec[7]-tvec[6])/(tvec[8]-tvec[6])+106.75) # Find d7 by linear interpolation discvec[7]<-discvec[6]+(discvec[8]-discvec[6])/(tvec[8]-tvec[6])*(tvec[7]-tvec[6]) # The resulting discount factors discvec plot(tvec,discvec,type="l") points(tvec,discvec) # The corresponding zero rates zerorates <- (-1)*log(discvec)/tvec zerorates plot(tvec,zerorates,type="l") points(tvec,zerorates)