yield0 <- 0.05
tm <- 20
cf <- c(rep(5, tm-1), 105)
duration(cf, 1:tm, yield0)
approxBondReturn(yield = c(yield0, 0.05), tm = tm, n = 1)
## ==> no price change, current yield is earned
approxBondReturn(yield = c(yield0, 0.04), tm = tm, n = 1)
## ==> current yield + price changed is earned
Run the code above in your browser using DataLab