Using gret l for Principles of Econometrics, 4th Edition
Garch-in-Mean
The Garch-in-mean (MGARCH) model adds the equation’s variance to the regression function. This allows the average value of the dependent variable to depend on volatility of the underlying asset. In this way, more risk (volatility) can lead to higher average return. The equations are listed below:
yt = во + Oht + et (14.9)
ht = 5 + aief-1 + ydt-ie[81]-! + eiht-i (14.10)
Notice that in this formulation we left the threshold term in the model. The errors are normally distributed with zero mean and variance ht.
The parameters of this model can be estimated using gretl, though the recursive nature of the likelihood function makes it a bit more difficult. In the script below (Figure 14.9) you will notice that we’ve defined a function to compute the log-likelihood.2 The function is called gim_filter and it contains eight arguments. The first argument is the time-series, y. Then, each of the parameters is listed (mu, theta, delta, alpha, gam, and beta) as scalars. The final argument is a placeholder for the variance, h, that is computed within the function.
Once the function is named and its arguments defined, you need to initiate series for the variances and the errors; these have been called lh and le, respectively. The log-likelihood function is computed using a loop that runs from the second observation through the last. The length of the series can be obtained using the saved result $nobs, which is assigned to the variable T.
Gretl’s loop syntax is very straightforward, though as we have shown in previous chapters, there are several variations. In this example the loop is controlled using the special index variable, i. In this case you specify starting and ending values for i, which is incremented by one each time round the loop. In the MGARCH example the loop syntax looks like this:
loop for i=2..T —quiet [Things to compute] end loop
The first line start the loop using an index variable named i. The first value of i is set to 2. The index i will increment by 1 until it reaches T, which has already been defined as being equal to $nobs. The end loop statement tells gretl the point at which to return to the top of the loop and advance the increment i. The —quiet option just reduces the amount of output that is written to the screen.
Within the loop itself, you’ll want to lag the index and create an indicator variable that will take the value of 1 when the news is bad (et-1 < 0). The next line squares the residual. lh[i] uses the loop index to place the variance computation from the iteration into the ith row of lh. The line that begins le[i]= works similarly for the errors of the mean equation.
The variances are collected in h and the residuals in le, the latter of which is returned when the function is called. The function is closed using end function.
If this looks too complicated, you can simply highlight the code with your cursor, copy it using Ctrl-C, and paste it into a gretl script file (or use the scripts provided with this book).
Once the function is defined, you need to initialize each parameter just as you did in TGARCH. The series that will eventually hold the variances also must be initialized. The latter is done using series h = NA, which creates the series h and fills it with missing values (NA). The missing values for observations 2 through T are replaced as the function loops.
Next, the built-in mle command is issued and the normal density kernel is specified just as it was in the TGARCH example. Then, use the predefined e=gim_filter( ) function, putting in the variable r for the time-series, the initialized parameters, and &h as a pointer to the variances that will be computed within the function. Issue the params statement to identify the parameters and have them print to the screen. Close the loop and run the script. The results appear in Figure
14.10 below. This is a difficult likelihood to maximize and gretl may take some time to compute the estimates. Still, it is quite remarkable that we get so close using a free piece of software and the numerical derivatives that it computes for us.
1 open "@gretldirdatapoereturns. gdt"
2 set echo off
3
3 scatters nasdaq allords ftse nikkei
4 freq nasdaq —normal
5 freq allords —normal
6 freq ftse —normal
7 freq nikkei —normal
9
8 open "@gretldirdatapoebyd. gdt"
11
9 # arch(1) Using built in command for arch
10 arch 1 r const
14
11 # garch(0,1)=arch(1)
12 garch 0 1 ; r const
17
13 # garch(1,1)
14 garch 1 1 ; r const
20
15 # LM test for arch
16 ols r const
17 modtest 1 —arch
24
18 # LM test manually
19 ols r const
20 series ehat = $uhat
21 series ehat2 = ehat*ehat
22 ols ehat2 const ehat2(-1)
23 scalar tr2 = $trsq
31
24 # plotting garch variances
25 garch 1 1 ; r const
26 series ht = $h
27 gnuplot ht time
36
28 # threshold arch
29 open "@gretldirdatapoebyd. gdt"
39
30 scalar mu = 0.5
31 scalar omega = .5
32 scalar alpha = 0.4
33 scalar delta = 0.1
34 scalar beta = 0
45
35 mle ll = -0.5*(log(h) + (e"2)/h)
36 series h = var(r)
37 series e = r - mu
series e2 = ert2 series e2m = e2 * (e<0)
series h = omega + alpha*e2(-1) + delta*e2m(-1) + beta*h(-1) params mu omega alpha delta beta end mle
# garch-in-mean — the function function gim_filter(series y,
scalar mu, scalar theta, scalar delta, scalar alpha, scalar gam, scalar beta, series *h)
series lh = var(y) series le = y - mu scalar T = $nobs loop for i=2..T --quiet scalar ilag = $i - 1 scalar d = (le[ilag]<0) scalar e2lag = le[ilag]rt2
lh[i] = delta + alpha*e2lag + gam*e2lag*d + beta*lh[ilag] le[i] = le[i] - theta*lh[i] end loop
series h = lh return series le
end function
# garch-in-mean
open "@gretldirdatapoebyd. gdt"
scalar mu = 0.8 scalar gam = .1 scalar alpha = 0.4 scalar beta = 0 scalar delta = .5 scalar theta = 0.1
series h
mle ll = -0.5*(log(2*pi) + log(h) + (ert2)/h)
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
e = gim_filter(r, mu, theta, delta, alpha, gam, beta, &h) params mu theta delta alpha gam beta end mle --robust
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
function gim_filter(series y,
scalar mu, scalar theta, scalar delta, scalar alpha, scalar gam, scalar beta, series *h)
series lh = var(y) series le = y - mu scalar T = $nobs loop for i=2..T —quiet scalar ilag = $i - 1 scalar d = (le[ilag]<0) scalar e2lag = le[ilag]rt2
lh[i] = delta + alpha*e2lag + gam*e2lag*d + beta*lh[ilag] le[i] = le[i] - theta*lh[i] end loop
series h = lh return series le
end function
open "c:Program FilesgretldatapoeBYD. gdtM
scalar mu = 0.8 scalar gam = .1 scalar alpha = 0.4 scalar beta = 0 scalar delta = .5 scalar theta = 0.1
series h = NA
mle ll = -0.5*(log(2*pi) + log(h) + (ert2)/h)
e = gim_filter(r, mu, theta, delta, alpha, gam, beta, &h) params mu theta delta alpha gam beta end mle --robust
Using numerical derivatives Tolerance = 1.81899e-012 Function evaluations: 95 Evaluations of gradient: 22
Model 1: ML, using observations 1-500 11 = -0.5*(log(2*pi) + log(h) + (e~2)/h) QML standard errors
estimate |
std. error |
z |
p-value |
||
ІШІ |
0.814458 |
0.0677112 |
12.03 |
2.52 e-033 |
* * * |
theta |
0.200302 |
0.060Э7ЭЭ |
3.2 93 |
0.0010 |
* * * |
delta |
0.3707=7 |
0.0653221 |
5.633 |
1.77e-03 |
* * * |
alpha |
0.296679 |
0.07344 Э 6 |
4.03Э |
5.3 6e-05 |
* * * |
gam |
0.313666 |
0.123117 |
2.443 |
0.0144 |
* * |
beta |
0.27Э006 |
0.0544013 |
5.12 Э |
2.92 e-07 |
*** |
1460.Э2 2 1470.345 |
Log-likelihood -724.4610
Schwarz criterion 1486.210
Figure 14.10: Garch-in-mean results