etb_xts = xts(etb$Último, order.by = etb$Fecha)
class(etb_xts)
## [1] "xts" "zoo"
summary(etb_xts)
## Index etb_xts
## Min. :2015-01-02 Min. : 74.0
## 1st Qu.:2017-01-05 1st Qu.:207.0
## Median :2019-01-16 Median :265.0
## Mean :2019-02-23 Mean :353.4
## 3rd Qu.:2021-01-19 3rd Qu.:529.5
## Max. :2024-12-30 Max. :655.0
plot(etb_xts, main = "precio ultimo")
El precio de la acción ha caído de más de 600 COP a menos de 100 COP entre 2015 y 2024.
No se observan patrones estacionales claros, pero sí una tendencia bajista prolongada.
rendimiento_etb = dailyReturn(etb_xts)
plot(rendimiento_etb, main = "Rendimiento Diario de la Acción ETB")
summary(rendimiento_etb)
## Index daily.returns
## Min. :2015-01-02 Min. :-0.1872910
## 1st Qu.:2017-01-05 1st Qu.:-0.0076727
## Median :2019-01-16 Median : 0.0000000
## Mean :2019-02-23 Mean :-0.0007236
## 3rd Qu.:2021-01-19 3rd Qu.: 0.0042530
## Max. :2024-12-30 Max. : 0.2045454
Los rendimientos diarios de la acción muestran alta volatilidad en varios periodos, especialmente a partir de 2019.
No se observan patrones estacionales claros, pero sí episodios de alta dispersión y cambios bruscos.
modelo1 = auto.arima(rendimiento_etb)
summary(modelo1)
## Series: rendimiento_etb
## ARIMA(1,0,1) with non-zero mean
##
## Coefficients:
## ar1 ma1 mean
## 0.5537 -0.6361 -7e-04
## s.e. 0.1579 0.1465 4e-04
##
## sigma^2 = 0.0005082: log likelihood = 4660.52
## AIC=-9313.05 AICc=-9313.03 BIC=-9290.72
##
## Training set error measures:
## ME RMSE MAE MPE MAPE MASE
## Training set -1.556461e-06 0.02252506 0.01266098 NaN Inf 0.6288238
## ACF1
## Training set -0.0006444324
El modelo se refiere mejor ARMA dando como modelo c(1,0,1).
autoplot(modelo1)
checkresiduals(modelo1)
##
## Ljung-Box test
##
## data: Residuals from ARIMA(1,0,1) with non-zero mean
## Q* = 13.541, df = 8, p-value = 0.09455
##
## Model df: 2. Total lags used: 10
ndiffs(rendimiento_etb)
## [1] 0
adf.test(rendimiento_etb)
## Warning in adf.test(rendimiento_etb): p-value smaller than printed p-value
##
## Augmented Dickey-Fuller Test
##
## data: rendimiento_etb
## Dickey-Fuller = -12.641, Lag order = 12, p-value = 0.01
## alternative hypothesis: stationary
H0 = No es ESTACIONARIA si el p-value es mayor que 0.05.
H1 = Si es ESTACIONARIA si el p-value es menor que 0.05.
Es estacionaria p-value = 0.01.
El mejor modelo según auto.arima() es ARIMA(1,0,1).
La prueba ADF confirma que la serie es estacionaria (p-value = 0.01 < 0.05).
Generamos el modelo ARCH a un rezago.
modeloarch1 = ArchTest(rendimiento_etb, lags = 1, demean = T)
modeloarch1
##
## ARCH LM-test; Null hypothesis: no ARCH effects
##
## data: rendimiento_etb
## Chi-squared = 37.317, df = 1, p-value = 1.004e-09
H0 = No hay efectos ARCH si el p-value es mayor que 0.05.
H1 = Si hay efectos ARCH si el p-value es menor que 0.05.
Errores_cuadrado = resid(modelo1)^2
plot(Errores_cuadrado, main = "Errores_cuadrado")
Los errores al cuadrado presentan picos aislados, indicando presencia de heterocedasticidad.
Se observa mayor concentración de volatilidad en periodos recientes.
Box.test(Errores_cuadrado, lag = 5, type = "Ljung-Box")
##
## Box-Ljung test
##
## data: Errores_cuadrado
## X-squared = 131.28, df = 5, p-value < 2.2e-16
Regresion1 = dynlm(Errores_cuadrado ~ L(Errores_cuadrado,1))
summary(Regresion1)
##
## Time series regression with "ts" data:
## Start = 2, End = 1963
##
## Call:
## dynlm(formula = Errores_cuadrado ~ L(Errores_cuadrado, 1))
##
## Residuals:
## Min 1Q Median 3Q Max
## -0.005613 -0.000440 -0.000421 -0.000198 0.041316
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 4.395e-04 4.738e-05 9.277 < 2e-16 ***
## L(Errores_cuadrado, 1) 1.342e-01 2.238e-02 5.995 2.42e-09 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.002037 on 1960 degrees of freedom
## Multiple R-squared: 0.018, Adjusted R-squared: 0.0175
## F-statistic: 35.93 on 1 and 1960 DF, p-value: 2.423e-09
autoplot(acf(Errores_cuadrado, lag.max = 2434, ylim = c(-0.5,1))) +
labs(title = "Autocorrelación parcial de los errores al cuadrado") +
xlab("Rezagos") +
ylab("Autocorrelación parcial")
ugarch1 = ugarchspec(mean.model = list(armaOrder = c(1,1)))
ugarch1
##
## *---------------------------------*
## * GARCH Model Spec *
## *---------------------------------*
##
## Conditional Variance Dynamics
## ------------------------------------
## GARCH Model : sGARCH(1,1)
## Variance Targeting : FALSE
##
## Conditional Mean Dynamics
## ------------------------------------
## Mean Model : ARFIMA(1,0,1)
## Include Mean : TRUE
## GARCH-in-Mean : FALSE
##
## Conditional Distribution
## ------------------------------------
## Distribution : norm
## Includes Skew : FALSE
## Includes Shape : FALSE
## Includes Lambda : FALSE
ugfit1 = ugarchfit(spec = ugarch1, data = rendimiento_etb)
ugfit1
##
## *---------------------------------*
## * GARCH Model Fit *
## *---------------------------------*
##
## Conditional Variance Dynamics
## -----------------------------------
## GARCH Model : sGARCH(1,1)
## Mean Model : ARFIMA(1,0,1)
## Distribution : norm
##
## Optimal Parameters
## ------------------------------------
## Estimate Std. Error t value Pr(>|t|)
## mu -0.000232 0.000302 -0.76824 0.442344
## ar1 0.399401 0.148799 2.68417 0.007271
## ma1 -0.528564 0.137248 -3.85115 0.000118
## omega 0.000017 0.000001 15.90677 0.000000
## alpha1 0.087185 0.009319 9.35575 0.000000
## beta1 0.877250 0.006880 127.51616 0.000000
##
## Robust Standard Errors:
## Estimate Std. Error t value Pr(>|t|)
## mu -0.000232 0.000328 -0.70694 0.479601
## ar1 0.399401 0.159490 2.50423 0.012272
## ma1 -0.528564 0.143537 -3.68242 0.000231
## omega 0.000017 0.000003 6.28222 0.000000
## alpha1 0.087185 0.032067 2.71880 0.006552
## beta1 0.877250 0.023247 37.73625 0.000000
##
## LogLikelihood : 4995.698
##
## Information Criteria
## ------------------------------------
##
## Akaike -5.0837
## Bayes -5.0667
## Shibata -5.0838
## Hannan-Quinn -5.0775
##
## Weighted Ljung-Box Test on Standardized Residuals
## ------------------------------------
## statistic p-value
## Lag[1] 1.756 0.1851
## Lag[2*(p+q)+(p+q)-1][5] 2.189 0.9114
## Lag[4*(p+q)+(p+q)-1][9] 4.089 0.6700
## d.o.f=2
## H0 : No serial correlation
##
## Weighted Ljung-Box Test on Standardized Squared Residuals
## ------------------------------------
## statistic p-value
## Lag[1] 0.004787 0.9448
## Lag[2*(p+q)+(p+q)-1][5] 0.409989 0.9706
## Lag[4*(p+q)+(p+q)-1][9] 0.585002 0.9974
## d.o.f=2
##
## Weighted ARCH LM Tests
## ------------------------------------
## Statistic Shape Scale P-Value
## ARCH Lag[3] 0.1709 0.500 2.000 0.6793
## ARCH Lag[5] 0.3131 1.440 1.667 0.9368
## ARCH Lag[7] 0.3644 2.315 1.543 0.9890
##
## Nyblom stability test
## ------------------------------------
## Joint Statistic: 3.7494
## Individual Statistics:
## mu 0.54541
## ar1 0.35556
## ma1 0.43519
## omega 0.22269
## alpha1 0.20417
## beta1 0.05814
##
## 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.3371 0.7361
## Negative Sign Bias 0.2364 0.8132
## Positive Sign Bias 0.8038 0.4216
## Joint Effect 0.7313 0.8658
##
##
## Adjusted Pearson Goodness-of-Fit Test:
## ------------------------------------
## group statistic p-value(g-1)
## 1 20 1096 1.359e-220
## 2 30 1280 4.671e-251
## 3 40 1396 1.018e-267
## 4 50 1477 4.860e-277
##
##
## Elapsed time : 0.291173
ugfit1@fit$coef
## mu ar1 ma1 omega alpha1
## -0.0002321637 0.3994007903 -0.5285642053 0.0000168269 0.0871849976
## beta1
## 0.8772504338
ug_var1 = ugfit1@fit$var
autoplot(ts(ug_var1))
ug_resid1 = (ugfit1@fit$residuals)^2
autoplot(ts(ug_resid1))
El modelo GARCH(1,1) estimado tiene un coeficiente β₁ ≈ 0.877, lo que indica alta persistencia en la volatilidad.
El coeficiente α₁ ≈ 0.087 sugiere que los shocks recientes afectan la varianza condicional, pero su impacto es moderado.
La serie de varianzas condicionales muestra picos de volatilidad concentrados en ciertos periodos.
Los residuos estandarizados presentan baja autocorrelación, validando un buen ajuste del modelo.
Las pruebas de Ljung-Box y ARCH LM confirman la ausencia de correlación serial y heterocedasticidad remanente en los residuos.
ug_forecast1 = ugarchforecast(ugfit1, n.ahead = 30)
ug_forecast1
##
## *------------------------------------*
## * GARCH Model Forecast *
## *------------------------------------*
## Model: sGARCH
## Horizon: 30
## Roll Steps: 0
## Out of Sample: 0
##
## 0-roll forecast [T0=2024-12-30]:
## Series Sigma
## T+1 -0.0002958 0.01284
## T+2 -0.0002576 0.01326
## T+3 -0.0002423 0.01365
## T+4 -0.0002362 0.01402
## T+5 -0.0002338 0.01437
## T+6 -0.0002328 0.01469
## T+7 -0.0002324 0.01500
## T+8 -0.0002323 0.01529
## T+9 -0.0002322 0.01557
## T+10 -0.0002322 0.01583
## T+11 -0.0002322 0.01608
## T+12 -0.0002322 0.01631
## T+13 -0.0002322 0.01654
## T+14 -0.0002322 0.01675
## T+15 -0.0002322 0.01695
## T+16 -0.0002322 0.01715
## T+17 -0.0002322 0.01733
## T+18 -0.0002322 0.01751
## T+19 -0.0002322 0.01768
## T+20 -0.0002322 0.01784
## T+21 -0.0002322 0.01799
## T+22 -0.0002322 0.01814
## T+23 -0.0002322 0.01828
## T+24 -0.0002322 0.01841
## T+25 -0.0002322 0.01854
## T+26 -0.0002322 0.01867
## T+27 -0.0002322 0.01878
## T+28 -0.0002322 0.01890
## T+29 -0.0002322 0.01901
## T+30 -0.0002322 0.01911
P_t <- etb$Último[nrow(etb)]
# Forecast de rendimientos reales extraídos del output
R_forecasts <- c(
-0.0002958, -0.0002576, -0.0002423, -0.0002362, -0.0002338, -0.0002328,
-0.0002324, -0.0002323, -0.0002322, -0.0002322, -0.0002322, -0.0002322,
-0.0002322, -0.0002322, -0.0002322, -0.0002322, -0.0002322, -0.0002322,
-0.0002322, -0.0002322, -0.0002322, -0.0002322, -0.0002322, -0.0002322,
-0.0002322, -0.0002322, -0.0002322, -0.0002322, -0.0002322, -0.0002322
)
# Precios pronosticados
# Último precio observado
P_t <- etb$Último[nrow(etb)]
# Cálculo de precios pronosticados
P_t1 <- P_t * (1 + R_forecasts[1])^0
P_t2 <- P_t1 * (1 + R_forecasts[2])^1
P_t3 <- P_t2 * (1 + R_forecasts[3])^2
P_t4 <- P_t3 * (1 + R_forecasts[4])^3
P_t5 <- P_t4 * (1 + R_forecasts[5])^4
P_t6 <- P_t5 * (1 + R_forecasts[6])^5
P_t7 <- P_t6 * (1 + R_forecasts[7])^6
P_t8 <- P_t7 * (1 + R_forecasts[8])^7
P_t9 <- P_t8 * (1 + R_forecasts[9])^8
P_t10 <- P_t9 * (1 + R_forecasts[10])^9
P_t11 <- P_t10 * (1 + R_forecasts[11])^10
P_t12 <- P_t11 * (1 + R_forecasts[12])^11
P_t13 <- P_t12 * (1 + R_forecasts[13])^12
P_t14 <- P_t13 * (1 + R_forecasts[14])^13
P_t15 <- P_t14 * (1 + R_forecasts[15])^14
P_t16 <- P_t15 * (1 + R_forecasts[16])^15
P_t17 <- P_t16 * (1 + R_forecasts[17])^16
P_t18 <- P_t17 * (1 + R_forecasts[18])^17
P_t19 <- P_t18 * (1 + R_forecasts[19])^18
P_t20 <- P_t19 * (1 + R_forecasts[20])^19
P_t21 <- P_t20 * (1 + R_forecasts[21])^20
P_t22 <- P_t21 * (1 + R_forecasts[22])^21
P_t23 <- P_t22 * (1 + R_forecasts[23])^22
P_t24 <- P_t23 * (1 + R_forecasts[24])^23
P_t25 <- P_t24 * (1 + R_forecasts[25])^24
P_t26 <- P_t25 * (1 + R_forecasts[26])^25
P_t27 <- P_t26 * (1 + R_forecasts[27])^26
P_t28 <- P_t27 * (1 + R_forecasts[28])^27
P_t29 <- P_t28 * (1 + R_forecasts[29])^28
P_t30 <- P_t29 * (1 + R_forecasts[30])^29
P_t1
## [1] 507
P_t2
## [1] 506.8694
P_t3
## [1] 506.6238
P_t4
## [1] 506.2649
P_t5
## [1] 505.7916
P_t6
## [1] 505.2031
P_t7
## [1] 504.4991
P_t8
## [1] 503.6793
P_t9
## [1] 502.7444
P_t10
## [1] 501.6948
P_t11
## [1] 500.531
P_t12
## [1] 499.2541
P_t13
## [1] 497.8647
P_t14
## [1] 496.364
P_t15
## [1] 494.7528
P_t16
## [1] 493.0324
P_t17
## [1] 491.2039
P_t18
## [1] 489.2685
P_t19
## [1] 487.2276
P_t20
## [1] 485.0825
P_t21
## [1] 482.8347
P_t22
## [1] 480.4858
P_t23
## [1] 478.0373
P_t24
## [1] 475.4908
P_t25
## [1] 472.848
P_t26
## [1] 470.1108
P_t27
## [1] 467.2808
P_t28
## [1] 464.3601
P_t29
## [1] 461.3504
P_t30
## [1] 458.2539
Comportamiento: Los rendimientos diarios muestran una media cercana a cero (-0.000232) con volatilidad variable a lo largo del tiempo.
Estacionariedad: Confirmada por la prueba ADF (p-value < 0.05), indicando que los rendimientos son estacionarios.
Autocorrelación: El modelo ARFIMA(1,0,1) ajustado sugiere la existencia de una débil estructura temporal en los rendimientos.
El modelo GARCH(1,1) estimado mostró alta persistencia en la volatilidad (β₁ ≈ 0.877) y un impacto moderado de los shocks recientes (α₁ ≈ 0.087).
Presencia de heterocedasticidad:
La prueba ARCH detectó heterocedasticidad (p-value < 0.05).
La autocorrelación de los errores al cuadrado fue significativa, confirmando variabilidad en la volatilidad.
La regresión de errores cuadrados mostró dependencia significativa, indicando efectos ARCH en la serie.
\[ \sigma^2_t = 1.68 \times 10^{-5} + 0.087 \epsilon^2_{t-1} + 0.877 \sigma^2_{t-1} \]
Alta persistencia en la volatilidad (β₁ = 0.877).
Impacto moderado de shocks recientes (α₁ = 0.087).
La suma α₁ + β₁ ≈ 0.964 (menor a 1), indicando un proceso estacionario pero con larga memoria en la volatilidad.
Rendimientos esperados: Constantes alrededor de -0.000232 (-0.0232% diario).
Precios proyectados:
| Horizonte | Precio Proyectado (COP) | Incremento (%) |
|---|---|---|
| T+1 | 507.00 | 0.00% |
| T+5 | 505.79 | -0.24% |
| T+10 | 501.69 | -1.05% |
| T+20 | 485.08 | -4.33% |
| T+30 | 458.25 | -9.61% |
Clustering de Volatilidad: Los períodos de alta volatilidad tienden a agruparse.
Persistencia: La volatilidad muestra memoria de largo plazo debido al alto valor de β₁.