# ugarchsim

Simulate univariate GARCH(P,Q) process with Gaussian innovations

## Syntax

```[U, H] = ugarchsim(Kappa, Alpha, Beta, NumSamples)
```

## Arguments

 `Kappa` Scalar constant term [[KAPPA]] of the GARCH process. `Alpha` `P`-by-`1` vector of coefficients, where `P` is the number of lags of the conditional variance included in the GARCH process. `Alpha` can be an empty matrix, in which case `P` is assumed 0; when `P = 0`, a GARCH(0,Q) process is actually an ARCH(Q) process. `Beta` `Q`-by-`1` vector of coefficients, where `Q` is the number of lags of the squared innovations included in the GARCH process. `NumSamples` Positive, scalar integer indicating the number of samples of the innovations `U` and conditional variance `H` (see below) to simulate.

## Description

`[U, H] = ugarchsim(Kappa, Alpha, Beta, NumSamples)` simulates a univariate GARCH(P,Q) process with Gaussian innovations.

`U` is a number of samples (`NUMSAMPLES`)-by-`1` vector of innovations (ɛt), representing a mean-zero, discrete-time stochastic process. The innovations time series `U` is designed to follow the GARCH(P,Q) process specified by the inputs `Kappa`, `Alpha`, and `Beta`.

`H` is a `NUMSAMPLES`-by-1 vector of the conditional variances ( ) corresponding to the innovations vector `U`. Note that `U` and `H` are the same length, and form a "matching" pair of vectors. As shown in the following equation, ${\sigma }_{t}^{2}$ (that is, `H(t)`) represents the time series inferred from the innovations time series {ɛt} (that is, `U`).

The time-conditional variance, ${\sigma }_{t}^{2}$, of a GARCH(P,Q) process is modeled as

${\sigma }_{t}^{2}=K+\sum _{i=1}^{P}{\alpha }_{i}{\sigma }_{t-i}^{2}+\sum _{j=1}^{Q}{\beta }_{j}{\epsilon }_{t-j}^{2},$

where α represents the argument `Alpha`, β represents `Beta`, and the GARCH(P,Q) coefficients {Κ, α, β} are subject to the following constraints.

$\begin{array}{l}\sum _{i=1}^{P}{\alpha }_{i}+\sum _{j=1}^{Q}{\beta }_{j}<1\\ K>0\\ \begin{array}{cc}{\alpha }_{i}\ge 0& i=1,2,\dots ,P\\ {\beta }_{j}\ge 0& j=1,2,\dots ,Q.\end{array}\end{array}$

Note that `U` is a vector of residuals or innovations (ɛt) of an econometric model, representing a mean-zero, discrete-time stochastic process.

Although ${\sigma }_{t}^{2}$ is generated using the equation above, ɛt and ${\sigma }_{t}^{2}$ are related as

${\epsilon }_{t}={\sigma }_{t}{\upsilon }_{t},$

where $\left\{{\upsilon }_{t}\right\}$ is an independent, identically distributed (iid) sequence ~ N(0,1).

The output vectors `U` and `H` are designed to be steady-state sequences in which transients have arbitrarily small effect. The (arbitrary) metric used by `ugarchsim` strips the first `N` samples of `U` and `H` such that the sum of the GARCH coefficients, excluding `Kappa`, raised to the `N`th power, does not exceed 0.01.

``` 0.01 = (sum(Alpha) + sum(Beta))^N ```

Thus

``` N = log(0.01)/log((sum(Alpha) + sum(Beta))) ```
 Note   The Econometrics Toolbox™ software provides a comprehensive and integrated computing environment for the analysis of volatility in time series. For information see the Econometrics Toolbox documentation or the financial products Web page at `http://www.mathworks.com/products/finprod/`.

## Examples

This example simulates a GARCH(P,Q) process with ```P = 2``` and `Q = 1`.

```% Set the random number generator seed for reproducability. rng('default') % Set the simulation parameters of GARCH(P,Q) = GARCH(2,1) process. Kappa = 0.25; %a positive scalar. Alpha = [0.2 0.1]'; %a column vector of nonnegative numbers (P = 2). Beta = 0.4; % Q = 1. NumSamples = 500; % number of samples to simulate. % Now simulate the process. [U , H] = ugarchsim(Kappa, Alpha, Beta, NumSamples); % Estimate the process parameters. P = 2; % Model order P (P = length of Alpha). Q = 1; % Model order Q (Q = length of Beta). [k, a, b] = ugarch(U , P , Q); disp(' ') disp(' Estimated Coefficients:') disp(' -----------------------') disp([k; a; b]) disp(' ') % Forecast the conditional variance using the estimated % coefficients. NumPeriods = 10; % Forecast out to 10 periods. [VarianceForecast, H1] = ugarchpred(U, k, a, b, NumPeriods); disp(' Variance Forecasts:') disp(' ------------------') disp(VarianceForecast) disp(' ') ```

When the above code is executed, the screen output looks like the display shown.

```____________________________________________________________ Diagnostic Information Number of variables: 4 Functions Objective: ugarchllf Gradient: finite-differencing Hessian: finite-differencing (or Quasi-Newton) Constraints Nonlinear constraints: do not exist Number of linear inequality constraints: 1 Number of linear equality constraints: 0 Number of lower bound constraints: 4 Number of upper bound constraints: 0 Algorithm selected medium-scale: SQP, Quasi-Newton, line-search ____________________________________________________________ End diagnostic information Max Line search Directional First-order Iter F-count f(x) constraint steplength derivative optimality Procedure 0 5 625.735 -0.05 1 12 611.683 -0.05614 0.25 -146 411 2 18 609.396 -0.0375 0.5 -98.1 94.8 3 24 600.17 -0.07969 0.5 -61.9 56.1 4 31 598.818 -0.05977 0.25 -24 27.9 5 38 598.308 -0.04482 0.25 -12.4 42.9 6 43 598.247 0 1 -15.7 23.9 7 48 598.02 0 1 -22.3 3.59 8 57 598.01 -0.02759 0.0625 -2.03 3.89 9 62 597.999 -0.01749 1 -1.48 0.249 10 67 597.999 -0.01638 1 -0.15 0.0365 11 72 597.999 -0.0164 1 -0.0269 0.00774 Hessian modified Local minimum possible. Constraints satisfied. fmincon stopped because the predicted change in the objective function is less than the default value of the function tolerance and constraints are satisfied to within the default value of the constraint tolerance. No active inequalities. Estimated Coefficients: ----------------------- 0.2868 0.1984 0.0164 0.4076 Variance Forecasts: ------------------ 0.4130 0.5453 0.6240 0.6740 0.7055 0.7254 0.7380 0.7460 0.7510 0.7542```

## References

James D. Hamilton, Time Series Analysis, Princeton University Press, 1994