FINM3007 Workshop 1
2.1 Zero-Coupon bonds and forward rates.
N <- 6
Tms <- seq(0.5, 3, by = 0.5)
Frd <- c(0.052, 0.056, 0.059, 0.061, 0.06, 0.059)
dT <- 0.5
P <- function(i) {
sum <- 0
for (j in 1:i) sum <- sum + dT * Frd[j]
return(exp(-sum))
}
indices <- 1:N
Pdata <- sapply(indices, P)
Pdata
## [1] 0.9743 0.9474 0.9199 0.8923 0.8659 0.8407
Generating the interpolated plot.
cs <- splinefun(Tms, Frd, method = "monoH.FC")
curve(cs(x, deriv = 0), 0, 3, col = "blue", ylab = "Forward rate", xlab = "Time")
points(Tms, Frd, col = "red", cex = 1)
text(1.8, 0.052, labels = "Interpolation of Forward Rates")
2.2 Spot rates.
R <- function(t, T, P) {
-log(P)/(T - t)
}
Rdata <- array(0, N)
for (j in 1:N) Rdata[j] <- R(0, Tms[j], Pdata[j])
Rdata
## [1] 0.05200 0.05400 0.05567 0.05700 0.05760 0.05783
csR <- splinefun(Tms, Rdata, method = "monoH.FC")
curve(csR(x, deriv = 0), 0, 3, col = "blue", ylab = "Spot Rate", xlab = "Time")
points(Tms, Rdata, col = "red", cex = 1)
text(1.8, 0.052, labels = "Interpolation of Spot Rates")
2.3 Par yields.
pY <- function(i) {
sum <- 0
for (j in 1:i) sum <- sum + Pdata[j]
return(2 * (1 - Pdata[i])/sum)
}
pYdata <- sapply(indices, pY)
pYdata
## [1] 0.05268 0.05471 0.05638 0.05771 0.05831 0.05855
cspY <- splinefun(Tms, pYdata, method = "monoH.FC")
curve(cspY(x, deriv = 0), 0, 3, col = "blue", ylab = "Par Yields", xlab = "Time")
points(Tms, pYdata, col = "red", cex = 1)
text(1.8, 0.052, labels = "Interpolation of Par Yields")
arrows(1.45, 0.0525, 1.2, 0.055, col = "blue", length = 0.1)
2.4 Instantaneous forward-rates
csP <- splinefun(Tms, Pdata, method = "monoH.FC")
ifr <- function(T) -csP(T, deriv = 1)/csP(T, deriv = 0)
curve(ifr(x), 0, 3, col = "blue", ylab = "Inst Fwd Rate", xlab = "Time")
points(Tms, Pdata, col = "red", cex = 5)
text(1.8, 0.056, labels = "First derivative is not continuous")
arrows(1.45, 0.0565, 1.2, 0.058, col = "blue", length = 0.1)
Exercise 4
csPC <- splinefun(Tms, Pdata, method = "natural")
ifrC <- function(T) -csPC(T, deriv = 1)/csPC(T, deriv = 0)
curve(ifrC(x), 0, 3, col = "blue", ylab = "Inst Fwd Rate", xlab = "Time")