Documentos de Académico
Documentos de Profesional
Documentos de Cultura
26 mayo de 2022
1 Persistencia en volatilidad
2 Modelos de volatilidad condicional
3 Comparando estrategias
4 GARCH asimétricos
5 GARCH no gaussianos
6 Validación del modelo
7 Forecast volatilidades
8 Referencias
Section 1
Introducción
Introducción
N N
N
!2
1 X 1 X 1 X
σ2 = (yi − ȳ )2 = yi2 − yi
n − 1 i=1 n − 1 i=1 n i=1
0.014
8.6
0.04
0.012
8.4
0.02
0.010
diff(x)
vol_x
x
8.2
0.00
0.008
8.0
−0.02
0.006
7.8
−0.04
1992 1994 1996 1998 1992 1994 1996 1998 1992 1994 1996 1998
Clase 2 Econometría Financiera 26 mayo de 2022 6 / 78
Introducción
Section 2
Efecto ARCH
Análisis preliminar
yt = t σt2
q
X q
X
σt2 = ω + 2
αi yt−i , ω > 0, αi > 0, αi < 1
i=1 i=1
Análisis preliminar
Análisis preliminar
xt
1500
precio
1000
500
1995 2000 2005 2010 2015
fecha
dif(xt)
50
0
.
−50
−100
−150
1995 2000 2005 2010 2015
Index
Transformación logarítmica
xt dif(xt)
50
1500
precio
.
1000 −50
500 −100
−150
1995 2000 2005 2010 2015 1995 2000 2005 2010 2015
fecha Index
log(xt) Dif(log(xt))
7.5
log(precio)
0.05
7.0
0.00
6.5
.
6.0 −0.05
5.5 −0.10
1995 2000 2005 2010 2015 1995 2000 2005 2010 2015
fecha Index
Persistencia de la volatilidad
La representación yt2 :
0.0100
0.0075
.
0.0050
0.0025
0.0000
1995 2000 2005 2010 2015
Index
Persistencia de la volatilidad
Un histograma de frecuencia sobre la primera diferencia de las
rentabilidades al cuadrado, brinda usualmente una primera
aproximación de la persistencia en volatilidad.
g1 <- data.frame(roro) %>%
ggplot(aes(x=roro)) + geom_histogram(fill="steelblue")
2500
2000
4000
1500
count
count
1000
2000
500
0 0
Clase 2 Econometría Financiera 26 mayo de 2022 14 / 78
Efecto ARCH
Persistencia de la volatilidad
Taylor (1982) demostró que el test ARMA sobre yt2 , es equivalente a
identificar la estructura ARCH. Por lo que, la presencia de clusters de
volatilidad o dependencia de orden no lineal en yt , puede testearse
por medio de los correlogramas de yt2 .
roro2 <- roro^2
library(astsa)
acf2(roro2, plot=T, main=" ")
−0.05 0.25
ACF
0 20 40 60 80
LAG
−0.05 0.25
PACF
0 20 40 60 80
LAG
Clase 2 Econometría Financiera 26 mayo de 2022 15 / 78
Efecto ARCH
yt = β0 + β1 Xt−q + t
Persistencia de la volatilidad
Ho : ρ1 = ρ2 = ... = ρm = 0
Box.test(roro^2, lag = 12, type = "Ljung")
##
## Box-Ljung test
##
## data: roro^2
## X-squared = 966.43, df = 12, p-value < 2.2e-16
##
## ARCH LM-test; Null hypothesis: no ARCH effects
##
## data: roro^2
## Chi-squared = 11.714, df = 1, p-value = 0.0006204
library(tseries)
mod1<-arima(roro,order = c(1,0,0))
e<-mod1$residuals^2
library(forecast)
ggtsdisplay(e, main="")
0.0100
0.0075
0.0050
0.0025
0.0000
0 1000 2000 3000 4000 5000 6000
0.15 0.15
PACF
0.10 0.10
ACF
0.05 0.05
0.00 0.00
0 10 20 30 0 10 20 30
Lag Lag
# FinTS::ArchTest
archtest <- aTSA::arch.test(mod1, output = F)
archtest
Agregación de volatilidad
Dependiendo de la frecuencia de los datos, obtendremos medidas de
volatilidad en esas mismas frecuencias, sin embargo, es frecuente
utilizar la volatilidad anual para presentar
√ una medida de la volatilidad
de un activo/serie, multiplicado por t:
√
σano = σdia 252
sqrt(252)*sd(roro)
## [1] 0.1573411
## [1] 197.9166
Clase 2 Econometría Financiera 26 mayo de 2022 20 / 78
Modelos de volatildiad condicional
Section 3
Ventanas de volatilidad
T
1 X
σt2 = e2
T i=1 t−i
Ventanas de volatilidad
0.025 0.025
0.020 0.020
0.015 0.015
0.010 0.010
0.005 0.005
abr. 05 1991 ene. 03 1994 ene. 01 1997 ene. 03 2000 ene. 01 2003 ene. 02 2006 ene. 01 2009 ene. 02 2012 sep. 09 2014
Ventanas de volatilidad
library(PerformanceAnalytics)
chart.RollingPerformance(R = roro,
width = 22, #ventana
scale = 252,
FUN = "sd.annualized")
0.4
0.3
0.2
0.1
abr. 05 1991 ene. 03 1994 ene. 01 1997 ene. 03 2000 ene. 01 2003 ene. 02 2006 ene. 01 2009 ene. 02 2012 sep. 09 2014
Ventanas de volatilidad: n?
0.6 0.4
0.3
0.3
0.4
0.2
0.2
0.2 0.1
0.1
abr. 05 1991 ene. 01 2001 ene. 01 2010 abr. 05 1991 ene. 01 2001 ene. 01 2010 abr. 05 1991 ene. 01 2001 ene. 01 2010
EWMA
T
X T
X
σn2 = 2
= αi en−1 , = αi = 1
i=1 i=1
2
σt+1 = λσt2 + (1 − λ)yt2
EWMA en R
r_oro <- diff(log(ts_precios))
tobs <- length(r_oro)
varEWMA<- var(r_oro);
lambda<-0.94
0.015
0.005
EWMA
ARCH
p
X
σt2 = α1 yt−1
2 2
+ α2 yt−2 2
+ ... + αp yt−p = 2
αi yt−i
i=1
ARCH: estimación en R
T
X
σt2 = ω + 2
αi et−i
i=1
library(fGarch)
fit_arch <- garchFit(~garch(1, 0), trace=FALSE, data = r_oro)
fit_arch@fit$matcoef
ARCH
– Ventana móvil (et2 = yt − y¯t ):
T
1 X
σt2 = e2
T i=1 t−i
– Exponencial:
T
X
σt2 = 2
αi et−i
i=1
– ARCH(p):
T
X
σt2 =ω+ 2
αi et−i
i=1
yt = µ + et
et ∼ N(0, σt2 )
q
X p
X
σt2 =ω+ 2
αi et−i + 2
βi σt−i
i=1 i=1
q
X p
X
σt2 = ω + 2
αi et−i + 2
βi σt−i
i=1 i=1
GARCH(p,q) contraste
Varianza positiva:
Estacionario:
GARCH: estimación
GARCH: estimación
plot(fit_garch, which = 3)
−0.05
−0.10
Index
autoplot(ts(volatility))
0.03
ts(volatility)
0.02
0.01
Section 4
GARCH mean
GARCH-mean
yt = µ + λσt2
et ∼ N(0, σt2 )
q
X p
X
σt2 =ω+ 2
αi et−i + 2
βi σt−i
i=1 i=1
GARCH-mean
ARMA-GARCH
yt = µ + ρt yt−1 + θ1 t−1
et ∼ N(0, σt2 )
q
X p
X
σt2 = ω + 2
αi et−i + 2
βi σt−i
i=1 i=1
ARMA-GARCH: fGarch
ARMA-GARCH: rugarch
library(rugarch)
garchspec <- ugarchspec(mean.model = list(armaOrder = c(0,0)),
variance.model = list(model = "sGARCH"),
distribution.model = "norm")
##
## *---------------------------------*
## * GARCH Model Fit *
## *---------------------------------*
##
## Conditional Variance Dynamics
## -----------------------------------
## GARCH Model : sGARCH(1,1)
## Mean Model : ARFIMA(0,0,0)
## Distribution
Clase 2
: norm Econometría Financiera 26 mayo de 2022 44 / 78
Comparando estrategias
Section 5
Comparando estrategias
Comparando estrategias
models <- list()
##
## Estimaciones GARCH
## =======================================================
## Dependent variable:
## -----------------------------------
## r_oro
## (1) (2) (3)
## -------------------------------------------------------
## mu Clase 2
0.0003** -0.00001
Econometría Financiera
-0.00000 26 mayo de 2022 46 / 78
Comparando estrategias
Comparando estrategias
Aqui se extrae el p-valor de cada modelo para posteriormente incluirlo
en la tabla de regresión.
get_pvals <- function(fm) {
fm@fit$matcoef[,4]
}
##
## Estimaciones GARCH
## =======================================================
## Dependent variable:
## -----------------------------------
## r_oro
## (1) (2) (3)
## -------------------------------------------------------
Clase 2 Econometría Financiera 26 mayo de 2022 47 / 78
Comparando estrategias
Comparando estrategias
vol_arch_oro <- models[[1]]@sigma.t
vol_garch_oro <- models[[2]]@sigma.t
0.04
0.03
value
0.02
0.01
0.00
1995 2000 2005 2010 2015
date
Clase 2 Econometría Financiera 26 mayo de 2022 48 / 78
Comparando estrategias
Comparando estrategias
vol_data %>%
gather(id, value, -date) %>%
dplyr::filter(id!="vol_arch_oro") %>%
ggplot(aes(x = date, y = value)) +
geom_line(aes(color = id), size = 1)+
theme_minimal() + theme(legend.position="bottom")
0.03
0.02
value
0.01
Comparando estrategias
Adicionalmente, podemos recuperar el conjunto de volatilidades
directamente de la lista de modelos realizada anteirormente.
vols_models <- map(models,"sigma.t")
vols_models2 <- do.call(cbind, vols_models)
head(vols_models2)
cor(vols_models2)
head(select_gacrch)
## model fit.fit.ics.1.
## AIC GACRH(1,1) -6.718
## AIC1 GACRH(1,2) -6.723
## AIC2 GACRH(1,3) -6.725
## AIC3 GACRH(2,1) -6.718
## AIC4 GACRH(2,2) -6.723
## AIC5 GACRH(2,3) -6.725
Clase 2 Econometría Financiera 26 mayo de 2022 52 / 78
GARCH asimétricos
Section 6
GARCH asimétricos
q h i p
α1 ε2t−i + γ1 1−
X X
σt2 = ω + 2
(εt ≤0) εt−i +
2
β1 σt−1
I=1 I=1
q h i p
γ1 1−
X X
σt2 =ω+ α1 ε2t−i + 2
(εt ≤0) εt−i + 2
β1 σt−1
I=1 I=1
coef(models[[4]])
ARCH δ = 2, γ = 0, β = 0.
GARCH δ = 2, γ = 0.
gjr − GARCH δ = 2.
coef(models[[4]])
# garchFit(~garch(1,1),data=roro,delta=2,leverage=T,trace=F,include.mean=F)
fit3_a <- ugarchfit(data = roro, spec = garchspec3)
coef(fit3_a)
ggplot(dataCurve,aes(x=lagres,y=volgarch)) +
geom_smooth(aes(color = "GARCH"),span = 0.9, se=F) +
geom_vline(xintercept = 0, size=0.1) +
labs(x = "Residuo (t-1)", y = "Volatilidad condicional (t)") +
geom_smooth(aes(x=lagres2,y=volgjr, color = "gjr-GARCh"), se=F) +
theme(legend.position="bottom")
0.030
Volatilidad condicional (t)
0.025
0.020
0.015
0.010
Section 7
GARCH no gaussianos
coef(models[[6]])
# garchFit(~garch(1,1),data=roro,cond.dist="std",trace=F,include.mean=F)
garchspec1 <- ugarchspec(distribution.model = "sstd")
show(fit3_a)
##
## *---------------------------------*
## * GARCH Model Fit *
## *---------------------------------*
##
## Conditional Variance Dynamics
## -----------------------------------
## GARCH Model : sGARCH(1,1)
## Mean Model : ARFIMA(1,0,1)
## Distribution
Clase 2
: sstd Econometría Financiera 26 mayo de 2022 67 / 78
forecast volatilidades
Section 8
forecast volatilidades
fGarch::predict(models[[5]],n.ahead=50,plot=TRUE)
^
Xt+h
x
^
Xt+h − 1.96 MSE
^
Xt+h + 1.96 MSE
−0.10
Index
sqrt(uncvariance(fit2_a))
## [1] 0.01706
## 2014-09-09
## T+1 0.006926
## T+2 0.006943
## T+3 0.006961
## T+4 0.006978
## T+5 0.006996
## T+6 0.007013
## T+7 0.007031
Section 9
Validación
likelihood(fit3_a)
## [1] 20944
infocriteria(fit3_a)
##
## Akaike -6.850
## Bayes -6.841
## Shibata -6.850
## Hannan-Quinn -6.847
75
50
25
0
0 1000 2000 3000 4000 5000 6000
0.09 0.09
0.06 0.06
PACF
ACF
0.03 0.03
0.00 0.00
−0.03 −0.03
0 10 20 30 0 10 20 30
Lag Lag
qnorm − QQ Plot
10
5
Sample Quantiles
0
−5
−4 −2 0 2 4
Theoretical Quantiles
T
1 X
MSE = (e 2 − σ̂t2 )
T t=1 t
garchresiduo <- residuals(fit2_a)
gjrresiduo <- residuals(fit3_a)
# MSE
mean(garchresiduo^2)
## [1] 0.00009827
# MSE varianza
mean((garchresiduo^2)^2 - sigma(fit2_a)^2)
## [1] -0.000102
##
## Box-Ljung test
##
## data: r_gjrgarch
## X-squared = 15, df = 1, p-value = 0.00008
Section 10
Referencias
Referencias