YieldCurve package

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

YieldCurve package

jaimie villanueva
Hi there,

I'm facing some problems since I've updated  the YieldCurve package from <<
YieldCurve_4.0 >> to << YieldCurve_4.1 >>

I would like to get Nelson Siegel rates. To do so, I'm using
"Nelson.Siegel" function in order to compute beta and lambda parameters and
"NSrates" function to compute Nelson Siegel rates. The thing is that the
following code I'm about to show You, did work in the past with my older
version of the package, but It doesn't work now.

The problem occurs when setting up Nelson Siegel function:

This is the code:

> Sys.info()
                     sysname                      release
   version
                   "Windows"                      "7 x64" "build 7601,
Service Pack 1"
                    nodename                      machine
     login
                    "JVC-PC"                     "x86-64"
     "JVC"
                        user               effective_user
                       "JVC"                        "JVC"

  library(RODBC)

>  library(TSA)
>  library(grDevices)
>  library(YieldCurve)
>  library(xts)
>
>
>  #########  CONFIGURACIÓN INICIAL
>  #
>
>  plazos.NG=array(c(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,
+ 21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,
+ 42,43,44,45,46,47,48,49,50))
>
>
 CURVA.EUR=array(c(1.415943,1.302205,1.380278,1.533634,1.725201,1.920058,2.083162,2.214956,
+   2.32518,2.422087,2.591747,2.735049,2.739023,2.644585,2.543769))

>
>  m=length(plazos.NG)
>  CURVA.EUR.NG=array(NA,c(m))
>  plazos.EUR=array(c(1,2,3,4,5,6,7,8,9,10,12,15,20,25,30))
>
>  #
>  #########
>
>  NEW.VECT.1=cbind(plazos.NG,CURVA.EUR.NG)
>  NEW.VECT.2=cbind(plazos.EUR,CURVA.EUR)
>
>
>  # CREAMOS EL VECTOR CON TIPOS
>
>  l= length(plazos.EUR)
>  posicX=1
>  posicY=1
>
>  for(k in 1:l)
+  {
+ # BUSCAMOS LA POSICION DE CADA PUNTO DE LA CURVA.
+
+ while(NEW.VECT.1[posicY,1]!= NEW.VECT.2[posicX,1]){posicY=posicY+1}
+ NEW.VECT.1[posicY,2]=NEW.VECT.2[posicX,2]
+ posicX=posicX+1
+ posicY=posicY+1
+
+  }
>
>  NSParameters= Nelson.Siegel(rate=NEW.VECT.1[,2],maturity=NEW.VECT.1[,1])
>  fitted.rates= NSrates(NSParameters, NEW.VECT.1[,1])

*Error in xts(matrix(0, nrow(Coeff), length(maturity)), order.by =
time(Coeff)) : *
*  order.by requires an appropriate time-based object*
*
*
Any help would be kindly appreciated.
Thanks in advance.

--
*Jaimie.*

        [[alternative HTML version deleted]]


_______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-sig-finance
-- Subscriber-posting only. If you want to post, subscribe first.
-- Also note that this is not the r-help list where general R questions should go.
Reply | Threaded
Open this post in threaded view
|

Re: YieldCurve package

Jeffrey Ryan
Try posting sessionInfo(). Your packages matter far more than your system in 99.99% of cases.

Also, providing the result of traceback() immediately after the failed call can be illustrative.

Best,
Jeff

Jeffrey Ryan    |    Founder    |    [hidden email]

www.lemnica.com

On Aug 11, 2013, at 10:56 AM, jaimie villanueva <[hidden email]> wrote:

> Hi there,
>
> I'm facing some problems since I've updated  the YieldCurve package from <<
> YieldCurve_4.0 >> to << YieldCurve_4.1 >>
>
> I would like to get Nelson Siegel rates. To do so, I'm using
> "Nelson.Siegel" function in order to compute beta and lambda parameters and
> "NSrates" function to compute Nelson Siegel rates. The thing is that the
> following code I'm about to show You, did work in the past with my older
> version of the package, but It doesn't work now.
>
> The problem occurs when setting up Nelson Siegel function:
>
> This is the code:
>
>> Sys.info()
>                     sysname                      release
>   version
>                   "Windows"                      "7 x64" "build 7601,
> Service Pack 1"
>                    nodename                      machine
>     login
>                    "JVC-PC"                     "x86-64"
>     "JVC"
>                        user               effective_user
>                       "JVC"                        "JVC"
>
>  library(RODBC)
>> library(TSA)
>> library(grDevices)
>> library(YieldCurve)
>> library(xts)
>>
>>
>> #########  CONFIGURACI�N INICIAL
>> #
>>
>> plazos.NG=array(c(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,
> + 21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,
> + 42,43,44,45,46,47,48,49,50))
>>
>>
> CURVA.EUR=array(c(1.415943,1.302205,1.380278,1.533634,1.725201,1.920058,2.083162,2.214956,
> +   2.32518,2.422087,2.591747,2.735049,2.739023,2.644585,2.543769))
>>
>> m=length(plazos.NG)
>> CURVA.EUR.NG=array(NA,c(m))
>> plazos.EUR=array(c(1,2,3,4,5,6,7,8,9,10,12,15,20,25,30))
>>
>> #
>> #########
>>
>> NEW.VECT.1=cbind(plazos.NG,CURVA.EUR.NG)
>> NEW.VECT.2=cbind(plazos.EUR,CURVA.EUR)
>>
>>
>> # CREAMOS EL VECTOR CON TIPOS
>>
>> l= length(plazos.EUR)
>> posicX=1
>> posicY=1
>>
>> for(k in 1:l)
> +  {
> + # BUSCAMOS LA POSICION DE CADA PUNTO DE LA CURVA.
> +
> + while(NEW.VECT.1[posicY,1]!= NEW.VECT.2[posicX,1]){posicY=posicY+1}
> + NEW.VECT.1[posicY,2]=NEW.VECT.2[posicX,2]
> + posicX=posicX+1
> + posicY=posicY+1
> +
> +  }
>>
>> NSParameters= Nelson.Siegel(rate=NEW.VECT.1[,2],maturity=NEW.VECT.1[,1])
>> fitted.rates= NSrates(NSParameters, NEW.VECT.1[,1])
>
> *Error in xts(matrix(0, nrow(Coeff), length(maturity)), order.by =
> time(Coeff)) : *
> *  order.by requires an appropriate time-based object*
> *
> *
> Any help would be kindly appreciated.
> Thanks in advance.
>
> --
> *Jaimie.*
>
>    [[alternative HTML version deleted]]
>
> _______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> -- Subscriber-posting only. If you want to post, subscribe first.
> -- Also note that this is not the r-help list where general R questions should go.

_______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-sig-finance
-- Subscriber-posting only. If you want to post, subscribe first.
-- Also note that this is not the r-help list where general R questions should go.
Reply | Threaded
Open this post in threaded view
|

Re: YieldCurve package

jaimie villanueva
   Hi All,

>
> As suggested, I'm coming back with the sessionInfo() and the traceback():
>
> > *sessionInfo()*
> R version 3.0.0 (2013-04-03)
> Platform: x86_64-w64-mingw32/x64 (64-bit)
>
> locale:
> [1] LC_COLLATE=Spanish_Spain.1252
> [2] LC_CTYPE=Spanish_Spain.1252
> [3] LC_MONETARY=Spanish_Spain.1252
> [4] LC_NUMERIC=C
> [5] LC_TIME=Spanish_Spain.1252
>
> attached base packages:
> [1] stats     graphics  grDevices utils
> [5] datasets  methods   base
>
> other attached packages:
> [1] YieldCurve_4.1  xts_0.9-3       zoo_1.7-9
> [4] TSA_1.01        tseries_0.10-31 mgcv_1.7-22
> [7] locfit_1.5-9.1  leaps_2.9       RODBC_1.3-6
>
> loaded via a namespace (and not attached):
> [1] grid_3.0.0      lattice_0.20-15 Matrix_1.0-12
> [4] nlme_3.1-109    quadprog_1.5-5  tools_3.0.0
>
>
> > *traceback()*
> 3: stop("order.by requires an appropriate time-based object")
> 2: xts(matrix(0, nrow(Coeff), length(maturity)), order.by = time(Coeff))
> 1: NSrates(NSParameters, NEW.VECT.1[, 1])
>
> I hope You find It useful
>
> Regards.
>
> Jaimie.
>
> *PS: Thanks Ryan for Your suggestion.*
>
>
> On Mon, Aug 12, 2013 at 5:33 AM, Jeff Ryan <[hidden email]> wrote:
>
>> Try posting sessionInfo(). Your packages matter far more than your system
>> in 99.99% of cases.
>>
>> Also, providing the result of traceback() immediately after the failed
>> call can be illustrative.
>>
>> Best,
>> Jeff
>>
>> Jeffrey Ryan    |    Founder    |    [hidden email]
>>
>> www.lemnica.com
>>
>> On Aug 11, 2013, at 10:56 AM, jaimie villanueva <
>> [hidden email]> wrote:
>>
>> > Hi there,
>> >
>> > I'm facing some problems since I've updated  the YieldCurve package
>> from <<
>> > YieldCurve_4.0 >> to << YieldCurve_4.1 >>
>> >
>> > I would like to get Nelson Siegel rates. To do so, I'm using
>> > "Nelson.Siegel" function in order to compute beta and lambda parameters
>> and
>> > "NSrates" function to compute Nelson Siegel rates. The thing is that the
>> > following code I'm about to show You, did work in the past with my older
>> > version of the package, but It doesn't work now.
>> >
>> > The problem occurs when setting up Nelson Siegel function:
>> >
>> > This is the code:
>> >
>> >> Sys.info()
>> >                     sysname                      release
>> >   version
>> >                   "Windows"                      "7 x64" "build 7601,
>> > Service Pack 1"
>> >                    nodename                      machine
>> >     login
>> >                    "JVC-PC"                     "x86-64"
>> >     "JVC"
>> >                        user               effective_user
>> >                       "JVC"                        "JVC"
>> >
>> >  library(RODBC)
>> >> library(TSA)
>> >> library(grDevices)
>> >> library(YieldCurve)
>> >> library(xts)
>> >>
>> >>
>> >> #########  CONFIGURACI�N INICIAL
>> >> #
>> >>
>> >> plazos.NG=array(c(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,
>> > + 21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,
>> > + 42,43,44,45,46,47,48,49,50))
>> >>
>> >>
>> >
>> CURVA.EUR=array(c(1.415943,1.302205,1.380278,1.533634,1.725201,1.920058,2.083162,2.214956,
>> > +   2.32518,2.422087,2.591747,2.735049,2.739023,2.644585,2.543769))
>> >>
>> >> m=length(plazos.NG)
>> >> CURVA.EUR.NG=array(NA,c(m))
>> >> plazos.EUR=array(c(1,2,3,4,5,6,7,8,9,10,12,15,20,25,30))
>> >>
>> >> #
>> >> #########
>> >>
>> >> NEW.VECT.1=cbind(plazos.NG,CURVA.EUR.NG)
>> >> NEW.VECT.2=cbind(plazos.EUR,CURVA.EUR)
>> >>
>> >>
>> >> # CREAMOS EL VECTOR CON TIPOS
>> >>
>> >> l= length(plazos.EUR)
>> >> posicX=1
>> >> posicY=1
>> >>
>> >> for(k in 1:l)
>> > +  {
>> > + # BUSCAMOS LA POSICION DE CADA PUNTO DE LA CURVA.
>> > +
>> > + while(NEW.VECT.1[posicY,1]!= NEW.VECT.2[posicX,1]){posicY=posicY+1}
>> > + NEW.VECT.1[posicY,2]=NEW.VECT.2[posicX,2]
>> > + posicX=posicX+1
>> > + posicY=posicY+1
>> > +
>> > +  }
>> >>
>> >> NSParameters=
>> Nelson.Siegel(rate=NEW.VECT.1[,2],maturity=NEW.VECT.1[,1])
>> >> fitted.rates= NSrates(NSParameters, NEW.VECT.1[,1])
>> >
>> > *Error in xts(matrix(0, nrow(Coeff), length(maturity)), order.by =
>> > time(Coeff)) : *
>> > *  order.by requires an appropriate time-based object*
>> > *
>> > *
>> > Any help would be kindly appreciated.
>> > Thanks in advance.
>> >
>> > --
>> > *Jaimie.*
>> >
>> >    [[alternative HTML version deleted]]
>> >
>> > _______________________________________________
>> > [hidden email] mailing list
>> > https://stat.ethz.ch/mailman/listinfo/r-sig-finance
>> > -- Subscriber-posting only. If you want to post, subscribe first.
>> > -- Also note that this is not the r-help list where general R questions
>> should go.
>>
>
>
>
> --
> *Jaimie.*
>


--
*Jaimie.*

        [[alternative HTML version deleted]]


_______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-sig-finance
-- Subscriber-posting only. If you want to post, subscribe first.
-- Also note that this is not the r-help list where general R questions should go.
Reply | Threaded
Open this post in threaded view
|

Re: YieldCurve package

Joshua Ulrich
In reply to this post by jaimie villanueva
Hi Jaimie,

The YieldCurve package works much better if you use a time-series of
rates/maturities.  For example, using xts:

# create xts object with a custom "maturity" attribute
x <- xts(t(NEW.VECT.1[,2]), Sys.Date(), maturity=NEW.VECT.1[,1],
  dimnames=list(NULL, paste("X", NEW.VECT.1[,1], sep="")))
xNSParam <- Nelson.Siegel(rate=x, maturity=attr(x,'maturity'))
xFitted <- NSrates(xNSParam, attr(x,'maturity'))

If you just want your code to work, convert NSParameters to xts before
you call NSrates:
fitted.rates= NSrates(xts(NSParameters,Sys.Date()), NEW.VECT.1[,1])

Best,
--
Joshua Ulrich  |  about.me/joshuaulrich
FOSS Trading  |  www.fosstrading.com


On Sun, Aug 11, 2013 at 10:56 AM, jaimie villanueva
<[hidden email]> wrote:

> Hi there,
>
> I'm facing some problems since I've updated  the YieldCurve package from <<
> YieldCurve_4.0 >> to << YieldCurve_4.1 >>
>
> I would like to get Nelson Siegel rates. To do so, I'm using
> "Nelson.Siegel" function in order to compute beta and lambda parameters and
> "NSrates" function to compute Nelson Siegel rates. The thing is that the
> following code I'm about to show You, did work in the past with my older
> version of the package, but It doesn't work now.
>
> The problem occurs when setting up Nelson Siegel function:
>
> This is the code:
>
>> Sys.info()
>                      sysname                      release
>    version
>                    "Windows"                      "7 x64" "build 7601,
> Service Pack 1"
>                     nodename                      machine
>      login
>                     "JVC-PC"                     "x86-64"
>      "JVC"
>                         user               effective_user
>                        "JVC"                        "JVC"
>
>   library(RODBC)
>>  library(TSA)
>>  library(grDevices)
>>  library(YieldCurve)
>>  library(xts)
>>
>>
>>  #########  CONFIGURACIÓN INICIAL
>>  #
>>
>>  plazos.NG=array(c(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,
> + 21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,
> + 42,43,44,45,46,47,48,49,50))
>>
>>
>  CURVA.EUR=array(c(1.415943,1.302205,1.380278,1.533634,1.725201,1.920058,2.083162,2.214956,
> +   2.32518,2.422087,2.591747,2.735049,2.739023,2.644585,2.543769))
>>
>>  m=length(plazos.NG)
>>  CURVA.EUR.NG=array(NA,c(m))
>>  plazos.EUR=array(c(1,2,3,4,5,6,7,8,9,10,12,15,20,25,30))
>>
>>  #
>>  #########
>>
>>  NEW.VECT.1=cbind(plazos.NG,CURVA.EUR.NG)
>>  NEW.VECT.2=cbind(plazos.EUR,CURVA.EUR)
>>
>>
>>  # CREAMOS EL VECTOR CON TIPOS
>>
>>  l= length(plazos.EUR)
>>  posicX=1
>>  posicY=1
>>
>>  for(k in 1:l)
> +  {
> + # BUSCAMOS LA POSICION DE CADA PUNTO DE LA CURVA.
> +
> + while(NEW.VECT.1[posicY,1]!= NEW.VECT.2[posicX,1]){posicY=posicY+1}
> + NEW.VECT.1[posicY,2]=NEW.VECT.2[posicX,2]
> + posicX=posicX+1
> + posicY=posicY+1
> +
> +  }
>>
>>  NSParameters= Nelson.Siegel(rate=NEW.VECT.1[,2],maturity=NEW.VECT.1[,1])
>>  fitted.rates= NSrates(NSParameters, NEW.VECT.1[,1])
>
> *Error in xts(matrix(0, nrow(Coeff), length(maturity)), order.by =
> time(Coeff)) : *
> *  order.by requires an appropriate time-based object*
> *
> *
> Any help would be kindly appreciated.
> Thanks in advance.
>
> --
> *Jaimie.*
>
>         [[alternative HTML version deleted]]
>
>
> _______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> -- Subscriber-posting only. If you want to post, subscribe first.
> -- Also note that this is not the r-help list where general R questions should go.

_______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-sig-finance
-- Subscriber-posting only. If you want to post, subscribe first.
-- Also note that this is not the r-help list where general R questions should go.
Reply | Threaded
Open this post in threaded view
|

Re: YieldCurve package

jaimie villanueva
Hi Joshua,

Thanks for Your advice. It's been really helpful.

Best.

Jaimie.

On Mon, Aug 12, 2013 at 6:37 PM, Joshua Ulrich <[hidden email]>wrote:

> Hi Jaimie,
>
> The YieldCurve package works much better if you use a time-series of
> rates/maturities.  For example, using xts:
>
> # create xts object with a custom "maturity" attribute
> x <- xts(t(NEW.VECT.1[,2]), Sys.Date(), maturity=NEW.VECT.1[,1],
>   dimnames=list(NULL, paste("X", NEW.VECT.1[,1], sep="")))
> xNSParam <- Nelson.Siegel(rate=x, maturity=attr(x,'maturity'))
> xFitted <- NSrates(xNSParam, attr(x,'maturity'))
>
> If you just want your code to work, convert NSParameters to xts before
> you call NSrates:
> fitted.rates= NSrates(xts(NSParameters,Sys.Date()), NEW.VECT.1[,1])
>
> Best,
> --
> Joshua Ulrich  |  about.me/joshuaulrich
> FOSS Trading  |  www.fosstrading.com
>
>
> On Sun, Aug 11, 2013 at 10:56 AM, jaimie villanueva
> <[hidden email]> wrote:
> > Hi there,
> >
> > I'm facing some problems since I've updated  the YieldCurve package from
> <<
> > YieldCurve_4.0 >> to << YieldCurve_4.1 >>
> >
> > I would like to get Nelson Siegel rates. To do so, I'm using
> > "Nelson.Siegel" function in order to compute beta and lambda parameters
> and
> > "NSrates" function to compute Nelson Siegel rates. The thing is that the
> > following code I'm about to show You, did work in the past with my older
> > version of the package, but It doesn't work now.
> >
> > The problem occurs when setting up Nelson Siegel function:
> >
> > This is the code:
> >
> >> Sys.info()
> >                      sysname                      release
> >    version
> >                    "Windows"                      "7 x64" "build 7601,
> > Service Pack 1"
> >                     nodename                      machine
> >      login
> >                     "JVC-PC"                     "x86-64"
> >      "JVC"
> >                         user               effective_user
> >                        "JVC"                        "JVC"
> >
> >   library(RODBC)
> >>  library(TSA)
> >>  library(grDevices)
> >>  library(YieldCurve)
> >>  library(xts)
> >>
> >>
> >>  #########  CONFIGURACIÓN INICIAL
> >>  #
> >>
> >>  plazos.NG=array(c(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,
> > + 21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,
> > + 42,43,44,45,46,47,48,49,50))
> >>
> >>
> >
>  CURVA.EUR=array(c(1.415943,1.302205,1.380278,1.533634,1.725201,1.920058,2.083162,2.214956,
> > +   2.32518,2.422087,2.591747,2.735049,2.739023,2.644585,2.543769))
> >>
> >>  m=length(plazos.NG)
> >>  CURVA.EUR.NG=array(NA,c(m))
> >>  plazos.EUR=array(c(1,2,3,4,5,6,7,8,9,10,12,15,20,25,30))
> >>
> >>  #
> >>  #########
> >>
> >>  NEW.VECT.1=cbind(plazos.NG,CURVA.EUR.NG)
> >>  NEW.VECT.2=cbind(plazos.EUR,CURVA.EUR)
> >>
> >>
> >>  # CREAMOS EL VECTOR CON TIPOS
> >>
> >>  l= length(plazos.EUR)
> >>  posicX=1
> >>  posicY=1
> >>
> >>  for(k in 1:l)
> > +  {
> > + # BUSCAMOS LA POSICION DE CADA PUNTO DE LA CURVA.
> > +
> > + while(NEW.VECT.1[posicY,1]!= NEW.VECT.2[posicX,1]){posicY=posicY+1}
> > + NEW.VECT.1[posicY,2]=NEW.VECT.2[posicX,2]
> > + posicX=posicX+1
> > + posicY=posicY+1
> > +
> > +  }
> >>
> >>  NSParameters=
> Nelson.Siegel(rate=NEW.VECT.1[,2],maturity=NEW.VECT.1[,1])
> >>  fitted.rates= NSrates(NSParameters, NEW.VECT.1[,1])
> >
> > *Error in xts(matrix(0, nrow(Coeff), length(maturity)), order.by =
> > time(Coeff)) : *
> > *  order.by requires an appropriate time-based object*
> > *
> > *
> > Any help would be kindly appreciated.
> > Thanks in advance.
> >
> > --
> > *Jaimie.*
> >
> >         [[alternative HTML version deleted]]
> >
> >
> > _______________________________________________
> > [hidden email] mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> > -- Subscriber-posting only. If you want to post, subscribe first.
> > -- Also note that this is not the r-help list where general R questions
> should go.
>


--
*Jaimie.*

        [[alternative HTML version deleted]]


_______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-sig-finance
-- Subscriber-posting only. If you want to post, subscribe first.
-- Also note that this is not the r-help list where general R questions should go.