下面是估计Nelson-Siegel利率模型中估计参数的R代码,最后R报错是什么意思啊?
###Nelson-Siegel Model, spot rate function
sr=function(tau,beta0,beta1,beta2,lamda)
{
beta0+beta1*(1-exp(-lamda*tau))/(lamda*tau)
+beta2*((1-exp(-lamda*tau))/(lamda*tau)-exp(-lamda*tau))
}
###Input cashflows with their maturity
###(15 bonds with maximum number of payments 25)
m=read.csv("maturity.csv")
cf=read.csv("CashFlow.csv")
m=as.matrix(m)
cf=as.matrix(cf)
###Object is to minimize the sum of cashflows of all bonds
Sum_CashFlow=function(beta0,beta1,beta2,lamda)
{
disc=exp(-m*sr(m,beta0,beta1,beta2,lamda))
CashFlowMatrix=cf*disc
CashFlow=as.vector(CashFlowMatrix)
CashFlow[is.na(CashFlow)]=0
sum(CashFlow)
}
nlm(Sum_CashFlow,c(4,-3,3,0.4))
R输出:
错误于beta1 * (1 - exp(-lamda * tau)) : 缺少'beta1'