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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sat Nov 3 20:11:44 CET 2012


Author: guirreri
Date: 2012-11-03 20:11:44 +0100 (Sat, 03 Nov 2012)
New Revision: 47

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


Modified: pkg/R/Nelson.Siegel.R
===================================================================
--- pkg/R/Nelson.Siegel.R	2012-11-03 19:10:17 UTC (rev 46)
+++ pkg/R/Nelson.Siegel.R	2012-11-03 19:11:44 UTC (rev 47)
@@ -1,16 +1,11 @@
 `Nelson.Siegel` <-
-function( rate, maturity, MidTau)
+function( rate, maturity )
   {
     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]))
+    pillars.number <- length(maturity)
+    lambdaValues <- seq(maturity[1], maturity[ pillars.number ], by=0.5)
 
-    lambdaValues <- c( MidTau,a1, a2, a3)
-    #if(is.vector(rate)) rate <- matrix(rate, 1, length(maturity))
-    #if(is.data.frame(rate)) rate <- data.matrix(rate)
-
     FinalResults <- matrix(0, nrow(rate), 4)
     colnames( FinalResults ) <- c("beta_0","beta_1","beta_2","lambda")
     j <- 1
@@ -22,7 +17,7 @@
           {
             lambdaTemp <- optimize(.factorBeta2,interval=c(0.001,1),
               maturity=lambdaValues[i],maximum=TRUE)$maximum
-            InterEstimation <- .NS.estimator(rate[j,], maturity, lambdaTemp)
+            InterEstimation <- .NS.estimator(as.numeric(rate[j,]), maturity, lambdaTemp)
             BetaCoef <- InterEstimation$Par
 	    if( BetaCoef[1]>0 & BetaCoef[1]<20)
               {

Modified: pkg/R/Svensson.R
===================================================================
--- pkg/R/Svensson.R	2012-11-03 19:10:17 UTC (rev 46)
+++ pkg/R/Svensson.R	2012-11-03 19:11:44 UTC (rev 47)
@@ -1,11 +1,12 @@
 `Svensson` <-
-function( rate, maturity, Tau1 = c(3,12), Tau2 = c(60,120))
+function( rate, maturity )
   {
 
     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])) )
+    pillars.number <- length(maturity)
+    Tau1Values <- seq(maturity[1], median(maturity), by=1)
+    Tau2Values <- seq(median(maturity), maturity[pillars.number], by=0.5)
     
     FinalResults <- matrix(0, nrow(rate), 6)
     FinalResultsTau2 <- matrix(0, length(Tau1Values), 7)   
@@ -18,10 +19,10 @@
         # colnames( InterResults ) <- c("beta0","beta1","beta2","beta_3","Tau1","Tau2","SSR")
         for( i in 1:length(Tau1Values))
           {
-            Tau1Temp <- optimize(.beta2Spot,interval=c(0.001,max(Tau1)),maturity=Tau1Values[i],maximum=TRUE)$maximum
+            Tau1Temp <- optimize(.beta2Spot,interval=c(0.001,max(Tau1Values)),maturity=Tau1Values[i],maximum=TRUE)$maximum
             for( a in 1:length(Tau2Values))
               {
-                Tau2Temp <- optimize(.beta2Spot,interval=c(0.001,max(Tau2)),maturity=Tau2Values[a],maximum=TRUE)$maximum 
+                Tau2Temp <- optimize(.beta2Spot,interval=c(0.001,maturity[pillars.number]),maturity=Tau2Values[a],maximum=TRUE)$maximum
                 InterEstimation <- .NSS.estimator(rate[j,], maturity, Tau1Temp, Tau2Temp)
                 BetaCoef <- InterEstimation$Par
                 SSR <- sum(InterEstimation$Res^2)



More information about the Yield-curve-commits mailing list