This simulates a univariate AR(1) with GARCH errors. A similar example in a multivariate setting is VARGARCHSIMULATE.RPF.

The model takes the form:

$$\begin{array}{l}{y_t} = \rho {y_{t - 1}} + {u_t} \\ {u_t} \sim N\left( {0,{h_t}} \right) \\ {h_t} = c + b{h_{t - 1}} + au_{t - 1}^2 \\\end{array}$$

These set the specific values used in the example:

compute cg=0.5

compute ag=.19

compute bg=.80

*

compute rho=.8

The GARCH part of the model is generated first. This uses U to hold the series of generated residuals, UU the squared residuals, and H the variances. The SET instruction does these sequentially by first computing H (which depends only upon the previous period's information), then U is randomized from the standard deviation derived from H, then UU is computed from U for use in the next period. UU and H are both initialized to the ergodic (stationary) variance of the GARCH process.

set uu = cg/(1-ag-bg)

set h  = uu

set u  = 0.0

*

set uu 2 nobs = h=cg+bg*h{1}+ag*uu{1},u=%ran(sqrt(h)),uu=u^2

The GARCH errors (U) are then used as the shocks in generating Y recursively. Y starts with a lag of zero, so the SET instruction runs from 2 on.

clear(zeros) y

set y 2 nobs = rho*y{1}+u

Note that the results will depend upon random numbers and so will be different if you run it.

Full Program

*
* GARCH parameters
*
compute cg=0.5
compute ag=.19
compute bg=.80
*
* AR parameter
*
compute rho=.8
*
compute nobs=1000
*
all nobs
*
* Initialize to the ergodic variance
*
set uu = cg/(1-ag-bg)
set h  = uu
set u  = 0.0
*
set uu 2 nobs = h=cg+bg*h{1}+ag*uu{1},u=%ran(sqrt(h)),uu=u^2
*
* Use GARCH residuals (u) as input to AR
*
clear(zeros) y
set y 2 nobs = rho*y{1}+u
graph(footer="Simulation of AR(1)-GARCH(1,1) model")
# y
*
garch(reg) / y
# constant y{1}


Graph

Output

These are the estimates of the GARCH model using the simulated data.

GARCH Model - Estimation by BFGS

Convergence in    28 Iterations. Final criterion was  0.0000016 <=  0.0000100

Dependent Variable Y

Usable Observations                       999

Log Likelihood                     -2921.6699

Variable                        Coeff      Std Error      T-Stat      Signif

************************************************************************************

1.  Constant                     0.1099163390 0.1119799663      0.98157  0.32631101

2.  Y{1}                         0.7989267149 0.0205495994     38.87797  0.00000000

3.  C                            0.2969545192 0.1224133653      2.42583  0.01527325

4.  A                            0.1629395693 0.0240381351      6.77838  0.00000000

5.  B                            0.8346786490 0.0207757113     40.17570  0.00000000