# NAG C Library Function Document

## 1Purpose

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

## 2Specification

 #include #include
 void nag_estimate_agarchI (const double yt[], const double x[], Integer tdx, Integer num, Integer p, Integer q, Integer nreg, Integer mn, Integer isym, double theta[], double se[], double sc[], double covar[], Integer tdc, double *hp, double et[], double ht[], double *lgf, Nag_Garch_Stationary_Type stat_opt, Nag_Garch_Est_Initial_Type est_opt, Integer max_iter, double tol, NagError *fail)

## 3Description

When ${\mathbf{isym}}=0$, nag_estimate_agarchI (g13fac) models a standard $\left(\gamma =0\right)$ univariate regression-GARCH$\left(p,q\right)$ process, with $p$ coefficients ${\alpha }_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,p$, $q$ coefficients, ${\beta }_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,q$, mean ${b}_{o}$, and $k$ linear regression coefficients ${b}_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,k$, which can be represented by:
 $y t = b o + xtT b + ε t$ (1)
 $ε t ∣ ψ t-1 ∼ N 0, h t$
 $h t = α 0 + ∑ i=1 q α i ε t-i 2 + ∑ i=1 p β i h t-i , t = 1 , … , T .$
When ${\mathbf{isym}}=1$, nag_estimate_agarchI (g13fac) models an asymmetric GARCH$\left(p,q\right)$ process where the conditional variance ${h}_{t}$ is given by:
 $h t = α 0 + ∑ i=1 q α i ε t-i + γ 2 + ∑ i=1 p β i h t-i , t = 1 , … , T .$
Here $T$ the number of terms in the sequence, ${y}_{t}$ denotes the endogenous variables, ${x}_{t}$ the exogenous variables, ${b}_{o}$ the mean, $b$ the regression coefficients, ${\epsilon }_{t}$ the residuals, $\gamma$ the asymmetry parameter, ${h}_{t}$ the conditional variance, and ${\psi }_{t}$ the information set of all information up to time $t$.
When ${\mathbf{isym}}=1$, nag_estimate_agarchI (g13fac) provides an estimate for $\stackrel{^}{\theta }$, the $\left(p+q+k+3\right)×1$ parameter vector $\theta =\left({b}_{o},{b}^{\mathrm{T}},{\omega }^{\mathrm{T}}\right)$ where ${\omega }^{\mathrm{T}}=\left({\alpha }_{0},{\alpha }_{1},\dots ,{\alpha }_{q},{\beta }_{1},\dots ,{\beta }_{p},\gamma \right)$ and ${b}^{\mathrm{T}}=\left({b}_{1},\dots ,{b}_{k}\right)$.
isym, mn, nreg can be used to simplify the GARCH$\left(p,q\right)$ expression in (1) as follows:
No Regression or Mean
• ${y}_{t}={\epsilon }_{t}$,
• ${\mathbf{isym}}=0$,
• ${\mathbf{mn}}=0$,
• ${\mathbf{nreg}}=0$, and
• $\theta$ is a $\left(p+q+1\right)×1$ vector.
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)×1$ vector.
Note: if the ${y}_{t}=\mu +{\epsilon }_{t}$, where $\mu$ is known (not to be estimated by nag_estimate_agarchI (g13fac)) 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 or 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)×1$ vector.
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

## 5Arguments

Note: for convenience npar will be used here to denote the expression $1+{\mathbf{q}}+{\mathbf{p}}+{\mathbf{isym}}+{\mathbf{mn}}+{\mathbf{nreg}}$ representing the number of model parameters.
1:    $\mathbf{yt}\left[{\mathbf{num}}\right]$const doubleInput
On entry: the sequence of observations, ${y}_{\mathit{t}}$, for $\mathit{t}=1,2,\dots ,T$.
2:    $\mathbf{x}\left[{\mathbf{num}}×{\mathbf{tdx}}\right]$const doubleInput
Note: the $i$th element of the $j$th vector $X$ is stored in ${\mathbf{x}}\left[\left(i-1\right)×{\mathbf{tdx}}+j-1\right]$.
On entry: row $t$ of x must contain the time dependent exogenous vector ${x}_{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$.
3:    $\mathbf{tdx}$IntegerInput
On entry: the stride separating matrix column elements in the array x.
Constraint: ${\mathbf{tdx}}\ge {\mathbf{nreg}}$.
4:    $\mathbf{num}$IntegerInput
On entry: the number of terms in the sequence, $T$.
Constraint: ${\mathbf{num}}\ge \mathit{npar}$.
5:    $\mathbf{p}$IntegerInput
On entry: the GARCH$\left(p,q\right)$ parameter $p$.
Constraint: ${\mathbf{p}}\ge 0$.
6:    $\mathbf{q}$IntegerInput
On entry: the GARCH$\left(p,q\right)$ parameter $q$.
Constraint: ${\mathbf{q}}\ge 1$.
7:    $\mathbf{nreg}$IntegerInput
On entry: $k$, the number of refression coefficients.
Constraint: ${\mathbf{nreg}}\ge 0$.
8:    $\mathbf{mn}$IntegerInput
On entry: if ${\mathbf{mn}}=1$, the mean term ${b}_{0}$ will be included in the model.
Constraint: ${\mathbf{mn}}=0$ or $1$.
9:    $\mathbf{isym}$IntegerInput
On entry: if ${\mathbf{isym}}=1$, the asymmetry term $\gamma$ will be included in the model.
Constraint: ${\mathbf{isym}}=0$ or $1$.
10:  $\mathbf{theta}\left[\mathit{npar}\right]$doubleInput/Output
On entry: the initial parameter estimates for the vector $\theta$.
The first element contains the coefficient ${\alpha }_{o}$, the next q elements contain the autoregressive coefficients ${\alpha }_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,q$.
The next p elements are the moving average coefficients ${\beta }_{\mathit{j}}$, for $\mathit{j}=1,2,\dots ,p$.
The next element contains the asymmetry parameter $\gamma$.
If ${\mathbf{est_opt}}=\mathrm{Nag_Garch_Est_Initial_False}$, (when ${\mathbf{mn}}=1$) the next term contains an initial estimate of the mean term ${b}_{o}$ and 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 q elements contain the coefficients ${\alpha }_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,q$.
The next p elements are the coefficients ${\beta }_{\mathit{j}}$, for $\mathit{j}=1,2,\dots ,p$.
The next element contains the estimate for the asymmetry parameter $\gamma$.
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$.
11:  $\mathbf{se}\left[\mathit{npar}\right]$doubleOutput
On exit: the standard errors for $\stackrel{^}{\theta }$.
The first element contains the standard error for ${\alpha }_{o}$.
The next q elements contain the standard errors for ${\alpha }_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,q$.
The next p 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{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$.
12:  $\mathbf{sc}\left[\mathit{npar}\right]$doubleOutput
On exit: the scores for $\stackrel{^}{\theta }$.
The first element contains the score for ${\alpha }_{o}$.
The next q elements contain the score for ${\alpha }_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,q$.
The next p 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{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$.
13:  $\mathbf{covar}\left[\mathit{npar}×{\mathbf{tdc}}\right]$doubleOutput
Note: the $\left(i,j\right)$th element of the matrix is stored in ${\mathbf{covar}}\left[\left(i-1\right)×{\mathbf{tdc}}+j-1\right]$.
On exit: the covariance matrix of the parameter estimates $\stackrel{^}{\theta }$, that is the inverse of the Fisher Information Matrix.
14:  $\mathbf{tdc}$IntegerInput
On entry: the stride separating matrix column elements in the array covar.
Constraint: ${\mathbf{tdc}}\ge \mathit{npar}$.
15:  $\mathbf{hp}$double *Input/Output
On entry: if ${\mathbf{est_opt}}=\mathrm{Nag_Garch_Est_Initial_False}$, hp is the value to be used for the pre-observed conditional variance.
If ${\mathbf{est_opt}}=\mathrm{Nag_Garch_Est_Initial_True}$, hp is not referenced.
On exit: if ${\mathbf{est_opt}}=\mathrm{Nag_Garch_Est_Initial_True}$, hp is the estimated value of the pre-observed of the conditional variance.
16:  $\mathbf{et}\left[{\mathbf{num}}\right]$doubleOutput
On exit: the estimated residuals, ${\epsilon }_{\mathit{t}}$, for $\mathit{t}=1,2,\dots ,T$.
17:  $\mathbf{ht}\left[{\mathbf{num}}\right]$doubleOutput
On exit: the estimated conditional variances, ${h}_{\mathit{t}}$, for $\mathit{t}=1,2,\dots ,T$.
18:  $\mathbf{lgf}$double *Output
On exit: the value of the log-likelihood function at $\stackrel{^}{\theta }$.
19:  $\mathbf{stat_opt}$Nag_Garch_Stationary_TypeInput
On entry: if ${\mathbf{stat_opt}}=\mathrm{Nag_Garch_Stationary_True}$, Stationary conditions are enforced.
If ${\mathbf{stat_opt}}=\mathrm{Nag_Garch_Stationary_False}$, Stationary conditions are not enforced.
Constraint: ${\mathbf{stat_opt}}=\mathrm{Nag_Garch_Stationary_True}$ or $\mathrm{Nag_Garch_Stationary_False}$.
20:  $\mathbf{est_opt}$Nag_Garch_Est_Initial_TypeInput
On entry: if ${\mathbf{est_opt}}=\mathrm{Nag_Garch_Est_Initial_True}$, the function provides initial parameter estimates of the regression terms $\left({b}_{0},{b}^{\mathrm{T}}\right)$.
If ${\mathbf{est_opt}}=\mathrm{Nag_Garch_Est_Initial_False}$, you must supply the initial estimations of the regression parameters $\left({b}_{0},{b}^{\mathrm{T}}\right)$.
Constraint: ${\mathbf{est_opt}}=\mathrm{Nag_Garch_Est_Initial_True}$ or $\mathrm{Nag_Garch_Est_Initial_False}$.
21:  $\mathbf{max_iter}$IntegerInput
On entry: the maximum number of iterations to be used by the optimization function when estimating the GARCH$\left(p,q\right)$ parameters. If max_iter 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{max_iter}}\ge 0$.
22:  $\mathbf{tol}$doubleInput
On entry: the tolerance to be used by the optimization function when estimating the GARCH$\left(p,q\right)$ parameters.
23:  $\mathbf{fail}$NagError *Input/Output
The NAG error argument (see Section 3.7 in How to Use the NAG Library and its Documentation).

## 6Error Indicators and Warnings

NE_2_INT_ARG_LT
On entry, ${\mathbf{num}}=〈\mathit{\text{value}}〉$ while $1+{\mathbf{q}}+{\mathbf{p}}+{\mathbf{isym}}+{\mathbf{mn}}+{\mathbf{nreg}}=〈\mathit{\text{value}}〉$. These parameters must satisfy ${\mathbf{num}}\ge 1+{\mathbf{q}}+{\mathbf{p}}+{\mathbf{isym}}+{\mathbf{mn}}+{\mathbf{nreg}}$.
On entry, ${\mathbf{tdc}}=〈\mathit{\text{value}}〉$ while $1+{\mathbf{q}}+{\mathbf{p}}+{\mathbf{isym}}+{\mathbf{mn}}+{\mathbf{nreg}}=〈\mathit{\text{value}}〉$. These parameters must satisfy ${\mathbf{tdc}}\ge 1+{\mathbf{q}}+{\mathbf{p}}+{\mathbf{isym}}+{\mathbf{mn}}+{\mathbf{nreg}}$.
On entry, ${\mathbf{tdx}}=〈\mathit{\text{value}}〉$ while ${\mathbf{nreg}}=〈\mathit{\text{value}}〉$. These parameters must satisfy ${\mathbf{tdx}}\ge {\mathbf{nreg}}$.
NE_ALLOC_FAIL
Dynamic memory allocation failed.
On entry, argument est_opt had an illegal value.
On entry, argument stat_opt had an illegal value.
NE_INT_ARG_LT
On entry, max_iter must not be less than 0: ${\mathbf{max_iter}}=〈\mathit{\text{value}}〉$.
On entry, ${\mathbf{nreg}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{nreg}}\ge 0$.
On entry, ${\mathbf{p}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{p}}\ge 0$.
On entry, ${\mathbf{q}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{q}}\ge 1$.
NE_INTERNAL_ERROR
An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact NAG for assistance.
NE_INVALID_INT_RANGE_2
Value $〈\mathit{\text{value}}〉$ given to isym is not valid. Correct range is 0 to 1.
Value $〈\mathit{\text{value}}〉$ given to mn is not valid. Correct range is 0 to 1.
NE_MAT_NOT_FULL_RANK
Matrix $X$ does not give a model of full rank.
NE_MAT_NOT_POS_DEF
Attempt to invert the second derivative matrix needed in the calculation of the covariance matrix of the parameter estimates has failed. The matrix is not positive definite, possibly due to rounding errors.

Not applicable.

## 8Parallelism and Performance

nag_estimate_agarchI (g13fac) is not threaded in any implementation.

None.

## 10Example

This example program illustrates the use of nag_estimate_agarchI (g13fac) to model a GARCH(1,1) sequence generated by nag_rand_agarchI (g05pdc), a three step forecast is then calculated using nag_forecast_agarchI (g13fbc).

### 10.1Program Text

Program Text (g13face.c)

None.

### 10.3Program Results

Program Results (g13face.r)