Debian Codegraph @

addons/gig/doc/gig.tex

raw
1 \documentclass[a4paper,11pt]{article}
2 \usepackage{geometry,gretlhds}
3 \usepackage{url,fancyvrb}
4 \usepackage{pifont}
5 \usepackage[utf8]{inputenc}
6 \usepackage[pdftex]{graphicx}
7 \usepackage{color}
8 % \usepackage{dcolumn,amsmath,mathrsfs}
9 \usepackage{dcolumn,amsmath}
10 \usepackage{natbib}
11 \usepackage{hyperref}
12
13 \bibliographystyle{gretl}
14
15 \graphicspath{{graphs/}}
16
17 \newcommand{\dtk}[1]{\texttt{\detokenize{#1}}}
18 \newenvironment{funcdoc}[1]
19 {\noindent\hrulefill\newline\dtk{#1}\par\noindent\hrulefill\par\medskip\par}
20 {\bigskip}
21
22 % ---------- Ripped from gretl.sty ----------------------------------------
23
24 \newcommand{\scriptname}{Listing}
25
26 \newcommand{\app}[1]{\textsf{#1}}
27 \newcommand{\cmd}[1]{\texttt{#1}}
28 \newcommand{\varname}[1]{\texttt{#1}}
29 \newcommand{\option}[1]{\texttt{-{}-#1}}
30
31 \newcommand{\ttsl}[1]{\ttfamily{\textsl{#1}}\normalfont}
32
33 \newenvironment{textcode}{\par\small\ttfamily}
34 {\normalfont\normalsize\par}
35
36 \DefineVerbatimEnvironment%
37 {code}{Verbatim}
38 {fontsize=\small, xleftmargin=1em}
39
40 \DefineVerbatimEnvironment%
41 {scode}{Verbatim}
42 {frame=lines, framesep=2ex, fontsize=\small,
43 formatcom=\color{myteal}, rulecolor=\color{mygray}}
44
45 \DefineVerbatimEnvironment%
46 {scodebit}{Verbatim}
47 {fontsize=\small, formatcom=\color{myteal}}
48
49 \DefineVerbatimEnvironment%
50 {scodebot}{Verbatim}
51 {frame=bottomline, framesep=2ex, fontsize=\small,
52 formatcom=\color{myteal}, rulecolor=\color{mygray}}
53
54 \renewcommand{\arraystretch}{1.2}
55
56 \definecolor{mygray}{rgb}{0.85,0.85,0.85}
57 \definecolor{myteal}{rgb}{0.0,0.25,0.15}
58
59 \def\floatpagefraction{.8}
60
61 %% add script as float (Listing)
62 \newcounter{script}[section]
63 \renewcommand \thescript
64 {\ifnum \c@chapter>\z@ \thechapter.\fi \@arabic\c@script}
65 \def\fps@script{tbp}
66 \def\ftype@script{1}
67 \def\ext@script{los}
68 \def\fnum@script{\scriptname\nobreakspace\thescript}
69 \newenvironment{script}
70 {\@float{script}}
71 {\end@float}
72 \newenvironment{script*}
73 {\@dblfloat{script}}
74 {\end@dblfloat}
75
76 \newcommand{\tip}[1]{\par\vspace{4pt}
77 \ding{43} {\small \sffamily #1}\par\smallskip}
78
79 % ---------- End rip ------------------------------------------------------
80
81 \newcommand{\stdu}{\ensuremath \varepsilon}
82 \newcommand{\uhat}{\ensuremath u}
83 \newcommand{\InfSet}[1]{\ensuremath \mathcal{F}_{#1}}
84 \newcommand{\IRF}[1]{\ensuremath \mathcal{I}_{#1}}
85 \newcommand{\FEVD}[1]{\ensuremath \mathcal{VD}_{#1}}
86 \newcommand{\pder}[2]{\ensuremath\frac{\partial #1}{\partial #2}}
87 \DeclareMathOperator{\VEC}{\mathrm{vec}}
88
89 \newcommand{\gig}{\texttt{gig}}
90
91 \definecolor{steel}{rgb}{0.03,0.20,0.45}
92
93 \hypersetup{pdftitle={The \gig\ package},
94 pdfauthor={Jack Lucchetti \and Stefano Balietti},
95 colorlinks=true,
96 linkcolor=blue,
97 urlcolor=red,
98 citecolor=steel,
99 bookmarksnumbered=true,
100 plainpages=false
101 }
102
103 \title{The \gig\ package}
104 \author{Jack Lucchetti \and Stefano Balietti}
105 \date{December 2023}
106 \begin{document}
107
108 \maketitle
109
110 \begin{abstract}
111 The \gig\ package is a collection of \app{gretl} scripts to estimate
112 univariate conditional heteroskedasticity models. % What is described
113 % here is \gig\ version 2.0, which is substantially different from the
114 % previous version: it makes use of several new \app{gretl} features and
115 % is totally incompatible with the old version. In return, you get a
116 % package that is considerably simpler to use, maintain and extend and
117 % integrates in a much smoother way with the \app{gretl} GUI.
118 \end{abstract}
119
120 \tableofcontents
121
122 \section{Introduction}
123
124 A general description of the models that \gig\ can handle can be given
125 by the following system:
126 \begin{eqnarray}
127 \label{eq:meaneq}
128 E_{t-1}(y_t) & = & \pi'x_t \\
129 \label{eq:espdef}
130 \uhat_{t} \equiv y_t - E_{t-1}(y_t) & \Longrightarrow &
131 y_t = \pi'x_t + \uhat_{t} \\
132 \label{eq:vareq}
133 h_t \equiv V_{t-1}(\uhat_{t}) & = &
134 v(\uhat_{t-1}, \uhat_{t-2}, \ldots,
135 h_{t-1}, h_{t-2}, \ldots, z_t) \\
136 \label{eq:stdinn}
137 \stdu_t & = & \frac{\uhat_{t}}{\sqrt{h_t}}
138 \end{eqnarray}
139 which could be read as follows: it is assumed (eq.~\ref{eq:meaneq})
140 that the conditional expectation\footnote{Of course, all the relevant
141 moments are supposed to exist.} of an observable variable $y_t$ to an
142 information set\footnote{We could be more rigorous and impress the
143 reader with $\sigma$-algebras and filtrations, but we can't be
144 bothered, ok?} $\InfSet{t-1}$ (denoted as $E_{t-1}$) is a linear
145 function of quantities known at time $t-1$. Clearly, the information
146 set may contain exogenous variables as well as lags of $y_t$, which
147 are all collected in the vector $x_t$. This makes it possible to write
148 an equation (eq.~\ref{eq:espdef}) for the conditional mean of $y_t$.
149
150 As for the conditional variance (eq.~\ref{eq:vareq}), this is assumed
151 to be a known function, with possibly also some observable exogenous
152 variables $z_t$. The most basic choice is the GARCH model, in which
153 \eqref{eq:vareq} specialises to
154 \[
155 h_t = \omega + \sum_{i=1}^q \alpha_i \uhat_{t-i}^2 +
156 \sum_{j=1}^p\beta_j h_{t-j} ,
157 \]
158 but a number of exotic alternatives have been devised in the past 30
159 years (see section \ref{sec:models}). Note that the conditional
160 variance, as specified in eq.~\eqref{eq:vareq}, may or may not contain
161 exogenous explanatory variables, but a constant term must always be
162 present (\gig\ adds one automatically otherwise). The
163 standardised innovations $\stdu_t$ are trivially defined by
164 eq.~\eqref{eq:stdinn}, and have zero conditional mean and unit
165 conditional variance by construction.
166
167 \tip{\emph{Nota bene}: the convention used in the previous version of \gig\
168 was to use the letter $p$ to indicate the ARCH order and $q$ for the
169 GARCH order, which was inconsistent with \app{gretl} itself and, most
170 importantly, with \cite{Bollerslev-86}. \textbf{This is now reversed},
171 so $p$ is the GARCH order and $q$ is the ARCH order.}
172
173
174 The parameters of these models are almost invariably estimated via
175 maximum likelihood (or pseudo-ML), which brings up the subject of a
176 suitable choice for the conditional distribution of $\stdu_t$. This has
177 also been the object of much speculation, given the need to
178 accommodate several stylised facts, such as leptokurtosis:
179 \gig\ provides algorithms for the most popular choices in the
180 applied literature (see Table \ref{tab:densities}).
181
182 \begin{table}[hptb]
183 \centering
184 \begin{footnotesize}
185 \begin{tabular}{p{0.275\textwidth}cr}
186 \hline
187 \textbf{Name} & \textbf{Density} & \textbf{Parameters} \\
188 \hline
189 \\
190 Normal &
191 $\frac{1}{\sqrt{2\pi h_t}}
192 \exp \left\{-\frac{\stdu_t^2}{2}\right\}$ &
193 none \\
194 Student's $t$ &
195 $\frac{K(\nu)}{\sqrt{h_t}}
196 \left[1+\frac{\stdu_t^2}{\nu-2}\right]^{-(\nu + 1)/2}$ &
197 $\nu > 2$ \\
198 Generalised Error Distribution (GED) &
199 $C(\nu)\exp\left\{-\left|\frac{\stdu_t}{\kappa_\nu}\right|^\nu\right\}$
200 & $\nu > 0$ \\
201 Skewed $t$ &
202 $\frac{b K(\nu)}{\sqrt{h_t}}
203 \left[1 + \frac{\zeta_t^2}{\nu - 2}\right]^{-(\nu + 1)/2}$
204 & $\nu > 2, \xi \in \Re$ \\
205 \\
206 Skewed GED &
207 $\left\{
208 \begin{array}{cc}
209 D(\nu) \exp\left\{-\beta_1 \left|\stdu_t - m\right|^\nu\right\} &
210 \stdu_t < m \\
211 D(\nu) \exp\left\{-\beta_2 \left|\stdu_t - m\right|^\nu\right\} &
212 \stdu_t \ge m
213 \end{array}
214 \right.$
215 & $\nu > 0, \xi \in \Re$ \\
216 \\
217 \hline
218 \hline
219 \end{tabular}
220 \end{footnotesize}
221
222 \begin{eqnarray*}
223 K(\nu) & = &
224 \frac{\Gamma\left[(\nu + 1)/2\right]} {\sqrt{\pi (\nu - 2)}\Gamma(\nu/2)} \\
225 C(\nu) & = &
226 \frac{\nu}{2}\sqrt{\frac{\Gamma(3/\nu)}{\Gamma(1/\nu)^3}} \\
227 \kappa_\nu & = &
228 \sqrt{2^{-\frac{2}{\nu}}\frac{\Gamma(1/\nu)}{\Gamma(3/\nu)}} \\
229 a & = & K(\nu) \cdot 4 \lambda \left( \frac{\nu - 2}{\nu - 1} \right) \\
230 b & = & \sqrt{1 + 3\lambda^2 - a^2} \\
231 \lambda & = & \tanh(\xi) \\
232 \zeta_t & = & \left\{
233 \begin{array}{ll}
234 \frac{b \stdu_t + a}{1-\lambda} & \mathrm{for\ } \stdu_t < -a/b \\
235 \frac{b \stdu_t + a}{1+\lambda} & \mathrm{for\ } \stdu_t > -a/b
236 \end{array}
237 \right. \\
238 D(\nu) & = &
239 \frac{1}{\Gamma(1/\nu)}\sqrt{\frac{\Gamma(3/\nu)}{2 \cdot \Gamma(1/\nu)}
240 \left(\frac{1 + \lambda}{1 - \lambda}\right)^3 -
241 \left(2 \lambda \Gamma(2/\nu)\right)^2 }
242 \end{eqnarray*}
243 \caption{Conditional densities for $\stdu_t$}
244 \label{tab:densities}
245 \end{table}
246
247 A brief remark on the skewed distributions: compared to their original
248 parametrisation, we treat $\lambda$ as the hyperbolic tangent of an
249 unconstrained real parameter $\xi$; this reparametrisation is
250 inconsequential in substance, but very helpful numerically.
251
252 \section{The models}
253 \label{sec:models}
254
255 \subsection{The APARCH Family}
256 \label{sec:APARCH}
257
258 Most of the models \gig\ can handle can be thought of as special
259 cases of the Asymmetric Power ARCH (APARCH) model, introduced by
260 \cite{Ding-Engle-Granger}. This model is able to accommodate
261 asymmetric effects and power transformations of the variance. Its
262 specification for the conditional variance is the following:
263 \begin{equation} \label{eq:aparch} \sigma_t^\delta = \omega'z_t +
264 \sum_{i=1}^q \alpha_i(|\uhat_{t-i}| - \gamma_i
265 \uhat_{t-i})^\delta + \sum_{j=1}^p\beta_j\sigma_{t-j}^\delta
266 \end{equation}
267 where $\sigma_t \equiv \sqrt{h_t}$, the parameter $\delta$ (assumed
268 positive, but typically ranging between 1 and 2) performs a Box-Cox
269 transformation and $\gamma$ captures the asymmetric effects. Special
270 values of the parameters give rise to the special cases enumerated in
271 Table \ref{tab:APARCH-submodels}.
272
273 \begin{table}[hptb]
274 \centering
275 \begin{tabular}{p{0.2\textwidth}p{0.3\textwidth}p{0.4\textwidth}}
276 \hline
277 MODEL & AUTHOR & CONSTRAINTS \\
278 \hline
279 \textbf{ARCH} & \cite{Engle-82} & $\delta=2$, $\gamma_i = 0$ for
280 $ i=1,\ldots,q$ and $\beta_j = 0$ for $j=1,\ldots,p$ \\
281 \hline
282 \textbf{GARCH} & \cite{Bollerslev-86} & $\delta=2$,
283 $\gamma_i = 0$ $ i=1,\ldots,q$ \\
284 \hline
285 \textbf{Taylor/Schwert GARCH} & \cite{Taylor} and \cite{Schwert} & $\delta=1$,
286 $\gamma_i = 0$ $ i=1,\ldots,q$\\
287 \hline
288 \textbf{GJR} & \cite{Glosten-Jagannathan-Runkle} & $\delta=2$ \\
289 \hline
290 \textbf{TARCH} & \cite{Zakoian} & $\delta=1$\\
291 \hline
292 \textbf{NARCH} & \cite{Higgins-Bera} & $\gamma_i = 0$ for
293 $ i=1,\ldots,p$ and $\beta_j = 0$ for $j=1,\ldots,p$\\
294 % \hline
295 % \textbf{Log-ARCH} & \cite{Geweke} and \cite{Pantula} & if
296 % $\delta \rightarrow 0$.\\
297 \hline
298 \end{tabular}
299 \caption{APARCH nested sub-models}
300 \label{tab:APARCH-submodels}
301 \end{table}
302
303 The GJR model is given a special treatment in \gig. Other software
304 packages adopt a different, albeit equivalent, parametrisation for the
305 same model (some programs even call it by some other name). What \gig\
306 considers to be the GJR model
307 \begin{equation} \label{eq:GJR-gig} \sigma_t^2 = \omega'z_t +
308 \sum_{i=1}^q \alpha_i(|\uhat_{t-i}| - \gamma_i
309 \uhat_{t-i})^2 + \sum_{j=1}^p\beta_j\sigma_{t-j}^2
310 \end{equation}
311 is sometimes reparametrised as
312 \begin{equation} \label{eq:GJR-eviews} \sigma_t^2 = \delta'z_t +
313 \sum_{i=1}^q \left( \alpha_i \uhat_{t-i}^2 + \gamma_i d_{t-i}
314 \uhat_{t-i}^2 \right) + \sum_{j=1}^p\beta_j\sigma_{t-j}^2
315 \end{equation}
316 where $d_t = 1$ if $\uhat_{t}<0$ and 0 otherwise. The correspondence
317 between the two sets of parameters is left as an exercise to the
318 reader. An example will be given in section \ref{sec:GUI}.
319
320 In order to facilitate comparisons, when you estimate a GJR model,
321 \gig\ will print out both forms. However, only the parameters
322 corresponding to \eqref{eq:GJR-gig} will be saved.
323
324 \subsection{The EGARCH model}
325 \label{sec:EGARCH}
326
327 The Exponential GARCH (EGARCH) model, put forward by \cite{Nelson}, is
328 the only model presently available in \gig\ that is not nested
329 in the APARCH model. This is because eq.~\eqref{eq:vareq} is written
330 in terms of the logarithm of the variance instead of the variance
331 itself. Moreover, it captures asymmetric effects as a function of the
332 standardised innovations. The log-conditional variance $\ln(h_t)$ is
333 thus given by:
334 \begin{equation}\label{eq:egarch-0}
335 \ln h_t = \bar{\omega}'z_t +
336 \sum_{i=1}^q \left[
337 \alpha_i \left( |\stdu_{t-i}| - \sqrt{2/\pi}\right) + \gamma_i \stdu_{t-i}
338 \right]+
339 \sum_{j=1}^p \beta_j \ln(h_{t-j})
340 \end{equation}
341
342 However, this is not the exact form that \gig\ uses: there are some
343 computational advantages in moving the term $\sqrt{2/\pi}$ out of the
344 summation operator. The model actually estimated is
345 \begin{equation}\label{eq:egarch}
346 \ln h_t = \omega'z_t +
347 \sum_{i=1}^q \left( \alpha_i |\stdu_{t-i}| + \gamma_i \stdu_{t-i} \right)+
348 \sum_{j=1}^p \beta_j \ln(h_{t-j})
349 \end{equation}
350 where the element of the vector $\omega$ corresponding to the constant
351 equals the corresponding term of $\bar{\omega}$ minus $\sqrt{2/\pi}
352 \cdot \sum_{i} \alpha_i$.
353
354 Note that the sign of the asymmetric component in the APARCH and
355 EGARCH models do not match (compare equations \eqref{eq:aparch} and
356 \eqref{eq:egarch}). This is rather unfortunate, since it means that
357 the parameter $\gamma$ must be given an opposite interpretation in the
358 two cases. However, we decided to keep the two formulations
359 inconsistent for compatibility with other software packages.
360
361 % It is worthwhile to point out that, as E[ln($h_t$)] $\neq$
362 % ln(E[$h_t$]), the EGARCH is thought to analyze the logarithm of the
363 % conditional variance, rather than the conditional variance itself,
364 % which can be estimated as follows:
365
366 % \begin{align}\label{eq:egarch-3}
367 % h_t & = \hat{\zeta}^*\sum_{j=1}^q(\hat{h}_{t-j}^{\hat{\beta}})
368 % \exp(\sum_{i=1}^p
369 % \frac{\hat{\alpha_i}|\uhat_{t-i}|+\hat{\phi}_i
370 % \uhat_{t-1}}{\sqrt{\hat{h}_{t-i}}})
371 % \intertext{where}
372 % \zeta^* & = \exp(\zeta - \sum_{i=1}^p \alpha_i\sqrt{\frac{2}{\pi}})
373 % \end{align}
374
375
376 \section{How you do things}
377
378 The central idea in \gig\ is that your model is contained in a
379 \app{gretl} bundle,\footnote{If you don't know what a bundle is in
380 \app{gretl}, you may want to have a look at the User's Guide,
381 chapter 11. In short, a bundle is a container for assorted objects,
382 such as matrices, series etcetera.} which is set up first with the
383 basic information about the model (what the dependent variable is,
384 what kind of model it is, and so on), and then filled with all the
385 quantities available after estimation (coefficients etc).
386
387 Like most statistical procedures that come with \app{gretl}, there are
388 two ways to accomplish the above: either you use a graphical
389 interface, which is very intuitive and easy to use, or you use a
390 script, which is more awkward at the beginning, but gives you more
391 power and flexibility.
392
393 In this section, we will look at a few examples. We will assume that
394 \gig\ is installed correctly as a \app{gretl} addon and that you
395 already have a certain degree of familiarity with \app{gretl}'s
396 interface and scripting syntax.
397
398
399 \subsection{The GUI way}
400 \label{sec:GUI}
401
402 Suppose you have already loaded the data you want to analyse, and have
403 already performed the necessary preliminary data transformations, if
404 any. For example, suppose you loaded the example \app{gretl} dataset
405 called \texttt{djclose}, and already have created a variable called
406 $y_t$ which contains the daily returns, that is
407 \begin{code}
408 series y = 100 * ldiff(djclose)
409 \end{code}
410 If you plot $y_t$, you'll see the typical financial time series plot,
411 with the volatility clustering and all the other famous ``stylised
412 facts'':
413 \begin{center}
414 \includegraphics[width=0.75\textwidth,height=0.35\textwidth]{graphs/djret}
415 \end{center}
416
417 The GUI hook to \gig\ can be found under the \emph{Model $>$ Time
418 Series $>$ GARCH variants} heading. By choosing it you'll be
419 presented with a window similar to the one shown in Figure
420 \ref{fig:GUI-gig}. The meaning of the various element should be rather
421 clear, except perhaps for a few that require some explanation.
422
423 \begin{figure}[htb]
424 \centering
425 \includegraphics[scale=0.45]{graphs/GUI-gig}
426 \caption{GUI hook for \gig}
427 \label{fig:GUI-gig}
428 \end{figure}
429
430 \begin{description}
431 \item[The regressors lists] These are two lists holding the exogenous
432 variables in the conditional mean ($x_t$ in equation
433 \ref{eq:meaneq}) and conditional variance equation ($z_t$ in
434 equation \ref{eq:vareq}), respectively. They both default to
435 \texttt{null}, an empty list, although in the variance regressors
436 list a constant term is automatically included if absent. If some
437 lists are already defined, you can pick them from the list;
438 alternatively, you can create lists on the fly by using the ``+''
439 button. Note that, from version 1.9.3 of \app{gretl} onwards, you
440 can use a single series in lieu of a list proper, so for example if
441 you want a constant to appear in your conditional mean, you may just
442 type \texttt{const} in the ``mean regressors'' text box.
443
444 Note, however, that you you have two separate GUI elements for
445 including in your mean specification the most common choices, that
446 is a constant term and/or lags of the dependent variable. Hence,
447 you'll need to specify the mean regressors only if you have mean
448 terms other than those (for example, a time trend or some other
449 exogenous variable).
450
451 \item[Covariance estimator] Here you can choose between 3 algorithms
452 for computing the variance-covariance matrix of the estimated
453 parameters. Sandwich (also known as QMLE: see \cite{bolwoo92}) is
454 the default, but OPG is the fastest.
455 \item[Verbosity] An integer, ranging from 0 to 2: the default is 1,
456 which means you want to see the estimated model. If you choose 0,
457 you see nothing (all results can be retrieved later); if you choose
458 2, you get to see the BFGS iterations, which may be helpful in some
459 cases, especially when the algorithm fails to converge (see also
460 section \ref{sec:numerical}).
461 \end{description}
462
463 Now suppose that we want to estimate a GJR(1,1) model with a constant
464 as mean regressor and the $t$ distribution as the density for the
465 standardised innovations $\stdu_t$. In practice, the following model:
466 \begin{eqnarray*}
467 y_t & = & \mu + \uhat_{t} \\
468 h_t \equiv V_{t-1}(\uhat_{t}) & = & \omega +
469 \alpha(|\uhat_{t-1}| - \gamma \uhat_{t-1})^2 + \beta h_{t-1} \\
470 f(\stdu_t | \InfSet{t-1}) & = & \frac{K(\nu)}{\sqrt{h_t}}
471 \left[1+\frac{\stdu_t^2}{\nu-2}\right]^{-(\nu + 1)/2}
472 \end{eqnarray*}
473
474 \begin{figure}[htb]
475 \centering
476 \includegraphics[scale=0.45]{graphs/GUI-gig-GJR}
477 \caption{GUI hook for \gig\ (GJR example)}
478 \label{fig:GUI-gig-GJR}
479 \end{figure}
480
481 All you have to do is select the appropriate entries in the
482 \dtk{GUI_gig} window. When it looks like Figure
483 \ref{fig:GUI-gig-GJR}, just press OK\footnote{Note a subtle difference
484 between Figure \ref{fig:GUI-gig} and Figure
485 \ref{fig:GUI-gig-GJR}. In the latter, the ``close this dialog'' tick
486 box near the bottom is not ticked. This, of course, has no effect on
487 the estimates, but may be quite handy if you want to revise your
488 model interactively.} and, after a second or two, the following
489 estimate should appear.\footnote{Note that the GJR model is presented
490 with both parametrisations discussed in section
491 \ref{sec:APARCH}.} The asterisk at the end of the first line of the
492 output indicates that the analytical score was used for estimation.:
493
494 \begin{code}
495 Model: GJR(1,1) [Glosten et al.] (Student's t)*
496 Dependent variable: y
497 Sample: 1980/01/03-1989/12/29 (T = 2527), VCV method: Robust
498
499 Conditional mean equation
500
501 coefficient std. error z p-value
502 -----------------------------------------------------
503 const 0.0483897 0.0170808 2.833 0.0046 ***
504
505 Conditional variance equation
506
507 coefficient std. error z p-value
508 -------------------------------------------------------
509 omega 0.0249070 0.00890124 2.798 0.0051 ***
510 alpha 0.0332144 0.00895699 3.708 0.0002 ***
511 gamma 0.0259622 0.108140 0.2401 0.8103
512 beta 0.939891 0.0155313 60.52 0.0000 ***
513
514 (alt. parametrization)
515
516 coefficient std. error z p-value
517 --------------------------------------------------------
518 delta 0.0249070 0.00890123 2.798 0.0051 ***
519 alpha 0.0315122 0.00726215 4.339 1.43e-05 ***
520 gamma 0.00344928 0.0149219 0.2312 0.8172
521 beta 0.939891 0.0155313 60.52 0.0000 ***
522
523 Conditional density parameters
524
525 coefficient std. error z p-value
526 ------------------------------------------------------
527 ni 5.54597 0.738486 7.510 5.92e-14 ***
528
529 Llik: -3408.87517 AIC: 6829.75034
530 BIC: 6864.75906 HQC: 6842.45322
531 \end{code}
532
533 In fact, the estimate above will be contained in a window on top of
534 which you get several icons: the most interesting are
535 \begin{description}
536 \item[a ``Save'' icon] Use this to save the output as text or to store
537 the model bundle as a gretl icon for later use.
538 \item[a ``Save bundle content'' icon] If you click here, you will see
539 a list of all the objects contained in the bundle holding your
540 model. A complete list is available as Appendix
541 \ref{sec:bundle_struct}, but most names should be
542 self-explanatory. This is where you retrieve stuff for later
543 processing. You also have the option (on top) of saving the whole
544 bundle as such, for later processing.\footnote{In fact, at this
545 stage, the bundle will already be in the Icon View with a
546 temporary name. Do we want to advertise this or should we let the
547 user discover this little trick by himself?} For example, suppose
548 that you want to save the standardised residuals. From the
549 \emph{Save} menu, just pick the \emph{stduhat} entry. A dialog
550 similar to the one shown in Figure \ref{fig:GUI-saveres} should
551 appear: just give the series any time you want and, optionally, a
552 description. For example, you can choose ``\texttt{e}'' as the
553 series name and on ``Estimated standardised residuals'' as the
554 description. The series \texttt{e} should now appear in your main
555 \app{gretl} window, so you can plot it, analyse it, save it
556 etcetera.
557
558 \item[a ``Graph'' icon] By clicking here, you can choose for a plot to
559 display: the choice is between a ``Time series'' plot and a
560 ``Density'' plot. For more details on the nature of these plots, see
561 section \ref{sec:plots}. To edit and/or save those plots, just
562 right-click on them.
563 \end{description}
564
565 \begin{figure}[htb]
566 \centering
567 \includegraphics[scale=0.5]{graphs/GUI-saveres}
568 \caption{GUI window for saving bundle elements}
569 \label{fig:GUI-saveres}
570 \end{figure}
571
572 % \begin{figure}[htb]
573 % \centering
574 % \includegraphics[scale=0.5]{graphs/ts-plot-gjr}
575 % \caption{Post-estimation time series plot (GJR example)}
576 % \label{fig:ts-plot-gjr}
577 % \end{figure}
578
579
580 \subsection{Scripts: a plain-vanilla GARCH}
581 \label{sec:plain-garch}
582
583 The typical way to use \gig\ from a script is to break the sequence of
584 operations implicit in the GUI call in a series of steps. This will
585 (hopefully) help you write nice, tidy, modular and reusable scripts.
586
587 The two functions that you cannot avoid using are called
588 \dtk{gig_setup} and \dtk{gig_estimate}: the former creates a
589 bundle with the basic info about your model, the latter populates it
590 with the estimates. The GUI interface merges these two actions into
591 one, but when you work from a script keeping the two separate has its
592 pros.
593
594 To give you a very simple example of the way the two functions work,
595 we will estimate the most basic GARCH model, that is one in which
596 equations \eqref{eq:espdef} and \eqref{eq:vareq} specialise to
597 \begin{eqnarray*}
598 y_t & = & \uhat_{t} \\
599 h_t & = & \omega + \alpha \uhat_{t-1}^2 + \beta h_{t-1}
600 \end{eqnarray*}
601 and the conditional distribution of $\uhat_{t}$ is assumed to be
602 normal, that is $\uhat_{t} | \InfSet{t-1} \sim N(0, h_t)$.
603
604 The corresponding script reads as follows:
605 \begin{code}
606 # Import the gig library
607 include gig.gfn
608
609 # Read the data and compute returns
610 open djclose
611 y = 100*ldiff(djclose)
612
613 # Estimate a plain-vanilla GARCH model
614 plato = gig_setup(y)
615 gig_estimate(&plato)
616 \end{code}
617
618 The first function we use is \dtk{gig_setup}: this function
619 creates a bundle (called \texttt{plato} in the present example), which
620 contains the basic information on the model that are needed for
621 estimation, that is the dependent variable, the model type and the
622 regressors for the mean and variance equations. In this case, however,
623 the only parameter we need to pass to the function needs is the name
624 of the series containing $y_t$. This is because \dtk{gig_setup}
625 has several default options that allow you to omit some arguments in
626 certain cases. Since in this example the model for the conditional
627 variance is GARCH (the default) and there are no exogenous regressors
628 either in the mean equation nor in the variance equation, you may just
629 omit the corresponding parameters. The complete list of parameters to
630 \dtk{gig_setup} can be found in the Appendix, section
631 \ref{sec:gig_setup}.
632
633 Once the model is set up, we pass the address of the bundle which
634 contains it as the argument to the function
635 \dtk{gig_estimate}. This function performs the actual estimation
636 via maximum likelihood and (by default) prints out the results:
637 \begin{code}
638 Model: GARCH(1,1) [Bollerslev] (Normal)*
639 Dependent variable: y
640 Sample: 1980/01/03-1989/12/29 (T = 2527), VCV method: Robust
641
642 Conditional variance equation
643
644 coefficient std. error z p-value
645 -------------------------------------------------------
646 omega 0.0476635 0.0332897 1.432 0.1522
647 alpha 0.0905285 0.0566925 1.597 0.1103
648 beta 0.871816 0.0674671 12.92 3.38e-38 ***
649
650 Llik: -3575.27720 AIC: 7156.55440
651 BIC: 7174.05876 HQC: 7162.90584
652 \end{code}
653
654 Note that the main purpose of \dtk{gig_estimate} is to run the
655 maximum likelihood estimation routine and store its output into the
656 bundle whose address is given as the function's first argument (in
657 this case, \texttt{plato}). The \dtk{gig_estimate} function also
658 accepts a second argument: a scalar which sets the verbosity of the
659 output. Its default value (which can be omitted, as above) is 1, which
660 causes the estimation output to be printed out. If set to 0, the
661 estimation takes place silently, which can be useful at times (in a
662 loop, for example); on the contrary, the value 2 forces
663 \dtk{gig_estimate} to print out all the BFGS iterations. You can
664 print out the contents of an estimated model any time after it has
665 been estimated, via the \dtk{gig_print} function.
666
667 \subsection{Regressors}
668 \label{sec:regressors}
669
670 Here we run a model similar to the one shown in the previous example,
671 with a few differences. First, we assume that the conditional density
672 for innovations is a skewed GED, where its shape and skew parameters
673 will have to be estimated. Moreover, we will introduce explanatory
674 variables for both the mean and the variance equation.
675 \begin{eqnarray*}
676 y_t & = & \pi_0 + \pi_1 y_{t-1} + \uhat_{t} \\
677 h_t & = & \omega_0 +
678 \omega_1 v_{t-1} + \omega_2 s_{t-1} +
679 \alpha \uhat_{t-1}^2 + \beta h_{t-1}
680 \end{eqnarray*}
681 where $v_t$ is the log volume and $s_t$ is the log High/Low ratio.
682
683 \begin{code}
684 # Import the gig library
685 include gig.gfn
686
687 # Read the data
688 open msft.gdt
689
690 # compute returns
691 r = 100*ldiff(Close)
692
693 # compute the variance regressors
694 lv = ln(Volume/1000000)
695 hl = ln(High/Low) * 100
696
697 # set up the regressor lists
698 list X = const
699 list vX = const lv(-1) hl(-1)
700
701 # set up the model
702 socrates = gig_setup(r, 1, X, vX, 1)
703 gig_set_dist(&socrates, 4)
704
705 # estimate
706 gig_estimate(&socrates)
707 \end{code}
708
709 In this case, we call \dtk{gig_setup} with 5 parameters: the
710 dependent variable, the model type (1, which stands for GARCH), the
711 two lists of regressors for the mean and the variance equation and the
712 number of AR lags in the mean equation.
713
714 Note that in this case you could have done things a little differently
715 with the same effect: first, you could have included $y_{t-1}$ in the
716 list \texttt{X} via
717 \begin{code}
718 list X = const r(-1)
719 \end{code}
720 and this is indeed the way you would do things in earlier versions of
721 \gig. However, it is advisable to follow the new syntax and specify
722 lags of the dependent variable as regressors separately.\footnote{Don't
723 ask why.} Second, you could have used \texttt{const} instead of
724 \texttt{X} in the call to \dtk{gig_setup} and use the nice gretl
725 feature of being able to use a series name as a synonym for a
726 one-element list, so
727 \begin{code}
728 socrates = gig_setup(r, 1, const, vX, 1)
729 \end{code}
730 would have worked just as well.
731
732 The model will be contained in a bundle named \texttt{socrates}. The
733 task of setting the conditional distribution for $\stdu_t$ is
734 delegated to the \dtk{gig_set_dist} function, which takes as
735 parameters the address to the bundle and a numerical code identifying
736 the density. In this example, 4 stands for the skewed GED
737 distribution; see Table \ref{tab:modelcodes}, right-hand side for the
738 full list. The output follows:
739
740 \begin{code}
741 Model: GARCH(1,1) [Bollerslev] (Skewed GED)
742 Dependent variable: r
743 Sample: 1990/01/04-2009/02/11 (T = 4817), VCV method: Robust
744
745 Conditional mean equation
746
747 coefficient std. error z p-value
748 ------------------------------------------------------
749 const 0.0474803 0.0274078 1.732 0.0832 *
750 AR1 -0.0248744 0.0141066 -1.763 0.0778 *
751
752 Conditional variance equation
753
754 coefficient std. error z p-value
755 --------------------------------------------------------
756 const 0.169134 0.183983 0.9193 0.3579
757 lv_1 -0.125632 0.0441290 -2.847 0.0044 ***
758 hl_1 0.425972 0.116401 3.660 0.0003 ***
759 alpha 0.0331390 0.0126196 2.626 0.0086 ***
760 beta 0.787553 0.0456421 17.25 1.03e-66 ***
761
762 Conditional density parameters
763
764 coefficient std. error z p-value
765 --------------------------------------------------------
766 ni 1.38025 0.0601761 22.94 1.99e-116 ***
767 lambda 0.0330455 0.0206053 1.604 0.1088
768
769 Llik: -9964.53237 AIC: 19947.06473
770 BIC: 20005.38389 HQC: 19967.54332
771 \end{code}
772
773 \subsection{Tweaking the model specification}
774 \label{sec:tweak}
775
776 In the previous subsection, we used the \dtk{gig_set_dist}
777 function to record into the bundle a piece of information (the
778 conditional distribution) necessary for estimation. Another similar
779 function is \dtk{gig_set_pq}, which sets the GARCH and ARCH
780 orders. In general, however, most aspects can be set simply by setting
781 the bundle elements to specific values (see section
782 \ref{sec:bundle_struct} for a complete list of the bundle elements).
783
784 The reason why you'll want to use \dtk{gig_set_dist} and
785 \dtk{gig_set_pq} is that a few adjustments have to be made to
786 other bundle elements, and by using those functions you let \gig\ do
787 it for you in the proper way. But in many cases all you have to do is
788 set the appropriate bundle element to the appropriate value. An
789 exception to this rule is the \dtk{gig_set_vcvtype} function: it
790 provides an alternative to setting the \texttt{vcvtype} scalar by
791 using a string, which should be easier to remember. The example below
792 should be rather self-explanatory, but you may also want to have a
793 look at Table \ref{tab:tweaks}, which provides a quick guide to common
794 operations.
795
796 \begin{code}
797 open b-g.gdt --quiet
798 include gig.gfn
799 democritus = gig_setup(Y, 6, const) # APARCH(1,1)
800 gig_estimate(&democritus) # estimate
801 gig_set_pq(&democritus, 1, 2) # set q to 2
802 gig_set_vcvtype(&democritus, "Hessian") # set vcvtype to Hessian
803 gig_estimate(&democritus) # re-estimate
804 \end{code}
805
806 Another function that can be useful at times is
807 \dtk{gig_set_vQR}: unfortunately, the lack of analytical
808 derivatives at this stage of development of \gig\ makes it relatively
809 prone to numerical issues when exogenous variables are present in the
810 variance equation. It is advisable to express the variance regressors
811 in such a way that the matrix $T^{-1} \sum_t z_t z_t'$ is numerically
812 well-conditioned. If you call \dtk{gig_set_vQR} with 1 as second
813 parameter, \gig\ will will try to do it for you via a QR
814 decomposition. In most cases we've tried, it seems to work quite
815 nicely, but this feature should be considered experimental and is
816 disabled by default.
817
818 \begin{table}[htbp]
819 \centering
820 \begin{tabular}{p{0.35\textwidth}p{0.6\textwidth}}
821 \hline
822 \hline
823 \textbf{It you want to\ldots} &
824 \textbf{You have to\ldots} \\
825 \hline
826 Change the type of an existing model &
827 You can't. Re-create the bundle with \dtk{gig_setup} \\
828 Change the dependent variable of an existing model &
829 You can't. Re-create the bundle with \dtk{gig_setup} \\
830 Change the regressors for an existing model &
831 You can't. Re-create the bundle with \dtk{gig_setup} \\
832 Change the AR order for an existing model &
833 You can't. Re-create the bundle with \dtk{gig_setup} \\
834 Re-estimate an existing model on a different sample &
835 You can't. Run the appropriate \texttt{smpl} command first
836 and then re-create the bundle with \dtk{gig_setup} \\
837 Change the density for an existing model &
838 Use \dtk{gig_set_dist} with the appropriate density code \\
839 Change the orders of the polynomials for an existing model &
840 Use \dtk{gig_set_pq} \\
841 Change the way the covariance matrix is computed &
842 Set the bundle element \texttt{vcvtype} to 0, 1 or 2, or use
843 \dtk{gig_set_vcvtype} \\
844 Change the initial values for BFGS &
845 Set the bundle element \texttt{inipar} to your liking; be sure you
846 know what you're doing \\
847 Toggle QR decomposition for variance regressors &
848 Use \dtk{gig_set_vQR} \\
849 Change the verbosity of BFGS &
850 You can't change it permanently: it's the second parameter to
851 \dtk{gig_estimate} \\
852 \hline
853 \hline
854 \end{tabular}
855 \caption{Tweaking models}
856 \label{tab:tweaks}
857 \end{table}
858
859 \subsection{Forecasting}
860 \label{sec:forecast}
861
862 As of version 2.2 (July 2016) there is now a function for
863 simulation-based variance
864 forecasting named \dtk{gig_var_fcast}. It takes 3 arguments:
865 \begin{enumerate}
866 \item a pointer to the bundle containing the model
867 \item the horizon up to which you want the forecast
868 \item the number of draws to use in the simulation
869 \end{enumerate}
870
871 In practice, future values for $\sigma^2_t$ will be calculated by
872 means of equation \eqref{eq:aparch};\footnote{No, no EGARCH yet;
873 sorry.} the future $\uhat_t$ terms are drawn with replacement from
874 the residuals of the model. It will return a matrix with the
875 simulation results (one per row) for your playing pleasure.
876
877 The same matrix can be used as the first argument to the companion
878 function \dtk{gig_vfgraph}, for which we defer to section
879 \ref{sec:plots}. A brief example follows.
880
881 \begin{scode}
882 set echo off
883 set messages off
884 set seed 123
885
886 open b-g.gdt --quiet
887 include gig.gfn
888 heraclitus = gig_setup(Y, 1, const)
889 gig_estimate(&heraclitus)
890
891 # ---------------
892 # forecast
893 # ---------------
894
895 scalar horizon = 390
896 scalar rep = 400
897 matrix varfore = gig_var_fcast(&heraclitus, 39, 1024)
898 \end{scode}
899
900 The matrix \texttt{varfore} will contain 39 rows and 1024 columns with
901 the simulation results. If, for example, you'd like to calculate the
902 median of the simulated variances, all you have to do is
903 \begin{code}
904 matrix median_vola = quantile(varfore, 0.5)
905 \end{code}
906
907 \section{Plots}
908 \label{sec:plots}
909
910 \begin{figure}[htbp]
911 \centering
912 \begin{tabular}{cc}
913 \includegraphics[scale=0.5]{graphs/plot_ex} &
914 \includegraphics[scale=0.5]{graphs/dplot_ex} \\
915 \dtk{gig_plot} example &
916 \dtk{gig_dplot} example
917 \end{tabular}
918 \caption{Example plots}
919 \label{fig:ex-plots}
920 \end{figure}
921
922
923 The \gig\ package provides three built-in functions for plotting the
924 results of a model: \dtk{gig_plot}, \dtk{gig_dplot} and
925 \dtk{gig_vfgraph}, which correspond to the ``Time series'',
926 ``Density'' and the ``Forecast'' entries of the ``Plot'' GUI menu (see
927 subsection \ref{sec:GUI}).
928
929 The \dtk{gig_plot} function produces a plot that is very similar to
930 the one that \app{gretl}'s native GARCH routine gives you after
931 estimation, that is a time-plot of the model residuals and the
932 estimated conditional standard deviation.
933
934 The \dtk{gig_plot} function, instead, compares the estimated density
935 of the standardised innovations to their non-parametric kernel
936 estimate and can be used for judging visually how adequate the choice
937 of a conditional distribution is.
938
939 The following code
940 fragment exemplifies of their usage in a script; the input code:
941
942 \begin{code}
943 include gig.gfn
944 open b-g.gdt
945 epicurus = gig_setup(Y,7,const)
946 gig_set_dist(&epicurus, 1)
947 gig_estimate(&epicurus)
948 gig_plot(&epicurus)
949 gig_dplot(&epicurus)
950 \end{code}
951 produces the following output
952 \begin{code}
953 Model: EGARCH(1,1) [Nelson] (Student's t)
954 Dependent variable: Y
955 Sample: 1-1974 (T = 1974), VCV method: Robust
956
957 Conditional mean equation
958
959 coefficient std. error z p-value
960 ---------------------------------------------------------
961 const -0.000238229 0.00686306 -0.03471 0.9723
962
963 Conditional variance equation
964
965 coefficient std. error z p-value
966 -------------------------------------------------------
967 omega -0.220313 0.0623767 -3.532 0.0004 ***
968 alpha 0.255802 0.0624886 4.094 4.25e-05 ***
969 gamma -0.0379411 0.0181844 -2.086 0.0369 **
970 beta 0.977675 0.0125505 77.90 0.0000 ***
971
972 Conditional density parameters
973
974 coefficient std. error z p-value
975 ------------------------------------------------------
976 ni 4.12520 0.402748 10.24 1.28e-24 ***
977
978 Llik: -986.08927 AIC: 1984.17853
979 BIC: 2017.70544 HQC: 1996.49706
980 \end{code}
981 and the plots shown in Figure \ref{fig:ex-plots}.
982
983 The function \dtk{gig_vfgraph}, instead, is a little more complex: it
984 takes four arguments. The first one is a matrix with the results of
985 the simulations used to forecast the variances, such as the one
986 produced by the \dtk{gig_var_fcast} function. The other two are two
987 scalars indicating how many observation of the in-sample fitted
988 variants you want in the graph and the width of the coverage region
989 (between 0 and 1).
990
991 \section{Numerical issues}
992 \label{sec:numerical}
993
994 \subsection{\gig\ is slow, especially EGARCH}
995 Analytical derivatives of the likelihood for APARCH model with normal
996 innovations were computed by \cite{Laurent}. At present, however,
997 \gig\ relies on numerical differentiation only for some of the models
998 it handles.\footnote{Note to the reader: we wouldn't feel offended if
999 \emph{you} helped with the code for the analytical score, you
1000 know. Not in the slightest.}
1001
1002 An important difference between equation \eqref{eq:aparch} and
1003 \eqref{eq:egarch} is that in the APARCH case the conditional variance
1004 can be written as a linear filter of the $\uhat_{t-i}$ variables,
1005 whereas in the EGARCH formulation you have the $\stdu_{t-i}$
1006 variables, so the EGARCH filter is not linear. Given the way \gig\ is
1007 presently written (and the fact that we haven't coded the analytical
1008 score for EGARCH yet), this implies that EGARCH filtering is much more
1009 time-consuming than APARCH filtering, and as a consequence estimation
1010 times are somewhat longer. We're working on this.
1011
1012 \subsection{The maximisation algorithm fails to converge}
1013
1014 All statistical models that rely on numerical optimisation methods may
1015 suffer from convergence or accuracy problems. In case you encounter
1016 convergence problems, you may want to try the following tricks:
1017 \begin{itemize}
1018 \item Enable the highest level of verbosity in
1019 \dtk{gig_estimate()} to see what goes wrong.
1020 \item Rescale your data. Estimation may be sensitive to the scale of
1021 the dependent variable and/or your explanatory variables. There is
1022 an internal algorithm to rescale some data ``sensibly'', but is not
1023 guaranteed to work. Should you encounter convergence problems, it is
1024 advisable to scale $y_t$ so that its variance is between 0.01 and
1025 100. A useful thumb rule is that, for example, returns should be
1026 computed as $r_t = 100 \cdot \Delta \ln P_t$.
1027 \item Try changing the optimisation algorithm via \texttt{set lbfgs}
1028 or \texttt{set optimizer newton}; see the User's Guide for more details.
1029 \item Try starting the algorithm from a different starting point than
1030 the default. In order to do this, you must modify the \texttt{coeff}
1031 element of the model bundle before calling
1032 \dtk{gig_estimate}. See the example below.
1033 \end{itemize}
1034
1035
1036 \begin{scode}
1037 include gig.gfn
1038 open b-g.gdt --quiet # Bollerslev-Ghysels esample dataset
1039 moo = gig_setup(Y, 3, const) # GJR, no regressors
1040 gig_set_pq(&moo, 2, 1) # set p and q (just for fun)
1041 theta_0 = moo.coeff # the automatic starting values
1042 print theta_0 # have a look at them
1043 gig_estimate(&moo,2) # now estimate verbosely
1044 theta_1 = {0; 0.5; 0.2; 0; 0.7; 0.1; 2} # choose another starting point
1045 moo.coeff = theta_1 # stuff it into the model
1046 gig_estimate(&moo,2) # now re-estimate verbosely
1047 \end{scode}
1048
1049 \subsection{The algorithm converges but complains about a singular
1050 Hessian}
1051
1052 All the items in the previous subsection apply. Moreover, consider
1053 that perhaps your problem \emph{is} ill-conditioned after
1054 all. Conditionally heteroskedastic model can be very picky, especially
1055 with few datapoints. Try similar models and/or slightly different
1056 sample ranges to see what happens.
1057
1058 \subsection{The algorithm converges, but the maximum is outside the
1059 admissible region!}
1060
1061 In the comfortable world of GARCH(1,1), the constraints $\alpha > 0$,
1062 $\beta \ge 0$ and $\alpha + \beta < 1$ are natural, because you want
1063 your conditional variances $h_t$ to be positive and finite for all
1064 $t$. Note that each of those requirements has a slightly different
1065 reason. First, $\alpha = 0$ would make the model underidentified, so
1066 $\alpha > 0$ is an absolute must. On the other hand, the requirement
1067 $\alpha + \beta < 1$ applies to the \emph{true} parameters, whereas
1068 their \emph{estimates} may well violate that requirement in a finite
1069 sample. For example, the point in the parameter space which maximises
1070 the likelihood may be outside the admissible range just because your
1071 dataset ends with a massive volatility burst. A similar argument goes
1072 for models with $q>1$; the second-lag ARCH parameter $\alpha_2$, for
1073 instance, must be positive to ensure that $h_t$ can never be negative,
1074 but in a finite sample the sequence of conditional variances that
1075 maximises the likelihood may include a small negative value for
1076 $\alpha_2$.
1077
1078 Besides, a good algorithm should handle the case, which is frequent in
1079 practice, where parameters go outside the admissible region during
1080 maximisation but eventually go back into it because the maximum is
1081 inside that region after all.
1082
1083 In such a situation, surely you wouldn't want the software to hide the
1084 problem from you, so just printing out something like
1085 \begin{code}
1086 I'm sorry, your estimates are outside the admissible region
1087 \end{code}
1088 would be a patronising decision from the software (that is, from
1089 us). In our opinion, the best policy is to treat such results for
1090 what they are: a finite-sample oddity if your model is right or (more
1091 likely) an indication that perhaps your model wasn't the best choice
1092 after all.
1093
1094 So, the current state of things in \gig\ is: no constraints are put on
1095 the parameters. In the future, we'll issue a warning if the algorithm
1096 stops at some unorthodox point. This is easy for a GARCH(1,1) model;
1097 for GARCH($p$,$q$) models it's more complex, but still possible
1098 \citep{NelCao92}.\footnote{Again, a little help with the coding of the
1099 Nelson--Cao conditions would be welcome.} However, it's not clear
1100 what to do with models with exogenous variables in the volatility
1101 equation or non-GARCH models. We are not aware of a generalisation of
1102 the Nelson--Cao conditions for the APARCH model; pointers would be
1103 appreciated, if any of you know of any.
1104
1105 \bibliography{gig}
1106
1107 %\clearpage
1108 \appendix
1109
1110 \section{List of functions}
1111 \label{sec:syntax}
1112 \subsection{Model setup}
1113 \label{sec:gig_setup}
1114
1115 \begin{funcdoc}{gig_setup(series depVar, scalar type, list X,
1116 list varX, scalar ARlags)}
1117 \begin{enumerate}
1118 \item a series containing $y_t$, the dependent variable \textbf{(required)}
1119 \item a scalar for the model type (see Table \ref{tab:modelcodes},
1120 left-hand side)
1121 \item a list with the exogenous variables in the mean equation: in
1122 terms of eq.~\eqref{eq:espdef}, the $x_t$ variables. Lags of the
1123 dependent variable, if any, must be included in this list. (Default:
1124 \texttt{null})
1125 \item a list with the exogenous variables in the variance equation: in
1126 terms of eq.~\eqref{eq:vareq}, the $z_t$ variables. A constant term
1127 is automatically included if absent. (Default: \texttt{null})
1128 \item a scalar, holding the number of autoregressive terms in the mean
1129 equation. (Default: 0)
1130 \end{enumerate}
1131 \end{funcdoc}
1132
1133 \begin{funcdoc}{gig_set_dist(bundle *b, int code)}
1134 \begin{enumerate}
1135 \item the address of a model bundle created via \dtk{gig_setup}
1136 \textbf{(required)}
1137 \item a scalar for the conditional density function (see Table \ref{tab:modelcodes},
1138 right-hand side)
1139 \end{enumerate}
1140 \end{funcdoc}
1141
1142 \begin{funcdoc}{gig_set_pq(bundle *b, int p, int q)}
1143 \begin{enumerate}
1144 \item the address of a model bundle created via \dtk{gig_setup}
1145 \textbf{(required)}
1146 \item $p$, the GARCH order (between 0 and 2, default 1)
1147 \item $q$, the ARCH order (minimum 1, default 1)
1148 \end{enumerate}
1149 \end{funcdoc}
1150
1151 \begin{funcdoc}{gig_set_vcvtype(bundle *b, string s)}
1152 \begin{enumerate}
1153 \item the address of a model bundle created via \dtk{gig_setup}
1154 \textbf{(required)}
1155 \item a string: ``Hessian'', ``OPG'' or ``Sandwich'';
1156 \textbf{(required)}. Note that
1157 \begin{enumerate}
1158 \item the function is case-insensitive, so ``opg'' and ``OPG''
1159 produce the same effect;
1160 \item other strings than the ones listed above produce no effect.
1161 \end{enumerate}
1162 \end{enumerate}
1163 \end{funcdoc}
1164
1165 \begin{funcdoc}{gig_set_vQR(bundle *b, boolean on_off)}
1166 \begin{enumerate}
1167 \item the address of a model bundle created via \dtk{gig_setup}
1168 \textbf{(required)}
1169 \item 1 to activate the QR decomposition for variance regressors, 0 to
1170 de-activate
1171 \end{enumerate}
1172 \end{funcdoc}
1173
1174 \subsection{Estimation}
1175 \label{sec:syntax_estim}
1176
1177 \begin{funcdoc}{gig_estimate(bundle *b, int verbose[0:2:1])}
1178
1179 General estimation function. % It returns a matrix with the estimation
1180 % results stored in packed form (see appendix \ref{sec:output_struct}).
1181 Its arguments are:
1182 \begin{enumerate}
1183 \item the address of a model bundle created via \dtk{gig_setup}
1184 \textbf{(required)}
1185 \item a verbosity switch, from 0 to 2. (Default: 1)
1186 \end{enumerate}
1187 \end{funcdoc}
1188
1189 \begin{table}[htbp]
1190 \centering
1191 \begin{tabular}{rl|rl}
1192 \hline
1193 \textbf{Code} & \textbf{Model Type} & \textbf{Code} & \textbf{Density Type} \\
1194 \hline
1195 0 & ARCH & 0 & Normal (default) \\
1196 1 & GARCH (default) & 1 & Student's $t$ \\
1197 2 & Taylor/Schwert GARCH & 2 & GED\\
1198 3 & GJR & 3 & Skewed $t$ \\
1199 4 & Zakoian's TARCH & 4 & Skewed GED \\
1200 5 & NARCH \\
1201 6 & APARCH \\
1202 7 & EGARCH \\
1203 \hline
1204 \hline
1205 \end{tabular}
1206 \caption{Model type/density function codes}
1207 \label{tab:modelcodes}
1208 \end{table}
1209
1210 \subsection{Output}
1211 \label{sec:syntax_output}
1212
1213 Note: these functions assume that the bundle they refer to contain a
1214 model that has already been estimated. No checks is performed.
1215
1216 \begin{funcdoc}{gig_print(bundle *b, scalar verbose)}
1217 Prints out a model.
1218 \end{funcdoc}
1219
1220 \begin{funcdoc}{gig_plot(bundle *b)}
1221 Plots the residuals/conditional SE graph.
1222 \end{funcdoc}
1223
1224 \begin{funcdoc}{gig_dplot(bundle *b)}
1225 Plots the estimated density of the standardized residuals versus its
1226 nonparametric estimate.
1227 \end{funcdoc}
1228
1229 \clearpage
1230
1231 \section{Bundle elements}
1232 \label{sec:bundle_struct}
1233 \begin{footnotesize}
1234 \begin{tabular}{rlp{0.7\textwidth}}
1235 \hline
1236 \textbf{Name} & \textbf{Type} & \textbf{Purpose} \\
1237 \hline
1238 \multicolumn{3}{c}{Model descriptors} \\
1239 \hline
1240 \texttt{type} & scalar & model type (as per Table \ref{tab:modelcodes})\\
1241 \texttt{AR} & scalar & AR order (mean equation) \\
1242 \texttt{p} & scalar & GARCH order\\
1243 \texttt{q} & scalar & ARCH order\\
1244 \texttt{cdist} & scalar & conditional density (as per Table \ref{tab:modelcodes})\\
1245 \texttt{mlistX} & matrix & list of mean regressors \\
1246 \texttt{vlistX} & matrix & list of variance regressors \\
1247 \texttt{mk} & scalar & number of mean regressors \\
1248 \texttt{vk} & scalar & number of variance regressors\\
1249 \texttt{nobs} & scalar & number of observations \\
1250 \texttt{t1} & scalar & first observation used \\
1251 \texttt{t2} & scalar & last observation used \\
1252 \hline
1253 \multicolumn{3}{c}{Strings} \\
1254 \hline
1255 \texttt{depvarname} & string & dependent variable name\\
1256 \texttt{mXnames} & string & mean regressors names \\
1257 \texttt{vXnames} & string & variance regressors names \\
1258 \hline
1259 \multicolumn{3}{c}{Data} \\
1260 \hline
1261 \texttt{y} & series & dependent variable \\
1262 \texttt{mX} & matrix & mean regressors \\
1263 \texttt{vX} & matrix & variance regressors\\
1264 \texttt{s2} & scalar & sample variance of the OLS residuals of $y$ on $X$
1265 \\
1266 \hline
1267 \multicolumn{3}{c}{Estimation parameters} \\
1268 \hline
1269 \texttt{scale} & scalar & auto-scaling (used internally) \\
1270 \texttt{vcvtype} & scalar & method for computing the covariance
1271 matrix: 0 = Sandwich (default), 1 = Hessian, 2 = OPG\\
1272 \texttt{inipar} & matrix & Starting values for BFGS \\
1273 \texttt{active} & matrix & indicates which elements of the parameter
1274 vector are active during ML estimation\\
1275 \dtk{vX_QR} & scalar & Toggles QR decomposition for variance regressors\\
1276 \hline
1277 \multicolumn{3}{c}{Estimation results} \\
1278 \hline
1279 \texttt{errcode} & scalar & error code from BFGS (0 = ok)\\
1280 \texttt{coeff} & matrix & coefficients \\
1281 \texttt{stderr} & matrix & std. deviations \\
1282 \texttt{vcv} & matrix & covariance matrix \\
1283 \texttt{uhat} & series & residuals \\
1284 \texttt{h} & series & conditional variance \\
1285 \texttt{stduhat} & series & standardised residuals \\
1286 \texttt{criteria} & matrix & information criteria\\
1287 \hline
1288 \hline
1289 \end{tabular}
1290 \end{footnotesize}
1291
1292 \clearpage
1293
1294 NOTA BENE: For APARCH models, the order in which the estimated
1295 parameters are stored in the \texttt{coeff} matrix is the following:
1296 \begin{enumerate}
1297 \item Conditional mean parameters
1298 \item $\omega_0 \ldots \omega_k$, where $k$ is the number of variance
1299 regressors; the constant in equation \eqref{eq:aparch} is here.
1300 \item $\alpha_1 \ldots \alpha_q$
1301 \item $\gamma_1 \ldots \gamma_q$; if the model contains ``leverage''
1302 terms (otherwise, \emph{eg} with the plain GARCH model, you have
1303 zeros here)
1304 \item $\beta_1 \ldots \beta_p$
1305 \item parameters for the conditional density: for example, degrees of
1306 freedom $\nu$ for Student's $t$.
1307 \end{enumerate}
1308 \end{document}
1309
1310
1311 %%% Local Variables:
1312 %%% mode: latex
1313 %%% TeX-master: t
1314 %%% End: