2016-10-13 41 views
1

我試圖估計靜態收益率曲線爲巴西在R使用termstrc包。我使用功能estim_nss.couponbonds並把0%的票面利率和$ 0現金流,除了最後一個是$ 1000(成熟時的面值) - 據我所知,這是執行此操作的函數,因爲estim_nss.zeroyields只計算動態曲線。問題是我收到以下錯誤消息:如何用R中的'termstrc'包估算靜態收益率曲線?

「(pos_cf [i] + 1)中的錯誤:pos_cf [i + 1]:NA/NaN參數此外:警告消息:在max(n_of_cf) :沒有非丟失的參數最大;返回-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) 

注意,我知道這question該報告同樣的問題。但是,它是用於動態曲線的。除此之外,沒有有用的答案。

回答

0

您的代碼有兩個問題。 (1)沒有命名第一個列表(這是錯誤的直接原因,但是如果修改它,會發生另一個錯誤)。 (2)在現金流量子表中,至少有一個ISIN級別需要多於一個數據。

# ... 
CFISIN <- as.character(c('ltn_2017','ltn_2018', 'ltn_2019', 
         'ltn_2021', 'ltn_2023', 'ltn_2023')) # added a 6th element 
CF <- c(1000,1000,1000,1000,1000, 1000)       # added a 6th 
DATE <- as.Date(c(42736,43101,43466,44197,44927, 44928), origin='1899-12-30') # added a 6th 

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 = brasil)      # named the list 

class(mybonds) <- "couponbonds" 
ns_res <-estim_nss.couponbonds(mybonds, 'brasil', method = "ns") 
注意:從這些行
bonddata <- bonddata[group] # prepro_bond()'s 1st line (the direct reason). 

# cf <- lapply(bonddata, create_cashflows_matrix) # the additional error 
create_cashflows_matrix(mybonds[[1]], include_price = F) # don't run 
+0

它的工作來到了錯誤!非常感謝! – danielkv

+0

我已經添加了兩個優惠券債券(其餘的期限比其他)到我的數據集和額外的錯誤(_Unror錯誤(pvcashflows,searchint,tol = tol,maxiter = 3000):f()值在終點不是對面sign_),現在正在發生在我身上。請注意,作爲息票債券,現金流量子清單中都有超過1個數據。你是否知道這類問題的其他來源? @ cuttlefish44 – danielkv

+0

@danielkv;我無法幫助你。可能來自'bond_yields()',它至少在(prepro_bond()'和'postpro_bond()'中。當'pvchasflows(-1)'和'pvcashflows(1)'是相同的符號時('pvchashflows'被定義),'uniroot(f = pvcashflows,interval = c(-1,1),...)在'bond_yields()')中。但我不知道更多細節,對不起。 ([相關的r-mailing-help](http://r.789695.n4.nabble.com/The-challenge-to-fit-the-greek-gov-curve-with-termstrc-R-Package-td4173116)。 html)) – cuttlefish44