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 GARCH(p,q)$\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 GARCH(p,q)$\text{GARCH}\left(p,q\right)$ process is represented by:
 q p ht = α0 + ∑ (αi + γIt − i)εt − i2 + ∑ βiht − i,  t = 1,2, … ,T; i = 1 i = 1
$ht = α0 + ∑i=1q ( αi + γ It-i ) ε t-i 2 + ∑ i=1 p βi ht-i , t=1,2,…,T ;$
where It = 1${I}_{t}=1$ if εt < 0${\epsilon }_{t}<0$, It = 0${I}_{t}=0$ if εt0${\epsilon }_{t}\ge 0$, and εtψt1 = N(0,ht)${\epsilon }_{t}\mid {\psi }_{t-1}=N\left(0,{h}_{t}\right)$ or εtψt1 = St(df,ht)${\epsilon }_{t}\mid {\psi }_{t-1}={S}_{t}\left(\mathit{df},{h}_{t}\right)$. Here St${S}_{t}$ is a standardized Student's t$t$-distribution with df$\mathit{df}$ degrees of freedom and variance ht${h}_{t}$, T$T$ is the number of observations in the sequence, εt${\epsilon }_{t}$ is the observed value of the GARCH(p,q)$\text{GARCH}\left(p,q\right)$ process at time t$t$, ht${h}_{t}$ is the conditional variance at time t$t$, and ψt${\psi }_{t}$ the set of all information up to time t$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:     dist – string (length ≥ 1)
The type of distribution to use for εt${\epsilon }_{t}$.
dist = 'N'${\mathbf{dist}}=\text{'N'}$
A Normal distribution is used.
dist = 'T'${\mathbf{dist}}=\text{'T'}$
A Student's t$t$-distribution is used.
Constraint: dist = 'N'${\mathbf{dist}}=\text{'N'}$ or 'T'$\text{'T'}$.
2:     num – int64int32nag_int scalar
T$T$, the number of terms in the sequence.
Constraint: num > 0${\mathbf{num}}>0$.
3:     ip – int64int32nag_int scalar
The number of coefficients, βi${\beta }_{\mathit{i}}$, for i = 1,2,,p$\mathit{i}=1,2,\dots ,p$.
Constraint: ip0${\mathbf{ip}}\ge 0$.
4:     iq – int64int32nag_int scalar
The number of coefficients, αi${\alpha }_{\mathit{i}}$, for i = 1,2,,q$\mathit{i}=1,2,\dots ,q$.
Constraint: iq1${\mathbf{iq}}\ge 1$.
5:     theta(iq + ip + 1${\mathbf{iq}}+{\mathbf{ip}}+1$) – double array
The first element must contain the coefficient αo${\alpha }_{o}$, the next iq elements must contain the coefficients αi${\alpha }_{\mathit{i}}$, for i = 1,2,,q$\mathit{i}=1,2,\dots ,q$. The remaining ip elements must contain the coefficients βj${\beta }_{\mathit{j}}$, for j = 1,2,,p$\mathit{j}=1,2,\dots ,p$.
Constraints:
• i = 2iq + ip + 1 theta(i) < 1.0$\sum _{\mathit{i}=2}^{{\mathbf{iq}}+{\mathbf{ip}}+1}{\mathbf{theta}}\left(\mathit{i}\right)<1.0$;
• theta(i)0.0${\mathbf{theta}}\left(\mathit{i}\right)\ge 0.0$, for i = 1$i=1$ and i = iq + 2,,iq + ip + 1$i={\mathbf{iq}}+2,\dots ,{\mathbf{iq}}+{\mathbf{ip}}+1$.
6:     gamma – double scalar
The asymmetry parameter γ$\gamma$ for the GARCH(p,q)$\text{GARCH}\left(p,q\right)$ sequence.
Constraint: gamma + theta(i)0.0${\mathbf{gamma}}+{\mathbf{theta}}\left(\mathit{i}\right)\ge 0.0$, for i = 2,3,,iq + 1$\mathit{i}=2,3,\dots ,{\mathbf{iq}}+1$.
7:     df – int64int32nag_int scalar
The number of degrees of freedom for the Student's t$t$-distribution.
If dist = 'N'${\mathbf{dist}}=\text{'N'}$, df is not referenced.
Constraint: if dist = 'T'${\mathbf{dist}}=\text{'T'}$, df > 2${\mathbf{df}}>2$.
8:     fcall – logical scalar
If fcall = true${\mathbf{fcall}}=\mathbf{true}$, a new sequence is to be generated, otherwise a given sequence is to be continued using the information in r.
9:     r(lr) – double array
lr, the dimension of the array, must satisfy the constraint lr2 × (ip + iq + 2)${\mathbf{lr}}\ge 2×\left({\mathbf{ip}}+{\mathbf{iq}}+2\right)$.
The array contains information required to continue a sequence if fcall = false${\mathbf{fcall}}=\mathbf{false}$.
10:   state( : $:$) – 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:     lr – int64int32nag_int scalar
Default: The dimension of the array r.
The dimension of the array r as declared in the (sub)program from which nag_rand_times_garch_gjr (g05pf) is called.
Constraint: lr2 × (ip + iq + 2)${\mathbf{lr}}\ge 2×\left({\mathbf{ip}}+{\mathbf{iq}}+2\right)$.

None.

### Output Parameters

1:     ht(num) – double array
The conditional variances ht${h}_{\mathit{t}}$, for t = 1,2,,T$\mathit{t}=1,2,\dots ,T$, for the GARCH(p,q)$\text{GARCH}\left(p,q\right)$ sequence.
2:     et(num) – double array
The observations εt${\epsilon }_{\mathit{t}}$, for t = 1,2,,T$\mathit{t}=1,2,\dots ,T$, for the GARCH(p,q)$\text{GARCH}\left(p,q\right)$ sequence.
3:     r(lr) – double array
Contains information that can be used in a subsequent call of nag_rand_times_garch_gjr (g05pf), with fcall = false${\mathbf{fcall}}=\mathbf{false}$.
4:     state( : $:$) – 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 updated information on the state of the generator.
5:     ifail – int64int32nag_int scalar
${\mathrm{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:
ifail = 1${\mathbf{ifail}}=1$
 On entry, dist ≠ 'N'${\mathbf{dist}}\ne \text{'N'}$ or 'T'$\text{'T'}$.
ifail = 2${\mathbf{ifail}}=2$
 On entry, num < 0${\mathbf{num}}<0$.
ifail = 3${\mathbf{ifail}}=3$
 On entry, ip < 0${\mathbf{ip}}<0$.
ifail = 4${\mathbf{ifail}}=4$
 On entry, iq < 1${\mathbf{iq}}<1$.
ifail = 5${\mathbf{ifail}}=5$
 On entry, α0 < 0${\alpha }_{0}<0$, or αi + γ < 0${\alpha }_{i}+\gamma <0$ for some αi${\alpha }_{i}$.
ifail = 51${\mathbf{ifail}}=51$
On entry, βi < 0${\beta }_{i}<0$ for some βi${\beta }_{i}$.
ifail = 52${\mathbf{ifail}}=52$
On entry, i = 1qαi + i = 1pβi1$\sum _{i=1}^{q}{\alpha }_{i}+\sum _{i=1}^{p}{\beta }_{i}\ge 1$.
ifail = 7${\mathbf{ifail}}=7$
 On entry, dist = 'T'${\mathbf{dist}}=\text{'T'}$ and df ≤ 2${\mathbf{df}}\le 2$.
ifail = 11${\mathbf{ifail}}=11$
The value of ip or iq is not the same as when r was set up in a previous call.
ifail = 12${\mathbf{ifail}}=12$
 On entry, lr < 2 × (ip + iq + 2)${\mathbf{lr}}<2×\left({\mathbf{ip}}+{\mathbf{iq}}+2\right)$.
ifail = 13${\mathbf{ifail}}=13$
 On entry, state vector was not initialized or has been corrupted.

Not applicable.

None.

## Example

```function nag_rand_times_garch_gjr_example
% Initialize the seed
seed = [int64(1762543)];
% genid and subid identify the base generator
genid = int64(1);
subid =  int64(1);

dist = 'N';
num = 10;
ip = 1;
iq = 1;
theta = [0.4; 0.1; 0.7];
gamma = 0.1;
df = int64(0);
fcall = true;
r = zeros(2*(ip+iq+2),1);
% Initialize the generator to a repeatable sequence
[state, ifail] = nag_rand_init_repeat(genid, subid, seed);

% Generate the first realisation
[ht, et, r, state, ifail] = nag_rand_times_garch_gjr(dist, int64(num), int64(ip), int64(iq), ...
theta, gamma, df, fcall, r, state);
% Display the results
if ifail == 0
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
else
fprintf('\n nag_rand_times_garch_gjr exited with ifail = %d \n', ifail);
end

% Generate a second realisation
fcall = false;
[ht, et, r, state, ifail] = nag_rand_times_garch_gjr(dist, int64(num), int64(ip), int64(iq), ...
theta, gamma, df, fcall, r, state);
% Display the results
if ifail == 0
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
else
fprintf('\n nag_rand_times_garch_gjr exited with ifail = %d \n', ifail);
end
```
```

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

```
```function g05pf_example
% Initialize the seed
seed = [int64(1762543)];
% genid and subid identify the base generator
genid = int64(1);
subid =  int64(1);

dist = 'N';
num = 10;
ip = 1;
iq = 1;
theta = [0.4; 0.1; 0.7];
gamma = 0.1;
df = int64(0);
fcall = true;
r = zeros(2*(ip+iq+2),1);
% Initialize the generator to a repeatable sequence
[state, ifail] = g05kf(genid, subid, seed);

% Generate the first realisation
[ht, et, r, state, ifail] = g05pf(dist, int64(num), int64(ip), int64(iq), ...
theta, gamma, df, fcall, r, state);
% Display the results
if ifail == 0
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
else
fprintf('\n g05pf exited with ifail = %d \n', ifail);
end

% Generate a second realisation
fcall = false;
[ht, et, r, state, ifail] = g05pf(dist, int64(num), int64(ip), int64(iq), ...
theta, gamma, df, fcall, r, state);
% Display the results
if ifail == 0
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
else
fprintf('\n g05pf exited with ifail = %d \n', ifail);
end
```
```

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

```