I need to do a rolling estimation of a GARCH(1,1), outputting 1-day ahead forecast for the conditional variance.
I have 2869 observations a need a rolling window of 783. Therefor the first estimated GARCH should be based on observation 1 through 783, outputting a forecasted conditional variance for observation 784. Hereafter a new estimation based on 2 through 784, forecasting a conditional variance for observation 785 etc etc.
From other studies I have pieced together this code:
Code: Select all
load var 'workfile with a return series called "return" containing 2869 observations
scalar noobs=2869
scalar nw=783
matrix(2869,1) results
for !i=nw to noobs
smpl !i-nw !i
equation garch_n
garch_n.ARCH(1,1) return
smpl !i !i
garch_n.forecast se var
scalar condvari_n = var
smpl @all
results(!i,1)=condvari_n
next
Secondly, I am looking into simulating a GARCH model 1000 times, calculating a return and finding the 5% quantile of the 1000 simulations. My code looks like this:
Code: Select all
matrix(!sim,1) var_n
matrix(1,1) result
'SIMULATE
!m=1000
for !sim=1 to !m
equation garch_n
garch_n.ARCH(1,1) return
scalar omega_n = garch_n.@coefs(1)
scalar alpha_n = garch_n.@coefs(2)
scalar beta_n = garch_n.@coefs(3)
series z = nrnd
series sigmat2_n = omega_n + (alpha_n * z(-1)^2) + (beta_n * sigmat2_n(-1))
series r_n = z*@sqrt(sigmat2_n)
var_n(!sim)=r_n
next
result=@quantile(var_n, 0.05)
