Fail to create couponbonds object in termstrc package using R -
i trying utilize r bundle termstrc estimate term structure. have prepare info couponbonds class required package. used false info prevent potential problem of real data. though tried lot, still didn't work. thought going wrong?
structure of official demo info works
data("govbonds") str(govbonds) list of 3 $ germany:list of 8 ..$ isin : chr [1:52] "de0001141414" "de0001137131" "de0001141422" "de0001137149" ... ..$ maturitydate: date[1:52], format: "2008-02-15" "2008-03-14" "2008-04-11" ... ..$ issuedate : date[1:52], format: "2002-08-14" "2006-03-08" "2003-04-11" ... ..$ couponrate : num [1:52] 0.0425 0.03 0.03 0.0325 0.0413 ... ..$ cost : num [1:52] 100 99.9 99.8 99.8 100.1 ... ..$ accrued : num [1:52] 4.09 2.66 2.43 2.07 2.39 ... ..$ cashflows :list of 3 .. ..$ isin: chr [1:384] "de0001141414" "de0001137131" "de0001141422" "de0001137149" ... .. ..$ cf : num [1:384] 104 103 103 103 104 ... .. ..$ date: date[1:384], format: "2008-02-15" "2008-03-14" "2008-04-11" ... ..$ today : date[1:1], format: "2008-01-30" #another 2 omitted here - attr(*, "class")= chr "couponbonds" > ns_res <- estim_nss(govbonds, c("germany"), method = "ns",tauconstr=list(c(0.2, 5, 0.1))) [1] "searching startparameters germany" beta0 beta1 beta2 tau1 5.008476 -1.092510 -3.209695 2.400100
my code prepare false data
bond=list() bond$china=list() n=30*12#suppose have n bond enddate=as.date('2014/11/7') isin=sprintf('de%010d',1:n)#some false isin bond$china$isin=isin bond$china$maturitydate=enddate+(1:n)*30 bond$china$issuedate=rep(enddate,n) bond$china$couponrate=rep(5/100,n) bond$china$price=rep(100,n) bond$china$accrued=rep(0,n) bond$china$cashflows=list() bond$china$cashflows$isin=isin bond$china$cashflows$cf=100+(1:n)*5/12 bond$china$cashflows$date=enddate+(1:n)*30 bond$china$today=enddate class(bond)='couponbonds' ns_res <- estim_nss(bond, c("china"), method = "ns",tauconstr=list(c(0.2, 5, 0.1)))
the output
error in `colnames<-`(`*tmp*`, value = c("de0000000001", "de0000000002", : effort set 'colnames' on object less 2 dimensions
the problem solved adding 1 cashflow amount 0 cashflow$cf
. set in way, @ to the lowest degree 1 bond should have @ to the lowest degree 2 cashflows. may face error caused uniroot
function. sure include cashflow after today
. termstrc
doesn't filter cashflow using today
.
r
No comments:
Post a Comment