Utilizar la serie asignada y calcule:
library(readxl)
aval <- read_excel("Aval.xlsx")
aval_xts <- xts(aval$Price, order.by = aval$Fecha)
class(aval_xts)
## [1] "xts" "zoo"
summary(aval_xts)
## Index aval_xts
## Min. :2015-01-02 00:00:00.00 Min. : 408.0
## 1st Qu.:2017-06-24 00:00:00.00 1st Qu.: 773.0
## Median :2019-12-17 12:00:00.00 Median :1140.0
## Mean :2019-12-24 09:48:58.96 Mean : 996.1
## 3rd Qu.:2022-06-22 18:00:00.00 3rd Qu.:1220.0
## Max. :2024-12-30 00:00:00.00 Max. :1505.0
plot(aval_xts, main = "Precio último")
rendimiento1 <- dailyReturn(aval_xts)
plot(rendimiento1, main = "Rendimiento del Precio Último")
modelo1 <- auto.arima(rendimiento1)
summary(modelo1)
## Series: rendimiento1
## ARIMA(0,0,0) with zero mean
##
## sigma^2 = 0.000296: log likelihood = 6392.14
## AIC=-12782.29 AICc=-12782.28 BIC=-12776.49
##
## Training set error measures:
## ME RMSE MAE MPE MAPE MASE ACF1
## Training set -0.0002833859 0.01720587 0.01098029 100 100 1 -0.03052614
autoplot(modelo1)
checkresiduals(modelo1)
##
## Ljung-Box test
##
## data: Residuals from ARIMA(0,0,0) with zero mean
## Q* = 29.796, df = 10, p-value = 0.000925
##
## Model df: 0. Total lags used: 10
ndiffs(rendimiento1)
## [1] 0
adf.test(rendimiento1)
## Warning in adf.test(rendimiento1): p-value smaller than printed p-value
##
## Augmented Dickey-Fuller Test
##
## data: rendimiento1
## Dickey-Fuller = -13.669, Lag order = 13, p-value = 0.01
## alternative hypothesis: stationary
skewness(modelo1$residuals)
## [1] 0.5227815
kurtosis(modelo1$residuals)
## [1] 26.33454
modeloarch1 <- ArchTest(rendimiento1, lags = 1, demean = T)
modeloarch1
##
## ARCH LM-test; Null hypothesis: no ARCH effects
##
## data: rendimiento1
## Chi-squared = 339.91, df = 1, p-value < 2.2e-16
errores_cuadrados1 <- resid(modelo1)^2
plot(errores_cuadrados1, main = "Errores cuadrados")
autoplot(acf(errores_cuadrados1, lag.max = 2418, ylim = c(-0.5, 1))) +
labs(title = "Autocorrelacion de los errores al cuadrado") +
xlab("Rezagos") +
ylab("Autocorrelacion")
autoplot(pacf(errores_cuadrados1, lag.max = 2418, ylim = c(-0.5, 1))) +
labs(title = "Autocorrelacion parcial de los errores al cuadrado") +
xlab("Rezagos") +
ylab("Autocorrelacion parcial")
Los errores cuadrados están autocorrelacionados, violando supuesto de homocedasticidad.
La estructura de la autocorrelación y la autocorrelación parcial sugiere dependencia en volatilidad a lo largo del tiempo.
El patrón es consistente con periodos de alta y baja variabilidad o volatilidad.
ugarch1 <- ugarchspec(mean.model = list(armaOrder = c(0,0)))
ugarch1
##
## *---------------------------------*
## * GARCH Model Spec *
## *---------------------------------*
##
## Conditional Variance Dynamics
## ------------------------------------
## GARCH Model : sGARCH(1,1)
## Variance Targeting : FALSE
##
## Conditional Mean Dynamics
## ------------------------------------
## Mean Model : ARFIMA(0,0,0)
## Include Mean : TRUE
## GARCH-in-Mean : FALSE
##
## Conditional Distribution
## ------------------------------------
## Distribution : norm
## Includes Skew : FALSE
## Includes Shape : FALSE
## Includes Lambda : FALSE
ugfit1 <- ugarchfit(spec = ugarch1, data = rendimiento1)
ugfit1
##
## *---------------------------------*
## * GARCH Model Fit *
## *---------------------------------*
##
## Conditional Variance Dynamics
## -----------------------------------
## GARCH Model : sGARCH(1,1)
## Mean Model : ARFIMA(0,0,0)
## Distribution : norm
##
## Optimal Parameters
## ------------------------------------
## Estimate Std. Error t value Pr(>|t|)
## mu 0.000492 0.000235 2.0884 0.036761
## omega 0.000015 0.000004 4.1986 0.000027
## alpha1 0.166359 0.010675 15.5840 0.000000
## beta1 0.786782 0.010936 71.9459 0.000000
##
## Robust Standard Errors:
## Estimate Std. Error t value Pr(>|t|)
## mu 0.000492 0.000464 1.05922 0.289498
## omega 0.000015 0.000016 0.96266 0.335720
## alpha1 0.166359 0.051743 3.21511 0.001304
## beta1 0.786782 0.085158 9.23912 0.000000
##
## LogLikelihood : 6801.845
##
## Information Criteria
## ------------------------------------
##
## Akaike -5.6227
## Bayes -5.6131
## Shibata -5.6227
## Hannan-Quinn -5.6192
##
## Weighted Ljung-Box Test on Standardized Residuals
## ------------------------------------
## statistic p-value
## Lag[1] 8.638 0.003292
## Lag[2*(p+q)+(p+q)-1][2] 8.879 0.003783
## Lag[4*(p+q)+(p+q)-1][5] 9.373 0.013316
## d.o.f=0
## H0 : No serial correlation
##
## Weighted Ljung-Box Test on Standardized Squared Residuals
## ------------------------------------
## statistic p-value
## Lag[1] 0.009188 0.9236
## Lag[2*(p+q)+(p+q)-1][5] 0.540776 0.9512
## Lag[4*(p+q)+(p+q)-1][9] 0.805970 0.9929
## d.o.f=2
##
## Weighted ARCH LM Tests
## ------------------------------------
## Statistic Shape Scale P-Value
## ARCH Lag[3] 0.005095 0.500 2.000 0.9431
## ARCH Lag[5] 0.241737 1.440 1.667 0.9553
## ARCH Lag[7] 0.367224 2.315 1.543 0.9888
##
## Nyblom stability test
## ------------------------------------
## Joint Statistic: 13.848
## Individual Statistics:
## mu 0.07484
## omega 0.38272
## alpha1 0.53565
## beta1 0.50191
##
## Asymptotic Critical Values (10% 5% 1%)
## Joint Statistic: 1.07 1.24 1.6
## Individual Statistic: 0.35 0.47 0.75
##
## Sign Bias Test
## ------------------------------------
## t-value prob sig
## Sign Bias 0.18341 0.8545
## Negative Sign Bias 0.87702 0.3806
## Positive Sign Bias 0.05605 0.9553
## Joint Effect 1.21171 0.7502
##
##
## Adjusted Pearson Goodness-of-Fit Test:
## ------------------------------------
## group statistic p-value(g-1)
## 1 20 645.1 1.506e-124
## 2 30 1147.0 6.634e-223
## 3 40 1541.9 1.439e-298
## 4 50 1858.1 0.000e+00
##
##
## Elapsed time : 0.1503942
ugfit1@fit$coef
## mu omega alpha1 beta1
## 4.915433e-04 1.543653e-05 1.663594e-01 7.867817e-01
ug_var <- ugfit1@fit$var
autoplot(ts(ug_var))
ug_resid1 <- (ugfit1@fit$residuals)^2
autoplot(ts(ug_resid1))
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.0004915 0.02209
## T+2 0.0004915 0.02193
## T+3 0.0004915 0.02176
## T+4 0.0004915 0.02161
## T+5 0.0004915 0.02146
## T+6 0.0004915 0.02131
## T+7 0.0004915 0.02118
## T+8 0.0004915 0.02104
## T+9 0.0004915 0.02092
## T+10 0.0004915 0.02080
## T+11 0.0004915 0.02068
## T+12 0.0004915 0.02057
## T+13 0.0004915 0.02046
## T+14 0.0004915 0.02036
## T+15 0.0004915 0.02026
## T+16 0.0004915 0.02017
## T+17 0.0004915 0.02008
## T+18 0.0004915 0.01999
## T+19 0.0004915 0.01991
## T+20 0.0004915 0.01983
## T+21 0.0004915 0.01975
## T+22 0.0004915 0.01968
## T+23 0.0004915 0.01961
## T+24 0.0004915 0.01955
## T+25 0.0004915 0.01948
## T+26 0.0004915 0.01942
## T+27 0.0004915 0.01937
## T+28 0.0004915 0.01931
## T+29 0.0004915 0.01926
## T+30 0.0004915 0.01921
valor_accion_aval <- aval$Price[1] * cumprod(1 + fitted(ug_forecast1))
valor_accion_aval[c(1, 5, 10, 20, 30)]
## [1] 446.2192 447.0972 448.1971 450.4051 452.6239
pronosticos <- data.frame(
Momentos = c("T+1 (1 día)", "T+5 (5 días)", "T+10 (10 días)", "T+20 (20 días)", "T+30 (30 días)"),
Precio_accion_aval = valor_accion_aval[c(1, 5, 10, 20, 30)]
)
print(pronosticos)
## Momentos Precio_accion_aval
## 1 T+1 (1 día) 446.2192
## 2 T+5 (5 días) 447.0972
## 3 T+10 (10 días) 448.1971
## 4 T+20 (20 días) 450.4051
## 5 T+30 (30 días) 452.6239