5  Temas Adicionales

5.1 Pruebas de raíz unitaria

5.1.1 Modelo base y problema de sobrediferenciación

Sea el proceso AR(1) causal (ruido gaussiano): \[ x_t=\phi x_{t-1}+w_t. \]

Aplicando \((1-B)\) a ambos lados: \[ \nabla x_t=\phi \nabla x_{t-1}+\nabla w_t,\quad y_t=\phi y_{t-1}+w_t-w_{t-1}, \] donde \(y_t=\nabla x_t\). Así, \(y_t\) es un ARMA\((1,1)\) no invertible: diferenciar puede introducir correlación espuria y problemas de invertibilidad.

Hipótesis de prueba

Se desea contrastar: \[ H_0:\ \phi=1 \quad \text{versus} \quad H_1:\ |\phi|<1. \]

5.1.2 Estimador LS y reexpresión bajo \(H_0\)

Bajo una caminata aleatoria \(x_t=x_{t-1}+w_t\) con \(x_0=0\) y \(\mu_x=0\), el estimador LS es \[ \hat{\phi}=\frac{\sum_{t=1}^{n} x_t x_{t-1}}{\sum_{t=1}^{n} x_{t-1}^2} =1+\frac{\frac{1}{n}\sum_{t=1}^{n} w_t x_{t-1}}{\frac{1}{n}\sum_{t=1}^{n} x_{t-1}^2}. \] Por tanto, \[ \hat{\phi}-1=\frac{\frac{1}{n\sigma_w^2}\sum_{t=1}^{n} w_t x_{t-1}} {\frac{1}{n\sigma_w^2}\sum_{t=1}^{n} x_{t-1}^2}. \]

Dado \(x_t=x_{t-1}+w_t\), se tiene \(x_t^2=x_{t-1}^2+2x_{t-1}w_t+w_t^2\), luego \[ x_{t-1}w_t=\tfrac{1}{2}\left(x_t^2-x_{t-1}^2-w_t^2\right), \] y al sumar, \[ \frac{1}{n\sigma_w^2}\sum_{t=1}^{n}x_{t-1}w_t =\frac{1}{2}\left(\frac{x_n^2}{n\sigma_w^2}-\frac{\sum_{t=1}^{n}w_t^2}{n\sigma_w^2}\right). \] Como \(x_n=\sum_{1}^{n}w_t\sim N(0,n\sigma_w^2)\), entonces \(\chi_1^2=\frac{x_n^2}{n\sigma_w^2}\) y \(\frac{1}{n}\sum_{1}^{n}w_t^2\to_p \sigma_w^2\). En consecuencia, \[ \frac{1}{n\sigma_w^2}\sum_{t=1}^{n}x_{t-1}w_t \xrightarrow{d} \tfrac{1}{2}\left(\chi_1^2-1\right). \]

5.1.3 Movimiento browniano estándar

Un proceso continuo \({W(t);t\ge 0}\) es browniano estándar si:

  1. \(W(0)=0\);
  2. incrementos independientes en puntos \(0\le t_1<\cdots<t_n\);
  3. \(W(t+\Delta t)-W(t)\sim N(0,\Delta t)\) para \(\Delta t>0\), con trayectorias casi seguramente continuas.

5.1.3.1 Teorema central funcional

Si \(\xi_1,\ldots,\xi_n\) iid con media 0 y varianza 1, para \(0\le t\le 1\): \[ S_n(t)=\frac{1}{\sqrt{n}}\sum_{j=1}^{[[ nt]]}\xi_j \xrightarrow{d} W(t). \] Bajo \(H_0\), \(x_s=w_1+\cdots+w_s\sim N(0,s\sigma_w^2)\) y \(\frac{x_s}{\sigma_w\sqrt{n}}\xrightarrow{d}W(s)\). Por tanto, \[ \sum_{t=1}^{n}\left(\frac{x_{t-1}}{\sigma_w\sqrt{n}}\right)^2\frac{1}{n} \xrightarrow{d}\int_{0}^{1}W^2(t),dt. \]

5.1.4 Estadístico DF y su límite

Ajustando el factor \(n^{-1}\) del denominador de la expresión de \(\hat \phi-1\):

\[ n(\hat{\phi}-1)= \frac{\frac{1}{n\sigma_w^2}\sum_{t=1}^{n} w_t x_{t-1}} {\frac{1}{n^{2}\sigma_w^2}\sum_{t=1}^{n} x_{t-1}^{2}} \xrightarrow{d}\frac{\tfrac{1}{2}\left(\chi_1^2-1\right)} {\int_{0}^{1}W^2(t),dt}. \] Este es el estadístico de Dickey–Fuller (DF). Su distribución no tiene forma cerrada; los cuantiles se obtienen por aproximación numérica o simulación.

5.1.5 Extensiones DF/ADF/PP

Reescribiendo \(x_t=\phi x_{t-1}+w_t\) como \(\nabla x_t=\gamma x_{t-1}+w_t\) con \(\gamma=\phi-1\), se prueba \(H_0:\gamma=0\) por regresión de \(\nabla x_t\) sobre \(x_{t-1}\). Para AR(\(p\)): \[ \nabla x_t=\gamma x_{t-1}+\sum_{j=1}^{p-1}\psi_j \nabla x_{t-j}+w_t, \] donde \(\gamma=\sum_{j=1}^{p}\phi_j-1\) y \(\psi_j=-\sum_{i=j}^{p}\phi_i\) para \(j=2,\ldots,p\). El ADF contrasta \(H_0:\gamma=0\) vía \(t_\gamma=\hat\gamma/\operatorname{se}(\hat\gamma)\) en la regresión sobre \(x_{t-1},\nabla x_{t-1},\ldots,\nabla x_{t-p+1}\). Para ARMA\((p,q)\) se usa ADF con \(p\) grande o el test de Phillips–Perron (PP), que trata de forma distinta la correlación serial y heterocedasticidad en los errores.

5.1.5.1 Ejemplo: Pruebas de raíz unitaria en la serie de varves glaciares

A continuación se usan pruebas DF, ADF y PP sobre el logaritmo de la serie de varves glaciares (cada prueba incluye constante y tendencia lineal). En ADF, el número de retardos AR \(k\) por defecto es \([[(n-1)^{1/3}]]\); en PP, \(k=[[ 0.04n^{1/4}]]\).

library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.1.4     ✔ readr     2.1.5
✔ forcats   1.0.0     ✔ stringr   1.5.2
✔ ggplot2   4.0.0     ✔ tibble    3.3.0
✔ lubridate 1.9.4     ✔ tidyr     1.3.1
✔ purrr     1.1.0     
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(astsa)
library(tseries)
Registered S3 method overwritten by 'quantmod':
  method            from
  as.zoo.data.frame zoo 
adf.test(log(varve), k = 0)      # DF
Warning in adf.test(log(varve), k = 0): p-value smaller than printed p-value

    Augmented Dickey-Fuller Test

data:  log(varve)
Dickey-Fuller = -12.857, Lag order = 0, p-value = 0.01
alternative hypothesis: stationary
adf.test(log(varve))             # ADF (k por defecto)

    Augmented Dickey-Fuller Test

data:  log(varve)
Dickey-Fuller = -3.5166, Lag order = 8, p-value = 0.04071
alternative hypothesis: stationary
pp.test(log(varve))              # PP
Warning in pp.test(log(varve)): p-value smaller than printed p-value

    Phillips-Perron Unit Root Test

data:  log(varve)
Dickey-Fuller Z(alpha) = -304.54, Truncation lag parameter = 6, p-value
= 0.01
alternative hypothesis: stationary

5.2 Modelos GARCH

5.2.1 Modelado de volatilidad: retornos y motivación

Si \(x_t\) es el valor del activo en \(t\), el retorno relativo es \[ r_t=\frac{x_t-x_{t-1}}{x_{t-1}}. \] Como \(x_t=(1+r_t)x_{t-1}\), si el cambio porcentual es pequeño: \[ \nabla\log(x_t)\approx r_t. \] Usaremos indistintamente \(r_t\equiv \nabla\log(x_t)\) o \((x_t-x_{t-1})/x_{t-1}\).

5.2.2 Modelo ARCH(1): definición y propiedades

5.2.2.1 Especificación básica

\[ \begin{aligned} r_t&=\sigma_t\epsilon_t, \\ \sigma_t^2&=\alpha_0+\alpha_1 r_{t-1}^2, \end{aligned} \] con \(\epsilon_t\sim \text{iid }N(0,1)\) y \(\alpha_0,\alpha_1\ge 0\).

La distribución condicional: \[ r_t\mid r_{t-1}\sim N\left(0,\ \alpha_0+\alpha_1 r_{t-1}^2\right). \]

5.2.2.2 Representación para \(r_t^2\)

A partir de la definición del modelo ARCH: \[ \begin{aligned} r_t^2 &= \sigma_t^2 \, \epsilon_t^2, \\ \alpha_0 + \alpha_1 r_{t-1}^2 &= \sigma_t^2, \end{aligned} \] y restando ambas ecuaciones se obtiene:

\[ r_t^2 - \left( \alpha_0 + \alpha_1 r_{t-1}^2 \right) = \sigma_t^2 (\epsilon_t^2 - 1), \] de donde se obtiene:

\[ r_t^2=\alpha_0+\alpha_1 r_{t-1}^2+v_t,\quad v_t=\sigma_t^2(\epsilon_t^2-1), \] donde \(\epsilon_t^2-1\) es \(\chi_1^2\) desplazada o centrada en 0.

Propiedades

Sea \(\mathcal{R}_s=\{r_s,r_{s-1},\ldots\}\). Entonces \[ \mathrm{E}(r_t)=\mathrm{E}[{\mathrm{E}(r_t\mid \mathcal{R}_{t-1})}] =\mathrm{E}[{\mathrm{E}(r_t\mid r_{t-1})}]=0, \] por lo tanto es una diferencia martingala y para \(h>0\), \[ \operatorname{cov}(r_{t+h},r_t)=\mathrm{E}{r_t\mathrm{E}(r_{t+h}\mid\mathcal{R}_{t+h-1})}=0. \]

Si \(0\le \alpha_1<1\) y \(\operatorname{var}(v_t)\) es finita y constante entonces \(r_t^2\) es AR(1) causal (estacionario), por lo que \[ \mathrm{E}(r_t^2)=\operatorname{var}(r_t)=\frac{\alpha_0}{1-\alpha_1}, \] y \[ \mathrm{E}(r_t^4)=\frac{3\alpha_0^2}{(1-\alpha_1)^2}\cdot \frac{1-\alpha_1^2}{1-3\alpha_1^2},\quad (3\alpha_1^2<1). \] La curtosis es \[ \kappa=\frac{\mathrm{E}(r_t^4)}{[\mathrm{E}(r_t^2)]^2}=3\frac{1-\alpha_1^2}{1-3\alpha_1^2}\ge 3, \] lo que indica colas pesadas (leptocurtosis). Si \(3\alpha_1^2<1\), \(\rho_{r^2}(h)=\alpha_1^h\ge 0\).

5.2.3 Estimación por verosimilitud condicional

La verosimilitud condicional de \(r_2,\ldots,r_n\) dado \(r_1\) es \[ L(\alpha_0,\alpha_1\mid r_1)=\prod_{t=2}^n f_{\alpha_0,\alpha_1}(r_t\mid r_{t-1}), \] y el criterio a minimizar es \[ l(\alpha_0,\alpha_1)=\tfrac{1}{2}\sum_{t=2}^n \ln(\alpha_0+\alpha_1 r_{t-1}^2) +\tfrac{1}{2}\sum_{t=2}^n \frac{r_t^2}{\alpha_0+\alpha_1 r_{t-1}^2}. \] El MLE solamente se obtiene por métodos numéricos. Para esto se necesita el gradiente: \[ \binom{\partial l/\partial \alpha_0}{\partial l/\partial \alpha_1} =\sum_{t=2}^n \binom{1}{r_{t-1}^2} \frac{\alpha_0+\alpha_1 r_{t-1}^2-r_t^2}{2(\alpha_0+\alpha_1 r_{t-1}^2)^2}. \]

Nota: la logverosimilitud para este tipo de modelo tiende a ser muy plana.

También es posible combinar un modelo de regresión con errores ARCH:

\[ x_t=\beta^t z_t+y_t \] donde \(y_t\) es ARCH. En particular un AR(1) podría tener errores ARCH:

\[ x_t=\phi x_{t-1}+r_t,\quad r_t=\sigma_t \epsilon_t,\quad \]

5.2.4 Extensiones

5.2.4.1 ARCH(p)

\[ \sigma_t^2=\alpha_0+\alpha_1 r_{t-1}^2+\cdots+\alpha_p r_{t-p}^2. \] La verosimilitud condicional: \[ L(\alpha\mid r_1,\ldots,r_p)=\prod_{t=p+1}^n f_\alpha(r_t\mid r_{t-1},\ldots,r_{t-p}). \]

5.2.4.2 GARCH(1,1) y ARMA para \(r_t^2\)

\[ \sigma_t^2=\alpha_0+\alpha_1 r_{t-1}^2+\beta_1 \sigma_{t-1}^2, \] y si \(\alpha_1+\beta_1<1\), \[ r_t^2=\alpha_0+(\alpha_1+\beta_1) r_{t-1}^2+v_t-\beta_1 v_{t-1}. \] donde \(v_t\) se definió anteriormente.

5.2.4.3 GARCH(p,q)

\[ \sigma_t^2=\alpha_0+\sum_{j=1}^p \alpha_j r_{t-j}^2+\sum_{j=1}^q \beta_j \sigma_{t-j}^2, \]

La estimación de máxima verosimilitud condicional de los parámetros del modelo GARCH\((p,q)\) es similar al caso ARCH\((p)\), en el cual la verosimilitud condicional es el producto de densidades \(\mathrm{N}(0, \sigma_t^2)\) con \(\sigma_t^2\) dado por la ecuación anterior, y donde la condición se establece sobre las primeras \(\max(p,q)\) observaciones, con \(\sigma_1^2 = \cdots = \sigma_q^2 = 0\). Una vez que se obtienen las estimaciones de los parámetros, el modelo puede utilizarse para obtener pronósticos de volatilidad de un paso adelante, denotados como \(\hat{\sigma}_{t+1}^2\), dados por

\[ \hat{\sigma}_{t+1}^2 = \hat{\alpha}_0 + \sum_{j=1}^{p} \hat{\alpha}_j r_{t+1-j}^2 + \sum_{j=1}^{q} \hat{\beta}_j \hat{\sigma}_{t+1-j}^2. \]

5.2.5 Prueba LM ARCH

En series financieras (y otras), la varianza condicional puede cambiar en el tiempo: periodos de alta volatilidad tienden a agruparse. Los modelos ARCH/GARCH modelan esa heterocedasticidad condicional.

Sea \({\varepsilon_t}\) la secuencia de residuos (por ejemplo, de un modelo para la media). Decimos que hay efecto ARCH de orden \(q\) si la varianza condicional en \(t\) depende de los cuadrados de los últimos \(q\) residuos: \[ \operatorname{Var}(\varepsilon_t\mid \mathcal F_{t-1}) = \alpha_0 + \alpha_1\varepsilon_{t-1}^2 + \cdots + \alpha_q\varepsilon_{t-q}^2, \quad \alpha_0>0, \alpha_j\ge 0. \]

La prueba LM ARCH (Engle) contrasta:

  • \(H_0\): no hay efecto ARCH (varianza condicional constante; \(\alpha_1=\cdots=\alpha_q=0\)).
  • \(H_1\): sí hay efecto ARCH de algún orden (\(\exists j:\alpha_j\ne 0\)).

Regresión auxiliar y estadístico

La prueba se implementa ajustando la regresión sobre los residuos al cuadrado: \[ \hat{\varepsilon}_t^2 =\alpha_0+\alpha_1\hat{\varepsilon}_{t-1}^2+\cdots+\alpha_q \hat{\varepsilon}_{t-q}^2+u_t. \]

Sea \(R^2\) el coeficiente de determinación de esta regresión y \(n\) el número de observaciones usadas. El estadístico LM es: \[ \text{LM}=nR^2 \overset{H_0}{\approx}\chi^2_q. \]

5.2.5.1 Ejemplo: Análisis ARCH en U.S. GNP

La ACF/PACF de los cuadrados de los residuales del AR(1) sugiere dependencia débil.

u = sarima(diff(log(gnp)), 1, 0, 0)
initial  value -4.589567 
iter   2 value -4.654150
iter   3 value -4.654150
iter   4 value -4.654151
iter   4 value -4.654151
iter   4 value -4.654151
final  value -4.654151 
converged
initial  value -4.655919 
iter   2 value -4.655921
iter   3 value -4.655922
iter   4 value -4.655922
iter   5 value -4.655922
iter   5 value -4.655922
iter   5 value -4.655922
final  value -4.655922 
converged
<><><><><><><><><><><><><><>
 
Coefficients: 
      Estimate     SE t.value p.value
ar1     0.3467 0.0627  5.5255       0
xmean   0.0083 0.0010  8.5398       0

sigma^2 estimated as 9.029569e-05 on 220 degrees of freedom 
 
AIC = -6.44694  AICc = -6.446693  BIC = -6.400958 
 

acf2(resid(u$fit)^2, 20)

     [,1] [,2] [,3] [,4]  [,5] [,6]  [,7] [,8] [,9] [,10] [,11] [,12] [,13]
ACF  0.12 0.13 0.03 0.13  0.01 0.05 -0.03 0.06 0.08 -0.08  0.09  0.10  0.01
PACF 0.12 0.12 0.00 0.12 -0.02 0.02 -0.04 0.05 0.08 -0.12  0.11  0.09 -0.05
     [,14] [,15] [,16] [,17] [,18] [,19] [,20]
ACF   0.04  0.15 -0.02  0.04 -0.05  0.01  0.05
PACF  0.05  0.13 -0.09  0.01 -0.05  0.00  0.04

Ajuste AR(1)-ARCH(1) con fGarch:

library(fGarch)
NOTE: Packages 'fBasics', 'timeDate', and 'timeSeries' are no longer
attached to the search() path when 'fGarch' is attached.

If needed attach them yourself in your R script by e.g.,
        require("timeSeries")
summary(garchFit(~ arma(1,0) + garch(1,0), diff(log(gnp))))

Series Initialization:
 ARMA Model:                arma
 Formula Mean:              ~ arma(1, 0)
 GARCH Model:               garch
 Formula Variance:          ~ garch(1, 0)
 ARMA Order:                1 0
 Max ARMA Order:            1
 GARCH Order:               1 0
 Max GARCH Order:           1
 Maximum Order:             1
 Conditional Dist:          norm
 h.start:                   2
 llh.start:                 1
 Length of Series:          222
 Recursion Init:            mci
 Series Scale:              0.01015924

Parameter Initialization:
 Initial Parameters:          $params
 Limits of Transformations:   $U, $V
 Which Parameters are Fixed?  $includes
 Parameter Matrix:
                     U          V    params includes
    mu     -8.20681904   8.206819 0.8205354     TRUE
    ar1    -0.99999999   1.000000 0.3466459     TRUE
    omega   0.00000100 100.000000 0.1000000     TRUE
    alpha1  0.00000001   1.000000 0.1000000     TRUE
    gamma1 -0.99999999   1.000000 0.1000000    FALSE
    delta   0.00000000   2.000000 2.0000000    FALSE
    skew    0.10000000  10.000000 1.0000000    FALSE
    shape   1.00000000  10.000000 4.0000000    FALSE
 Index List of Parameters to be Optimized:
    mu    ar1  omega alpha1 
     1      2      3      4 
 Persistence:                  0.1 


--- START OF TRACE ---
Selected Algorithm: nlminb 

R coded nlminb Solver: 

  0:     682.89527: 0.820535 0.346646 0.100000 0.100000
  1:     308.43148: 0.763492 0.258112  1.06104 0.352453
  2:     306.07332: 0.681276 0.195897  1.04763 0.304072
  3:     301.00807: 0.561958 0.448458 0.825277 0.0402737
  4:     298.88361: 0.383716 0.465477 0.632947 0.385969
  5:     296.74288: 0.504144 0.389445 0.683635 0.247795
  6:     296.67703: 0.497724 0.366843 0.688130 0.229496
  7:     296.60039: 0.500011 0.385702 0.703145 0.211105
  8:     296.59692: 0.515646 0.374174 0.690079 0.194961
  9:     296.56381: 0.513570 0.367018 0.702272 0.200013
 10:     296.55723: 0.523440 0.363126 0.708406 0.194151
 11:     296.55632: 0.522578 0.364913 0.710104 0.194839
 12:     296.55598: 0.520871 0.364956 0.710924 0.193212
 13:     296.55568: 0.519486 0.366571 0.710212 0.194511
 14:     296.55568: 0.519509 0.366597 0.710266 0.194512
 15:     296.55568: 0.519511 0.366585 0.710290 0.194451
 16:     296.55568: 0.519505 0.366562 0.710299 0.194464
 17:     296.55568: 0.519526 0.366560 0.710295 0.194472
 18:     296.55568: 0.519522 0.366563 0.710295 0.194471

Final Estimate of the Negative LLH:
 LLH:  -722.2849    norm LLH:  -3.253536 
          mu          ar1        omega       alpha1 
0.0052779470 0.3665625656 0.0000733096 0.1944713341 

R-optimhess Difference Approximated Hessian Matrix:
                 mu           ar1         omega        alpha1
mu     -2749495.418 -24170.124984  4.546826e+06 -1.586692e+03
ar1      -24170.125   -390.266822  1.253879e+04 -6.733789e+00
omega   4546825.784  12538.791045 -1.590043e+10 -7.069342e+05
alpha1    -1586.692     -6.733789 -7.069342e+05 -1.425395e+02
attr(,"time")
Time difference of 0.004799604 secs

--- END OF TRACE ---


Time to Estimate Parameters:
 Time difference of 0.02542353 secs

Title:
 GARCH Modelling 

Call:
 garchFit(formula = ~arma(1, 0) + garch(1, 0), data = diff(log(gnp))) 

Mean and Variance Equation:
 data ~ arma(1, 0) + garch(1, 0)
<environment: 0x55c60f614660>
 [data = diff(log(gnp))]

Conditional Distribution:
 norm 

Coefficient(s):
        mu         ar1       omega      alpha1  
0.00527795  0.36656257  0.00007331  0.19447133  

Std. Errors:
 based on Hessian 

Error Analysis:
        Estimate  Std. Error  t value Pr(>|t|)    
mu     5.278e-03   8.996e-04    5.867 4.44e-09 ***
ar1    3.666e-01   7.514e-02    4.878 1.07e-06 ***
omega  7.331e-05   9.011e-06    8.135 4.44e-16 ***
alpha1 1.945e-01   9.554e-02    2.035   0.0418 *  
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Log Likelihood:
 722.2849    normalized:  3.253536 

Description:
 Tue Oct 28 15:18:41 2025 by user:  


Standardised Residuals Tests:
                                 Statistic     p-Value
 Jarque-Bera Test   R    Chi^2   9.1180362 0.010472337
 Shapiro-Wilk Test  R    W       0.9842406 0.014336495
 Ljung-Box Test     R    Q(10)   9.8743260 0.451587525
 Ljung-Box Test     R    Q(15)  17.5585456 0.286584404
 Ljung-Box Test     R    Q(20)  23.4136291 0.268943681
 Ljung-Box Test     R^2  Q(10)  19.2821015 0.036822455
 Ljung-Box Test     R^2  Q(15)  33.2364834 0.004352735
 Ljung-Box Test     R^2  Q(20)  37.7425917 0.009518989
 LM Arch Test       R    TR^2   25.4162474 0.012969006

Information Criterion Statistics:
      AIC       BIC       SIC      HQIC 
-6.471035 -6.409726 -6.471669 -6.446282 
# Nota: garch(1,0) ≡ ARCH(1) en este código.

5.2.5.2 Ejemplo: Análisis GARCH del retorno DJIA

En este caso se usa errores t-Student para capturar colas un poco más pesadas(ver Manual fGarch):

library(xts)
Loading required package: zoo

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

    as.Date, as.Date.numeric

######################### Warning from 'xts' package ##########################
#                                                                             #
# The dplyr lag() function breaks how base R's lag() function is supposed to  #
# work, which breaks lag(my_xts). Calls to lag(my_xts) that you type or       #
# source() into this session won't work correctly.                            #
#                                                                             #
# Use stats::lag() to make sure you're not using dplyr::lag(), or you can add #
# conflictRules('dplyr', exclude = 'lag') to your .Rprofile to stop           #
# dplyr from breaking base R's lag() function.                                #
#                                                                             #
# Code in packages is not affected. It's protected by R's namespace mechanism #
# Set `options(xts.warn_dplyr_breaks_lag = FALSE)` to suppress this warning.  #
#                                                                             #
###############################################################################

Attaching package: 'xts'
The following objects are masked from 'package:dplyr':

    first, last
djiar = diff(log(djia$Close))[-1]
acf2(djiar)      # autocorrelación baja (no mostrado)

     [,1]  [,2] [,3]  [,4]  [,5] [,6]  [,7] [,8]  [,9] [,10] [,11] [,12] [,13]
ACF  -0.1 -0.06 0.05 -0.02 -0.06 0.01 -0.02 0.02 -0.01  0.04 -0.01  0.04  0.01
PACF -0.1 -0.07 0.04 -0.02 -0.06 0.00 -0.02 0.03 -0.01  0.04 -0.01  0.04  0.02
     [,14] [,15] [,16] [,17] [,18] [,19] [,20] [,21] [,22] [,23] [,24] [,25]
ACF  -0.04 -0.06  0.06  0.00 -0.07  0.02  0.05 -0.06  0.04  0.01 -0.01     0
PACF -0.04 -0.06  0.04  0.02 -0.06  0.00  0.04 -0.04  0.03  0.00  0.00     0
     [,26] [,27] [,28] [,29] [,30] [,31] [,32] [,33] [,34] [,35] [,36] [,37]
ACF      0  0.03 -0.03  0.01  0.02 -0.02  0.01  0.01 -0.09  0.03  0.03 -0.02
PACF     0  0.04 -0.03  0.00  0.02  0.00  0.00  0.01 -0.07  0.01  0.02  0.01
     [,38] [,39] [,40] [,41] [,42] [,43] [,44] [,45] [,46] [,47] [,48] [,49]
ACF      0  0.03  0.02  0.01  0.00 -0.06     0     0 -0.01  0.02  0.00 -0.04
PACF     0  0.01  0.04  0.02  0.01 -0.06     0     0 -0.01  0.01 -0.01 -0.05
     [,50] [,51] [,52] [,53] [,54] [,55] [,56] [,57] [,58] [,59] [,60] [,61]
ACF  -0.04 -0.02  0.03  0.00  0.00  0.01 -0.03  0.02  0.02 -0.07  0.02  0.02
PACF -0.04 -0.03  0.01  0.01  0.02  0.01 -0.03  0.01  0.02 -0.05  0.01  0.02
acf2(djiar^2)    # fuerte autocorrelación en cuadrados (no mostrado)

     [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13] [,14]
ACF   0.2 0.41 0.19 0.31 0.34 0.31 0.32 0.22 0.32  0.24  0.43  0.28  0.25  0.13
PACF  0.2 0.39 0.08 0.15 0.25 0.13 0.11 0.01 0.11  0.05  0.23  0.08 -0.07 -0.16
     [,15] [,16] [,17] [,18] [,19] [,20] [,21] [,22] [,23] [,24] [,25] [,26]
ACF   0.22  0.26  0.27  0.27  0.17  0.23  0.25  0.19  0.29  0.15  0.18  0.15
PACF -0.03  0.04  0.03  0.05 -0.01  0.00  0.09 -0.09  0.07 -0.01  0.00  0.00
     [,27] [,28] [,29] [,30] [,31] [,32] [,33] [,34] [,35] [,36] [,37] [,38]
ACF   0.28  0.22  0.22  0.14  0.16  0.20  0.14  0.25  0.10  0.17  0.12  0.16
PACF  0.12  0.02 -0.03 -0.06  0.00  0.01 -0.06  0.06 -0.03 -0.05  0.02 -0.06
     [,39] [,40] [,41] [,42] [,43] [,44] [,45] [,46] [,47] [,48] [,49] [,50]
ACF   0.15  0.10  0.08  0.08  0.11  0.13  0.13  0.08  0.09  0.11  0.07  0.08
PACF -0.06 -0.06 -0.03  0.01  0.00  0.03  0.02 -0.01  0.00  0.06 -0.02 -0.05
     [,51] [,52] [,53] [,54] [,55] [,56] [,57] [,58] [,59] [,60] [,61]
ACF   0.07  0.08  0.06  0.09  0.06  0.12  0.09  0.06  0.08  0.04  0.08
PACF  0.03  0.04  0.02 -0.02 -0.09  0.08  0.06  0.00  0.01 -0.02  0.00
library(fGarch)
summary(djia.g <- garchFit(~ arma(1,0) + garch(1,1), data = djiar,
                           cond.dist = 'std'))

Series Initialization:
 ARMA Model:                arma
 Formula Mean:              ~ arma(1, 0)
 GARCH Model:               garch
 Formula Variance:          ~ garch(1, 1)
 ARMA Order:                1 0
 Max ARMA Order:            1
 GARCH Order:               1 1
 Max GARCH Order:           1
 Maximum Order:             1
 Conditional Dist:          std
 h.start:                   2
 llh.start:                 1
 Length of Series:          2517
 Recursion Init:            mci
 Series Scale:              0.01210097

Parameter Initialization:
 Initial Parameters:          $params
 Limits of Transformations:   $U, $V
 Which Parameters are Fixed?  $includes
 Parameter Matrix:
                     U           V      params includes
    mu     -0.15336279   0.1533628  0.01533395     TRUE
    ar1    -0.99999999   1.0000000 -0.10129752     TRUE
    omega   0.00000100 100.0000000  0.10000000     TRUE
    alpha1  0.00000001   1.0000000  0.10000000     TRUE
    gamma1 -0.99999999   1.0000000  0.10000000    FALSE
    beta1   0.00000001   1.0000000  0.80000000     TRUE
    delta   0.00000000   2.0000000  2.00000000    FALSE
    skew    0.10000000  10.0000000  1.00000000    FALSE
    shape   1.00000000  10.0000000  4.00000000     TRUE
 Index List of Parameters to be Optimized:
    mu    ar1  omega alpha1  beta1  shape 
     1      2      3      4      6      9 
 Persistence:                  0.9 


--- START OF TRACE ---
Selected Algorithm: nlminb 

R coded nlminb Solver: 

  0:     2966.5649: 0.0153339 -0.101298 0.100000 0.100000 0.800000  4.00000
  1:     2944.7772: 0.0153351 -0.0991717 0.0803850 0.105688 0.794226  3.99986
  2:     2910.9438: 0.0153425 -0.0864389 0.0198837 0.162520 0.809278  4.00053
  3:     2891.9985: 0.0153434 -0.0855696 0.0349997 0.168391 0.817707  4.00077
  4:     2882.6364: 0.0153798 -0.0489475 0.0211398 0.164588 0.840541  4.00286
  5:     2881.9301: 0.0153823 -0.0484838 0.0204238 0.166791 0.845394  4.00314
  6:     2881.5679: 0.0153882 -0.0491671 0.0164038 0.164251 0.847793  4.00365
  7:     2880.9558: 0.0153959 -0.0493820 0.0174436 0.161528 0.852261  4.00434
  8:     2880.6291: 0.0154049 -0.0492037 0.0154767 0.158055 0.855764  4.00516
  9:     2880.3565: 0.0154166 -0.0487266 0.0159444 0.154678 0.859712  4.00626
 10:     2880.1243: 0.0154339 -0.0478609 0.0146355 0.150737 0.862389  4.00794
 11:     2879.9530: 0.0154638 -0.0476576 0.0149075 0.147959 0.865388  4.01087
 12:     2879.8201: 0.0155048 -0.0483157 0.0138749 0.146453 0.866639  4.01497
 13:     2879.7180: 0.0155488 -0.0477882 0.0141937 0.145774 0.867564  4.01936
 14:     2879.4141: 0.0157808 -0.0423403 0.0141381 0.141896 0.868277  4.04243
 15:     2878.3878: 0.0174980 -0.0569546 0.00848860 0.140360 0.874674  4.21079
 16:     2878.2927: 0.0193492 -0.0502757 0.0142265 0.160178 0.862535  4.37200
 17:     2876.3368: 0.0203874 -0.0461078 0.0117835 0.167862 0.852926  4.44641
 18:     2874.7342: 0.0206459 -0.0555791 0.0130825 0.138689 0.869340  4.42804
 19:     2874.6724: 0.0206462 -0.0554532 0.0123098 0.138461 0.869109  4.42806
 20:     2874.6548: 0.0206553 -0.0553211 0.0125311 0.138489 0.869292  4.42857
 21:     2874.6394: 0.0206635 -0.0550129 0.0122399 0.138334 0.869389  4.42904
 22:     2874.6234: 0.0206727 -0.0548830 0.0124501 0.138349 0.869554  4.42956
 23:     2874.6091: 0.0206813 -0.0546059 0.0121936 0.138189 0.869619  4.43005
 24:     2874.5943: 0.0206905 -0.0544775 0.0123915 0.138195 0.869769  4.43057
 25:     2874.5807: 0.0206992 -0.0542217 0.0121569 0.138035 0.869816  4.43107
 26:     2874.5667: 0.0207085 -0.0540958 0.0123467 0.138034 0.869956  4.43160
 27:     2874.5537: 0.0207174 -0.0538569 0.0121278 0.137877 0.869991  4.43211
 28:     2874.5403: 0.0207267 -0.0537340 0.0123108 0.137872 0.870123  4.43264
 29:     2874.5278: 0.0207356 -0.0535096 0.0121041 0.137717 0.870149  4.43315
 30:     2874.5149: 0.0207450 -0.0533899 0.0122810 0.137709 0.870275  4.43368
 31:     2874.5028: 0.0207540 -0.0531784 0.0120844 0.137558 0.870296  4.43419
 32:     2874.4904: 0.0207635 -0.0530620 0.0122555 0.137548 0.870416  4.43473
 33:     2874.4787: 0.0207726 -0.0528620 0.0120673 0.137401 0.870433  4.43525
 34:     2874.4667: 0.0207820 -0.0527489 0.0122328 0.137390 0.870549  4.43578
 35:     2874.4553: 0.0207912 -0.0525594 0.0120521 0.137247 0.870562  4.43630
 36:     2874.4437: 0.0208007 -0.0524496 0.0122124 0.137235 0.870674  4.43684
 37:     2874.4326: 0.0208099 -0.0522698 0.0120383 0.137096 0.870686  4.43736
 38:     2874.4213: 0.0208194 -0.0521631 0.0121935 0.137083 0.870794  4.43789
 39:     2874.4105: 0.0208287 -0.0519922 0.0120255 0.136949 0.870804  4.43842
 40:     2874.3995: 0.0208383 -0.0518887 0.0121759 0.136934 0.870909  4.43895
 41:     2874.3889: 0.0208476 -0.0517261 0.0120134 0.136805 0.870917  4.43948
 42:     2874.3782: 0.0208572 -0.0516257 0.0121593 0.136790 0.871020  4.44002
 43:     2874.3679: 0.0208666 -0.0514707 0.0120019 0.136664 0.871027  4.44055
 44:     2874.3574: 0.0208762 -0.0513733 0.0121435 0.136649 0.871126  4.44108
 45:     2874.3474: 0.0208856 -0.0512255 0.0119909 0.136527 0.871132  4.44161
 46:     2874.3371: 0.0208952 -0.0511310 0.0121283 0.136511 0.871229  4.44215
 47:     2874.3273: 0.0209047 -0.0509898 0.0119802 0.136393 0.871235  4.44268
 48:     2874.3172: 0.0209144 -0.0508982 0.0121136 0.136378 0.871329  4.44321
 49:     2874.3076: 0.0209239 -0.0507633 0.0119698 0.136263 0.871333  4.44374
 50:     2874.2977: 0.0209336 -0.0506745 0.0120995 0.136247 0.871425  4.44428
 51:     2874.2883: 0.0209431 -0.0505454 0.0119597 0.136136 0.871429  4.44481
 52:     2874.2786: 0.0209528 -0.0504593 0.0120858 0.136120 0.871519  4.44535
 53:     2874.2693: 0.0209624 -0.0503357 0.0119499 0.136012 0.871522  4.44588
 54:     2874.2598: 0.0209721 -0.0502524 0.0120725 0.135996 0.871609  4.44641
 55:     2874.2507: 0.0209817 -0.0501339 0.0119403 0.135891 0.871612  4.44694
 56:     2874.2414: 0.0209915 -0.0500532 0.0120596 0.135875 0.871697  4.44748
 57:     2874.2324: 0.0210011 -0.0499396 0.0119308 0.135773 0.871700  4.44801
 58:     2867.2502: 0.0374784 -0.0465701 0.0140411 0.146417 0.849465  5.34102
 59:     2865.2784: 0.0416151 -0.0568642 0.0115908 0.133741 0.863377  5.47854
 60:     2864.2803: 0.0508382 -0.0551564 0.0133502 0.137240 0.863921  5.39588
 61:     2861.7759: 0.0711833 -0.0514599 0.0116358 0.126101 0.868871  5.59207
 62:     2861.6890: 0.0720867 -0.0568481 0.0103059 0.127155 0.870034  5.77185
 63:     2861.6323: 0.0712594 -0.0580540 0.0105727 0.123206 0.871658  5.89046
 64:     2861.6059: 0.0710100 -0.0558795 0.0112294 0.125022 0.869481  5.92682
 65:     2861.6004: 0.0709184 -0.0550834 0.0110167 0.124375 0.870072  5.96212
 66:     2861.6000: 0.0709561 -0.0553609 0.0109915 0.124443 0.870018  5.97670
 67:     2861.6000: 0.0709474 -0.0553160 0.0109949 0.124443 0.870016  5.97866
 68:     2861.6000: 0.0709478 -0.0553153 0.0109957 0.124445 0.870013  5.97877

Final Estimate of the Negative LLH:
 LLH:  -8249.619    norm LLH:  -3.27756 
           mu           ar1         omega        alpha1         beta1 
 8.585376e-04 -5.531526e-02  1.610146e-06  1.244449e-01  8.700127e-01 
        shape 
 5.978770e+00 

R-optimhess Difference Approximated Hessian Matrix:
                  mu           ar1         omega        alpha1         beta1
mu     -4.791651e+07 -4.661861e+04 -1.205634e+09 -3.466862e+04 -9.149105e+04
ar1    -4.661861e+04 -2.490882e+03 -1.234074e+06 -8.203053e+00 -9.744031e+01
omega  -1.205634e+09 -1.234074e+06 -1.703962e+13 -5.515881e+08 -8.452220e+08
alpha1 -3.466862e+04 -8.203053e+00 -5.515881e+08 -3.611224e+04 -4.469020e+04
beta1  -9.149105e+04 -9.744031e+01 -8.452220e+08 -4.469020e+04 -6.270062e+04
shape  -9.970351e+02  8.557532e-02 -3.050363e+06 -1.832755e+02 -2.340762e+02
               shape
mu     -9.970351e+02
ar1     8.557532e-02
omega  -3.050363e+06
alpha1 -1.832755e+02
beta1  -2.340762e+02
shape  -2.547431e+00
attr(,"time")
Time difference of 0.07983613 secs

--- END OF TRACE ---


Time to Estimate Parameters:
 Time difference of 0.3876932 secs

Title:
 GARCH Modelling 

Call:
 garchFit(formula = ~arma(1, 0) + garch(1, 1), data = djiar, cond.dist = "std") 

Mean and Variance Equation:
 data ~ arma(1, 0) + garch(1, 1)
<environment: 0x55c612c3d470>
 [data = djiar]

Conditional Distribution:
 std 

Coefficient(s):
         mu          ar1        omega       alpha1        beta1        shape  
 8.5854e-04  -5.5315e-02   1.6101e-06   1.2444e-01   8.7001e-01   5.9788e+00  

Std. Errors:
 based on Hessian 

Error Analysis:
         Estimate  Std. Error  t value Pr(>|t|)    
mu      8.585e-04   1.470e-04    5.842 5.16e-09 ***
ar1    -5.532e-02   2.023e-02   -2.735 0.006238 ** 
omega   1.610e-06   4.459e-07    3.611 0.000305 ***
alpha1  1.244e-01   1.660e-02    7.496 6.55e-14 ***
beta1   8.700e-01   1.526e-02   57.022  < 2e-16 ***
shape   5.979e+00   7.917e-01    7.552 4.31e-14 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Log Likelihood:
 8249.619    normalized:  3.27756 

Description:
 Tue Oct 28 15:18:42 2025 by user:  


Standardised Residuals Tests:
                                  Statistic    p-Value
 Jarque-Bera Test   R    Chi^2  310.0081692 0.00000000
 Shapiro-Wilk Test  R    W        0.9820293 0.00000000
 Ljung-Box Test     R    Q(10)   16.8224601 0.07838596
 Ljung-Box Test     R    Q(15)   26.4481303 0.03356806
 Ljung-Box Test     R    Q(20)   28.7109935 0.09360790
 Ljung-Box Test     R^2  Q(10)   15.3676143 0.11922299
 Ljung-Box Test     R^2  Q(15)   19.1365044 0.20761469
 Ljung-Box Test     R^2  Q(20)   22.9288237 0.29230296
 LM Arch Test       R    TR^2    15.0397685 0.23926882

Information Criterion Statistics:
      AIC       BIC       SIC      HQIC 
-6.550353 -6.536453 -6.550364 -6.545309 
plot(djia.g,which=1)  # opciones de gráficos

5.2.6 Modelo APARCH

Modelo de potencia asimétrico ARCH con varianza condicional:

\[ \sigma_t^\delta=\alpha_0+\sum_{j=1}^p \alpha_j\left(\lvert r_{t-j}\rvert-\gamma_j r_{t-j}\right)^\delta +\sum_{j=1}^q \beta_j \sigma_{t-j}^\delta, \] Nótese que el modelo es GARCH cuando \(\delta = 2\) y \(\gamma_j = 0\), para \(j \in \{1, \ldots, p\}\). Los parámetros \(\gamma_j\) (\(|\gamma_j| \leq 1\)) son los parámetros de apalancamiento (leverage), que representan una medida de asimetría, y \(\delta > 0\) es el parámetro del término de potencia.

Un valor positivo [negativo] de \(\gamma_j\) significa que los choques negativos [positivos] pasados tienen un impacto más fuerte en la volatilidad condicional actual que los choques positivos [negativos] pasados. Este modelo combina la flexibilidad de un exponente variable con el coeficiente de asimetría para tener en cuenta el efecto de apalancamiento.

Además, para garantizar que \(\sigma_t > 0\), se asume que \(\alpha_0 > 0\), \(\alpha_j \geq 0\) (con al menos un \(\alpha_j > 0\)) y \(\beta_j \geq 0\).

5.2.6.1 Continuación del ejemplo del DJIA:

Siempre con errores t-Student:

library(xts)
library(fGarch)
summary(djia.ap <- garchFit(~ arma(1,0) + aparch(1,1), data = djiar,
                            cond.dist = 'std'))

Series Initialization:
 ARMA Model:                arma
 Formula Mean:              ~ arma(1, 0)
 GARCH Model:               aparch
 Formula Variance:          ~ aparch(1, 1)
 ARMA Order:                1 0
 Max ARMA Order:            1
 GARCH Order:               1 1
 Max GARCH Order:           1
 Maximum Order:             1
 Conditional Dist:          std
 h.start:                   2
 llh.start:                 1
 Length of Series:          2517
 Recursion Init:            mci
 Series Scale:              0.01210097

Parameter Initialization:
 Initial Parameters:          $params
 Limits of Transformations:   $U, $V
 Which Parameters are Fixed?  $includes
 Parameter Matrix:
                     U           V      params includes
    mu     -0.15336279   0.1533628  0.01533395     TRUE
    ar1    -0.99999999   1.0000000 -0.10129752     TRUE
    omega   0.00000100 100.0000000  0.10000000     TRUE
    alpha1  0.00000001   1.0000000  0.10000000     TRUE
    gamma1 -0.99999999   1.0000000  0.10000000     TRUE
    beta1   0.00000001   1.0000000  0.80000000     TRUE
    delta   0.00000000   2.0000000  2.00000000     TRUE
    skew    0.10000000  10.0000000  1.00000000    FALSE
    shape   1.00000000  10.0000000  4.00000000     TRUE
 Index List of Parameters to be Optimized:
    mu    ar1  omega alpha1 gamma1  beta1  delta  shape 
     1      2      3      4      5      6      7      9 
 Persistence:                  0.901 


--- START OF TRACE ---
Selected Algorithm: nlminb 

R coded nlminb Solver: 

  0:     2956.2216: 0.0153339 -0.101298 0.100000 0.100000 0.100000 0.800000  2.00000  4.00000
  1:     2933.7103: 0.0153349 -0.0994952 0.0816702 0.105086 0.101441 0.794372  1.99989  3.99987
  2:     2915.7667: 0.0153364 -0.0969033 0.0659019 0.116672 0.103734 0.795785  2.00000  3.99997
  3:     2868.4755: 0.0153445 -0.0848310 0.0240071 0.174769 0.115713 0.826263  2.00000  4.00127
  4:     2866.0067: 0.0153484 -0.0806140 0.0223751 0.179103 0.121376 0.835430  2.00000  4.00180
  5:     2865.7487: 0.0153525 -0.0768014 0.0131222 0.176106 0.127212 0.838921  1.99992  4.00228
  6:     2863.1420: 0.0153538 -0.0756613 0.0180358 0.176968 0.129016 0.841888  2.00000  4.00245
  7:     2856.2449: 0.0153875 -0.0476167 0.00965957 0.170079 0.175758 0.860641  1.99995  4.00607
  8:     2853.4108: 0.0154249 -0.0295659 0.0252436 0.165440 0.224654 0.839180  1.99938  4.00936
  9:     2853.0448: 0.0154257 -0.0299884 0.0155240 0.163926 0.225784 0.836602  1.99923  4.00941
 10:     2850.4568: 0.0154262 -0.0301237 0.0197886 0.165257 0.226344 0.839033  1.99934  4.00951
 11:     2849.7888: 0.0154284 -0.0309518 0.0166941 0.166172 0.229095 0.841761  1.99938  4.00981
 12:     2849.3808: 0.0154318 -0.0322155 0.0188338 0.167018 0.233146 0.843406  1.99940  4.01023
 13:     2848.6297: 0.0154356 -0.0334350 0.0170783 0.166875 0.237702 0.842613  1.99931  4.01065
 14:     2848.2726: 0.0154392 -0.0343915 0.0177679 0.167228 0.241904 0.845217  1.99934  4.01111
 15:     2847.6118: 0.0154433 -0.0353050 0.0161095 0.167003 0.246509 0.844166  1.99923  4.01155
 16:     2839.6580: 0.0155653 -0.0553493 0.0222431 0.178380 0.380319 0.824116  1.99673  4.02506
 17:     2839.3512: 0.0155658 -0.0550968 0.0204751 0.177743 0.380646 0.823994  1.99667  4.02511
 18:     2838.9545: 0.0155699 -0.0530330 0.0209096 0.175844 0.383429 0.828959  1.99653  4.02564
 19:     2838.4453: 0.0155822 -0.0490947 0.0190161 0.175891 0.387313 0.827244  1.99538  4.02695
 20:     2838.2004: 0.0155983 -0.0451962 0.0202650 0.176410 0.391417 0.827097  1.99373  4.02871
 21:     2837.9655: 0.0156258 -0.0427583 0.0191101 0.176071 0.394484 0.826442  1.99035  4.03170
 22:     2837.7164: 0.0156586 -0.0433600 0.0199725 0.175167 0.395086 0.827962  1.98601  4.03528
 23:     2837.4877: 0.0156899 -0.0444502 0.0188067 0.173444 0.395339 0.829067  1.98177  4.03873
 24:     2837.2542: 0.0157227 -0.0444858 0.0196845 0.172775 0.396371 0.830254  1.97741  4.04241
 25:     2837.0243: 0.0157544 -0.0436348 0.0187730 0.171889 0.398204 0.830412  1.97322  4.04605
 26:     2836.8012: 0.0157867 -0.0431291 0.0196235 0.171422 0.399701 0.831316  1.96895  4.04979
 27:     2836.5848: 0.0158187 -0.0432528 0.0186828 0.170271 0.400698 0.831832  1.96461  4.05354
 28:     2836.3739: 0.0158508 -0.0434055 0.0194501 0.169589 0.401625 0.832972  1.96028  4.05734
 29:     2836.1649: 0.0158827 -0.0431931 0.0185802 0.168628 0.402869 0.833293  1.95598  4.06117
 30:     2835.9597: 0.0159145 -0.0428368 0.0193553 0.168170 0.404207 0.834156  1.95172  4.06504
 31:     2835.7585: 0.0159462 -0.0426654 0.0185188 0.167252 0.405404 0.834462  1.94744  4.06892
 32:     2835.5621: 0.0159779 -0.0426467 0.0192452 0.166709 0.406444 0.835427  1.94316  4.07284
 33:     2835.3683: 0.0160095 -0.0425704 0.0184359 0.165808 0.407541 0.835744  1.93888  4.07678
 34:     2835.1779: 0.0160411 -0.0423779 0.0191523 0.165365 0.408710 0.836588  1.93464  4.08076
 35:     2834.9901: 0.0160726 -0.0421938 0.0183829 0.164555 0.409882 0.836832  1.93040  4.08474
 36:     2834.8061: 0.0161042 -0.0420878 0.0190714 0.164114 0.410966 0.837674  1.92617  4.08876
 37:     2834.6246: 0.0161357 -0.0420095 0.0183222 0.163312 0.412035 0.837939  1.92194  4.09279
 38:     2834.4462: 0.0161673 -0.0418854 0.0189920 0.162910 0.413121 0.838736  1.91773  4.09685
 39:     2834.2698: 0.0161987 -0.0417390 0.0182750 0.162177 0.414233 0.838949  1.91352  4.10092
 40:     2834.0965: 0.0162303 -0.0416151 0.0189257 0.161805 0.415308 0.839711  1.90934  4.10501
 41:     2833.9253: 0.0162618 -0.0415237 0.0182290 0.161092 0.416362 0.839927  1.90514  4.10911
 42:     2833.7569: 0.0162934 -0.0414219 0.0188604 0.160741 0.417408 0.840667  1.90097  4.11324
 43:     2833.5901: 0.0163250 -0.0413048 0.0181889 0.160075 0.418472 0.840852  1.89680  4.11737
 44:     2833.4261: 0.0163566 -0.0411882 0.0188048 0.159756 0.419520 0.841555  1.89265  4.12152
 45:     2833.2636: 0.0163883 -0.0410937 0.0181531 0.159117 0.420555 0.841733  1.88849  4.12568
 46:     2833.1037: 0.0164201 -0.0410006 0.0187518 0.158815 0.421575 0.842418  1.88435  4.12986
 47:     2832.9452: 0.0164519 -0.0409017 0.0181207 0.158211 0.422604 0.842576  1.88021  4.13404
 48:     2832.7890: 0.0164838 -0.0407973 0.0187056 0.157937 0.423625 0.843229  1.87609  4.13824
 49:     2832.6341: 0.0165157 -0.0407067 0.0180929 0.157360 0.424638 0.843376  1.87196  4.14245
 50:     2832.4815: 0.0165478 -0.0406213 0.0186628 0.157101 0.425636 0.844012  1.86786  4.14667
 51:     2832.3300: 0.0165799 -0.0405346 0.0180677 0.156553 0.426639 0.844146  1.86374  4.15089
 52:     2832.1806: 0.0166122 -0.0404422 0.0186253 0.156317 0.427635 0.844755  1.85965  4.15513
 53:     2832.0323: 0.0166446 -0.0403594 0.0180468 0.155794 0.428627 0.844877  1.85556  4.15937
 54:     2831.8860: 0.0166771 -0.0402797 0.0185914 0.155574 0.429607 0.845469  1.85148  4.16362
 55:     2831.7406: 0.0167096 -0.0402025 0.0180284 0.155074 0.430588 0.845580  1.84740  4.16787
 56:     2831.5971: 0.0167424 -0.0401200 0.0185619 0.154873 0.431564 0.846150  1.84334  4.17214
 57:     2823.2275: 0.0241723 -0.0178143 0.0279421 0.154694 0.570032 0.852884 0.917653  5.13851
 58:     2823.0077: 0.0243118 -0.0209096 0.0315367 0.155146 0.569922 0.857579 0.900545  5.15526
 59:     2820.5079: 0.0243219 -0.0208801 0.0294576 0.153786 0.569402 0.856246 0.913322  5.15707
 60:     2820.0209: 0.0243261 -0.0259732 0.0222170 0.153394 0.574190 0.864662 0.914968  5.15741
 61:     2819.2340: 0.0243310 -0.0260678 0.0232473 0.153113 0.573853 0.865714 0.928086  5.15821
 62:     2814.8421: 0.0250357 -0.0398787 0.0179842 0.132129 0.560768 0.879198  1.17994  5.25066
 63:     2814.8331: 0.0254014 -0.0459558 0.0176973 0.127988 0.560005 0.881149  1.15004  5.28917
 64:     2814.4735: 0.0257755 -0.0467011 0.0185883 0.127078 0.563492 0.882539  1.14177  5.29761
 65:     2814.2272: 0.0257944 -0.0428649 0.0182816 0.128524 0.566955 0.880937  1.15745  5.27588
 66:     2813.7698: 0.0261858 -0.0419618 0.0205550 0.126865 0.575104 0.878813  1.16041  5.27253
 67:     2813.4645: 0.0265757 -0.0420537 0.0199896 0.126314 0.578671 0.878986  1.15776  5.28170
 68:     2812.8046: 0.0272480 -0.0320793 0.0193600 0.130919 0.591671 0.876133  1.19909  5.24647
 69:     2807.7324: 0.0427119 -0.0513132 0.0210760 0.111811 0.708844 0.891478  1.07619  5.77275
 70:     2801.4712: 0.0560713 -0.0740097 0.0208609 0.114749 0.814103 0.879998  1.09695  6.51607
 71:     2800.2814: 0.0553548 -0.0644686 0.0202525 0.107577 0.852183 0.886684  1.07015  6.48728
 72:     2799.8245: 0.0532178 -0.0594050 0.0214275 0.105320 0.890711 0.889987  1.07690  6.46536
 73:     2798.3999: 0.0510334 -0.0569062 0.0207359 0.103398 0.923747 0.890912  1.06938  6.47024
 74:     2796.9941: 0.0438258 -0.0476311 0.0199962 0.0978223  1.00000 0.895386  1.07274  6.73868
 75:     2796.8730: 0.0433183 -0.0483913 0.0202190 0.0982598  1.00000 0.894017  1.07497  7.09290
 76:     2796.8639: 0.0434729 -0.0476753 0.0199892 0.0976425  1.00000 0.893818  1.09162  7.27643
 77:     2796.8505: 0.0433533 -0.0483650 0.0202096 0.0977215  1.00000 0.894083  1.07973  7.27834
 78:     2796.8484: 0.0433224 -0.0483607 0.0202113 0.0980776  1.00000 0.894201  1.07448  7.26945
 79:     2796.8473: 0.0432669 -0.0482305 0.0202565 0.0981140  1.00000 0.894400  1.07069  7.27836
 80:     2796.8472: 0.0432528 -0.0481818 0.0202574 0.0980857  1.00000 0.894466  1.07018  7.28534
 81:     2796.8472: 0.0432523 -0.0481871 0.0202604 0.0980913  1.00000 0.894455  1.07022  7.28569
 82:     2796.8472: 0.0432531 -0.0481833 0.0202594 0.0980894  1.00000 0.894456  1.07024  7.28577

Final Estimate of the Negative LLH:
 LLH:  -8311.583    norm LLH:  -3.302178 
           mu           ar1         omega        alpha1        gamma1 
 0.0005234050 -0.0481832641  0.0001798009  0.0980893747  0.9999999900 
        beta1         delta         shape 
 0.8944563711  1.0702355865  7.2857704887 

R-optimhess Difference Approximated Hessian Matrix:
                  mu           ar1         omega        alpha1        gamma1
mu      -92572375.49 -1.304310e+05 -6.613022e+08 -2.435867e+06 -1.277035e+05
ar1       -130430.97 -2.960609e+03 -7.708017e+05 -1.492684e+03 -7.809006e+01
omega  -661302169.81 -7.708017e+05 -9.933158e+09 -3.284973e+07 -1.721832e+06
alpha1   -2435867.05 -1.492684e+03 -3.284973e+07 -1.662171e+05 -8.715935e+03
gamma1    -127703.52 -7.809006e+01 -1.721832e+06 -8.715935e+03 -9.620990e+03
beta1    -3642690.42 -3.791544e+03 -5.191605e+07 -2.185958e+05 -1.146447e+04
delta     -248101.20 -2.643135e+02 -3.568338e+06 -1.497208e+04 -7.831015e+02
shape       -4448.78 -2.850922e+00 -4.321048e+04 -2.197835e+02 -1.153887e+01
               beta1         delta         shape
mu      -3642690.416 -2.481012e+05  -4448.780252
ar1        -3791.544 -2.643135e+02     -2.850922
omega  -51916048.337 -3.568338e+06 -43210.482623
alpha1   -218595.807 -1.497208e+04   -219.783489
gamma1    -11464.468 -7.831015e+02    -11.538865
beta1    -320129.731 -2.153576e+04   -285.455040
delta     -21535.759 -1.520674e+03    -19.343988
shape       -285.455 -1.934399e+01     -1.118540
attr(,"time")
Time difference of 0.1307454 secs

--- END OF TRACE ---


Time to Estimate Parameters:
 Time difference of 0.6131003 secs

Title:
 GARCH Modelling 

Call:
 garchFit(formula = ~arma(1, 0) + aparch(1, 1), data = djiar, 
    cond.dist = "std") 

Mean and Variance Equation:
 data ~ arma(1, 0) + aparch(1, 1)
<environment: 0x55c612118120>
 [data = djiar]

Conditional Distribution:
 std 

Coefficient(s):
        mu         ar1       omega      alpha1      gamma1       beta1  
 0.0005234  -0.0481833   0.0001798   0.0980894   1.0000000   0.8944564  
     delta       shape  
 1.0702356   7.2857705  

Std. Errors:
 based on Hessian 

Error Analysis:
         Estimate  Std. Error  t value Pr(>|t|)    
mu      5.234e-04   1.525e-04    3.433 0.000598 ***
ar1    -4.818e-02   1.934e-02   -2.491 0.012729 *  
omega   1.798e-04   3.443e-05    5.222 1.77e-07 ***
alpha1  9.809e-02   1.030e-02    9.525  < 2e-16 ***
gamma1  1.000e+00   1.045e-02   95.728  < 2e-16 ***
beta1   8.945e-01   1.049e-02   85.279  < 2e-16 ***
delta   1.070e+00   1.350e-01    7.928 2.22e-15 ***
shape   7.286e+00   1.123e+00    6.490 8.61e-11 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Log Likelihood:
 8311.583    normalized:  3.302178 

Description:
 Tue Oct 28 15:18:43 2025 by user:  


Standardised Residuals Tests:
                                 Statistic     p-Value
 Jarque-Bera Test   R    Chi^2  245.156078 0.000000000
 Shapiro-Wilk Test  R    W        0.983058 0.000000000
 Ljung-Box Test     R    Q(10)   15.595870 0.111800290
 Ljung-Box Test     R    Q(15)   26.450980 0.033541324
 Ljung-Box Test     R    Q(20)   30.170758 0.067133620
 Ljung-Box Test     R^2  Q(10)   19.176843 0.038073151
 Ljung-Box Test     R^2  Q(15)   30.466591 0.010345882
 Ljung-Box Test     R^2  Q(20)   35.364460 0.018246902
 LM Arch Test       R    TR^2    29.577276 0.003231735

Information Criterion Statistics:
      AIC       BIC       SIC      HQIC 
-6.598000 -6.579468 -6.598020 -6.591274 
plot(djia.ap,which=2)  # opciones de gráficos

5.2.7 Volatilidad estocástica (introducción)

En GARCH, \(\sigma_t^2\) es determinística condicionalmente. El modelo de volatilidad estocástica introduce aleatoriedad: \[ r_t=\sigma_t \epsilon_t \ \Rightarrow\ \log r_t^2=\log \sigma_t^2+\log \epsilon_t^2 \] y la volatilidad latente sigue \[ \log \sigma_{t+1}^2=\phi_0+\phi_1 \log \sigma_t^2+w_t,\quad w_t\sim \text{iid }N(0,\sigma_w^2). \] El objetivo es estimar \(\phi_0,\phi_1,\sigma_w^2\) y predecir la volatilidad futura.

5.3 Modelos de Umbral (Threshold Models)

Para una serie temporal estacionaria, la mejor predicción lineal hacia adelante es igual a la mejor predicción lineal hacia atrás. Esto se debe a que la matriz de varianza-covarianza \(\Gamma = {\gamma(i-j)}_{i,j=1}^n\) es simétrica y los procesos gaussianos tienen distribuciones idénticas al invertirse en el tiempo. Sin embargo, muchas series reales no cumplen esta propiedad: por ejemplo, las muertes por influenza aumentan más rápido de lo que disminuyen, mostrando asimetrías y no estacionalidad perfecta.

5.3.1 Modelos TARMA (Threshold ARMA)

Una alternativa no lineal es el modelo TARMA (Threshold ARMA), que ajusta modelos lineales locales en distintos regímenes. Un modelo SETARMA (Self-Exciting Threshold ARMA) de \(k\) regímenes se define como:

\[ x_t = \begin{cases} \phi_0^{(1)} + \sum_{i=1}^{p_1} \phi_i^{(1)} x_{t-i} + w_t^{(1)} + \sum_{j=1}^{q_1} \theta_j^{(1)} w_{t-j}^{(1)}, & \text{si } x_{t-d} \le r_1 \\ \phi_0^{(2)} + \sum_{i=1}^{p_2} \phi_i^{(2)} x_{t-i} + w_t^{(2)} + \sum_{j=1}^{q_2} \theta_j^{(2)} w_{t-j}^{(2)}, & \text{si } r_1 < x_{t-d} \le r_2 \\ \vdots & \vdots \\ \phi_0^{(k)} + \sum_{i=1}^{p_k} \phi_i^{(k)} x_{t-i} + w_t^{(k)} + \sum_{j=1}^{q_k} \theta_j^{(k)} w_{t-j}^{(k)}, & \text{si } r_{k-1} < x_{t-d} \end{cases} \]

donde \(w_t^{(j)} \sim \text{iid } N(0, \sigma_j^2)\) para \(j = 1, \ldots, k\), \(d\) es un retardo, y \(r_1 < \cdots < r_{k-1}\) son los umbrales que dividen los regímenes.

Cada régimen corresponde a un modelo ARMA diferente, y las condiciones de estacionariedad e invertibilidad dependen de las propiedades de cada régimen.

Extensiones del modelo

El umbral puede depender de valores pasados del proceso o de variables exógenas. En ese caso, puede sustituirse \(x_{t-d}\) por otra variable \(y_{t-d}\) que represente tales variables.

5.3.1.1 Ejemplo: Modelado de la serie de influenza

Se estudia la serie mensual de muertes por neumonía e influenza, \(\mathrm{flu}_t\), que muestra un leve descenso y una clara no linealidad. Para eliminar la tendencia, se trabaja con las primeras diferencias:

\[ x_t = \mathrm{flu}_t - \mathrm{flu}_{t-1}. \]

Se observa que \(x_t\) aumenta lentamente y luego puede saltar bruscamente cuando supera aproximadamente 0.05, sugiriendo dos regímenes según \(x_{t-1}\).

El modelo ajustado es:

\[ \begin{array}{ll} x_t = \alpha^{(1)} + \sum_{j=1}^{p} \phi_j^{(1)} x_{t-j} + w_t^{(1)}, & x_{t-1} < 0.05 \\ x_t = \alpha^{(2)} + \sum_{j=1}^{p} \phi_j^{(2)} x_{t-j} + w_t^{(2)}, & x_{t-1} \ge 0.05 \end{array} \]

con \(p = 6\), luego reducido a \(p = 4\). El modelo final estimado fue:

\[ \begin{aligned} \hat{x}_t &= 0 + 0.51_{(.08)} x_{t-1} - 0.20_{(.06)} x_{t-2} + 0.12_{(.05)} x_{t-3} - 0.11_{(.05)} x_{t-4} + \hat{w}_t^{(1)}, \quad x_{t-1} < 0.05 \\ \hat{x}_t &= 0.40 - 0.75_{(.17)} x_{t-1} - 1.03_{(.21)} x_{t-2} - 2.05_{(1.05)} x_{t-3} - 6.71_{(1.25)} x_{t-4} + \hat{w}_t^{(2)}, \quad x_{t-1} \ge 0.05 \end{aligned} \]

con desviaciones estándar estimadas \(\hat{\sigma}_1 = 0.05\) y \(\hat{\sigma}_2 = 0.07\). El umbral 0.05 se superó 17 veces.

5.3.1.2 Implementación en R

A continuación, se muestra el código para realizar el análisis:

# Representar la serie con iniciales de meses
flu %>%
  ts() %>%
  {plot(., type = "c"); points(., pch = substr(month.abb, 1, 1), cex = 0.8, font = 2)}

# Diferenciación
dflu <- diff(flu)

# Gráfico de dispersión con ajuste lowess
library(astsa)
lag1.plot(dflu, corr = FALSE)

# Definir umbral
thrsh <- 0.05

# Crear matriz de retardos
Z <- ts.intersect(
  dflu,
  stats::lag(dflu, -1),
  stats::lag(dflu, -2),
  stats::lag(dflu, -3),
  stats::lag(dflu, -4)
)

# Indicadores de regímenes
ind1 <- ifelse(Z[, 2] < thrsh, 1, NA)
ind2 <- ifelse(Z[, 2] < thrsh, NA, 1)

# Ajustes lineales por régimen
X1 <- Z[, 1] * ind1
X2 <- Z[, 1] * ind2

fit1 <- lm(X1 ~ Z[, 2:5])
fit2 <- lm(X2 ~ Z[, 2:5])

summary(fit1)

Call:
lm(formula = X1 ~ Z[, 2:5])

Residuals:
     Min       1Q   Median       3Q      Max 
-0.13312 -0.02049  0.00218  0.01667  0.26666 

Coefficients:
                              Estimate Std. Error t value Pr(>|t|)    
(Intercept)                   0.004471   0.004894   0.914 0.363032    
Z[, 2:5]stats::lag(dflu, -1)  0.506650   0.078319   6.469  3.2e-09 ***
Z[, 2:5]stats::lag(dflu, -2) -0.200086   0.056573  -3.537 0.000604 ***
Z[, 2:5]stats::lag(dflu, -3)  0.121047   0.054463   2.223 0.028389 *  
Z[, 2:5]stats::lag(dflu, -4) -0.110938   0.045979  -2.413 0.017564 *  
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 0.04578 on 105 degrees of freedom
  (17 observations deleted due to missingness)
Multiple R-squared:  0.3763,    Adjusted R-squared:  0.3526 
F-statistic: 15.84 on 4 and 105 DF,  p-value: 3.568e-10
summary(fit2)

Call:
lm(formula = X2 ~ Z[, 2:5])

Residuals:
      Min        1Q    Median        3Q       Max 
-0.089975 -0.036825 -0.006328  0.040765  0.129509 

Coefficients:
                             Estimate Std. Error t value Pr(>|t|)    
(Intercept)                   0.40794    0.04675   8.726 1.53e-06 ***
Z[, 2:5]stats::lag(dflu, -1) -0.74833    0.16644  -4.496 0.000732 ***
Z[, 2:5]stats::lag(dflu, -2) -1.03231    0.21137  -4.884 0.000376 ***
Z[, 2:5]stats::lag(dflu, -3) -2.04504    1.05000  -1.948 0.075235 .  
Z[, 2:5]stats::lag(dflu, -4) -6.71178    1.24538  -5.389 0.000163 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 0.0721 on 12 degrees of freedom
  (110 observations deleted due to missingness)
Multiple R-squared:  0.9207,    Adjusted R-squared:  0.8943 
F-statistic: 34.85 on 4 and 12 DF,  p-value: 1.618e-06
# Predicciones
D <- cbind(rep(1, nrow(Z)), Z[, 2:5])
p1 <- D %*% coef(fit1)
p2 <- D %*% coef(fit2)
prd <- ifelse(Z[, 2] < thrsh, p1, p2)

# Gráfico de predicciones
plot(dflu, ylim = c(-0.5, 0.5), type = 'p', pch = 3)
lines(prd)

# Cálculo de errores y bandas de predicción
prde1 <- sqrt(sum(resid(fit1)^2) / df.residual(fit1))
prde2 <- sqrt(sum(resid(fit2)^2) / df.residual(fit2))
prde <- ifelse(Z[, 2] < thrsh, prde1, prde2)

tx <- time(dflu)[-(1:4)]
xx <- c(tx, rev(tx))
yy <- c(prd - 2 * prde, rev(prd + 2 * prde))

polygon(xx, yy, border = 8, col = gray(0.6, alpha = 0.25))
abline(h = 0.05, col = 4, lty = 6)

5.3.1.3 Uso del paquete tsDyn

También puede emplearse el paquete tsDyn para ajustar automáticamente modelos de umbral.

library(tsDyn)
u <- setar(dflu, m = 4, thDelay = 0, th = 0.05)  # ajuste con umbral fijo
Warning: 
With the threshold you gave (0.05) there is a regime with less than trim=15% observations (86.61%, 13.39%, )
Warning: Possible unit root in the high regime. Roots are: 0.6182 0.6244 0.6244
0.6182
u <- setar(dflu, m = 4, thDelay = 0)             # ajuste con umbral estimado
Warning: Possible unit root in the high regime. Roots are: 0.8074 0.8074 1.3596
1.3596
BIC(u)
[1] -678.5372
AIC(u)
[1] -710.1644
summary(u)

Non linear autoregressive model

SETAR model ( 2 regimes)
Coefficients:
Low regime:
      const.L        phiL.1        phiL.2        phiL.3        phiL.4 
 0.0006269563  0.4608089284 -0.2243720404  0.1100931813 -0.1307031988 

High regime:
   const.H     phiH.1     phiH.2     phiH.3     phiH.4 
 0.2035231 -0.4071318 -1.4686776  0.3768388 -0.8298225 

Threshold:
-Variable: Z(t) = + (1) X(t)+ (0)X(t-1)+ (0)X(t-2)+ (0)X(t-3)
-Value: 0.03646
Proportion of points in low regime: 84.25%   High regime: 15.75% 

Residuals:
       Min         1Q     Median         3Q        Max 
-0.2632248 -0.0195074  0.0044446  0.0210898  0.2854727 

Fit:
residuals variance = 0.003739,  AIC = -710, MAPE = 541.4%

Coefficient(s):

           Estimate  Std. Error  t value  Pr(>|t|)    
const.L  0.00062696  0.00699184   0.0897  0.928698    
phiL.1   0.46080893  0.11083474   4.1576 6.035e-05 ***
phiL.2  -0.22437204  0.07882706  -2.8464  0.005196 ** 
phiL.3   0.11009318  0.07608021   1.4471  0.150464    
phiL.4  -0.13070320  0.06406509  -2.0402  0.043511 *  
const.H  0.20352307  0.02632410   7.7314 3.505e-12 ***
phiH.1  -0.40713175  0.13413815  -3.0352  0.002944 ** 
phiH.2  -1.46867761  0.17439989  -8.4213 8.911e-14 ***
phiH.3   0.37683878  0.75269827   0.5007  0.617527    
phiH.4  -0.82982249  0.84051869  -0.9873  0.325478    
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Threshold
Variable: Z(t) = + (1) X(t) + (0) X(t-1)+ (0) X(t-2)+ (0) X(t-3)

Value: 0.03646

5.4 Modelos ARMAX Multivariados

Se introduce la extensión multivariante de la regresión básica: para salidas \(y_{t1},\dots,y_{tk}\),

\[ \begin{equation*} y_{t i}=\beta_{i 1} z_{t 1}+\beta_{i 2} z_{t 2}+\cdots+\beta_{i r} z_{t r}+w_{t i} \end{equation*} \]

con \(i=1,\dots,k\). En forma matricial, con \(y_t=(y_{t1},\dots,y_{tk})'\), \(\mathcal{B}=\{\beta_{ij}\}_{i=1,..,k;j=1,..,r}\),

\[ \begin{equation*} y_{t}=\mathcal{B} z_{t}+w_{t}. \end{equation*} \]

Asumimos \(\mathrm{E}\{w_t w_t'\}=\Sigma_w\) (matriz \(k\times k\)) y normalidad. Estimadores MLE:

\[ \begin{equation*} \hat{\mathcal{B}}=\left(\sum_{t=1}^{n} y_{t} z_{t}^{\prime}\right)\left(\sum_{t=1}^{n} z_{t} z_{t}^{\prime}\right)^{-1}, \end{equation*} \] \[ \begin{equation*} \hat{\Sigma}_{w}=\frac{1}{n-r} \sum_{t=1}^{n}\left(y_{t}-\hat{\mathcal{B}} z_{t}\right)\left(y_{t}-\hat{\mathcal{B}} z_{t}\right)^{\prime}. \end{equation*} \]

Errores estándar: \[ \begin{equation*} \operatorname{se}\left(\hat{\beta}_{i j}\right)=\sqrt{c_{i i} \hat{\sigma}_{j j}}, \end{equation*} \] donde \(c_{ii}\) es el elemento (i)-ésimo diagonal de \(\left(\sum z_t z_t'\right)^{-1}\) y \(\hat{\sigma}_{jj}\) el (j)-ésimo diagonal de \(\hat{\Sigma}_w\).

Criterios de información: \[ \begin{equation*} \mathrm{AIC}=\ln \left|\hat{\Sigma}_{w}\right|+\frac{2}{n}\left(k r+\frac{k(k+1)}{2}\right), \end{equation*} \] \[ \begin{equation*} \mathrm{AICc}=\ln \left|\hat{\Sigma}_{w}\right|+\frac{k(r+n)}{n-k-r-1}. \end{equation*} \]

5.4.1 Modelo VAR(1): formulación y estimación

Modelo autoregresivo vectorial de primer orden: \[ \begin{equation*} x_{t}=\alpha+\Phi x_{t-1}+w_{t}, \end{equation*} \] con \(\mathrm{E}(w_t w_t')=\Sigma_w\) \(k\times k\) y \(\alpha=(I-\Phi)\mu\) si \(\mathrm{E}(x_t)=\mu\).

Identificación con regresión multivariante: \(y_t=x_t\), \(\mathcal{B}=(\alpha,\Phi)\), \(z_t=(1,x_{t-1})\). Estimación condicional de \(\Sigma_w\):

\[ \begin{equation*} \hat{\Sigma}_{w}=(n-1)^{-1} \sum_{t=2}^{n}\left(x_{t}-\hat{\alpha}-\hat{\Phi} x_{t-1}\right)\left(x_{t}-\hat{\alpha}-\hat{\Phi} x_{t-1}\right)^{\prime}. \end{equation*} \]

Extensión ARX (exógenas) de orden (p): \[ \begin{equation*} x_{t}=\Gamma u_{t}+\sum_{j=1}^{p} \Phi_{j} x_{t-j}+w_{t}. \end{equation*} \]

5.4.1.1 Ejemplo (Contaminación, clima y mortalidad)

# Paquete para VAR
library(vars)
Loading required package: MASS

Attaching package: 'MASS'
The following object is masked from 'package:dplyr':

    select
Loading required package: strucchange
Loading required package: sandwich

Attaching package: 'strucchange'
The following object is masked from 'package:stringr':

    boundary
Loading required package: urca
Loading required package: lmtest
# Matriz de series: mortalidad, temperatura, particulado
x <- cbind(cmort, tempr, part)

# Ajuste VAR(1) con constante y tendencia
summary(VAR(x, p = 1, type = "both"))

VAR Estimation Results:
========================= 
Endogenous variables: cmort, tempr, part 
Deterministic variables: both 
Sample size: 507 
Log Likelihood: -5116.02 
Roots of the characteristic polynomial:
0.8931 0.4953 0.1444
Call:
VAR(y = x, p = 1, type = "both")


Estimation results for equation cmort: 
====================================== 
cmort = cmort.l1 + tempr.l1 + part.l1 + const + trend 

          Estimate Std. Error t value Pr(>|t|)    
cmort.l1  0.464824   0.036729  12.656  < 2e-16 ***
tempr.l1 -0.360888   0.032188 -11.212  < 2e-16 ***
part.l1   0.099415   0.019178   5.184 3.16e-07 ***
const    73.227292   4.834004  15.148  < 2e-16 ***
trend    -0.014459   0.001978  -7.308 1.07e-12 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1


Residual standard error: 5.583 on 502 degrees of freedom
Multiple R-Squared: 0.6908, Adjusted R-squared: 0.6883 
F-statistic: 280.3 on 4 and 502 DF,  p-value: < 2.2e-16 


Estimation results for equation tempr: 
====================================== 
tempr = cmort.l1 + tempr.l1 + part.l1 + const + trend 

          Estimate Std. Error t value Pr(>|t|)    
cmort.l1 -0.244046   0.042105  -5.796 1.20e-08 ***
tempr.l1  0.486596   0.036899  13.187  < 2e-16 ***
part.l1  -0.127661   0.021985  -5.807 1.13e-08 ***
const    67.585598   5.541550  12.196  < 2e-16 ***
trend    -0.006912   0.002268  -3.048  0.00243 ** 
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1


Residual standard error: 6.4 on 502 degrees of freedom
Multiple R-Squared: 0.5007, Adjusted R-squared: 0.4967 
F-statistic: 125.9 on 4 and 502 DF,  p-value: < 2.2e-16 


Estimation results for equation part: 
===================================== 
part = cmort.l1 + tempr.l1 + part.l1 + const + trend 

          Estimate Std. Error t value Pr(>|t|)    
cmort.l1 -0.124775   0.079013  -1.579    0.115    
tempr.l1 -0.476526   0.069245  -6.882 1.77e-11 ***
part.l1   0.581308   0.041257  14.090  < 2e-16 ***
const    67.463501  10.399163   6.487 2.10e-10 ***
trend    -0.004650   0.004256  -1.093    0.275    
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1


Residual standard error: 12.01 on 502 degrees of freedom
Multiple R-Squared: 0.3732, Adjusted R-squared: 0.3683 
F-statistic: 74.74 on 4 and 502 DF,  p-value: < 2.2e-16 



Covariance matrix of residuals:
       cmort  tempr   part
cmort 31.172  5.975  16.65
tempr  5.975 40.965  42.32
part  16.654 42.323 144.26

Correlation matrix of residuals:
       cmort  tempr   part
cmort 1.0000 0.1672 0.2484
tempr 0.1672 1.0000 0.5506
part  0.2484 0.5506 1.0000

Resultados clave (parciales, en el texto): estimaciones \(\hat{\alpha}, \hat{\beta}, \hat{\Phi}\), \(\hat{\Sigma}_w\) y ecuación de predicción para mortalidad \(\hat{M}_t=73.23-0.014t+0.46M_{t-1}-0.36T_{t-1}+0.10P_{t-1}\) con \(R^2\approx 0.69\).

5.4.2 Extensión a VAR(p): forma general y SSE

Definiciones: \[ z_t=\left(1, x_{t-1}^\prime, x_{t-2}^\prime,\ldots,x_{t-p}^\prime\right)^\prime,\quad \mathcal{B}=\left(\alpha,\Phi_1,\ldots,\Phi_p\right). \]

Modelo: \[ \begin{equation*} x_{t}=\alpha+\sum_{j=1}^{p} \Phi_{j} x_{t-j}+w_{t}, \end{equation*} \] Suma de cuadrados de los errores: \[ \begin{equation*} \mathrm{SSE}=\sum_{t=p+1}^{n}\left(x_{t}-\mathcal{B} z_{t}\right)\left(x_{t}-\mathcal{B} z_{t}\right)^{\prime}. \end{equation*} \] Estimador condicional de \(\Sigma_w\): \[ \begin{equation*} \hat{\Sigma}_{w}=\operatorname{SSE}/(n-p). \end{equation*} \]

Criterio BIC: \[ \begin{equation*} \mathrm{BIC}=\log \left|\hat{\Sigma}_{w}\right|+k^{2} p \ln n / n. \end{equation*} \]

5.4.2.1 Selección de orden y ajuste

# Selección de orden con varios criterios
VARselect(x, lag.max = 10, type = "both")
$selection
AIC(n)  HQ(n)  SC(n) FPE(n) 
     9      5      2      9 

$criteria
                  1           2           3           4           5           6
AIC(n)     11.73780    11.30185    11.26788    11.23030    11.17634    11.15266
HQ(n)      11.78758    11.38149    11.37738    11.36967    11.34557    11.35176
SC(n)      11.86463    11.50477    11.54689    11.58541    11.60755    11.65996
FPE(n) 125216.91717 80972.28678 78268.19568 75383.73647 71426.10041 69758.25113
                 7           8           9          10
AIC(n)    11.15247    11.12878    11.11915    11.12019
HQ(n)     11.38144    11.38760    11.40784    11.43874
SC(n)     11.73587    11.78827    11.85473    11.93187
FPE(n) 69749.89175 68122.40518 67476.96374 67556.45243
# Ajuste del modelo BIC: VAR(2) con constante y tendencia
summary(fit <- VAR(x, p = 2, type = "both"))

VAR Estimation Results:
========================= 
Endogenous variables: cmort, tempr, part 
Deterministic variables: both 
Sample size: 506 
Log Likelihood: -4987.186 
Roots of the characteristic polynomial:
0.8807 0.8807 0.5466 0.4746 0.4746 0.4498
Call:
VAR(y = x, p = 2, type = "both")


Estimation results for equation cmort: 
====================================== 
cmort = cmort.l1 + tempr.l1 + part.l1 + cmort.l2 + tempr.l2 + part.l2 + const + trend 

          Estimate Std. Error t value Pr(>|t|)    
cmort.l1  0.297059   0.043734   6.792 3.15e-11 ***
tempr.l1 -0.199510   0.044274  -4.506 8.23e-06 ***
part.l1   0.042523   0.024034   1.769  0.07745 .  
cmort.l2  0.276194   0.041938   6.586 1.15e-10 ***
tempr.l2 -0.079337   0.044679  -1.776  0.07639 .  
part.l2   0.068082   0.025286   2.692  0.00733 ** 
const    56.098652   5.916618   9.482  < 2e-16 ***
trend    -0.011042   0.001992  -5.543 4.84e-08 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1


Residual standard error: 5.295 on 498 degrees of freedom
Multiple R-Squared: 0.7227, Adjusted R-squared: 0.7188 
F-statistic: 185.4 on 7 and 498 DF,  p-value: < 2.2e-16 


Estimation results for equation tempr: 
====================================== 
tempr = cmort.l1 + tempr.l1 + part.l1 + cmort.l2 + tempr.l2 + part.l2 + const + trend 

          Estimate Std. Error t value Pr(>|t|)    
cmort.l1 -0.108889   0.050667  -2.149  0.03211 *  
tempr.l1  0.260963   0.051292   5.088 5.14e-07 ***
part.l1  -0.050542   0.027844  -1.815  0.07010 .  
cmort.l2 -0.040870   0.048587  -0.841  0.40065    
tempr.l2  0.355592   0.051762   6.870 1.93e-11 ***
part.l2  -0.095114   0.029295  -3.247  0.00125 ** 
const    49.880485   6.854540   7.277 1.34e-12 ***
trend    -0.004754   0.002308  -2.060  0.03993 *  
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1


Residual standard error: 6.134 on 498 degrees of freedom
Multiple R-Squared: 0.5445, Adjusted R-squared: 0.5381 
F-statistic: 85.04 on 7 and 498 DF,  p-value: < 2.2e-16 


Estimation results for equation part: 
===================================== 
part = cmort.l1 + tempr.l1 + part.l1 + cmort.l2 + tempr.l2 + part.l2 + const + trend 

          Estimate Std. Error t value Pr(>|t|)    
cmort.l1  0.078934   0.091773   0.860 0.390153    
tempr.l1 -0.388808   0.092906  -4.185 3.37e-05 ***
part.l1   0.388814   0.050433   7.709 6.92e-14 ***
cmort.l2 -0.325112   0.088005  -3.694 0.000245 ***
tempr.l2  0.052780   0.093756   0.563 0.573724    
part.l2   0.382193   0.053062   7.203 2.19e-12 ***
const    59.586169  12.415669   4.799 2.11e-06 ***
trend    -0.007582   0.004180  -1.814 0.070328 .  
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1


Residual standard error: 11.11 on 498 degrees of freedom
Multiple R-Squared: 0.4679, Adjusted R-squared: 0.4604 
F-statistic: 62.57 on 7 and 498 DF,  p-value: < 2.2e-16 



Covariance matrix of residuals:
       cmort  tempr   part
cmort 28.034  7.076  16.33
tempr  7.076 37.627  40.88
part  16.325 40.880 123.45

Correlation matrix of residuals:
       cmort  tempr   part
cmort 1.0000 0.2179 0.2775
tempr 0.2179 1.0000 0.5998
part  0.2775 0.5998 1.0000
# Diagnóstico: ACFs y prueba Portmanteau ajustada
acf(resid(fit), 52)

serial.test(fit, lags.pt = 12, type = "PT.adjusted")

    Portmanteau Test (adjusted)

data:  Residuals of VAR object fit
Chi-squared = 162.35, df = 90, p-value = 4.602e-06

Interpretación: BIC selecciona (p=2) (frente a AIC/FPE/HQ). El diagnóstico multivariante indica que el modelo no captura efectos concurrentes (correlaciones residuales no nulas), por lo que el test Q (equivalente al Ljung-Box univariado) rechaza ruido blanco.

Estadístico Q: \[ \begin{equation*} Q=n^{2} \sum_{h=1}^{H} \frac{1}{n-h} \operatorname{tr}\left[\hat{\Gamma}_{w}(h) \hat{\Gamma}_{w}(0)^{-1} \hat{\Gamma}_{w}(h) \hat{\Gamma}_{w}(0)^{-1}\right], \end{equation*} \] donde \[ \hat{\Gamma}_{w}(h)=n^{-1} \sum_{t=1}^{n-h} \hat{w}_{t+h} \hat{w}_{t}^{\prime}. \]

5.4.2.2 Predicción con VAR

# Pronósticos y fanchart
fit.pr <- predict(fit, n.ahead = 24, ci = 0.95)
fanchart(fit.pr)

5.4.3 Ecuaciones de Yule–Walker multivariadas

Para VAR((p)): \[ \begin{align*} \Gamma(h) & =\sum_{j=1}^{p} \Phi_{j} \Gamma(h-j), \quad h=1,2,\ldots \\ \Gamma(0) & =\sum_{j=1}^{p} \Phi_{j} \Gamma(-j)+\Sigma_{w}. \end{align*} \] Estimadores de autocovarianza: \[ \begin{equation*} \hat{\Gamma}(h)=n^{-1} \sum_{t=1}^{n-h}\left(x_{t+h}-\bar{x}\right)\left(x_{t}-\bar{x}\right)^{\prime}, \quad h=0,1,\ldots,n-1, \end{equation*} \] Correlaciones cruzadas: \[ \begin{equation*} \hat{\rho}_{i, j}(h)=\frac{\hat{\gamma}_{i, j}(h)}{\sqrt{\hat{\gamma}_{i, i}(0)} \sqrt{\hat{\gamma}_{j, j}(0)}}. \end{equation*} \]

5.4.4 Distribución asintótica de estimadores VAR

Sea \(\phi=\operatorname{vec}(\Phi_1,\ldots,\Phi_p)\) (vector \(k^2p\times 1\). Entonces, \[ \begin{equation*} \sqrt{n}(\hat{\phi}-\phi) \sim A N\left(0, \Sigma_{w} \otimes \Gamma_{pp}^{-1}\right), \end{equation*} \] donde \(\Gamma_{pp}={\Gamma(i-j)}_{i,j=1}^p\). Errores estándar a partir de \(\hat{\Sigma}_w) y (\hat{\Gamma}_{pp}\).

5.4.5 VARMA y ARMAX multivariados: operadores y condiciones

Definiciones de operadores: \[ \begin{equation*} \Phi(B)=I-\Phi_{1} B-\cdots-\Phi_{p} B^{p} \end{equation*} \] \[ \begin{equation*} \Theta(B)=I+\Theta_{1} B+\cdots+\Theta_{q} B^{q}. \end{equation*} \]

Modelo VARMA((p,q)) centrado: \[ \begin{equation*} \Phi(B) x_{t}=\Theta(B) w_{t}. \end{equation*} \]

ARMAX vectorial: \[ \begin{equation*} x_{t}=\Gamma u_{t}+\sum_{j=1}^{p} \Phi_{j} x_{t-j}+\sum_{k=1}^{q} \Theta_{k} w_{t-k}+w_{t}. \end{equation*} \]

Causalidad: raíces de \(|\Phi(z)|\) fuera del círculo unitario; Invertibilidad: raíces de \(|\Theta(z)|\) fuera del círculo unitario. Representaciones: \[ x_t=\Psi(B)w_t,\quad \Psi(B)=\sum_{j=0}^\infty \Psi_j B^j,\ \Psi_0=I; \] \[ w_t=\Pi(B)x_t,\quad \Pi(B)=\sum_{j=0}^\infty \Pi_j B^j,\ \Pi_0=I. \]

5.4.6 Estructura de autocovarianza

Para modelo causal ARMA((p,q)) ((h)): \[ \begin{equation*} \Gamma(h)=\sum_{j=0}^{\infty} \Psi_{j+h} \Sigma_{w} \Psi_{j}^{\prime}, \end{equation*} \] Para MA((q)): \[ \begin{equation*} \Gamma(h)=\sum_{j=0}^{q-h} \Theta_{j+h} \Sigma_{w} \Theta_{j}^{\prime}, \quad \Theta_0=I, \end{equation*} \] y \(\Gamma(h)=0\) para (h>q).

5.4.7 Algoritmo de Spliid para VARMA (estimación rápida)

Modelo general con media no nula: \[ \begin{equation*} x_{t}=\alpha+\Phi_{1} x_{t-1}+\cdots+\Phi_{p} x_{t-p}+w_{t}+\Theta_{1} w_{t-1}+\cdots+\Theta_{q} w_{t-q}. \end{equation*} \] Si \(\mu=\mathrm{E}x_t\), entonces \(\alpha=(I-\Phi_1-\cdots-\Phi_p)\mu\).

Si \(w_{t-1},\dots,w_{t-q}\) fueran observables, el modelo anterior se puede reescribir como regresión multivariante: \[ \begin{equation*} x_{t}=\mathcal{B} z_{t}+w_{t}, \end{equation*} \] \[ \begin{equation*} z_{t}=\left(1, x_{t-1}^{\prime}, \ldots, x_{t-p}^{\prime}, w_{t-1}^{\prime}, \ldots, w_{t-q}^{\prime}\right)^{\prime}, \end{equation*} \] \[ \begin{equation*} \mathcal{B}=\left[\alpha, \Phi_{1}, \ldots, \Phi_{p}, \Theta_{1}, \ldots, \Theta_{q}\right]. \end{equation*} \]

Actualización de innovaciones (dadas \(\mathcal{B}_0\)):

\[ \begin{equation*} w_{t-j}=x_{t-j}-\mathcal{B}_{0} z_{t-j}, \quad j=1,\ldots,q. \end{equation*} \]

Los nuevos valores de \(w_t\) se incluyen en las covariables \(z_t\) y se vuelve a estimar \(\mathcal{B}\) hasta convergencia (no necesariamente MLE, pero cercano y útil como inicialización para métodos de espacio de estados).

5.4.7.1 Ejemplo (Algoritmo de Spliid con marima)

library(marima)

# Definición del modelo VARMA(2,1)
model <- define.model(kvar = 3, ar = c(1, 2), ma = c(1))
arp <- model$ar.pattern; map <- model$ma.pattern

# Detrendeo de mortalidad (cmort) y armado de matriz de datos
cmort.d <- resid(detr <- lm(cmort ~ time(cmort), na.action = NULL))
xdata <- matrix(cbind(cmort.d, tempr, part), ncol = 3) # quitar atributos ts

# Ajuste VARMA con penalización
fit <- marima(xdata, ar.pattern = arp, ma.pattern = map, means = c(0, 1, 1),
              penalty = 1)
All cases in data,  1  to  508  accepted for completeness.
508 3  = MARIMA - dimension of data 
# Innovaciones y diagnóstico (no mostrado)
innov <- t(resid(fit)); plot.ts(innov); acf(innov, na.action = na.pass)

# Valores ajustados para mortalidad (recomponer con tendencia)
pred <- ts(t(fitted(fit))[,1], start = start(cmort), freq = frequency(cmort)) +
  detr$coef[1] + detr$coef[2] * time(cmort)

plot(pred, ylab = "Cardiovascular Mortality", lwd = 2)
points(cmort)

# Impresión de estimaciones y estadísticos t^2
short.form(fit$ar.estimates, leading = FALSE)
, , Lag=1

       x1=y1     x2=y2     x3=y3
y1 -0.311106  0.000000 -0.113831
y2  0.000000 -0.656331  0.048208
y3 -0.108892  0.000000 -0.860911

, , Lag=2

       x1=y1     x2=y2     x3=y3
y1 -0.333368  0.132523 -0.047171
y2  0.000000 -0.200135  0.054616
y3  0.179117 -0.102144 -0.151250
short.form(fit$ar.fvalues, leading = FALSE)
, , Lag=1

       x1=y1    x2=y2      x3=y3
y1 51.211590  0.00000   7.909997
y2  0.000000 41.73927   3.141522
y3  1.571085  0.00000 113.299823

, , Lag=2

       x1=y1     x2=y2    x3=y3
y1 67.241600 11.890684 2.515931
y2  0.000000  8.101381 2.903037
y3  4.860958  1.768893 6.477311
short.form(fit$ma.estimates, leading = FALSE)
, , Lag=1

       x1=y1     x2=y2     x3=y3
y1  0.000000 -0.186710 -0.106470
y2 -0.114446 -0.446431  0.000000
y3  0.000000 -0.278378 -0.672962
short.form(fit$ma.fvalues, leading = FALSE)
, , Lag=1

      x1=y1     x2=y2    x3=y3
y1 0.000000 14.514812  4.75441
y2 4.683436 16.375957  0.00000
y3 0.000000  8.079861 47.56415
# Matriz de covarianza residual
fit$resid.cov
          u1        u2        u3
u1 27.346796  6.503133  13.79950
u2  6.503133 36.202990  38.12202
u3 13.799495 38.122018 109.20702