我正在尝试使用 R 中的包来估计巴西的静态收益率曲线termstrc
。我正在使用该函数estim_nss.couponbonds
并将 0% 的票面利率和 0 美元的现金流量,除了最后一个是 1000 美元(到期时的面值) - 据我所知,这是执行此操作的函数,因为estim_nss.zeroyields
它只计算动态曲线。问题是我收到以下错误消息:
“(pos_cf[i] + 1) 中的错误:pos_cf[i + 1]:NA/NaN 参数此外:警告消息:在 max(n_of_cf) 中:max 没有非缺失参数;返回 -Inf”
我尝试使用跟踪问题,trace(estim_nss.couponbons, edit=T)
但找不到pos_cf[i]+1
计算的位置。根据名称,我认为它可能来自postpro_bond
函数并使用trace(postpro_bond, edit=T)
,但我无法再次找到计算。我相信“cf”来自现金流,因此在计算现金流时可能会出现一些问题。我曾经create_cashflows_matrix
测试过这个理论,但它运作良好,所以我不确定问题出在现金流上。
代码是:
#Creating the 'couponbond' class
ISIN <- as.character(c('ltn_2017','ltn_2018', 'ltn_2019', 'ltn_2021','ltn_2023')) #Bond's identification
MATURITYDATE <- as.Date(c(42736, 43101, 43466, 44197, 44927), origin='1899-12-30') #Dates are in system's format
ISSUEDATE <- as.Date(c(41288,41666,42395, 42073, 42395), origin='1899-12-30') #Dates are in system's format
COUPONRATE <- rep(0,5) #Coupon rates are 0 because these are zero-coupon bonds
PRICE <- c(969.32, 867.77, 782.48, 628.43, 501.95) #Prices seen 'TODAY'
ACCRUED <- rep(0.1,5) #There is no accrued interest in the brazilian bond's market
#Creating the cashflows sublist
CFISIN <- as.character(c('ltn_2017','ltn_2018', 'ltn_2019', 'ltn_2021', 'ltn_2023')) #Bond's identification
CF <- c(1000,1000,1000,1000,1000)# The face-values
DATE <- as.Date(c(42736, 43101, 43466, 44197, 44927), origin='1899-12-30') #Dates are in system's format
CASHFLOWS <- list(CFISIN,CF,DATE)
names(CASHFLOWS) <- c("ISIN","CF","DATE")
TODAY <- as.Date(42646, origin='1899-12-30')
brasil <- list(ISIN,MATURITYDATE,ISSUEDATE,
COUPONRATE,PRICE,ACCRUED,CASHFLOWS,TODAY)
names(brasil) <- c("ISIN","MATURITYDATE","ISSUEDATE","COUPONRATE",
"PRICE","ACCRUED","CASHFLOWS","TODAY")
mybonds <- list(brasil)
class(mybonds) <- "couponbonds"
#Estimating the zero-yield curve
ns_res <-estim_nss.couponbonds(mybonds, 'brasil' ,method = "ns")
#Testing the hypothesis that the error comes from the cashflow matrix
cf_p <- create_cashflows_matrix(mybonds[[1]], include_price = T)
m_p <- create_maturities_matrix(mybonds[[1]], include_price = T)
b <- bond_yields(cf_p,m_p)
请注意,我知道这个问题报告了同样的问题。但是,它适用于动态曲线。除此之外,没有有用的答案。