It is not a bug. It works fine for simulations which are not 'appended' to an existing series. But in your case, it leads to discarding one observation. I think it is possible to circumvent the problem by changing the source code as follows:
in GarchSimulation.R put # before the line "data = data[-(1:n.start),]" and recompile fGarch. I hope it works. If not, you have to find another workaround...

Michal



----- Original Message ----
From: Andrey Riabushenko <cdome@bk.ru>
To: michal miklovic <mmiklovic@yahoo.com>; r-sig-finance@stat.math.ethz.ch
Sent: Saturday, May 17, 2008 2:32:10 PM
Subject: Re: [R-SIG-Finance] garchFit and garchSim

Thank you Michal Miklovic, it is working now

Here is a working code

forecast_garch = function(returns, n.ahead) {
    returns = as.vector(returns)

    model = garchFit(~garch(1,1), data=returns)
    params = model@fit$matcoef[,1]
    mu = params[1]
    omega = params[2]
    alpha = params[3]
    beta = params[4]

    presample = cbind(residuals(model, standardize =TRUE), model@h.t, returns)
    spec = garchSpec(list(mu = mu, alpha = alpha, beta = beta, omega = omega), 
presample=presample)

    m = matrix(NA, n.ahead, MAX_SIM)

    for(i in 1:MAX_SIM) {
        m[,i] = as.vector(garchSim(spec, n=n.ahead+1, n.start = 0))
    }
    return(m)
}


The small little thing is left. if n if equal to 10 the garchSim returns 
series of length 9. That is way I have placed n = a.ahead + 1. Is this a bug?


I am using R-2.6.1 built from sources with ATLAS on FreeBSD 7.0, the version 
of fGarch is 260.72 (also built from source)


Thank you once again.



В сообщении от Saturday 17 May 2008 13:42:49 вы написали:
> Hi,
>
> the correct order in presample is: innovations, h.t and returns. Next, I
> think it is necessary to first define a model by garchSpec and then use the
> definition to simulate it, have a look at the documentation. Btw, you can
> put 'mu' into the definition instead of adding it to the simulated series.
> I would set n.start = 0 in case of 'extending' an analysed series by
> simulation. n.start should be used when you simulate a series that is not
> 'appended' to another series. Concerning the arma simulation, I had another
> look at it and now I understand what you are doing and I think it is OK.
> Sorry for the confusion. Next time you post a question to mailing list,
> please indicate the version of R and packages you are using. It could be
> helpful because some packages get updated quite frequently.
>
> Regards,
>
> Michal
>
>
>
>
> ----- Original Message ----
> From: Andrey Riabushenko <cdome@bk.ru>
> To: michal miklovic <mmiklovic@yahoo.com>; r-sig-finance@stat.math.ethz.ch
> Sent: Saturday, May 17, 2008 11:33:16 AM
> Subject: Re: [R-SIG-Finance] garchFit and garchSim
>
> Thanks a lot. I am making progress, but still some problems left
> I am running
>
> returns = as.vector(returns)
> model = garchFit(~garch(1,1), data=returns)
>
> params = model@fit$matcoef[,1]
> mu = params[1]
> omega = params[2]
> alpha = params[3]
> beta = params[4]
>
> presample = cbind(returns, residuals(model, standardize =TRUE), model@h.t)
>
> sim = mu + garchSim(list(alpha = alpha, beta = beta, omega = omega),
> n=n.ahead, n.start = length(returns), presample=presample)
>
> But what I get is
> head(sim)
> NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
>
> What it is wrong?
>
>
> Also it is not clear why arima simulation is wrong  if n.ahead > 1, I need
> more than 1 for my study?
>
> > The modeled series is readily available - in your case it is 'returns'.
> > h.t can be obtained by m@h.t and starting values for the innovations,
> > i.e. the standardised residuals, can be obtained by residuals(m,
> > standardize = TRUE).
> >
> > Hope this helps.
> >
> > Michal


      
	[[alternative HTML version deleted]]

