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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Nov 1 17:27:43 CET 2012


Author: guirreri
Date: 2012-11-01 17:27:43 +0100 (Thu, 01 Nov 2012)
New Revision: 43

Modified:
   pkg/R/NSrates.R
   pkg/R/Nelson.Siegel.R
   pkg/R/Srates.R
   pkg/R/Svensson.R
Log:


Modified: pkg/R/NSrates.R
===================================================================
--- pkg/R/NSrates.R	2012-11-01 16:27:12 UTC (rev 42)
+++ pkg/R/NSrates.R	2012-11-01 16:27:43 UTC (rev 43)
@@ -1,10 +1,11 @@
 `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) )
     colnames(Curve) <- make.names(maturity)
 
-    for(i in 1:nrow(Coeff)) 
+    for(i in 1:nrow(Curve))
       {
         Curve[i,] <- Coeff[i,1] * rep(1, length(maturity)) +
           Coeff[i,2] * .factorBeta1(Coeff[i,4], maturity) +

Modified: pkg/R/Nelson.Siegel.R
===================================================================
--- pkg/R/Nelson.Siegel.R	2012-11-01 16:27:12 UTC (rev 42)
+++ pkg/R/Nelson.Siegel.R	2012-11-01 16:27:43 UTC (rev 43)
@@ -2,7 +2,7 @@
 function( rate, maturity, MidTau)
   {
     rate <- try.xts(rate,error=as.matrix)
-    
+    if(ncol(rate)==1) rate<-matrix(as.vector(rate),1,nrow(rate))
     a1 <- mean(c(MidTau[1],MidTau[2]))
     a2 <- mean(c(MidTau[1],MidTau[3]))
     a3 <- mean(c(MidTau[2],MidTau[3]))

Modified: pkg/R/Srates.R
===================================================================
--- pkg/R/Srates.R	2012-11-01 16:27:12 UTC (rev 42)
+++ pkg/R/Srates.R	2012-11-01 16:27:43 UTC (rev 43)
@@ -1,20 +1,22 @@
 `Srates`<- function( Coeff, maturity, whichRate="Forward" )
   {
     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) )
     colnames(Curve) <- make.names(maturity)
 
     switch(whichRate,
       Forward =
       {
-        colnames(CurveForward) <- maturity
+        CurveForward <- Curve
         for(i in 1:nrow(Coeff))
           {
-            Curve[i,] <- Coeff[i,1] +
+            CurveForward[i,] <- Coeff[i,1]+
               Coeff[i,2] * .beta1Forward( maturity, Coeff[i,5] ) +
               Coeff[i,3] * .beta2Forward( maturity, Coeff[i,5] ) +
               Coeff[i,4] * .beta2Forward( maturity, Coeff[i,6] )
           }
+          FinalCurve<-CurveForward
       },
       Spot =
       {
@@ -25,6 +27,7 @@
               Coeff[i,3] * .beta2Spot( maturity, Coeff[i,5] ) +
               Coeff[i,4] * .beta2Spot( maturity, Coeff[i,6] )
           }
+          FinalCurve <- Curve
       })
-    reclass( Curve, Coeff )
+    reclass( FinalCurve, Coeff )
   }

Modified: pkg/R/Svensson.R
===================================================================
--- pkg/R/Svensson.R	2012-11-01 16:27:12 UTC (rev 42)
+++ pkg/R/Svensson.R	2012-11-01 16:27:43 UTC (rev 43)
@@ -3,13 +3,10 @@
   {
 
     rate <- try.xts(rate, error=as.matrix)
-
+    if(ncol(rate)==1) rate<-matrix(as.vector(rate),1,nrow(rate))
     Tau1Values <- c( Tau1, mean(c(Tau1[1],Tau1[2])) )
     Tau2Values <- c( Tau2, mean(c(Tau2[1],Tau2[2])) )
     
-    #if(is.data.frame(rate)) rate <- data.matrix(rate)
-    #if(is.vector(rate)) rate <- matrix(rate, 1, length(maturity))
-    
     FinalResults <- matrix(0, nrow(rate), 6)
     FinalResultsTau2 <- matrix(0, length(Tau1Values), 7)   
     colnames( FinalResults ) <- c("beta_0","beta_1","beta_2","beta_3","tau1","tau2" )



More information about the Yield-curve-commits mailing list