You are on page 1of 12

Task 02

Example of analysing data and residual volatility and estimating


ARCH and GARCH models:
The following data contains:
S&P Composite index returns Ret over the period 1954:1-2001:9;
the consumer price index (CPI) inflation rate Inf.
the change in the three-month Treasury-Bill (T-bill) rate DT.bill.
txt1 <- "http://uosis.mif.vu.lt/~rlapinskas/(data%20R&GRETL/"
txt2 <- "S&P.txt"
#Read it as an excel file
SP <- read.table(paste0(txt1, txt2), header = TRUE)
SP <- read.table(paste0(txt1, txt2), header = TRUE)
SP <- ts(SP, start = 1954, freq = 12)

We begin by modelling the return series rett as a function of a constant, one lag of returns rett1 , one lag
of the inflation rate inf lt1 and one lag of the first-difference of the three-month T-bill rate dTbill_{t-1}.
We expect our model to be of the form:

Yt = 0 + 1 X1,t + ... + (X1,t , ...)wt

wherewt are i.i.d. with conditional mean 0 and conditional variance 1.


We will begin by adding the first lags of the necessary variables and create the usual OLS model;
Then, we will test the hypothesis H0 : residualsof M odel1arenormal. In conventional regression
models, rejection of the null would lead to change the specification, but non-normality is an inherent
feature of the errors from the regression models for financial data (as such robust standard errors are
needed).
suppressPackageStartupMessages({library(dynlm)})
mdl.1 <- dynlm(Ret ~ L(Ret) + L(Inf.) + L(DT.bill), data = SP)
summary(mdl.1)

##
## Time series regression with "ts" data:
## Start = 1954(2), End = 2001(8)
##
## Call:
## dynlm(formula = Ret ~ L(Ret) + L(Inf.) + L(DT.bill), data = SP)
##
## Residuals:
## Min 1Q Median 3Q Max
## -12.1199 -1.8907 0.1141 2.0607 10.3608
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 1.17715 0.21004 5.604 3.26e-08 ***
## L(Ret) 0.20799 0.04102 5.070 5.39e-07 ***

1
## L(Inf.) -1.17945 0.44805 -2.632 0.00871 **
## L(DT.bill) -1.25007 0.29135 -4.291 2.10e-05 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 3.259 on 567 degrees of freedom
## Multiple R-squared: 0.1011, Adjusted R-squared: 0.0963
## F-statistic: 21.25 on 3 and 567 DF, p-value: 4.688e-13
As mentioned, we need to correct the standard errors of our model:
suppressPackageStartupMessages({
library(sandwich)
library(lmtest)
})
coeftest(mdl.1, df = Inf, vcov = vcov(mdl.1, "HC"))

##
## z test of coefficients:
##
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) 1.177149 0.210040 5.6044 2.090e-08 ***
## L(Ret) 0.207991 0.041023 5.0701 3.976e-07 ***
## L(Inf.) -1.179451 0.448045 -2.6324 0.008477 **
## L(DT.bill) -1.250071 0.291351 -4.2906 1.782e-05 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
where:
vcov - variance-covariance matrix Heteroskedasticity Corrected
HC means Whites estimator
z-test (using a normal approximation (df = Inf)) is performed
As we can see, all the coefficients are statistically significant.
We can test the residual normality with the Shapiro-Wilk test:
shapiro.test(mdl.1$residuals)

##
## Shapiro-Wilk normality test
##
## data: mdl.1$residuals
## W = 0.97873, p-value = 2.233e-07
# tseries::jarque.bera.test(mdl.1$residuals)

Since p-value < 0.05 we reject the null hypothesis that our residuals are normal.
Let us look at the residual correlograms:
suppressPackageStartupMessages({library(forecast)})
tsdisplay(mdl.1$residuals)

2
10
0
10
mdl.1$residuals

1960 1970 1980 1990 2000


0.10

0.10
PACF
ACF

0.10 0.00

0.10 0.00
0 5 10 15 20 25 30 35 0 5 10 15 20 25 30 35

Lag Lag

Box.test(mdl.1$residuals, lag = 15)

##
## Box-Pierce test
##
## data: mdl.1$residuals
## X-squared = 23.766, df = 15, p-value = 0.06917
We do not reject the null hypothesis that the autocorrelations are not statistically significantly different from
zero.
Let us test the same with the squared residuals:
tsdisplay(mdl.1$residuals^2)

3
100
0
mdl.1$residuals^2

1960 1970 1980 1990 2000


0.10

0.10
PACF
ACF

0.10 0.00

0.10 0.00
0 5 10 15 20 25 30 35 0 5 10 15 20 25 30 35

Lag Lag

Box.test(mdl.1$residuals^2, lag = 6)

##
## Box-Pierce test
##
## data: mdl.1$residuals^2
## X-squared = 17.567, df = 6, p-value = 0.007412
We reject the null hypothesis, which means that our residuals are autocorrelated.
We will now test the residuals for ARCH(6) (according to the ACF of the squared residuals):
suppressPackageStartupMessages({library(fGarch)})
mdl.res <- mdl.1$residuals
mdl.arch <- garchFit(formula = ~ garch(6, 0), trace = FALSE, data = mdl.res)
summary(mdl.arch)

##
## Title:
## GARCH Modelling
##
## Call:
## garchFit(formula = ~garch(6, 0), data = mdl.res, trace = FALSE)
##
## Mean and Variance Equation:
## data ~ garch(6, 0)
## <environment: 0x0000000034499c20>
## [data = mdl.res]

4
##
## Conditional Distribution:
## norm
##
## Coefficient(s):
## mu omega alpha1 alpha2 alpha3
## -1.5103e-16 5.6728e+00 1.2585e-01 1.2245e-02 1.2945e-01
## alpha4 alpha5 alpha6
## 1.1232e-02 9.3974e-02 1.2805e-01
##
## Std. Errors:
## based on Hessian
##
## Error Analysis:
## Estimate Std. Error t value Pr(>|t|)
## mu -1.510e-16 1.286e-01 0.000 1.0000
## omega 5.673e+00 1.072e+00 5.294 1.2e-07 ***
## alpha1 1.259e-01 5.986e-02 2.102 0.0355 *
## alpha2 1.225e-02 3.999e-02 0.306 0.7595
## alpha3 1.294e-01 6.952e-02 1.862 0.0626 .
## alpha4 1.123e-02 3.852e-02 0.292 0.7706
## alpha5 9.397e-02 6.653e-02 1.412 0.1578
## alpha6 1.280e-01 5.793e-02 2.210 0.0271 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Log Likelihood:
## -1468.767 normalized: -2.572272
##
## Description:
## Tue Feb 21 07:14:23 2017 by user: Andrius
##
##
## Standardised Residuals Tests:
## Statistic p-Value
## Jarque-Bera Test R Chi^2 28.08916 7.952716e-07
## Shapiro-Wilk Test R W 0.9883611 0.0001652405
## Ljung-Box Test R Q(10) 10.2739 0.416801
## Ljung-Box Test R Q(15) 22.56042 0.09392936
## Ljung-Box Test R Q(20) 27.36542 0.1252926
## Ljung-Box Test R^2 Q(10) 1.268283 0.9994941
## Ljung-Box Test R^2 Q(15) 6.411728 0.9719713
## Ljung-Box Test R^2 Q(20) 9.804126 0.9715862
## LM Arch Test R TR^2 2.103424 0.9992301
##
## Information Criterion Statistics:
## AIC BIC SIC HQIC
## 5.172564 5.233473 5.172179 5.196327
We see that alpha6 coefficient is statistically significant and we reject the null hypothesis H0 : 1 = ... =
6 = 0 in:

5

t = t wt


2
t = E(2t |t1 ) = + 1 2t1 + ... + 6 2t6
Thus, the residuals of our model make ARCH(6). The ARCH(6) model has many parameters and one
common advice is to replace the model by GARCH(1, 1):
mdl.garch <- garchFit(formula = ~ garch(1, 1), trace = FALSE, data = mdl.res)
summary(mdl.garch)

##
## Title:
## GARCH Modelling
##
## Call:
## garchFit(formula = ~garch(1, 1), data = mdl.res, trace = FALSE)
##
## Mean and Variance Equation:
## data ~ garch(1, 1)
## <environment: 0x0000000032917160>
## [data = mdl.res]
##
## Conditional Distribution:
## norm
##
## Coefficient(s):
## mu omega alpha1 beta1
## -1.5103e-16 1.1511e+00 1.1392e-01 7.8510e-01
##
## Std. Errors:
## based on Hessian
##
## Error Analysis:
## Estimate Std. Error t value Pr(>|t|)
## mu -1.510e-16 1.292e-01 0.000 1.00000
## omega 1.151e+00 5.183e-01 2.221 0.02636 *
## alpha1 1.139e-01 4.002e-02 2.846 0.00442 **
## beta1 7.851e-01 6.584e-02 11.925 < 2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Log Likelihood:
## -1472.623 normalized: -2.579025
##
## Description:
## Tue Feb 21 07:14:23 2017 by user: Andrius
##
##
## Standardised Residuals Tests:
## Statistic p-Value
## Jarque-Bera Test R Chi^2 36.679 1.084565e-08
## Shapiro-Wilk Test R W 0.9851709 1.483964e-05
## Ljung-Box Test R Q(10) 10.01125 0.4395069
## Ljung-Box Test R Q(15) 22.05404 0.1063948

6
## Ljung-Box Test R Q(20) 27.39449 0.1245256
## Ljung-Box Test R^2 Q(10) 7.909245 0.6377014
## Ljung-Box Test R^2 Q(15) 13.07198 0.5967378
## Ljung-Box Test R^2 Q(20) 17.00733 0.6524979
## LM Arch Test R TR^2 8.202932 0.7690776
##
## Information Criterion Statistics:
## AIC BIC SIC HQIC
## 5.172060 5.202514 5.171962 5.183941
From the summary we see that Shapiro-Wilk Test and Jarque-Bera Test reject the null hypothesis
that residuals are normal.
The Ljung-Box Test does not reject the null hypothesis that residuals form WN. They also do not
reject the null hypothesis that the squared residuals R2 are WN.
As a final step, we combine the regression model for conditional mean and the GARCH model for conditional
variance:
(Quick example with ARCH(6):)
suppressPackageStartupMessages({library(rugarch)})
ret <- SP[,1]
infl <- SP[,2]
dTbill <- SP[,3]
spec.dt <- cbind(ret[1:571], infl[1:571], dTbill[1:571])
mdl.spec.arch <- ugarchspec(
variance.model = list(garchOrder = c(0, 6)),
mean.model = list(armaOrder = c(0,0),
include.mean = TRUE,
external.regressors = spec.dt)
)
mdl.spec.arch

##
## *---------------------------------*
## * GARCH Model Spec *
## *---------------------------------*
##
## Conditional Variance Dynamics
## ------------------------------------
## GARCH Model : sGARCH(0,6)
## Variance Targeting : FALSE
##
## Conditional Mean Dynamics
## ------------------------------------
## Mean Model : ARFIMA(0,0,0)
## Include Mean : TRUE
## GARCH-in-Mean : FALSE
## Exogenous Regressor Dimension: 3
##
## Conditional Distribution
## ------------------------------------
## Distribution : norm
## Includes Skew : FALSE
## Includes Shape : FALSE
## Includes Lambda : FALSE

7
mdl.spec.arch.fit <- ugarchfit(data = ret[2:572], spec = mdl.spec.arch)

suppressPackageStartupMessages({library(rugarch)})
ret <- SP[,1]
infl <- SP[,2]
dTbill <- SP[,3]
spec.dt <- cbind(ret[1:571], infl[1:571], dTbill[1:571])
mdl.spec.garch <- ugarchspec(
variance.model = list(garchOrder = c(1, 1)),
mean.model = list(armaOrder = c(0,0),
include.mean = TRUE,
external.regressors = spec.dt)
)
mdl.spec.garch

##
## *---------------------------------*
## * GARCH Model Spec *
## *---------------------------------*
##
## Conditional Variance Dynamics
## ------------------------------------
## GARCH Model : sGARCH(1,1)
## Variance Targeting : FALSE
##
## Conditional Mean Dynamics
## ------------------------------------
## Mean Model : ARFIMA(0,0,0)
## Include Mean : TRUE
## GARCH-in-Mean : FALSE
## Exogenous Regressor Dimension: 3
##
## Conditional Distribution
## ------------------------------------
## Distribution : norm
## Includes Skew : FALSE
## Includes Shape : FALSE
## Includes Lambda : FALSE
mdl.spec.garch.fit <- ugarchfit(data = ret[2:572], spec = mdl.spec.garch)
mdl.spec.garch.fit

##
## *---------------------------------*
## * GARCH Model Fit *
## *---------------------------------*
##
## Conditional Variance Dynamics
## -----------------------------------
## GARCH Model : sGARCH(1,1)
## Mean Model : ARFIMA(0,0,0)
## Distribution : norm
##
## Optimal Parameters
## ------------------------------------

8
## Estimate Std. Error t value Pr(>|t|)
## mu 1.31263 0.204030 6.4335 0.000000
## mxreg1 0.18528 0.045487 4.0731 0.000046
## mxreg2 -1.31787 0.456021 -2.8899 0.003853
## mxreg3 -1.19690 0.309909 -3.8621 0.000112
## omega 1.19923 0.536503 2.2353 0.025400
## alpha1 0.11996 0.041406 2.8970 0.003767
## beta1 0.77559 0.068169 11.3775 0.000000
##
## Robust Standard Errors:
## Estimate Std. Error t value Pr(>|t|)
## mu 1.31263 0.230400 5.6972 0.000000
## mxreg1 0.18528 0.043918 4.2187 0.000025
## mxreg2 -1.31787 0.547165 -2.4085 0.016016
## mxreg3 -1.19690 0.361031 -3.3152 0.000916
## omega 1.19923 0.598210 2.0047 0.044996
## alpha1 0.11996 0.047766 2.5113 0.012028
## beta1 0.77559 0.069713 11.1254 0.000000
##
## LogLikelihood : -1472.298
##
## Information Criteria
## ------------------------------------
##
## Akaike 5.1814
## Bayes 5.2347
## Shibata 5.1811
## Hannan-Quinn 5.2022
##
## Weighted Ljung-Box Test on Standardized Residuals
## ------------------------------------
## statistic p-value
## Lag[1] 0.08685 0.7682
## Lag[2*(p+q)+(p+q)-1][2] 0.26510 0.8155
## Lag[4*(p+q)+(p+q)-1][5] 1.49164 0.7420
## d.o.f=0
## H0 : No serial correlation
##
## Weighted Ljung-Box Test on Standardized Squared Residuals
## ------------------------------------
## statistic p-value
## Lag[1] 0.002882 0.9572
## Lag[2*(p+q)+(p+q)-1][5] 1.322472 0.7834
## Lag[4*(p+q)+(p+q)-1][9] 4.093256 0.5731
## d.o.f=2
##
## Weighted ARCH LM Tests
## ------------------------------------
## Statistic Shape Scale P-Value
## ARCH Lag[3] 0.0002154 0.500 2.000 0.9883
## ARCH Lag[5] 0.8432633 1.440 1.667 0.7800
## ARCH Lag[7] 3.7926024 2.315 1.543 0.3775
##
## Nyblom stability test

9
## ------------------------------------
## Joint Statistic: 0.8629
## Individual Statistics:
## mu 0.13023
## mxreg1 0.06168
## mxreg2 0.13919
## mxreg3 0.02595
## omega 0.11633
## alpha1 0.09033
## beta1 0.15680
##
## Asymptotic Critical Values (10% 5% 1%)
## Joint Statistic: 1.69 1.9 2.35
## Individual Statistic: 0.35 0.47 0.75
##
## Sign Bias Test
## ------------------------------------
## t-value prob sig
## Sign Bias 0.8170 0.41426
## Negative Sign Bias 0.8844 0.37684
## Positive Sign Bias 0.7499 0.45362
## Joint Effect 8.1065 0.04386 **
##
##
## Adjusted Pearson Goodness-of-Fit Test:
## ------------------------------------
## group statistic p-value(g-1)
## 1 20 27.77 0.08787
## 2 30 47.65 0.01597
## 3 40 55.76 0.03990
## 4 50 59.56 0.14348
##
##
## Elapsed time : 0.4523079
We can also forecast the data:
forc.garch.mdl <- ugarchforecast(mdl.spec.garch.fit, n.ahead = 20)
forc.garch.mdl

##
## *------------------------------------*
## * GARCH Model Forecast *
## *------------------------------------*
## Model: sGARCH
## Horizon: 20
## Roll Steps: 0
## Out of Sample: 0
##
## 0-roll forecast [T0=1971-07-26 02:00:00]:
## Series Sigma
## T+1 1.313 5.580
## T+2 1.313 5.393
## T+3 1.313 5.220
## T+4 1.313 5.059

10
## T+5 1.313 4.912
## T+6 1.313 4.775
## T+7 1.313 4.650
## T+8 1.313 4.534
## T+9 1.313 4.429
## T+10 1.313 4.332
## T+11 1.313 4.243
## T+12 1.313 4.162
## T+13 1.313 4.088
## T+14 1.313 4.021
## T+15 1.313 3.959
## T+16 1.313 3.904
## T+17 1.313 3.853
## T+18 1.313 3.807
## T+19 1.313 3.765
## T+20 1.313 3.728
plot(forc.garch.mdl, which = 1)

Forecast Series
w/th unconditional 1Sigma bands

Horizon: 20

Actual
10

Forecast
5
Series

GARCH model : sGARCH


5
10

May Jun Jul Aug

Time/Horizon

plot(forc.garch.mdl, which = 3)

11
Forecast Unconditional Sigma
(n.roll = 0)

Horizon: 20

Actual
5.5

Forecast
5.0
4.5
Sigma

4.0

GARCH model : sGARCH


3.5
3.0

Jul 05 Jul 15 Jul 25 Aug 04 Aug 14

Time/Horizon

12

You might also like