在 R 中進行債券評價與分析
Clifford Ang
Senior Vice President, Compass Lexecon
bondprc() 函式來簡化計算p:票面金額r:票面利率ttm:剩餘到期年數y:殖利率cf <- c(rep(p * r, ttm - 1), p * (1 + r))
rep(x, y)-重複 y 次 x 的值x = p * r=票息金額y = ttm - 1=到期年數減 1 年p * (1 + r)=本金+最後一期票息cf <- data.frame(cf)
cf$t <- as.numeric(rownames(cf))
cf 向量的 rownames() 依序為 1、2、3、4,直到債券的 ttmas.numeric() 確保讀成數值cf$pv_factor <- 1 / (1 + y)^cf$t
cf$pv <- cf$cf * cf$pv_factor
sum(cf$pv)
bondprc() 函式p、r、ttm、ybondprc <- function(p, r, ttm, y){
cf <- c(rep(p * r, ttm - 1), p * (1 + r))
cf <- data.frame(cf)
cf$t <- as.numeric(rownames(cf))
cf$pv_factor <- 1 / (1 + y)^cf$t
cf$pv <- cf$cf * cf$pv_factor
sum(cf$pv)
}
在 R 中進行債券評價與分析