[R] Basic R timeseries data manipulation
Benjamin Dickgiesser
dickgiesser at gmail.com
Mon Nov 20 19:54:51 CET 2006
Thx for the advise.
I came up with
at <- rt - (3.75101e-04 + 9.61877e-02 * lag(rt,1) - 2.48071e-02 * lag(rt,2))
sigma <- 7.86872e-07 + 7.37382e-02 sigma[-1] + 9.20691e-01 * lag(rt,1)
the first line seems to work but I am unsure how to calculate sigma.
Would I really have to create a loop to do the calculations?
Thx agian,
Benjamin
On 11/20/06, Prof Brian Ripley <ripley at stats.ox.ac.uk> wrote:
> On Mon, 20 Nov 2006, Benjamin Dickgiesser wrote:
>
> > To elaborate a bit, I fitted a AR(2)-Garch(1,1) model to the Dow Jones
> > log returns and am now trying to calculate the variance suggested by
> > the model.
> >
> > #Get log returns
> > rt <- diff(log(getStock(1)$value))
> > #Fit Garch(1,1) and AR(2)
> > fit = garchFit(~arma(2,0), ~garch(1,1), series = rt)
> >
> > #Coefficient(s):
> > # mu ar1 ar2 omega alpha1
> > beta1
> > # 3.75101e-04 9.61877e-02 -2.48071e-02 7.86872e-07 7.37382e-02
> > 9.20691e-01
> >
> > Now I was trying to something in the lines of:
> > n <- length(rt) - 2
> > at <- vector(length = n)
>
> That line does nothing useful: 'at' is discarded at the next.
>
> > at <- rt - (3.75101e-04 + 9.61877e-02 rt[-1] - 2.48071e-02 rt[-2])
> > var <- 7.86872e-07 + 7.37382e-02 sigma[-1] + 9.20691e-01 rt[-1]
> >
> > which doesn't work..
>
> Since in R you write a*b and not a b, you will get a syntax error. Beyond
> that, for a time series rt[-1] may not be what you expect (it is not a
> time series, for example), rt[-2] is not a lagged version of the
> original series, and sigma is undefined.
>
> I suggest you explore filter(), lag() and ts.intersect().
>
> --
> Brian D. Ripley, ripley at stats.ox.ac.uk
> Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
> University of Oxford, Tel: +44 1865 272861 (self)
> 1 South Parks Road, +44 1865 272866 (PA)
> Oxford OX1 3TG, UK Fax: +44 1865 272595
>
More information about the R-help
mailing list