Modelo GARCH

Modelizando volatilidad
Modelo GARCH
volatilidad
Author

Javier Sánchez García

Published

January 1, 2013

Hasta ahora, los modelos presentados modelizan el comportamiento de una variable mediante una combinación lineal de parámetros, variables y término error:

\[ Y_t = \beta_0 + \beta_1X_{1,t} + \beta_2X_{2,t} + \ldots + \beta_k X_{k,t} + u_t \] Sin embargo, muchas series temporales, como las financieras, presentan un fenómeno conocido como clustering de volatilidad. Esto implica que las series temporales tienen variabilidad cambiante con periodos de alta y baja volatilidad caracterizados por su persistencia.

Esta volatilidad cambiante se puede modelizar a través de la varianza del término error de una serie temporal:

\[ Y_t = \beta_0 + \dots + e_t \]

\[ e_t \sim \mathcal{N}(0,v_t) \]

\[ v_t = \alpha_0 + \alpha_1e^2_{t-1} + \alpha_2e^2_{t-2} + \ldots + \alpha_pe^2_{t-p} + \beta_1v_{t-1} + \beta_2v_{t-2} + \ldots + \beta_qv_{t-q} \]

donde ahora la media del término error es constante y cero, pero la varianza es variable y depende de los errores al cuadrado retardados \(p\) periodos (término autorregresivo) y de las perturbaciones aleatorias retardadas \(q\) periodos (término de medias móviles).

Sin embargo, para que este modelo tenga sentido, lo primero es testar que la serie presente efectos ARCH en sus errores. A menudo, series con distribuciones de probabilidad de colas pesadas y mucha variabilidad suelen presentarlos.

library(forecast, quietly = T)
Warning: package 'forecast' was built under R version 4.2.3
Registered S3 method overwritten by 'quantmod':
  method            from
  as.zoo.data.frame zoo 
library(Ecdat, quietly = T)
Warning: package 'Ecdat' was built under R version 4.2.3
Warning: package 'Ecfun' was built under R version 4.2.3

Attaching package: 'Ecfun'
The following object is masked from 'package:forecast':

    BoxCox
The following object is masked from 'package:base':

    sign

Attaching package: 'Ecdat'
The following object is masked from 'package:datasets':

    Orange
library(ggplot2, quietly=T)
Warning: package 'ggplot2' was built under R version 4.2.3
data("PPP")
r1 <- diff(PPP[,1])
autoplot(r1) + xlab("") + ylab("") + theme_bw()

hist(r1, main="")

Sin embargo, como siempre un test estadístico formal es necesario para contrastarlo de forma fiable. El test prueba si los parámetros \(\alpha_1, \alpha_2, \ldots, \alpha_j\) de la regresión:

\[ e^2_t = \alpha_0 + \alpha_1e^2_{t-1} + \alpha_2e^2_{t-2} + \ldots + \alpha_je^2_{t-j} + \epsilon_t \]

son conjuntamente significativos mediante un estadístico multiplicador de Lagrange (LM), con hipótesis nula \(\alpha_1, \alpha_2, \ldots, \alpha_j = 0\) e hipótesis alternativa de lo contrario.

library(FinTS, quietly = T)

Attaching package: 'zoo'
The following objects are masked from 'package:base':

    as.Date, as.Date.numeric

Attaching package: 'FinTS'
The following object is masked from 'package:forecast':

    Acf
ArchTest(r1) #Por defecto, j=12.

    ARCH LM-test; Null hypothesis: no ARCH effects

data:  r1
Chi-squared = 111.23, df = 12, p-value < 2.2e-16

Para modelizar la serie, la elección del orden (\(p\) , \(q\)) de los parámetros se puede hacer por prueba error, analizando cuales de los mismos son estadísticamente significativos. Sin embargo, una opción estandar suele ser el modelo GARCH(1,1).

library(rugarch, quietly = T)

Attaching package: 'rugarch'
The following object is masked from 'package:stats':

    sigma
especificacion <- ugarchspec(
           variance.model=list(model="sGARCH",
                               garchOrder=c(1,1)),
           mean.model=list(armaOrder=c(1,0)), 
           distribution.model="std") #Modelo GARCH(1,1) y para la serie AR(1).
ajuste <- ugarchfit(spec=especificacion, data=r1) #Estimación
ajuste #Resultados del modelo

*---------------------------------*
*          GARCH Model Fit        *
*---------------------------------*

Conditional Variance Dynamics   
-----------------------------------
GARCH Model : sGARCH(1,1)
Mean Model  : ARFIMA(1,0,0)
Distribution    : std 

Optimal Parameters
------------------------------------
        Estimate  Std. Error  t value Pr(>|t|)
mu      0.004984    0.000439 11.34215 0.000000
ar1     0.538940    0.079915  6.74390 0.000000
omega   0.000000    0.000002  0.16057 0.872432
alpha1  0.075840    0.058460  1.29729 0.194531
beta1   0.889464    0.059334 14.99082 0.000000
shape   8.160328    4.027879  2.02596 0.042769

Robust Standard Errors:
        Estimate  Std. Error  t value Pr(>|t|)
mu      0.004984    0.001877 2.655733 0.007914
ar1     0.538940    0.414437 1.300415 0.193459
omega   0.000000    0.000026 0.009621 0.992324
alpha1  0.075840    0.725487 0.104537 0.916744
beta1   0.889464    0.777960 1.143328 0.252902
shape   8.160328   16.195748 0.503856 0.614362

LogLikelihood : 821.4546 

Information Criteria
------------------------------------
                    
Akaike       -8.8157
Bayes        -8.7113
Shibata      -8.8177
Hannan-Quinn -8.7734

Weighted Ljung-Box Test on Standardized Residuals
------------------------------------
                        statistic p-value
Lag[1]                      1.440 0.23010
Lag[2*(p+q)+(p+q)-1][2]     1.464 0.45773
Lag[4*(p+q)+(p+q)-1][5]     5.232 0.08831
d.o.f=1
H0 : No serial correlation

Weighted Ljung-Box Test on Standardized Squared Residuals
------------------------------------
                        statistic p-value
Lag[1]                      2.267  0.1322
Lag[2*(p+q)+(p+q)-1][5]     3.020  0.4034
Lag[4*(p+q)+(p+q)-1][9]     3.755  0.6305
d.o.f=2

Weighted ARCH LM Tests
------------------------------------
            Statistic Shape Scale P-Value
ARCH Lag[3]   0.01748 0.500 2.000  0.8948
ARCH Lag[5]   1.07364 1.440 1.667  0.7112
ARCH Lag[7]   1.37046 2.315 1.543  0.8469

Nyblom stability test
------------------------------------
Joint Statistic:  53.6379
Individual Statistics:               
mu      0.81013
ar1     2.24817
omega  19.88440
alpha1  0.10444
beta1   0.09910
shape   0.06491

Asymptotic Critical Values (10% 5% 1%)
Joint Statistic:         1.49 1.68 2.12
Individual Statistic:    0.35 0.47 0.75

Sign Bias Test
------------------------------------
                   t-value   prob sig
Sign Bias           0.5919 0.5546    
Negative Sign Bias  0.3373 0.7363    
Positive Sign Bias  2.2463 0.0259  **
Joint Effect        5.5338 0.1366    


Adjusted Pearson Goodness-of-Fit Test:
------------------------------------
  group statistic p-value(g-1)
1    20     16.19      0.64462
2    30     31.16      0.35782
3    40     49.59      0.11910
4    50     67.70      0.03947


Elapsed time : 0.1111982 
rfit <- ts(ajuste@fit$fitted.values, frequency = 12, start=c(1981,2))
estimacion <- ts.union(r1, rfit)
autoplot(estimacion) + xlab("") + ylab("") + theme_bw()

Una vez estimado el modelo, se pueden realizar predicciones.

submuestra = ugarchfit(data = r1, spec = especificacion, out.sample=4)
prediccion = ugarchforecast(submuestra, n.ahead=4) 
prediccion

*------------------------------------*
*       GARCH Model Forecast         *
*------------------------------------*
Model: sGARCH
Horizon: 4
Roll Steps: 0
Out of Sample: 4

0-roll forecast [T0=feb. 1996]:
      Series    Sigma
T+1 0.003954 0.003128
T+2 0.004448 0.003117
T+3 0.004718 0.003106
T+4 0.004866 0.003095
predserie <- ts(prediccion@forecast$seriesFor, start=c(1996,07), frequency = 12)
comb <- ts.union(r1,predserie)
autoplot(comb) + theme_bw()

#Probar plot(prediccion)