Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

Chapter Contents
Chapter Introduction
NAG Toolbox

# NAG Toolbox: nag_rand_times_garch_gjr (g05pf)

## Purpose

nag_rand_times_garch_gjr (g05pf) generates a given number of terms of a GJR $\text{GARCH}\left(p,q\right)$ process (see Glosten et al. (1993)).

## Syntax

[ht, et, r, state, ifail] = g05pf(dist, num, ip, iq, theta, gamma, df, fcall, r, state, 'lr', lr)
[ht, et, r, state, ifail] = nag_rand_times_garch_gjr(dist, num, ip, iq, theta, gamma, df, fcall, r, state, 'lr', lr)

## Description

A GJR $\text{GARCH}\left(p,q\right)$ process is represented by:
 $ht = α0 + ∑i=1q αi + γ It-i ε t-i 2 + ∑ i=1 p βi ht-i , t=1,2,…,T ;$
where ${I}_{t}=1$ if ${\epsilon }_{t}<0$, ${I}_{t}=0$ if ${\epsilon }_{t}\ge 0$, and ${\epsilon }_{t}\mid {\psi }_{t-1}=N\left(0,{h}_{t}\right)$ or ${\epsilon }_{t}\mid {\psi }_{t-1}={S}_{t}\left(\mathit{df},{h}_{t}\right)$. Here ${S}_{t}$ is a standardized Student's $t$-distribution with $\mathit{df}$ degrees of freedom and variance ${h}_{t}$, $T$ is the number of observations in the sequence, ${\epsilon }_{t}$ is the observed value of the $\text{GARCH}\left(p,q\right)$ process at time $t$, ${h}_{t}$ is the conditional variance at time $t$, and ${\psi }_{t}$ the set of all information up to time $t$. Symmetric GARCH sequences are generated when $\gamma$ is zero, otherwise asymmetric GARCH sequences are generated with $\gamma$ specifying the amount by which negative shocks are to be enhanced.
One of the initialization functions nag_rand_init_repeat (g05kf) (for a repeatable sequence if computed sequentially) or nag_rand_init_nonrepeat (g05kg) (for a non-repeatable sequence) must be called prior to the first call to nag_rand_times_garch_gjr (g05pf).

## References

Bollerslev T (1986) Generalised autoregressive conditional heteroskedasticity Journal of Econometrics 31 307–327
Engle R (1982) Autoregressive conditional heteroskedasticity with estimates of the variance of United Kingdom inflation Econometrica 50 987–1008
Engle R and Ng V (1993) Measuring and testing the impact of news on volatility Journal of Finance 48 1749–1777
Glosten L, Jagannathan R and Runkle D (1993) Relationship between the expected value and the volatility of nominal excess return on stocks Journal of Finance 48 1779–1801
Hamilton J (1994) Time Series Analysis Princeton University Press

## Parameters

### Compulsory Input Parameters

1:     $\mathrm{dist}$ – string (length ≥ 1)
The type of distribution to use for ${\epsilon }_{t}$.
${\mathbf{dist}}=\text{'N'}$
A Normal distribution is used.
${\mathbf{dist}}=\text{'T'}$
A Student's $t$-distribution is used.
Constraint: ${\mathbf{dist}}=\text{'N'}$ or $\text{'T'}$.
2:     $\mathrm{num}$int64int32nag_int scalar
$T$, the number of terms in the sequence.
Constraint: ${\mathbf{num}}>0$.
3:     $\mathrm{ip}$int64int32nag_int scalar
The number of coefficients, ${\beta }_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,p$.
Constraint: ${\mathbf{ip}}\ge 0$.
4:     $\mathrm{iq}$int64int32nag_int scalar
The number of coefficients, ${\alpha }_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,q$.
Constraint: ${\mathbf{iq}}\ge 1$.
5:     $\mathrm{theta}\left({\mathbf{iq}}+{\mathbf{ip}}+1\right)$ – double array
The first element must contain the coefficient ${\alpha }_{o}$, the next iq elements must contain the coefficients ${\alpha }_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,q$. The remaining ip elements must contain the coefficients ${\beta }_{\mathit{j}}$, for $\mathit{j}=1,2,\dots ,p$.
Constraints:
• $\sum _{\mathit{i}=2}^{{\mathbf{iq}}+{\mathbf{ip}}+1}{\mathbf{theta}}\left(\mathit{i}\right)<1.0$;
• ${\mathbf{theta}}\left(\mathit{i}\right)\ge 0.0$, for $i=1$ and $i={\mathbf{iq}}+2,\dots ,{\mathbf{iq}}+{\mathbf{ip}}+1$.
6:     $\mathrm{gamma}$ – double scalar
The asymmetry parameter $\gamma$ for the $\text{GARCH}\left(p,q\right)$ sequence.
Constraint: ${\mathbf{gamma}}+{\mathbf{theta}}\left(\mathit{i}\right)\ge 0.0$, for $\mathit{i}=2,3,\dots ,{\mathbf{iq}}+1$.
7:     $\mathrm{df}$int64int32nag_int scalar
The number of degrees of freedom for the Student's $t$-distribution.
If ${\mathbf{dist}}=\text{'N'}$, df is not referenced.
Constraint: if ${\mathbf{dist}}=\text{'T'}$, ${\mathbf{df}}>2$.
8:     $\mathrm{fcall}$ – logical scalar
If ${\mathbf{fcall}}=\mathit{true}$, a new sequence is to be generated, otherwise a given sequence is to be continued using the information in r.
9:     $\mathrm{r}\left({\mathbf{lr}}\right)$ – double array
The array contains information required to continue a sequence if ${\mathbf{fcall}}=\mathit{false}$.
10:   $\mathrm{state}\left(:\right)$int64int32nag_int array
Note: the actual argument supplied must be the array state supplied to the initialization routines nag_rand_init_repeat (g05kf) or nag_rand_init_nonrepeat (g05kg).
Contains information on the selected base generator and its current state.

### Optional Input Parameters

1:     $\mathrm{lr}$int64int32nag_int scalar
Default: the dimension of the array r.
The dimension of the array r.
Constraint: ${\mathbf{lr}}\ge 2×\left({\mathbf{ip}}+{\mathbf{iq}}+2\right)$.

### Output Parameters

1:     $\mathrm{ht}\left({\mathbf{num}}\right)$ – double array
The conditional variances ${h}_{\mathit{t}}$, for $\mathit{t}=1,2,\dots ,T$, for the $\text{GARCH}\left(p,q\right)$ sequence.
2:     $\mathrm{et}\left({\mathbf{num}}\right)$ – double array
The observations ${\epsilon }_{\mathit{t}}$, for $\mathit{t}=1,2,\dots ,T$, for the $\text{GARCH}\left(p,q\right)$ sequence.
3:     $\mathrm{r}\left({\mathbf{lr}}\right)$ – double array
Contains information that can be used in a subsequent call of nag_rand_times_garch_gjr (g05pf), with ${\mathbf{fcall}}=\mathit{false}$.
4:     $\mathrm{state}\left(:\right)$int64int32nag_int array
Contains updated information on the state of the generator.
5:     $\mathrm{ifail}$int64int32nag_int scalar
${\mathbf{ifail}}={\mathbf{0}}$ unless the function detects an error (see Error Indicators and Warnings).

## Error Indicators and Warnings

Errors or warnings detected by the function:
${\mathbf{ifail}}=1$
On entry, dist is not valid.
${\mathbf{ifail}}=2$
Constraint: ${\mathbf{num}}\ge 0$.
${\mathbf{ifail}}=3$
Constraint: ${\mathbf{ip}}\ge 0$.
${\mathbf{ifail}}=4$
Constraint: ${\mathbf{iq}}\ge 1$.
${\mathbf{ifail}}=5$
Constraint: ${\alpha }_{i}+\gamma \ge 0$.
${\mathbf{ifail}}=7$
Constraint: ${\mathbf{df}}\ge 3$.
${\mathbf{ifail}}=11$
ip or iq is not the same as when r was set up in a previous call.
${\mathbf{ifail}}=12$
On entry, lr is not large enough, ${\mathbf{lr}}=_$: minimum length required .
${\mathbf{ifail}}=13$
On entry, state vector has been corrupted or not initialized.
${\mathbf{ifail}}=51$
Constraint: ${\mathbf{theta}}\left(i\right)\ge 0.0$.
${\mathbf{ifail}}=52$
Constraint: sum of ${\mathbf{theta}}\left(\mathit{i}\right)$, for $\mathit{i}=1,2,\dots ,{\mathbf{ip}}+{\mathbf{iq}}$ is $\text{}<1.0$.
${\mathbf{ifail}}=-99$
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.

Not applicable.

None.

## Example

This example first calls nag_rand_init_repeat (g05kf) to initialize a base generator then calls nag_rand_times_garch_gjr (g05pf) to generate two realizations, each consisting of ten observations, from a GJR $\mathrm{GARCH}\left(1,1\right)$ model.
```function g05pf_example

fprintf('g05pf example results\n\n');

% Initialize the generator to a repeatable sequence
seed  = [int64(1762543)];
genid = int64(1);
subid = int64(1);
[state, ifail] = g05kf( ...
genid, subid, seed);

% Input parameters
dist  = 'N';
num   = int64(10);
ip    = int64(1);
iq    = int64(1);
theta = [0.4; 0.1; 0.7];
gamma = 0.1;
df    = int64(0);
fcall = true;
r     = zeros(2*(ip+iq+2),1);

% Generate the first realisation
[ht, et, r, state, ifail] = g05pf( ...
dist, num, ip, iq, theta,  ...
gamma, df, fcall, r, state);
% Display the results
fprintf('\n Realisation Number 1\n');
fprintf('   i            ht(i)            et(i)\n');
fprintf('  --------------------------------------\n');
for i=1:num
fprintf('  %2d  %16.4f %16.4f\n', i, ht(i), et(i));
end

% Generate a second realisation
fcall = false;
[ht, et, r, state, ifail] = g05pf( ...
dist, num, ip, iq, theta,  ...
gamma, df, fcall, r, state);
% Display the results
fprintf('\n Realisation Number 2\n');
fprintf('   i            ht(i)            et(i)\n');
fprintf('  --------------------------------------\n');
for i=1:num
fprintf('  %2d  %16.4f %16.4f\n', i, ht(i), et(i));
end

```
```g05pf example results

Realisation Number 1
i            ht(i)            et(i)
--------------------------------------
1            1.8000           0.4679
2            1.6819          -1.6152
3            2.0991           0.9592
4            1.9614           1.1701
5            1.9099          -1.7355
6            2.3393          -0.0289
7            2.0377          -0.4201
8            1.8617           1.0865
9            1.8212          -0.0061
10            1.6749           0.5754

Realisation Number 2
i            ht(i)            et(i)
--------------------------------------
1            1.6055          -2.0776
2            2.3872          -1.0034
3            2.2724           0.4756
4            2.0133          -2.2871
5            2.8554           0.4012
6            2.4149          -0.9125
7            2.2570          -1.0732
8            2.2102           3.7105
9            3.3239           2.3530
10            3.2804           0.1388
```