This is an example of the simulation of a multivariate (DVECH) GARCH process. This is a mean zero process. A more complicated example with a similar GARCH error process, but with a VAR mean model can be found at VARGARCHSIMULATE.RPF.

This sets the number of observations and number of variables:

compute nobs=500

compute n=2

This sets up the control parameters for the GARCH process—as a DVECH process, the C, A and B are all n×nSYMMETRIC matrices, so only the lower triangle needs to be specified. If you want a process larger than 2 variables, you'll need to expand these matrices to the proper dimension:

dec symm vc(n,n) va(n,n) vb(n,n)

compute vc=||.05|.01,.05||

compute va=||.08|.05,.08||

compute vb=||.90|.85,.90||

This computes the stationary covariance matrix. Because this is a DVECH, this can be done element by element.

dec symm h0(n,n)

ewise h0(i,j)=vc(i,j)/(1-va(i,j)-vb(i,j))

This creates the formulas which simulate the mean zero DVECH process. HF will compute the variance given the lagged outer product of residuals (UU) and lagged variance (H); HU (in order)

- computes the covariance matrix
- does mean zero normal draws with the just computed covariance matrix using %RANMVNORMAL
- computes and saves the outer product of the residuals using %OUTERXX
- saves the residuals into the elements of the VEC[SERIES] U using %PT
- returns the covariance matrix as the final value of the FRML

frml hf = vc+va.*uu{1}+vb.*h{1}

frml hu = hx=hf,ux=%ranmvnormal(%decomp(hx)),uu=%outerxx(ux),%pt(u,t,ux),hx

This initializes the outer product and variance series to the stationary variance of the process, then simulates the process from entries 2 on. The series are generated as a side effect in the calculation of HU.

gset uu = h0

gset h = h0

*

* Generate starting in entry 2. This creates the simulated GARCH process

* as a side effect of generating the sequence of covariance matrices.

*

gset h 2 nobs = hu(t)

These graph the two simulated series and extract and graph the simulated variance of the first series. The results depend upon random number and so will differ from run to run unless you use the SEED instruction.

graph(footer="First simulated series")

# u(1)

graph(footer="Second simulated series")

# u(2)

set h11 = h(t)(1,1)

graph(footer="Simulated variance for first series")

# h11

Full Program

compute nobs=500 compute n=2 * all nobs * * u is the simulated GARCH process * dec vect[series] u(n) * * H is the series of variance matrices, UU is the series of lagged outer * products of the residuals. * dec series[symm] h uu dec symm vc(n,n) va(n,n) vb(n,n) compute vc=||.05|.01,.05|| compute va=||.05|.05,.05|| compute vb=||.90|.85,.90|| * * Compute the stationary variance * dec symm h0(n,n) ewise h0(i,j)=vc(i,j)/(1-va(i,j)-vb(i,j)) * dec frml[symm] hf hu dec symm hx dec vect ux * frml hf = vc+va.*uu{1}+vb.*h{1} frml hu = hx=hf,ux=%ranmvnormal(%decomp(hx)),uu=%outerxx(ux),%pt(u,t,ux),hx * * Initialize the UU and H series for the pre-sample values * gset uu = h0 gset h = h0 * * Generate starting in entry 2. * gset h 2 500 = hu(t) * * Graph the series and variance series * graph(footer="First simulated series") # u(1) graph(footer="Second simulated series") # u(2) set h11 = h(t)(1,1) graph(footer="Simulated variance for first series") # h11

Graphs