# Using the termstrc package in R

I am attempting to use the function estim_nss from the termstrc package in R to find the spot curve from constant maturity rates published by the Fed. I am using this package because I will need to deal with variable rate coupon bonds in the future. The function requires an object of class "couponbonds" but I cannot figure out how to create this class. I tried creating a list object with similar data but the function rejects this object with the following message:

Error in UseMethod("estim_nss") : no applicable method for 'estim_nss' applied to an object of class "list"

Any assistance would be appreciated.

-
You might want to try the YieldCurve package. I found it easier to use. –  Joshua Ulrich Dec 20 '12 at 14:09
Thanks, Josh. My understanding is that the YieldCurve package doesn't handle variable coupon bonds which will eventually limit my data set. –  ProbablePattern Dec 21 '12 at 14:57

You can create the data using the procedure described in the reference manual on pages 31 and 32. The necessary code is copied below:

# The following code may be used to generate an empty data set,
# which can then be filled with bond data:
ISIN <- vector()
MATURITYDATE <- vector()
STARTDATE <- vector()
COUPONRATE <- vector()
PRICE <- vector()
ACCRUED <- vector()
CFISIN <- vector()
CF <- vector()
DATE <- vector()
CASHFLOWS <- list(CFISIN,CF,DATE)
names(CASHFLOWS) <- c("ISIN","CF","DATE")
TODAY <- vector()

mycountry1 <- list(ISIN,MATURITYDATE,STARTDATE,
COUPONRATE,PRICE,ACCRUED,CASHFLOWS,TODAY)
mycountry2 <- list(ISIN,MATURITYDATE,STARTDATE,
COUPONRATE,PRICE,ACCRUED,CASHFLOWS,TODAY)
names(mycountry1) <- c("ISIN","MATURITYDATE","STARTDATE","COUPONRATE",
"PRICE","ACCRUED","CASHFLOWS","TODAY")
names(mycountry2) <- c("ISIN","MATURITYDATE","STARTDATE","COUPONRATE",
"PRICE","ACCRUED","CASHFLOWS","TODAY")
mybonds <- list(mycountry1,mycountry2)
names(mybonds) <- c("mycountry1","mycountry2")


Finally set the class of the object just created:

class(mybonds)="couponbonds"

-
Thanks! After an hour or two of skimming through 80 pages, I would never have found that tidbit without any reference to the couponbonds class. –  ProbablePattern Dec 20 '12 at 13:33
I spent the day replicating this format and it does not solve the original problem. Producing an object with the exact same structure as the "couponbonds" class is still a list that is rejected by the est_nss function. –  ProbablePattern Dec 21 '12 at 20:22

It turned out to be more simple than I thought. First, be sure to replace "STARTDATE" with "ISSUEDATE" when building the list. Once the list is build simply reclassify it using the following command:

class(mybonds)="couponbonds"

That's it!

-
So the docs are wrong? –  Bob Jansen Dec 22 '12 at 17:34
They appear to be. –  ProbablePattern Dec 30 '12 at 20:12
I've mailed the package maintainer and added that last line to my answer. –  Bob Jansen Jan 1 '13 at 14:43
The author mailed me that this change will be considered for the next revision of the package. –  Bob Jansen Jan 3 '13 at 20:06