Bond Valuation and Analysis in R
Clifford Ang
Senior Vice President, Compass Lexecon
uniroot()
function in R to help us automate the processytm <- function(cf) {
uniroot(bval, c(0, 1), cf = cf)$root
}
ytm()
function using uniroot()
cf
) and uses a modified bond valuation function (bval
)c(0,1)
limits the interval for the search to a yield between 0% and 100%cf <- c(-92.64, 5, 5, 5, 5, 5, 5, 5, 5, 5, 105)
bval <- function(i, cf, t = seq(along = cf)) sum(cf / (1 + i)^t)
bval()
that uses the modified cash flow vector (cf
)bondprc()
functiont
)i
)Bond Valuation and Analysis in R