On 05-12-2009, at 13:56, Davor Horvatic wrote:
Concerning mle, I like to test and check results independently and I
came across
a problem.
Can anyone supply explicit code to determine GARCH(1,1) coefficients
with different method (OLS, MLE via R ...) for the simple example from
the user guide.
open djclose
series y = 100*ldiff(djclose)
scalar mu = 0.0
scalar omega = 1
scalar alpha = 0.4
scalar beta = 0.0
mle ll = check ? (-0.5*(log(h) + (e
2
)/h)) : NA
series e = y - mu
series h = var(y)
series h = omega + alpha*(e(-1))
2
+ beta*h(-1)
scalar check = (alpha>0) && (beta>0)
params mu omega alpha beta
end mle
Using R 2.10.0 (patched) on Mac OS X 10.6.2.
Copied gretldata to folder containing R script.
Inserted below are the R script and the R output.
Differences with gretl are small and are not worth to worrying about.
BTW. Just in case: I am not a Garch-guru. I found the R garch function by doing ??garch.
Berend
-----------------------------------------------------
The R script is
<script>
library(tseries)
# load data from gretl
gretldata <- read.table("gretldata.txt", header=TRUE)
gretldata <- ts(gretldata, start=c(1980, 1), frequency = 5)
yts <- gretldata[2:nrow(gretldata),"y"]
yts.garch1 <- garch(yts)
yts.garch2 <- garch(yts,start=c(1,0.4,0.01))
yts.garch3 <-
garch(yts,start=c(1,0.4,0.01),control=garch.control(grad="numerical"))
summary(yts.garch1)
summary(yts.garch2)
summary(yts.garch3)
</script>
Summary output is:
<OUTPUT>
summary(yts.garch1)
Call:
garch(x = yts)
Model:
GARCH(1,1)
Residuals:
Min 1Q Median 3Q Max
-11.74204 -0.49793 0.05298 0.61346 5.02039
Coefficient(s):
Estimate Std. Error t value Pr(>|t|)
a0 0.047597 0.005323 8.942 <2e-16 ***
a1 0.090520 0.002552 35.470 <2e-16 ***
b1 0.871903 0.008238 105.844 <2e-16 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Diagnostic Tests:
Jarque Bera Test
data: Residuals
X-squared = 14613.68, df = 2, p-value < 2.2e-16
Box-Ljung test
data: Squared.Residuals
X-squared = 0.4014, df = 1, p-value = 0.5263
summary(yts.garch2)
Call:
garch(x = yts, start = c(1, 0.4, 0.01))
Model:
GARCH(1,1)
Residuals:
Min 1Q Median 3Q Max
-11.74210 -0.49793 0.05298 0.61346 5.02040
Coefficient(s):
Estimate Std. Error t value Pr(>|t|)
a0 0.047597 0.005323 8.942 <2e-16 ***
a1 0.090519 0.002552 35.470 <2e-16 ***
b1 0.871903 0.008238 105.845 <2e-16 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Diagnostic Tests:
Jarque Bera Test
data: Residuals
X-squared = 14613.83, df = 2, p-value < 2.2e-16
Box-Ljung test
data: Squared.Residuals
X-squared = 0.4015, df = 1, p-value = 0.5263
summary(yts.garch3)
Call:
garch(x = yts, control = garch.control(grad = "numerical"), start = c(1,
0.4, 0.01))
Model:
GARCH(1,1)
Residuals:
Min 1Q Median 3Q Max
-11.74140 -0.49798 0.05298 0.61343 5.02026
Coefficient(s):
Estimate Std. Error t value Pr(>|t|)
a0 0.047649 0.005328 8.943 <2e-16 ***
a1 0.090545 0.002553 35.465 <2e-16 ***
b1 0.871830 0.008243 105.765 <2e-16 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Diagnostic Tests:
Jarque Bera Test
data: Residuals
X-squared = 14607.92, df = 2, p-value < 2.2e-16
Box-Ljung test
data: Squared.Residuals
X-squared = 0.401, df = 1, p-value = 0.5266
</OUTPUT>