我正在尝试计算到期收益率,但下面函数的答案很奇怪......我正在寻找的正确答案...... get_ytm(100,3,0.04,4,108.8516) ---> 0.01
谁能解决我的误解?
get_ytm <- function(F,T,c,f,PV){
cf <- c(rep((F*c)/f,T*f-1), F*(1+c/f))
PV <- function(ytm,cf.,t=seq(along=cf.),f.=f){
cf.pv.factor <- exp(-ytm/f.*t)
cf.pv <- cf. * cf.pv.factor
sum(cf.pv)
}
uniroot(PV,c(0.001,0.2),cf.=cf,extendInt ="yes")$root
}