[R-SIG-Finance] garchFit and garchSim

Andrey Riabushenko cdome at bk.ru
Sat May 17 14:32:10 CEST 2008


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 at fit$matcoef[,1]
	mu = params[1]
	omega = params[2]
	alpha = params[3]
	beta = params[4]

	presample = cbind(residuals(model, standardize =TRUE), model at 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 at bk.ru>
> To: michal miklovic <mmiklovic at yahoo.com>; r-sig-finance at 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 at fit$matcoef[,1]
> mu = params[1]
> omega = params[2]
> alpha = params[3]
> beta = params[4]
>
> presample = cbind(returns, residuals(model, standardize =TRUE), model at 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 at 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



More information about the R-SIG-Finance mailing list