# UNIVERSIDAD NACIONAL DEL ALTIPLANO
# INGENIERIA ESTADISTICA E INFORMATICA
# CURSO: SERIES DE TIEMPO

library(readxl)
## Warning: package 'readxl' was built under R version 4.0.2
library(lubridate)
## Warning: package 'lubridate' was built under R version 4.0.5
## 
## Attaching package: 'lubridate'
## The following objects are masked from 'package:base':
## 
##     date, intersect, setdiff, union
library(tidyverse)
## Warning: package 'tidyverse' was built under R version 4.0.5
## -- Attaching packages --------------------------------------- tidyverse 1.3.1 --
## v ggplot2 3.3.3     v purrr   0.3.4
## v tibble  3.1.5     v dplyr   1.0.7
## v tidyr   1.1.4     v stringr 1.4.0
## v readr   2.0.2     v forcats 0.5.1
## Warning: package 'ggplot2' was built under R version 4.0.3
## Warning: package 'tibble' was built under R version 4.0.5
## Warning: package 'tidyr' was built under R version 4.0.5
## Warning: package 'readr' was built under R version 4.0.5
## Warning: package 'dplyr' was built under R version 4.0.5
## Warning: package 'forcats' was built under R version 4.0.5
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x lubridate::as.difftime() masks base::as.difftime()
## x lubridate::date()        masks base::date()
## x dplyr::filter()          masks stats::filter()
## x lubridate::intersect()   masks base::intersect()
## x dplyr::lag()             masks stats::lag()
## x lubridate::setdiff()     masks base::setdiff()
## x lubridate::union()       masks base::union()
library(car)
## Warning: package 'car' was built under R version 4.0.5
## Loading required package: carData
## 
## Attaching package: 'car'
## The following object is masked from 'package:dplyr':
## 
##     recode
## The following object is masked from 'package:purrr':
## 
##     some
library(tseries)
## Warning: package 'tseries' was built under R version 4.0.5
## Registered S3 method overwritten by 'quantmod':
##   method            from
##   as.zoo.data.frame zoo
library(astsa)
## Warning: package 'astsa' was built under R version 4.0.5
library(foreign)
## Warning: package 'foreign' was built under R version 4.0.3
library(timsac)
## Warning: package 'timsac' was built under R version 4.0.3
library(vars)
## Warning: package 'vars' was built under R version 4.0.5
## Loading required package: MASS
## 
## Attaching package: 'MASS'
## The following object is masked from 'package:dplyr':
## 
##     select
## Loading required package: strucchange
## Warning: package 'strucchange' was built under R version 4.0.5
## Loading required package: zoo
## 
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
## 
##     as.Date, as.Date.numeric
## Loading required package: sandwich
## 
## Attaching package: 'strucchange'
## The following object is masked from 'package:stringr':
## 
##     boundary
## Loading required package: urca
## Warning: package 'urca' was built under R version 4.0.5
## Loading required package: lmtest
## Warning: package 'lmtest' was built under R version 4.0.2
library(lmtest)
library(mFilter)
## Warning: package 'mFilter' was built under R version 4.0.5
library(dynlm)
## Warning: package 'dynlm' was built under R version 4.0.5
library(nlme)
## Warning: package 'nlme' was built under R version 4.0.5
## 
## Attaching package: 'nlme'
## The following object is masked from 'package:dplyr':
## 
##     collapse
library(broom)
## Warning: package 'broom' was built under R version 4.0.5
library(kableExtra)
## Warning: package 'kableExtra' was built under R version 4.0.5
## 
## Attaching package: 'kableExtra'
## The following object is masked from 'package:dplyr':
## 
##     group_rows
library(knitr)
library(MASS)
library(parallel)
library(car)
library(mlogit)
## Warning: package 'mlogit' was built under R version 4.0.5
## Loading required package: dfidx
## Warning: package 'dfidx' was built under R version 4.0.5
## 
## Attaching package: 'dfidx'
## The following object is masked from 'package:MASS':
## 
##     select
## The following object is masked from 'package:stats':
## 
##     filter
library(dplyr)
library(tidyr)
library(forecast)
## Warning: package 'forecast' was built under R version 4.0.5
## 
## Attaching package: 'forecast'
## The following object is masked from 'package:nlme':
## 
##     getResponse
## The following object is masked from 'package:astsa':
## 
##     gas
library(fpp2)
## Warning: package 'fpp2' was built under R version 4.0.5
## -- Attaching packages ---------------------------------------------- fpp2 2.4 --
## v fma       2.4     v expsmooth 2.3
## Warning: package 'fma' was built under R version 4.0.5
## Warning: package 'expsmooth' was built under R version 4.0.5
## -- Conflicts ------------------------------------------------- fpp2_conflicts --
## x forecast::getResponse() masks nlme::getResponse()
## x car::some()             masks purrr::some()
## 
## Attaching package: 'fpp2'
## The following object is masked from 'package:astsa':
## 
##     oil
library(stats)
library(quantmod)
## Warning: package 'quantmod' was built under R version 4.0.5
## Loading required package: xts
## Warning: package 'xts' was built under R version 4.0.5
## 
## Attaching package: 'xts'
## The following objects are masked from 'package:dplyr':
## 
##     first, last
## Loading required package: TTR
library(urca)
library(FinTS)
## Warning: package 'FinTS' was built under R version 4.0.5
## 
## Attaching package: 'FinTS'
## The following object is masked from 'package:forecast':
## 
##     Acf
library(fGarch)
## Warning: package 'fGarch' was built under R version 4.0.5
## Loading required package: timeDate
## Warning: package 'timeDate' was built under R version 4.0.5
## Loading required package: timeSeries
## Warning: package 'timeSeries' was built under R version 4.0.5
## 
## Attaching package: 'timeSeries'
## The following object is masked from 'package:zoo':
## 
##     time<-
## Loading required package: fBasics
## Warning: package 'fBasics' was built under R version 4.0.5
## 
## Attaching package: 'fBasics'
## The following object is masked from 'package:TTR':
## 
##     volatility
## The following object is masked from 'package:mlogit':
## 
##     stdev
## The following object is masked from 'package:astsa':
## 
##     nyse
## The following object is masked from 'package:car':
## 
##     densityPlot
library(parallel)
library(rugarch)
## Warning: package 'rugarch' was built under R version 4.0.5
## 
## Attaching package: 'rugarch'
## The following object is masked from 'package:purrr':
## 
##     reduce
## The following object is masked from 'package:stats':
## 
##     sigma
library(rmgarch)
## Warning: package 'rmgarch' was built under R version 4.0.5
## 
## Attaching package: 'rmgarch'
## The following objects are masked from 'package:xts':
## 
##     first, last
## The following objects are masked from 'package:dplyr':
## 
##     first, last
library(kableExtra)

ipc <- read_excel("E:/SERIES DE TIEMPO/TAREA 08/ipc.xls")
#View(ipc)
attach(ipc)
names(ipc)
## [1] "IPCREND"
# Rentabilidad de tu variable

#Descargar precios de Acciones de Yahoo Finance
startDate <- as.Date("2007-02-03") #Peridodo de tiempo que nosotros estamos interesados
endDate <- as.Date("2021-08-03")

getSymbols("IBM", from = startDate, to = endDate)
## 'getSymbols' currently uses auto.assign=TRUE by default, but will
## use auto.assign=FALSE in 0.5-0. You will still be able to use
## 'loadSymbols' to automatically load data. getOption("getSymbols.env")
## and getOption("getSymbols.auto.assign") will still be checked for
## alternate defaults.
## 
## This message is shown once per session and may be disabled by setting 
## options("getSymbols.warning4.0"=FALSE). See ?getSymbols for details.
## [1] "IBM"
rIBM2 <- dailyReturn(IBM)
head(rIBM2)
##            daily.returns
## 2007-02-05  0.0122013157
## 2007-02-06 -0.0052799241
## 2007-02-07 -0.0031047081
## 2007-02-08  0.0008037303
## 2007-02-09 -0.0107407883
## 2007-02-12  0.0003043961
chartSeries(rIBM2)

# Con lso Datos
IPCREND <- ipc$IPCREND

#Generar Serie de Teimpo de los rendimeintos 
ipcrents <- ts(IPCREND, start = c(2000,02), end = c(2021,12), frequency = 12)
chartSeries(ipcrents)

# 1. Estimar Modelo
arima22 <- arima(ipcrents, order = c(2,0,2))
arima22
## 
## Call:
## arima(x = ipcrents, order = c(2, 0, 2))
## 
## Coefficients:
##           ar1      ar2     ma1     ma2  intercept
##       -0.3691  -0.9408  0.4119  0.8594     1.2715
## s.e.   0.0812   0.0440  0.1205  0.0787     0.3371
## 
## sigma^2 estimated as 30.89:  log likelihood = -824.57,  aic = 1661.15
# 2. Calcular Residuales al 2
rescuad <- resid(arima22)^2
rescuad
##               Jan          Feb          Mar          Apr          May
## 2000              1.035513e+02 6.922266e-03 1.083708e+02 1.264297e+02
## 2001 9.727145e+01 8.244875e+01 1.535968e+00 1.595475e+00 2.178268e+01
## 2002 1.078626e+02 6.509171e+00 3.227793e+01 4.360079e-01 1.750207e+01
## 2003 8.785178e+00 1.171259e+01 4.087135e+00 1.081217e+02 8.779729e-01
## 2004 3.533052e+01 2.373438e+01 1.755241e+01 4.493129e+01 3.781467e-03
## 2005 7.860589e-01 1.982777e+01 7.780724e+01 1.542015e+01 8.094713e+00
## 2006 1.826541e+01 1.242034e+00 5.386227e+00 1.857714e+01 1.158128e+02
## 2007 2.273624e+01 3.177304e+01 3.513057e+01 1.098133e-02 6.364367e+01
## 2008 2.566964e+01 8.273033e-01 4.201191e+01 1.532412e+01 1.965913e+01
## 2009 1.892159e+02 5.381601e+01 5.201190e+01 5.116716e+01 1.751755e+02
## 2010 2.082273e+01 2.803664e+00 3.606709e+00 1.316866e+00 3.498857e+00
## 2011 4.512109e+01 2.065681e+00 5.992118e-01 7.740512e+00 2.415389e+01
## 2012 9.688435e-02 1.197208e+00 9.108061e+00 5.446485e-01 2.567146e+01
## 2013 1.290542e+00 1.735606e+01 2.084332e-02 3.565998e+01 1.452511e+01
## 2014 2.557719e+01 3.868208e+01 5.470365e+00 1.358683e+00 2.051335e+00
## 2015 3.927949e+01 3.692205e+01 8.840998e+00 4.330461e+00 1.522015e+00
## 2016 1.644370e+02 7.565100e+01 2.715697e+01 5.758237e+01 9.010468e+00
## 2017 7.161073e+00 9.817563e-01 5.489639e+01 2.906530e+02 2.745064e+01
## 2018 8.605062e+01 1.187803e+02 6.820896e+00 5.924814e+01 5.330519e+00
## 2019 1.256998e+01 1.369390e+01 5.161773e+00 1.388325e+00 3.496195e+00
## 2020 2.440475e-01 9.247628e+00 1.125885e+00 2.517501e+01 1.219149e+01
## 2021 6.674113e+00 4.587882e+01 7.777152e+00 1.341933e+02 1.421673e+01
##               Jun          Jul          Aug          Sep          Oct
## 2000 1.531378e+02 6.873317e+01 3.070940e+01 6.582846e+01 8.767593e+00
## 2001 9.809887e+00 1.308236e+00 5.948420e+01 2.808676e+02 2.863400e+01
## 2002 8.938570e+01 1.184765e+02 7.585237e+00 6.036962e+01 4.911458e+00
## 2003 1.299381e+01 1.385550e+01 4.893561e+00 1.402751e+00 3.681527e+00
## 2004 2.291674e-01 9.359321e+00 1.170217e+00 2.524673e+01 1.204708e+01
## 2005 6.681195e+00 4.601369e+01 7.806550e+00 1.340454e+02 1.416283e+01
## 2006 1.218280e+01 3.194945e+00 5.124632e+00 2.729820e+01 1.636042e+01
## 2007 1.043255e+01 6.438904e+00 2.125456e+00 4.775894e+00 4.135123e+00
## 2008 8.695524e+01 4.993008e+01 4.073014e+01 5.264552e+01 3.394817e+02
## 2009 3.676393e-01 4.794002e+01 3.613112e+00 3.671062e+01 1.478884e+01
## 2010 3.971802e+01 4.326904e+00 2.397306e+00 1.507333e+01 1.296222e+01
## 2011 1.376958e+00 8.143019e+00 4.852422e+00 5.638620e+01 4.844353e+01
## 2012 1.847846e+01 3.800027e-01 1.079508e+01 6.920367e+00 9.326226e-01
## 2013 9.097379e+00 6.267617e-02 3.052091e+01 3.469359e-01 1.537199e+00
## 2014 3.879498e+00 7.839436e-02 1.187793e+01 4.416654e+00 2.473695e+00
## 2015 2.215764e+00 1.921952e+00 1.492484e+01 9.800020e+01 9.208689e-01
## 2016 1.230195e+02 6.549646e-01 1.059263e+02 9.058204e+01 2.206748e+00
## 2017 5.228746e+00 2.665593e+01 1.026031e+02 5.852820e+00 3.414063e+01
## 2018 2.750620e-03 1.067677e-01 8.201558e+00 1.176414e+01 4.428761e+00
## 2019 2.871497e+01 1.486808e+00 3.491637e+01 2.361197e+01 1.784827e+01
## 2020 1.904037e+01 3.517736e+01 7.702229e-01 1.992364e+01 7.802203e+01
## 2021 4.942161e+01 1.286711e+01 1.825873e+01 1.255162e+00 5.400576e+00
##               Nov          Dec
## 2000 1.133564e+02 3.157459e-01
## 2001 3.839706e+00 2.707132e+01
## 2002 2.265344e-02 8.234690e-02
## 2003 2.844168e+01 1.411071e+00
## 2004 1.906146e+01 3.537718e+01
## 2005 4.945744e+01 1.281547e+01
## 2006 2.551436e+01 2.795308e+01
## 2007 3.608009e+01 1.866248e+00
## 2008 7.927146e-02 2.879428e+01
## 2009 1.983772e+01 1.144039e+01
## 2010 9.827160e+00 2.498924e+01
## 2011 1.716799e-01 4.854706e-03
## 2012 2.485440e-02 1.897861e+01
## 2013 4.158737e+00 9.893299e-01
## 2014 1.319364e+01 9.315179e+00
## 2015 1.098690e+02 1.167004e+02
## 2016 3.206232e+00 2.195685e+01
## 2017 7.022816e-01 1.811095e+01
## 2018 1.090023e+02 9.819373e-01
## 2019 4.498381e+01 1.076923e-03
## 2020 1.545357e+01 8.164506e+00
## 2021 1.860972e+01 1.159035e+02
chartSeries(rescuad)

# 3. Hacer una Regresion con los Residuales al cuadrado rezagados
ipc.arch <- dynlm(rescuad ~ L(rescuad), data = ipc)
summary(ipc.arch)
## 
## Time series regression with "ts" data:
## Start = 2000(3), End = 2021(12)
## 
## Call:
## dynlm(formula = rescuad ~ L(rescuad), data = ipc)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -66.106 -26.288 -17.217   7.333 306.326 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 27.09298    3.44691   7.860 1.02e-13 ***
## L(rescuad)   0.11515    0.06171   1.866   0.0632 .  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 46.7 on 260 degrees of freedom
## Multiple R-squared:  0.01322,    Adjusted R-squared:  0.00942 
## F-statistic: 3.482 on 1 and 260 DF,  p-value: 0.06317
#Funcion de Autocorrelacion parcial y Autocorrelacion
acf.res2 <- acf(rescuad, main = 'ACF Residuales al Cuadrado', lag.max = 100, ylim = c(-0.5,1))

acf.res2 <- pacf(rescuad, main = 'PACF Residuales al Cuadrado', lag.max = 100, ylim = c(-0.5,1))

# Observamos las graficas y no es un ruido blanco

#Probamos con archtest
ipcarchtest <- ArchTest(ipcrents, lags = 1, demean = T)
ipcarchtest
## 
##  ARCH LM-test; Null hypothesis: no ARCH effects
## 
## data:  ipcrents
## Chi-squared = 3.0036, df = 1, p-value = 0.08308
#Probamos con archtest con 2 rezagos
ipcarchtest1 <- ArchTest(ipcrents, lags = 2, demean = T)
ipcarchtest1
## 
##  ARCH LM-test; Null hypothesis: no ARCH effects
## 
## data:  ipcrents
## Chi-squared = 15.488, df = 2, p-value = 0.0004333
#Estimar el Modelo GARCH con default
ug_spec <- ugarchspec()
ug_spec
## 
## *---------------------------------*
## *       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
#Estimar otro modelo con ARMA
ug_spec1 <- ugarchspec(mean.model = list(armaOrder = c(1,0)))
ug_spec1
## 
## *---------------------------------*
## *       GARCH Model Spec          *
## *---------------------------------*
## 
## Conditional Variance Dynamics    
## ------------------------------------
## GARCH Model      : sGARCH(1,1)
## Variance Targeting   : FALSE 
## 
## Conditional Mean Dynamics
## ------------------------------------
## Mean Model       : ARFIMA(1,0,0)
## Include Mean     : TRUE 
## GARCH-in-Mean        : FALSE 
## 
## Conditional Distribution
## ------------------------------------
## Distribution :  norm 
## Includes Skew    :  FALSE 
## Includes Shape   :  FALSE 
## Includes Lambda  :  FALSE
#Estimar otro modelo con ARMA 2
ug_spec2 <- ugarchspec(mean.model = list(armaOrder = c(2,2)))
ug_spec2
## 
## *---------------------------------*
## *       GARCH Model Spec          *
## *---------------------------------*
## 
## Conditional Variance Dynamics    
## ------------------------------------
## GARCH Model      : sGARCH(1,1)
## Variance Targeting   : FALSE 
## 
## Conditional Mean Dynamics
## ------------------------------------
## Mean Model       : ARFIMA(2,0,2)
## Include Mean     : TRUE 
## GARCH-in-Mean        : FALSE 
## 
## Conditional Distribution
## ------------------------------------
## Distribution :  norm 
## Includes Skew    :  FALSE 
## Includes Shape   :  FALSE 
## Includes Lambda  :  FALSE
#Estimar Modelo
ugfit <- ugarchfit(spec = ug_spec, data = ipcrents)
ugfit
## 
## *---------------------------------*
## *          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       1.42777    0.332887   4.2891 0.000018
## ar1      0.54586    0.455801   1.1976 0.231079
## ma1     -0.49892    0.472866  -1.0551 0.291385
## omega    1.84995    0.984054   1.8799 0.060118
## alpha1   0.14543    0.046777   3.1089 0.001878
## beta1    0.79846    0.051867  15.3942 0.000000
## 
## Robust Standard Errors:
##         Estimate  Std. Error  t value Pr(>|t|)
## mu       1.42777    0.350022   4.0791 0.000045
## ar1      0.54586    0.222217   2.4564 0.014033
## ma1     -0.49892    0.227403  -2.1940 0.028238
## omega    1.84995    0.742707   2.4908 0.012745
## alpha1   0.14543    0.040335   3.6055 0.000312
## beta1    0.79846    0.040320  19.8028 0.000000
## 
## LogLikelihood : -817.7611 
## 
## Information Criteria
## ------------------------------------
##                    
## Akaike       6.2643
## Bayes        6.3458
## Shibata      6.2633
## Hannan-Quinn 6.2971
## 
## Weighted Ljung-Box Test on Standardized Residuals
## ------------------------------------
##                         statistic p-value
## Lag[1]                    0.04609 0.83001
## Lag[2*(p+q)+(p+q)-1][5]   1.57244 0.99646
## Lag[4*(p+q)+(p+q)-1][9]   8.65877 0.03254
## d.o.f=2
## H0 : No serial correlation
## 
## Weighted Ljung-Box Test on Standardized Squared Residuals
## ------------------------------------
##                         statistic p-value
## Lag[1]                      1.026  0.3112
## Lag[2*(p+q)+(p+q)-1][5]     2.712  0.4622
## Lag[4*(p+q)+(p+q)-1][9]     5.212  0.3990
## d.o.f=2
## 
## Weighted ARCH LM Tests
## ------------------------------------
##             Statistic Shape Scale P-Value
## ARCH Lag[3]  0.001655 0.500 2.000  0.9676
## ARCH Lag[5]  2.267553 1.440 1.667  0.4151
## ARCH Lag[7]  3.400527 2.315 1.543  0.4413
## 
## Nyblom stability test
## ------------------------------------
## Joint Statistic:  0.5122
## Individual Statistics:              
## mu     0.13816
## ar1    0.03553
## ma1    0.03511
## omega  0.08013
## alpha1 0.04858
## beta1  0.07678
## 
## 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           2.0274 0.04365  **
## Negative Sign Bias  1.1937 0.23369    
## Positive Sign Bias  0.3245 0.74581    
## Joint Effect        8.0244 0.04551  **
## 
## 
## Adjusted Pearson Goodness-of-Fit Test:
## ------------------------------------
##   group statistic p-value(g-1)
## 1    20     22.55    0.2576821
## 2    30     38.03    0.1217455
## 3    40     60.50    0.0152213
## 4    50     89.28    0.0003861
## 
## 
## Elapsed time : 1.506551
ugfit1 <- ugarchfit(spec = ug_spec1, data = ipcrents)
ugfit1
## 
## *---------------------------------*
## *          GARCH Model Fit        *
## *---------------------------------*
## 
## Conditional Variance Dynamics    
## -----------------------------------
## GARCH Model  : sGARCH(1,1)
## Mean Model   : ARFIMA(1,0,0)
## Distribution : norm 
## 
## Optimal Parameters
## ------------------------------------
##         Estimate  Std. Error  t value Pr(>|t|)
## mu      1.430307    0.317965  4.49832 0.000007
## ar1     0.041174    0.065039  0.63307 0.526690
## omega   1.818985    0.982407  1.85156 0.064089
## alpha1  0.145484    0.047037  3.09294 0.001982
## beta1   0.799692    0.051654 15.48166 0.000000
## 
## Robust Standard Errors:
##         Estimate  Std. Error  t value Pr(>|t|)
## mu      1.430307    0.347244  4.11902 0.000038
## ar1     0.041174    0.052107  0.79019 0.429420
## omega   1.818985    0.745100  2.44126 0.014636
## alpha1  0.145484    0.041278  3.52449 0.000424
## beta1   0.799692    0.041245 19.38890 0.000000
## 
## LogLikelihood : -817.9684 
## 
## Information Criteria
## ------------------------------------
##                    
## Akaike       6.2583
## Bayes        6.3262
## Shibata      6.2576
## Hannan-Quinn 6.2856
## 
## Weighted Ljung-Box Test on Standardized Residuals
## ------------------------------------
##                         statistic p-value
## Lag[1]                     0.1128  0.7369
## Lag[2*(p+q)+(p+q)-1][2]    0.1196  0.9999
## Lag[4*(p+q)+(p+q)-1][5]    1.6901  0.7979
## d.o.f=1
## H0 : No serial correlation
## 
## Weighted Ljung-Box Test on Standardized Squared Residuals
## ------------------------------------
##                         statistic p-value
## Lag[1]                      1.048  0.3059
## Lag[2*(p+q)+(p+q)-1][5]     2.697  0.4653
## Lag[4*(p+q)+(p+q)-1][9]     5.311  0.3852
## d.o.f=2
## 
## Weighted ARCH LM Tests
## ------------------------------------
##             Statistic Shape Scale P-Value
## ARCH Lag[3] 2.564e-05 0.500 2.000  0.9960
## ARCH Lag[5] 2.482e+00 1.440 1.667  0.3742
## ARCH Lag[7] 3.689e+00 2.315 1.543  0.3936
## 
## Nyblom stability test
## ------------------------------------
## Joint Statistic:  0.4741
## Individual Statistics:              
## mu     0.15921
## ar1    0.03259
## omega  0.08128
## alpha1 0.04769
## beta1  0.07729
## 
## Asymptotic Critical Values (10% 5% 1%)
## Joint Statistic:          1.28 1.47 1.88
## Individual Statistic:     0.35 0.47 0.75
## 
## Sign Bias Test
## ------------------------------------
##                    t-value    prob sig
## Sign Bias           2.0275 0.04364  **
## Negative Sign Bias  1.1688 0.24358    
## Positive Sign Bias  0.2863 0.77489    
## Joint Effect        8.0417 0.04516  **
## 
## 
## Adjusted Pearson Goodness-of-Fit Test:
## ------------------------------------
##   group statistic p-value(g-1)
## 1    20     23.92      0.19923
## 2    30     28.22      0.50635
## 3    40     58.67      0.02232
## 4    50     68.37      0.03507
## 
## 
## Elapsed time : 0.7869971
ugfit2 <- ugarchfit(spec = ug_spec2, data = ipcrents)
ugfit2
## 
## *---------------------------------*
## *          GARCH Model Fit        *
## *---------------------------------*
## 
## Conditional Variance Dynamics    
## -----------------------------------
## GARCH Model  : sGARCH(1,1)
## Mean Model   : ARFIMA(2,0,2)
## Distribution : norm 
## 
## Optimal Parameters
## ------------------------------------
##         Estimate  Std. Error   t value Pr(>|t|)
## mu       1.45611    0.308282    4.7233 0.000002
## ar1     -0.28095    0.005462  -51.4353 0.000000
## ar2     -1.01291    0.001806 -560.9958 0.000000
## ma1      0.28061    0.008486   33.0683 0.000000
## ma2      1.00788    0.001637  615.7106 0.000000
## omega    1.81023    0.977792    1.8513 0.064120
## alpha1   0.13522    0.043732    3.0921 0.001988
## beta1    0.80429    0.052725   15.2544 0.000000
## 
## Robust Standard Errors:
##         Estimate  Std. Error   t value Pr(>|t|)
## mu       1.45611    0.359660    4.0486 0.000052
## ar1     -0.28095    0.002559 -109.8026 0.000000
## ar2     -1.01291    0.001333 -759.8792 0.000000
## ma1      0.28061    0.004403   63.7260 0.000000
## ma2      1.00788    0.000447 2254.4072 0.000000
## omega    1.81023    0.834521    2.1692 0.030069
## alpha1   0.13522    0.039425    3.4299 0.000604
## beta1    0.80429    0.048912   16.4436 0.000000
## 
## LogLikelihood : -812.0082 
## 
## Information Criteria
## ------------------------------------
##                    
## Akaike       6.2358
## Bayes        6.3445
## Shibata      6.2340
## Hannan-Quinn 6.2795
## 
## Weighted Ljung-Box Test on Standardized Residuals
## ------------------------------------
##                          statistic   p-value
## Lag[1]                       1.476 2.244e-01
## Lag[2*(p+q)+(p+q)-1][11]     8.868 1.394e-05
## Lag[4*(p+q)+(p+q)-1][19]    16.400 9.714e-03
## d.o.f=4
## H0 : No serial correlation
## 
## Weighted Ljung-Box Test on Standardized Squared Residuals
## ------------------------------------
##                         statistic p-value
## Lag[1]                     0.3337  0.5635
## Lag[2*(p+q)+(p+q)-1][5]    2.5705  0.4911
## Lag[4*(p+q)+(p+q)-1][9]    5.5903  0.3481
## d.o.f=2
## 
## Weighted ARCH LM Tests
## ------------------------------------
##             Statistic Shape Scale P-Value
## ARCH Lag[3]  0.000354 0.500 2.000  0.9850
## ARCH Lag[5]  3.946008 1.440 1.667  0.1789
## ARCH Lag[7]  4.873507 2.315 1.543  0.2376
## 
## Nyblom stability test
## ------------------------------------
## Joint Statistic:  1.0547
## Individual Statistics:              
## mu     0.23219
## ar1    0.04018
## ar2    0.05339
## ma1    0.04614
## ma2    0.07996
## omega  0.05516
## alpha1 0.04639
## beta1  0.06071
## 
## Asymptotic Critical Values (10% 5% 1%)
## Joint Statistic:          1.89 2.11 2.59
## Individual Statistic:     0.35 0.47 0.75
## 
## Sign Bias Test
## ------------------------------------
##                    t-value    prob sig
## Sign Bias           1.8611 0.06386   *
## Negative Sign Bias  0.5204 0.60325    
## Positive Sign Bias  0.2486 0.80387    
## Joint Effect        8.7034 0.03351  **
## 
## 
## Adjusted Pearson Goodness-of-Fit Test:
## ------------------------------------
##   group statistic p-value(g-1)
## 1    20     33.96     0.018587
## 2    30     50.57     0.007827
## 3    40     57.46     0.028587
## 4    50     71.03     0.021480
## 
## 
## Elapsed time : 2.008999
#Imprimir coeficientes de tu modelo ARMA(2,2)+GARCH(1,1)
ugfit2@fit$coef
##         mu        ar1        ar2        ma1        ma2      omega     alpha1 
##  1.4561066 -0.2809535 -1.0129144  0.2806130  1.0078815  1.8102265  0.1352214 
##      beta1 
##  0.8042917
#Pronostico
ugfore <- ugarchforecast(ugfit2, n, ahead =10)
ugfore
## 
## *------------------------------------*
## *       GARCH Model Forecast         *
## *------------------------------------*
## Model: sGARCH
## Horizon: 10
## Roll Steps: 0
## Out of Sample: 0
## 
## 0-roll forecast [T0=Dic. 2021]:
##       Series Sigma
## T+1  -0.9021 5.494
## T+2   3.6595 5.492
## T+3   3.2257 5.491
## T+4  -1.2730 5.490
## T+5   0.4304 5.489
## T+6   4.5086 5.488
## T+7   1.6375 5.487
## T+8  -1.6867 5.486
## T+9   2.1554 5.485
## T+10  4.4431 5.484