[Yield-curve-commits] r50 - pkg/R

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sat Jan 19 12:58:29 CET 2013


Author: guirreri
Date: 2013-01-19 12:58:29 +0100 (Sat, 19 Jan 2013)
New Revision: 50

Modified:
   pkg/R/NSrates.R
Log:
Adjusting to fit the xts dataset

Modified: pkg/R/NSrates.R
===================================================================
--- pkg/R/NSrates.R	2012-11-25 11:44:20 UTC (rev 49)
+++ pkg/R/NSrates.R	2013-01-19 11:58:29 UTC (rev 50)
@@ -1,15 +1,14 @@
 `NSrates` <- function ( Coeff, maturity )
   {
     Coeff <- try.xts( Coeff, error=as.matrix )
-    if(ncol(Coeff)==1) Coeff<-matrix(as.vector(Coeff),1,nrow(Coeff))
-    Curve <- matrix( 0, nrow(Coeff), length(maturity) )
+    Curve <- xts(matrix( 0, nrow(Coeff), length(maturity) ), order.by=time(Coeff))
     colnames(Curve) <- make.names(maturity)
 
     for(i in 1:nrow(Curve))
       {
-        Curve[i,] <- Coeff[i,1] * rep(1, length(maturity)) +
-          Coeff[i,2] * .factorBeta1(Coeff[i,4], maturity) +
-          Coeff[i,3] * .factorBeta2(Coeff[i,4], maturity )
+        Curve[i,] <- as.numeric(Coeff[i,1]) * rep(1, length(maturity)) +
+          as.numeric(Coeff[i,2]) * as.numeric(.factorBeta1(Coeff[i,4], maturity) ) +
+          as.numeric(Coeff[i,3]) * as.numeric(.factorBeta2(Coeff[i,4], maturity ))
       }
     return( Curve )
   } 



More information about the Yield-curve-commits mailing list