g13fa estimates the parameters of either a standard univariate regression GARCH process, or a univariate regression-type I $\text{AGARCH}\left(p,q\right)$ process (see Engle and Ng (1993)).

# Syntax

C#
```public static void g13fa(
string dist,
double[] yt,
double[,] x,
int num,
int ip,
int iq,
int nreg,
int mn,
int isym,
int npar,
double[] theta,
double[] se,
double[] sc,
double[,] covr,
ref double hp,
double[] et,
double[] ht,
out double lgf,
bool[] copts,
int maxit,
double tol,
out int ifail
)```
Visual Basic
```Public Shared Sub g13fa ( _
dist As String, _
yt As Double(), _
x As Double(,), _
num As Integer, _
ip As Integer, _
iq As Integer, _
nreg As Integer, _
mn As Integer, _
isym As Integer, _
npar As Integer, _
theta As Double(), _
se As Double(), _
sc As Double(), _
covr As Double(,), _
ByRef hp As Double, _
et As Double(), _
ht As Double(), _
<OutAttribute> ByRef lgf As Double, _
copts As Boolean(), _
maxit As Integer, _
tol As Double, _
<OutAttribute> ByRef ifail As Integer _
)```
Visual C++
```public:
static void g13fa(
String^ dist,
array<double>^ yt,
array<double,2>^ x,
int num,
int ip,
int iq,
int nreg,
int mn,
int isym,
int npar,
array<double>^ theta,
array<double>^ se,
array<double>^ sc,
array<double,2>^ covr,
double% hp,
array<double>^ et,
array<double>^ ht,
[OutAttribute] double% lgf,
array<bool>^ copts,
int maxit,
double tol,
[OutAttribute] int% ifail
)```
F#
```static member g13fa :
dist : string *
yt : float[] *
x : float[,] *
num : int *
ip : int *
iq : int *
nreg : int *
mn : int *
isym : int *
npar : int *
theta : float[] *
se : float[] *
sc : float[] *
covr : float[,] *
hp : float byref *
et : float[] *
ht : float[] *
lgf : float byref *
copts : bool[] *
maxit : int *
tol : float *
ifail : int byref -> unit
```

#### Parameters

dist
Type: System..::..String
On entry: the type of distribution to use for ${e}_{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"}$.
yt
Type: array<System..::..Double>[]()[][]
An array of size [num]
On entry: the sequence of observations, ${y}_{\mathit{t}}$, for $\mathit{t}=1,2,\dots ,T$.
x
Type: array<System..::..Double,2>[,](,)[,][,]
An array of size [dim1, dim2]
Note: dim1 must satisfy the constraint: $\mathrm{dim1}\ge {\mathbf{num}}$
Note: the second dimension of the array x must be at least ${\mathbf{nreg}}$.
On entry: row $\mathit{t}$ of x must contain the time dependent exogenous vector ${x}_{\mathit{t}}$, where ${x}_{\mathit{t}}^{\mathrm{T}}=\left({x}_{\mathit{t}}^{1},\dots ,{x}_{\mathit{t}}^{k}\right)$, for $\mathit{t}=1,2,\dots ,T$.
num
Type: System..::..Int32
On entry: $T$, the number of terms in the sequence.
Constraints:
• ${\mathbf{num}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left({\mathbf{ip}},{\mathbf{iq}}\right)$;
• ${\mathbf{num}}\ge {\mathbf{nreg}}+{\mathbf{mn}}$.
ip
Type: System..::..Int32
On entry: the number of coefficients, ${\beta }_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,p$.
Constraint: ${\mathbf{ip}}\ge 0$ (see also npar).
iq
Type: System..::..Int32
On entry: the number of coefficients, ${\alpha }_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,q$.
Constraint: ${\mathbf{iq}}\ge 1$ (see also npar).
nreg
Type: System..::..Int32
On entry: $k$, the number of regression coefficients.
Constraint: ${\mathbf{nreg}}\ge 0$ (see also npar).
mn
Type: System..::..Int32
On entry: if ${\mathbf{mn}}=1$, the mean term ${b}_{0}$ will be included in the model.
Constraint: ${\mathbf{mn}}=0$ or $1$.
isym
Type: System..::..Int32
On entry: if ${\mathbf{isym}}=1$, the asymmetry term $\gamma$ will be included in the model.
Constraint: ${\mathbf{isym}}=0$ or $1$.
npar
Type: System..::..Int32
On entry: the number of parameters to be included in the model. ${\mathbf{npar}}=1+{\mathbf{iq}}+{\mathbf{ip}}+{\mathbf{isym}}+{\mathbf{mn}}+{\mathbf{nreg}}$ when ${\mathbf{dist}}=\text{"N"}$, and ${\mathbf{npar}}=2+{\mathbf{iq}}+{\mathbf{ip}}+{\mathbf{isym}}+{\mathbf{mn}}+{\mathbf{nreg}}$ when ${\mathbf{dist}}=\text{"T"}$.
Constraint: ${\mathbf{npar}}<20$.
theta
Type: array<System..::..Double>[]()[][]
An array of size [npar]
On entry: the initial parameter estimates for the vector $\theta$.
The first element must contain the coefficient ${\alpha }_{o}$ and the next iq elements must contain the coefficients ${\alpha }_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,q$.
The next ip elements must contain the coefficients ${\beta }_{\mathit{j}}$, for $\mathit{j}=1,2,\dots ,p$.
If ${\mathbf{isym}}=1$, the next element must contain the asymmetry parameter $\gamma$.
If ${\mathbf{dist}}=\text{"T"}$, the next element must contain $\mathit{df}$, the number of degrees of freedom of the Student's $t$-distribution.
If ${\mathbf{mn}}=1$, the next element must contain the mean term ${b}_{o}$.
If ${\mathbf{copts}}\left[1\right]=\mathrm{false}$, the remaining nreg elements are taken as initial estimates of the linear regression coefficients ${b}_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,k$.
On exit: the estimated values $\stackrel{^}{\theta }$ for the vector $\theta$.
The first element contains the coefficient ${\alpha }_{o}$, the next iq elements contain the coefficients ${\alpha }_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,q$.
The next ip elements are the coefficients ${\beta }_{\mathit{j}}$, for $\mathit{j}=1,2,\dots ,p$.
If ${\mathbf{isym}}=1$, the next element contains the estimate for the asymmetry parameter $\gamma$.
If ${\mathbf{dist}}=\text{"T"}$, the next element contains an estimate for $\mathit{df}$, the number of degrees of freedom of the Student's $t$-distribution.
If ${\mathbf{mn}}=1$, the next element contains an estimate for the mean term ${b}_{o}$.
The final nreg elements are the estimated linear regression coefficients ${b}_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,k$.
se
Type: array<System..::..Double>[]()[][]
An array of size [npar]
On exit: the standard errors for $\stackrel{^}{\theta }$.
The first element contains the standard error for ${\alpha }_{o}$. The next iq elements contain the standard errors for ${\alpha }_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,q$. The next ip elements are the standard errors for ${\beta }_{\mathit{j}}$, for $\mathit{j}=1,2,\dots ,p$.
If ${\mathbf{isym}}=1$, the next element contains the standard error for $\gamma$.
If ${\mathbf{dist}}=\text{"T"}$, the next element contains the standard error for $\mathit{df}$, the number of degrees of freedom of the Student's $t$-distribution.
If ${\mathbf{mn}}=1$, the next element contains the standard error for ${b}_{o}$.
The final nreg elements are the standard errors for ${b}_{\mathit{j}}$, for $\mathit{j}=1,2,\dots ,k$.
sc
Type: array<System..::..Double>[]()[][]
An array of size [npar]
On exit: the scores for $\stackrel{^}{\theta }$.
The first element contains the score for ${\alpha }_{o}$.
The next iq elements contain the score for ${\alpha }_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,q$.
The next ip elements are the scores for ${\beta }_{\mathit{j}}$, for $\mathit{j}=1,2,\dots ,p$.
If ${\mathbf{isym}}=1$, the next element contains the score for $\gamma$.
If ${\mathbf{dist}}=\text{"T"}$, the next element contains the score for $\mathit{df}$, the number of degrees of freedom of the Student's $t$-distribution.
If ${\mathbf{mn}}=1$, the next element contains the score for ${b}_{o}$.
The final nreg elements are the scores for ${b}_{\mathit{j}}$, for $\mathit{j}=1,2,\dots ,k$.
covr
Type: array<System..::..Double,2>[,](,)[,][,]
An array of size [dim1, npar]
Note: dim1 must satisfy the constraint: $\mathrm{dim1}\ge {\mathbf{npar}}$
On exit: the covariance matrix of the parameter estimates $\stackrel{^}{\theta }$, that is the inverse of the Fisher Information Matrix.
hp
Type: System..::..Double%
On entry: if ${\mathbf{copts}}\left[1\right]=\mathrm{false}$, hp is the value to be used for the pre-observed conditional variance; otherwise hp is not referenced.
On exit: if ${\mathbf{copts}}\left[1\right]=\mathrm{true}$, hp is the estimated value of the pre-observed conditional variance.
et
Type: array<System..::..Double>[]()[][]
An array of size [num]
On exit: the estimated residuals, ${\epsilon }_{\mathit{t}}$, for $\mathit{t}=1,2,\dots ,T$.
ht
Type: array<System..::..Double>[]()[][]
An array of size [num]
On exit: the estimated conditional variances, ${h}_{\mathit{t}}$, for $\mathit{t}=1,2,\dots ,T$.
lgf
Type: System..::..Double%
On exit: the value of the log-likelihood function at $\stackrel{^}{\theta }$.
copts
Type: array<System..::..Boolean>[]()[][]
An array of size [$2$]
On entry: the options to be used by g13fa.
${\mathbf{copts}}\left[0\right]=\mathrm{true}$
Stationary conditions are enforced, otherwise they are not.
${\mathbf{copts}}\left[1\right]=\mathrm{true}$
The method provides initial parameter estimates of the regression terms, otherwise these are to be provided by you.
maxit
Type: System..::..Int32
On entry: the maximum number of iterations to be used by the optimization method when estimating the $\text{GARCH}\left(p,q\right)$ parameters. If maxit is set to $0$, the standard errors, score vector and variance-covariance are calculated for the input value of $\theta$ in theta; however the value of $\theta$ is not updated.
Constraint: ${\mathbf{maxit}}\ge 0$.
tol
Type: System..::..Double
On entry: the tolerance to be used by the optimization method when estimating the $\text{GARCH}\left(p,q\right)$ parameters.
ifail
Type: System..::..Int32%
On exit: ${\mathbf{ifail}}={0}$ unless the method detects an error or a warning has been flagged (see [Error Indicators and Warnings]).

# Description

A univariate regression-type I $\text{AGARCH}\left(p,q\right)$ process, with $q$ coefficients ${\alpha }_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,q$, $p$ coefficients ${\beta }_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,p$, and $k$ linear regression coefficients ${b}_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,k$, can be represented by:
 $yt=bo+xtTb+εt$ (1)
 $ht=α0+∑i=1qαiεt-i+γ2+∑i=1pβiht-i, t=1,2,…,T$ (2)
where ${\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 terms in the sequence, ${y}_{t}$ denotes the endogenous variables, ${x}_{t}$ the exogenous variables, ${b}_{o}$ the regression mean, $b$ the regression coefficients, ${\epsilon }_{t}$ the residuals, ${h}_{t}$ the conditional variance, $\mathit{df}$ the number of degrees of freedom of the Student's $t$-distribution, and ${\psi }_{t}$ the set of all information up to time $t$.
g13fa provides an estimate for $\stackrel{^}{\theta }$, the parameter vector $\theta =\left({b}_{o},{b}^{\mathrm{T}},{\omega }^{\mathrm{T}}\right)$ where ${b}^{\mathrm{T}}=\left({b}_{1},\dots ,{b}_{k}\right)$, ${\omega }^{\mathrm{T}}=\left({\alpha }_{0},{\alpha }_{1},\dots ,{\alpha }_{q},{\beta }_{1},\dots ,{\beta }_{p},\gamma \right)$ when ${\mathbf{dist}}=\text{"N"}$ and ${\omega }^{\mathrm{T}}=\left({\alpha }_{0},{\alpha }_{1},\dots ,{\alpha }_{q},{\beta }_{1},\dots ,{\beta }_{p},\gamma ,\mathit{df}\right)$ when ${\mathbf{dist}}=\text{"T"}$.
isym, mn and nreg can be used to simplify the $\text{GARCH}\left(p,q\right)$ expression in (1) as follows:
No Regression and No Mean
• ${y}_{t}={\epsilon }_{t}$,
• ${\mathbf{isym}}=0$,
• ${\mathbf{mn}}=0$,
• ${\mathbf{nreg}}=0$ and
• $\theta$ is a $\left(p+q+1\right)$ vector when ${\mathbf{dist}}=\text{"N"}$ and a $\left(p+q+2\right)$ vector when ${\mathbf{dist}}=\text{"T"}$.
No Regression
• ${y}_{t}={b}_{o}+{\epsilon }_{t}$,
• ${\mathbf{isym}}=0$,
• ${\mathbf{mn}}=1$,
• ${\mathbf{nreg}}=0$ and
• $\theta$ is a $\left(p+q+2\right)$ vector when ${\mathbf{dist}}=\text{"N"}$ and a $\left(p+q+3\right)$ vector when ${\mathbf{dist}}=\text{"T"}$.
Note:  if the ${y}_{t}=\mu +{\epsilon }_{t}$, where $\mu$ is known (not to be estimated by g13fa) then (1) can be written as ${y}_{t}^{\mu }={\epsilon }_{t}$, where ${y}_{t}^{\mu }={y}_{t}-\mu$. This corresponds to the case No Regression and No Mean, with ${y}_{t}$ replaced by ${y}_{t}-\mu$.
No Mean
• ${y}_{t}={x}_{t}^{\mathrm{T}}b+{\epsilon }_{t}$,
• ${\mathbf{isym}}=0$,
• ${\mathbf{mn}}=0$,
• ${\mathbf{nreg}}=k$ and
• $\theta$ is a $\left(p+q+k+1\right)$ vector when ${\mathbf{dist}}=\text{"N"}$ and a $\left(p+q+k+2\right)$ vector when ${\mathbf{dist}}=\text{"T"}$.

# 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
Hamilton J (1994) Time Series Analysis Princeton University Press

# Error Indicators and Warnings

Note: g13fa may return useful information for one or more of the following detected errors or warnings.
Errors or warnings detected by the method:
Some error messages may refer to parameters that are dropped from this interface (LDX, LDCOVR) In these cases, an error in another parameter has usually caused an incorrect value to be inferred.
${\mathbf{ifail}}=1$
 On entry, ${\mathbf{nreg}}<0$, or ${\mathbf{mn}}>1$, or ${\mathbf{mn}}<0$, or ${\mathbf{isym}}>1$, or ${\mathbf{isym}}<0$, or ${\mathbf{iq}}<1$, or ${\mathbf{ip}}<0$, or ${\mathbf{npar}}\ge 20$, or npar has an invalid value, or ${\mathbf{dist}}\ne \text{"N"}$, or ${\mathbf{dist}}\ne \text{"T"}$, or ${\mathbf{maxit}}<0$, or ${\mathbf{num}}<\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left({\mathbf{ip}},{\mathbf{iq}}\right)$, or ${\mathbf{num}}<{\mathbf{nreg}}+{\mathbf{mn}}$.
${\mathbf{ifail}}=2$
 On entry, ${\mathbf{lwork}}<\left({\mathbf{nreg}}+3\right)×{\mathbf{num}}+{\mathbf{npar}}+403$.
${\mathbf{ifail}}=3$
The matrix $X$ is not full rank.
${\mathbf{ifail}}=4$
The information matrix is not positive definite.
${\mathbf{ifail}}=5$
The maximum number of iterations has been reached.
${\mathbf{ifail}}=6$
The log-likelihood cannot be optimized any further.
${\mathbf{ifail}}=7$
No feasible model parameters could be found.
${\mathbf{ifail}}=-9000$
An error occured, see message report.
${\mathbf{ifail}}=-6000$
Invalid Parameters $〈\mathit{\text{value}}〉$
${\mathbf{ifail}}=-4000$
Invalid dimension for array $〈\mathit{\text{value}}〉$
${\mathbf{ifail}}=-8000$
Negative dimension for array $〈\mathit{\text{value}}〉$
${\mathbf{ifail}}=-6000$
Invalid Parameters $〈\mathit{\text{value}}〉$

Not applicable.

None.

None.

# Example

This example fits a $\text{GARCH}\left(1,1\right)$ model with Student's $t$-distributed residuals to some simulated data.

Example program (C#): g13fae.cs

Example program data: g13fae.d

Example program results: g13fae.r