Hi Joshua,

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

Best.

Jaimie.

On Mon, Aug 12, 2013 at 6:37 PM, Joshua Ulrich <josh.m.ulrich@gmail.com>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
> <jaimie.villanueva@gmail.com> 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]]
> >
> >
> > _______________________________________________
> > R-SIG-Finance@r-project.org 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]]

