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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sat May 18 17:47:23 CEST 2013


Author: guirreri
Date: 2013-05-18 17:47:22 +0200 (Sat, 18 May 2013)
New Revision: 55

Modified:
   pkg/R/NSrates.R
Log:
Solve Bug on NSrates

Modified: pkg/R/NSrates.R
===================================================================
--- pkg/R/NSrates.R	2013-01-27 15:34:11 UTC (rev 54)
+++ pkg/R/NSrates.R	2013-05-18 15:47:22 UTC (rev 55)
@@ -1,14 +1,13 @@
 `NSrates` <- function ( Coeff, maturity )
   {
-    Curve <- xts(matrix( 0, nrow(Coeff), length(maturity) ), order.by=time(Coeff))
+    Curve <- try.xts(matrix(0, nrow(Coeff), length(maturity)), order.by = time(Coeff), error=as.matrix)
     colnames(Curve) <- make.names(maturity)
-    Coeff <- as.matrix( Coeff )
-    
-    for(i in 1:nrow(Curve))
-      {
-        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 )
-  } 
+    Coeff <- as.matrix(Coeff)
+    for (i in 1:nrow(Curve)) {
+        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