[Yield-curve-commits] r54 - in pkg: R data man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sun Jan 27 16:34:12 CET 2013


Author: guirreri
Date: 2013-01-27 16:34:11 +0100 (Sun, 27 Jan 2013)
New Revision: 54

Modified:
   pkg/R/NSrates.R
   pkg/R/Srates.R
   pkg/R/Svensson.R
   pkg/R/beta.R
   pkg/data/ECBYieldCurve.rda
   pkg/man/ECBYieldCurve.Rd
   pkg/man/Srates.Rd
   pkg/man/Svensson.Rd
Log:


Modified: pkg/R/NSrates.R
===================================================================
--- pkg/R/NSrates.R	2013-01-20 20:30:11 UTC (rev 53)
+++ pkg/R/NSrates.R	2013-01-27 15:34:11 UTC (rev 54)
@@ -1,9 +1,9 @@
 `NSrates` <- function ( Coeff, maturity )
   {
-    Coeff <- try.xts( Coeff, error=as.matrix )
     Curve <- xts(matrix( 0, nrow(Coeff), length(maturity) ), order.by=time(Coeff))
     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)) +

Modified: pkg/R/Srates.R
===================================================================
--- pkg/R/Srates.R	2013-01-20 20:30:11 UTC (rev 53)
+++ pkg/R/Srates.R	2013-01-27 15:34:11 UTC (rev 54)
@@ -1,10 +1,10 @@
 `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) )
+    Curve <- xts(matrix( 0, nrow(Coeff), length(maturity) ), order.by=time(Coeff))
     colnames(Curve) <- make.names(maturity)
-
+    Coeff <- as.matrix(Coeff)
+    
     switch(whichRate,
       Forward =
       {

Modified: pkg/R/Svensson.R
===================================================================
--- pkg/R/Svensson.R	2013-01-20 20:30:11 UTC (rev 53)
+++ pkg/R/Svensson.R	2013-01-27 15:34:11 UTC (rev 54)
@@ -23,7 +23,7 @@
             for( a in 1:length(Tau2Values))
               {
                 Tau2Temp <- optimize(.beta2Spot,interval=c(0.001,maturity[pillars.number]),maturity=Tau2Values[a],maximum=TRUE)$maximum
-                InterEstimation <- .NSS.estimator(as.numric(rate[j,]), maturity, Tau1Temp, Tau2Temp)
+                InterEstimation <- .NSS.estimator(as.numeric(rate[j,]), maturity, Tau1Temp, Tau2Temp)
                 BetaCoef <- InterEstimation$Par
                 SSR <- sum(InterEstimation$Res^2)
                 InterResultsTau2[a,] <- c(BetaCoef, Tau1Temp, Tau2Temp, SSR)

Modified: pkg/R/beta.R
===================================================================
--- pkg/R/beta.R	2013-01-20 20:30:11 UTC (rev 53)
+++ pkg/R/beta.R	2013-01-27 15:34:11 UTC (rev 54)
@@ -1,31 +1,31 @@
 `.beta1Spot` <- function(maturity, tau)
   {
-    (1 - exp(-maturity/tau))/(maturity/tau)
+   as.numeric( (1 - exp(-maturity/tau))/(maturity/tau))
   }
 
 `.beta2Spot` <- function(maturity, tau)
   {
-    ((1 - exp(-maturity/tau))/(maturity/tau) - exp(-maturity/tau))
+   as.numeric(  ((1 - exp(-maturity/tau))/(maturity/tau) - exp(-maturity/tau)) )
   }
 
 `.beta1Forward` <- function(maturity, tau)
   {
-    exp(-maturity/tau) 
+       as.numeric( exp(-maturity/tau) )
   }
 
 `.beta2Forward` <- function(maturity, tau)
   {
-    exp(-maturity/tau) * (maturity/tau)  
+       as.numeric( exp(-maturity/tau) * (maturity/tau) )
   }
 
 `.factorBeta1` <- function(lambda, maturity)
   {
-    (1-exp(-lambda*maturity)) / (lambda*maturity) 
+   as.numeric( (1-exp(-lambda*maturity)) / (lambda*maturity) )
   }
 
 `.factorBeta2` <- function(lambda, maturity)
   {
-    (1-exp(-lambda*maturity)) / (lambda*maturity) - exp(-lambda*maturity) 
+  as.numeric( (1-exp(-lambda*maturity)) / (lambda*maturity) - exp(-lambda*maturity) )
   }
 
 `.NS.estimator` <- function( rate, maturity, lambda )

Modified: pkg/data/ECBYieldCurve.rda
===================================================================
(Binary files differ)

Modified: pkg/man/ECBYieldCurve.Rd
===================================================================
--- pkg/man/ECBYieldCurve.Rd	2013-01-20 20:30:11 UTC (rev 53)
+++ pkg/man/ECBYieldCurve.Rd	2013-01-27 15:34:11 UTC (rev 54)
@@ -3,62 +3,32 @@
 \docType{data}
 \title{ Yield curve data spot rate, AAA-rated bonds, maturities from 3 months to 30 years}
 \description{
-Government bond, nominal, all triple A issuer companies. The maturity are 3 and 6 months and from 1 year to 30 years with frequency business day, provided by European Central Bank.
+Government bond, nominal, all triple A issuer companies. The maturities are 3 and 6 months and from 1 year to 30 years with frequency business day, provided by European Central Bank.
+The range date is from 2006-12-29 to 2009-07-24.
 }
 \usage{data(ECBYieldCurve)}
 \format{
-  A data frame with 655 observations on the following 32 variables.
-  \describe{
-    \item{\code{X3M}}{interest rate with maturity 3 months}
-    \item{\code{X6M}}{interest rate with maturity 6 months}
-    \item{\code{X1Y}}{interest rate with maturity 1 year}
-    \item{\code{X2Y}}{interest rate with maturity 2 years}
-    \item{\code{X3Y}}{interest rate with maturity 3 years}
-    \item{\code{X4Y}}{interest rate with maturity 4 years}
-    \item{\code{X5Y}}{interest rate with maturity 5 years}
-    \item{\code{X6Y}}{interest rate with maturity 6 years}
-    \item{\code{X7Y}}{interest rate with maturity 7 years}
-    \item{\code{X8Y}}{interest rate with maturity 8 years}
-    \item{\code{X9Y}}{interest rate with maturity 9 years}
-    \item{\code{X10Y}}{interest rate with maturity 10 years}
-    \item{\code{X11Y}}{interest rate with maturity 11 years}
-    \item{\code{X12Y}}{interest rate with maturity 12 years}
-    \item{\code{X13Y}}{interest rate with maturity 13 years}
-    \item{\code{X14Y}}{interest rate with maturity 14 years}
-    \item{\code{X15Y}}{interest rate with maturity 15 years}
-    \item{\code{X16Y}}{interest rate with maturity 16 years}
-    \item{\code{X17Y}}{interest rate with maturity 17 years}
-    \item{\code{X18Y}}{interest rate with maturity 18 years}
-    \item{\code{X19Y}}{interest rate with maturity 19 years}
-    \item{\code{X20Y}}{interest rate with maturity 20 years}
-    \item{\code{X21Y}}{interest rate with maturity 21 years}
-    \item{\code{X22Y}}{interest rate with maturity 22 years}
-    \item{\code{X23Y}}{interest rate with maturity 23 years}
-    \item{\code{X24Y}}{interest rate with maturity 24 years}
-    \item{\code{X25Y}}{interest rate with maturity 25 years}
-    \item{\code{X26Y}}{interest rate with maturity 26 years}
-    \item{\code{X27Y}}{interest rate with maturity 27 years}
-    \item{\code{X28Y}}{interest rate with maturity 28 years}
-    \item{\code{X29Y}}{interest rate with maturity 29 years}
-    \item{\code{X30Y}}{interest rate with maturity 30 years}
-  }
+It is an \code{xts} object with 32 interest rate at different matuirties and 655 obeservations.
 }
 
 \source{
 \acronym{ECB}: \url{http://www.ecb.europa.eu/stats/money/yc/html/index.en.html}.\cr
-Data set is also available for download in Excel format at \url{http://www.guirreri.host22.com/index.php?p=1_2_Documents}. 
 }
 
 \examples{
+### plot ECB Yield Curve ###
 data(ECBYieldCurve)
-## maybe str(ECBYieldCurve) ; plot(ECBYieldCurve) 
-tau <- c(3/12,6/12,1:30)
-par(mfrow=c(1,2))
-plot(tau,ECBYieldCurve[1,],type="o", ylim=c(0,5), 
-	main="European Union's yield curve",sub="29/12/2006")
+
+first(ECBYieldCurve,'3 day')
+last(ECBYieldCurve,'3 day')
+
+mat.ECB <- tau <- c(3/12,6/12,1:30)
+
+par(mfrow=c(2,3))
+for( i in c(1,2,3,653,654,655) ){
+plot(mat.ECB, ECBYieldCurve[i,], type="o", xlab="Maturities structure in years", ylab="Interest rates values")
+title(main=paste("European Central Bank yield curve obeserved at",time(ECBYieldCurve[i], sep=" ") ))
 grid()
-plot(tau,ECBYieldCurve[655,],type="o", ylim=c(0,5), 
-	main="European Union's yield curve",sub="24/07/2009")
-grid()
 }
+}
 \keyword{datasets}

Modified: pkg/man/Srates.Rd
===================================================================
--- pkg/man/Srates.Rd	2013-01-20 20:30:11 UTC (rev 53)
+++ pkg/man/Srates.Rd	2013-01-27 15:34:11 UTC (rev 54)
@@ -28,13 +28,14 @@
 
 \examples{
 data(ECBYieldCurve)
-rate.ECB = ECBYieldCurve[1:5,]
+rate.ECB = first(ECBYieldCurve,'2 day')
 maturity.ECB = c(0.25,0.5,seq(1,30,by=1))
 SvenssonParameters <- Svensson(rate.ECB, maturity.ECB)
 Svensson.rate <- Srates( SvenssonParameters ,maturity.ECB,"Spot")
 
-plot(maturity.ECB, rate.ECB[5,],main="Fitting Svensson yield curve", type="o")
-lines(maturity.ECB, Svensson.rate[5,], col=2)
+plot(maturity.ECB, last(rate.ECB,'1 day'),main="Fitting Svensson yield curve",
+  xlab=c("Pillars in years"), ylab=c("Rates"),type="o")
+lines(maturity.ECB, last(Svensson.rate,'1 day'), col=2)
 legend("topleft",legend=c("observed yield curve","fitted yield curve"),
 col=c(1,2),lty=1)
 grid()

Modified: pkg/man/Svensson.Rd
===================================================================
--- pkg/man/Svensson.Rd	2013-01-20 20:30:11 UTC (rev 53)
+++ pkg/man/Svensson.Rd	2013-01-27 15:34:11 UTC (rev 54)
@@ -48,7 +48,7 @@
  xlab=c("Pillars in years"), type="l", col=3)
 lines( maturity.ECB, ECBYieldCurve[5,],col=2)
 legend("topleft",legend=c("fitted yield curve","observed yield curve"),
-col=c(1,2),lty=1)
+col=c(3,2),lty=1)
 grid()
 }
 \keyword{models}



More information about the Yield-curve-commits mailing list