# ============================================================
# ANALISIS VOLATILITAS SAHAM HRUM
# Model: ARCH / GARCH
# ============================================================

# 1. BACA DATA
library(readxl)
## Warning: package 'readxl' was built under R version 4.5.3
data <- read_excel("C:/ARW/UAS_ARW/Data_Saham_Soal Nomor 1.xlsx", sheet = "Saham")
head(data)
## # A tibble: 6 × 2
##   Date                Close
##   <dttm>              <dbl>
## 1 2021-01-04 15:00:00   610
## 2 2021-01-05 15:00:00   610
## 3 2021-01-06 15:00:00   592
## 4 2021-01-07 16:00:00   670
## 5 2021-01-08 16:00:00   780
## 6 2021-01-11 15:00:00   826
# 2. BERSIHKAN DATA
# cek tipe data kolom date
str(data$Date)
##  POSIXct[1:1378], format: "2021-01-04 15:00:00" "2021-01-05 15:00:00" "2021-01-06 15:00:00" ...
# Konversi ke numerik lalu ke date
data$Date <- as.numeric(data$Date)
data$Date <- as.Date(data$Date, origin = "1899-12-30")

# cek range tanggal
range(data$Date, na.rm = TRUE)
## [1] "4409307-02-17" "4903717-04-13"
# Cek beberapa tangga pertama
head(data$Date, 10)
##  [1] "4409307-02-17" "4409543-09-08" "4409780-03-28" "4410026-08-26"
##  [5] "4410263-03-17" "4410963-01-06" "4411199-07-28" "4411436-02-16"
##  [9] "4411672-09-05" "4411909-03-28"
# Bersihkan kolom close
data$Close <- as.numeric(gsub("COMPUTED_VALUE", NA, data$Close))
data <- na.omit(data)
cat("Jumlah data:", nrow(data), "\n")
## Jumlah data: 1378
# 3. TIME SERIES & RETURN
library(xts)
## Warning: package 'xts' was built under R version 4.5.2
## Loading required package: zoo
## Warning: package 'zoo' was built under R version 4.5.2
## 
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
## 
##     as.Date, as.Date.numeric
harga <- xts(data$Close, order.by = data$Date)
plot(harga, main = "Harga Saham HRUM", col = "blue", ylab = "Harga")

return_xts <- diff(log(harga))
return_xts <- na.omit(return_xts)
plot(return_xts, main = "Return Saham HRUM", col = "darkgreen", ylab = "Return")

# Konversi ke vektor numerik
return <- as.numeric(return_xts)

# 4. UJI STASIONER (ADF)
library(urca)
## Warning: package 'urca' was built under R version 4.5.3
adf <- ur.df(return, type = "drift", lags = 2)
summary(adf)
## 
## ############################################### 
## # Augmented Dickey-Fuller Test Unit Root Test # 
## ############################################### 
## 
## Test regression drift 
## 
## 
## Call:
## lm(formula = z.diff ~ z.lag.1 + 1 + z.diff.lag)
## 
## Residuals:
##       Min        1Q    Median        3Q       Max 
## -0.128963 -0.018381 -0.000819  0.016041  0.180869 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  0.0001944  0.0009124   0.213    0.831    
## z.lag.1     -0.9985271  0.0469335 -21.275   <2e-16 ***
## z.diff.lag1  0.0125424  0.0377798   0.332    0.740    
## z.diff.lag2 -0.0348510  0.0268698  -1.297    0.195    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.03382 on 1370 degrees of freedom
## Multiple R-squared:  0.4982, Adjusted R-squared:  0.4971 
## F-statistic: 453.4 on 3 and 1370 DF,  p-value: < 2.2e-16
## 
## 
## Value of test-statistic is: -21.2754 226.3239 
## 
## Critical values for test statistics: 
##       1pct  5pct 10pct
## tau2 -3.43 -2.86 -2.57
## phi1  6.43  4.59  3.78
# 5. MODEL ARIMA (MEAN)
library(forecast)
## Warning: package 'forecast' was built under R version 4.5.3
auto.arima(return, trace = TRUE)
## 
##  Fitting models using approximations to speed things up...
## 
##  ARIMA(2,0,2) with non-zero mean : -5404.354
##  ARIMA(0,0,0) with non-zero mean : -5403.453
##  ARIMA(1,0,0) with non-zero mean : -5400.57
##  ARIMA(0,0,1) with non-zero mean : -5401.584
##  ARIMA(0,0,0) with zero mean     : -5405.377
##  ARIMA(1,0,1) with non-zero mean : -5399.704
## 
##  Now re-fitting the best model(s) without approximations...
## 
##  ARIMA(0,0,0) with zero mean     : -5405.377
## 
##  Best model: ARIMA(0,0,0) with zero mean
## Series: return 
## ARIMA(0,0,0) with zero mean 
## 
## sigma^2 = 0.001154:  log likelihood = 2703.69
## AIC=-5405.38   AICc=-5405.38   BIC=-5400.15
model_arima <- Arima(return_xts, order = c(1,0,0), include.mean = TRUE)
summary(model_arima)
## Series: return_xts 
## ARIMA(1,0,0) with non-zero mean 
## 
## Coefficients:
##          ar1   mean
##       0.0096  3e-04
## s.e.  0.0269  9e-04
## 
## sigma^2 = 0.001155:  log likelihood = 2703.79
## AIC=-5401.59   AICc=-5401.57   BIC=-5385.9
## 
## Training set error measures:
##                         ME       RMSE        MAE MPE MAPE     MASE         ACF1
## Training set -3.741311e-08 0.03396319 0.02432459 NaN  Inf 1.002017 0.0004568386
resid <- residuals(model_arima)

# 6. UJI EFEK ARCH
library(nortsTest)
## Warning: package 'nortsTest' was built under R version 4.5.3
## Registered S3 method overwritten by 'quantmod':
##   method            from
##   as.zoo.data.frame zoo
## Registered S3 methods overwritten by 'nortsTest':
##   method      from    
##   autoplot.ts forecast
##   fortify.ts  forecast
arch.test(resid)
## 
##  Box-Ljung test
## 
## data:  y^2
## X-squared = 52.137, df = 2, p-value = 4.772e-12
## alternative hypothesis: y is heteroscedastic
# 7. ESTIMASI MODEL ARCH/GARCH
library(rugarch)
## Warning: package 'rugarch' was built under R version 4.5.3
## Loading required package: parallel
spec1 <- ugarchspec(
  variance.model = list(model = "sGARCH", garchOrder = c(1,0)),
  mean.model = list(armaOrder = c(1,0), include.mean = TRUE)
)
fit1 <- ugarchfit(spec1, data = return)
fit1
## 
## *---------------------------------*
## *          GARCH Model Fit        *
## *---------------------------------*
## 
## Conditional Variance Dynamics    
## -----------------------------------
## GARCH Model  : sGARCH(1,0)
## Mean Model   : ARFIMA(1,0,0)
## Distribution : norm 
## 
## Optimal Parameters
## ------------------------------------
##         Estimate  Std. Error  t value Pr(>|t|)
## mu      0.000248    0.000859  0.28896 0.772611
## ar1    -0.026799    0.031019 -0.86396 0.387612
## omega   0.000988    0.000046 21.34214 0.000000
## alpha1  0.138411    0.034446  4.01819 0.000059
## 
## Robust Standard Errors:
##         Estimate  Std. Error  t value Pr(>|t|)
## mu      0.000248    0.000839  0.29595  0.76726
## ar1    -0.026799    0.025705 -1.04255  0.29716
## omega   0.000988    0.000087 11.34181  0.00000
## alpha1  0.138411    0.040384  3.42733  0.00061
## 
## LogLikelihood : 2726.633 
## 
## Information Criteria
## ------------------------------------
##                     
## Akaike       -3.9544
## Bayes        -3.9393
## Shibata      -3.9545
## Hannan-Quinn -3.9488
## 
## Weighted Ljung-Box Test on Standardized Residuals
## ------------------------------------
##                         statistic p-value
## Lag[1]                     0.4375  0.5083
## Lag[2*(p+q)+(p+q)-1][2]    2.0156  0.2081
## Lag[4*(p+q)+(p+q)-1][5]    4.4130  0.1670
## d.o.f=1
## H0 : No serial correlation
## 
## Weighted Ljung-Box Test on Standardized Squared Residuals
## ------------------------------------
##                         statistic p-value
## Lag[1]                     0.1100 0.74014
## Lag[2*(p+q)+(p+q)-1][2]    0.7947 0.56990
## Lag[4*(p+q)+(p+q)-1][5]    6.8052 0.05781
## d.o.f=1
## 
## Weighted ARCH LM Tests
## ------------------------------------
##             Statistic Shape Scale  P-Value
## ARCH Lag[2]     1.365 0.500 2.000 0.242605
## ARCH Lag[4]     5.615 1.397 1.611 0.062306
## ARCH Lag[6]    11.820 2.222 1.500 0.004902
## 
## Nyblom stability test
## ------------------------------------
## Joint Statistic:  1.5843
## Individual Statistics:              
## mu     0.23257
## ar1    0.05856
## omega  0.88604
## alpha1 1.19356
## 
## 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.4869 0.6264    
## Negative Sign Bias  0.4839 0.6285    
## Positive Sign Bias  0.1459 0.8840    
## Joint Effect        0.3068 0.9588    
## 
## 
## Adjusted Pearson Goodness-of-Fit Test:
## ------------------------------------
##   group statistic p-value(g-1)
## 1    20     97.55    1.482e-12
## 2    30    109.51    2.783e-11
## 3    40    159.88    1.424e-16
## 4    50    185.71    8.741e-18
## 
## 
## Elapsed time : 1.408073
spec2 <- ugarchspec(
  variance.model = list(model = "sGARCH", garchOrder = c(2,0)),
  mean.model = list(armaOrder = c(1,0), include.mean = TRUE)
)
fit2 <- ugarchfit(spec2, data = return)
fit2
## 
## *---------------------------------*
## *          GARCH Model Fit        *
## *---------------------------------*
## 
## Conditional Variance Dynamics    
## -----------------------------------
## GARCH Model  : sGARCH(2,0)
## Mean Model   : ARFIMA(1,0,0)
## Distribution : norm 
## 
## Optimal Parameters
## ------------------------------------
##         Estimate  Std. Error  t value Pr(>|t|)
## mu      0.000327    0.000847  0.38637 0.699220
## ar1    -0.030349    0.031124 -0.97511 0.329505
## omega   0.000905    0.000052 17.49048 0.000000
## alpha1  0.133904    0.033973  3.94150 0.000081
## alpha2  0.084363    0.035318  2.38866 0.016910
## 
## Robust Standard Errors:
##         Estimate  Std. Error  t value Pr(>|t|)
## mu      0.000327    0.000802  0.40796 0.683303
## ar1    -0.030349    0.027298 -1.11179 0.266230
## omega   0.000905    0.000101  8.99333 0.000000
## alpha1  0.133904    0.040538  3.30316 0.000956
## alpha2  0.084363    0.048903  1.72509 0.084511
## 
## LogLikelihood : 2731.015 
## 
## Information Criteria
## ------------------------------------
##                     
## Akaike       -3.9594
## Bayes        -3.9404
## Shibata      -3.9594
## Hannan-Quinn -3.9523
## 
## Weighted Ljung-Box Test on Standardized Residuals
## ------------------------------------
##                         statistic p-value
## Lag[1]                     0.7494  0.3867
## Lag[2*(p+q)+(p+q)-1][2]    1.8295  0.2773
## Lag[4*(p+q)+(p+q)-1][5]    3.6778  0.2815
## d.o.f=1
## H0 : No serial correlation
## 
## Weighted Ljung-Box Test on Standardized Squared Residuals
## ------------------------------------
##                         statistic p-value
## Lag[1]                     0.1617 0.68756
## Lag[2*(p+q)+(p+q)-1][5]    4.9437 0.15763
## Lag[4*(p+q)+(p+q)-1][9]   11.8086 0.02005
## d.o.f=2
## 
## Weighted ARCH LM Tests
## ------------------------------------
##             Statistic Shape Scale  P-Value
## ARCH Lag[3]     3.287 0.500 2.000 0.069827
## ARCH Lag[5]    10.331 1.440 1.667 0.005456
## ARCH Lag[7]    13.053 2.315 1.543 0.003460
## 
## Nyblom stability test
## ------------------------------------
## Joint Statistic:  1.7094
## Individual Statistics:              
## mu     0.23032
## ar1    0.05856
## omega  0.84301
## alpha1 1.22401
## alpha2 0.09558
## 
## 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          0.36266 0.7169    
## Negative Sign Bias 0.22264 0.8238    
## Positive Sign Bias 0.04418 0.9648    
## Joint Effect       0.15409 0.9846    
## 
## 
## Adjusted Pearson Goodness-of-Fit Test:
## ------------------------------------
##   group statistic p-value(g-1)
## 1    20      95.9    2.942e-12
## 2    30     108.6    3.872e-11
## 3    40     150.7    4.780e-15
## 4    50     177.5    1.857e-16
## 
## 
## Elapsed time : 0.4328799
spec3 <- ugarchspec(
  variance.model = list(model = "sGARCH", garchOrder = c(1,1)),
  mean.model = list(armaOrder = c(1,0), include.mean = TRUE)
)
fit3 <- ugarchfit(spec3, data = return)
fit3
## 
## *---------------------------------*
## *          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     -0.000054    0.000822 -0.065579 0.947713
## ar1    -0.005346    0.029394 -0.181864 0.855690
## omega   0.000065    0.000018  3.568404 0.000359
## alpha1  0.088988    0.018673  4.765535 0.000002
## beta1   0.855167    0.028366 30.148005 0.000000
## 
## Robust Standard Errors:
##         Estimate  Std. Error   t value Pr(>|t|)
## mu     -0.000054    0.000823 -0.065513 0.947765
## ar1    -0.005346    0.026372 -0.202707 0.839364
## omega   0.000065    0.000030  2.173316 0.029757
## alpha1  0.088988    0.026983  3.297891 0.000974
## beta1   0.855167    0.045125 18.951184 0.000000
## 
## LogLikelihood : 2764.786 
## 
## Information Criteria
## ------------------------------------
##                     
## Akaike       -4.0084
## Bayes        -3.9894
## Shibata      -4.0084
## Hannan-Quinn -4.0013
## 
## Weighted Ljung-Box Test on Standardized Residuals
## ------------------------------------
##                         statistic p-value
## Lag[1]                     0.1756  0.6752
## Lag[2*(p+q)+(p+q)-1][2]    1.7418  0.3152
## Lag[4*(p+q)+(p+q)-1][5]    3.3990  0.3379
## d.o.f=1
## H0 : No serial correlation
## 
## Weighted Ljung-Box Test on Standardized Squared Residuals
## ------------------------------------
##                         statistic p-value
## Lag[1]                      1.852  0.1736
## Lag[2*(p+q)+(p+q)-1][5]     2.466  0.5131
## Lag[4*(p+q)+(p+q)-1][9]     3.131  0.7371
## d.o.f=2
## 
## Weighted ARCH LM Tests
## ------------------------------------
##             Statistic Shape Scale P-Value
## ARCH Lag[3]    0.6455 0.500 2.000  0.4217
## ARCH Lag[5]    0.8473 1.440 1.667  0.7787
## ARCH Lag[7]    0.9811 2.315 1.543  0.9166
## 
## Nyblom stability test
## ------------------------------------
## Joint Statistic:  0.7056
## Individual Statistics:             
## mu     0.2117
## ar1    0.1482
## omega  0.1721
## alpha1 0.2053
## beta1  0.1601
## 
## 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          0.34932 0.7269    
## Negative Sign Bias 0.07335 0.9415    
## Positive Sign Bias 0.23073 0.8176    
## Joint Effect       0.41854 0.9364    
## 
## 
## Adjusted Pearson Goodness-of-Fit Test:
## ------------------------------------
##   group statistic p-value(g-1)
## 1    20     79.08    2.679e-09
## 2    30    105.98    1.055e-10
## 3    40    133.97    2.423e-12
## 4    50    195.44    2.201e-19
## 
## 
## Elapsed time : 0.4661701
spec4 <- ugarchspec(
  variance.model = list(model = "sGARCH", garchOrder = c(1,0)),
  mean.model = list(armaOrder = c(1,0), include.mean = TRUE)
)
fit4 <- ugarchfit(spec4, data = return)
fit4
## 
## *---------------------------------*
## *          GARCH Model Fit        *
## *---------------------------------*
## 
## Conditional Variance Dynamics    
## -----------------------------------
## GARCH Model  : sGARCH(1,0)
## Mean Model   : ARFIMA(1,0,0)
## Distribution : norm 
## 
## Optimal Parameters
## ------------------------------------
##         Estimate  Std. Error  t value Pr(>|t|)
## mu      0.000248    0.000859  0.28896 0.772611
## ar1    -0.026799    0.031019 -0.86396 0.387612
## omega   0.000988    0.000046 21.34214 0.000000
## alpha1  0.138411    0.034446  4.01819 0.000059
## 
## Robust Standard Errors:
##         Estimate  Std. Error  t value Pr(>|t|)
## mu      0.000248    0.000839  0.29595  0.76726
## ar1    -0.026799    0.025705 -1.04255  0.29716
## omega   0.000988    0.000087 11.34181  0.00000
## alpha1  0.138411    0.040384  3.42733  0.00061
## 
## LogLikelihood : 2726.633 
## 
## Information Criteria
## ------------------------------------
##                     
## Akaike       -3.9544
## Bayes        -3.9393
## Shibata      -3.9545
## Hannan-Quinn -3.9488
## 
## Weighted Ljung-Box Test on Standardized Residuals
## ------------------------------------
##                         statistic p-value
## Lag[1]                     0.4375  0.5083
## Lag[2*(p+q)+(p+q)-1][2]    2.0156  0.2081
## Lag[4*(p+q)+(p+q)-1][5]    4.4130  0.1670
## d.o.f=1
## H0 : No serial correlation
## 
## Weighted Ljung-Box Test on Standardized Squared Residuals
## ------------------------------------
##                         statistic p-value
## Lag[1]                     0.1100 0.74014
## Lag[2*(p+q)+(p+q)-1][2]    0.7947 0.56990
## Lag[4*(p+q)+(p+q)-1][5]    6.8052 0.05781
## d.o.f=1
## 
## Weighted ARCH LM Tests
## ------------------------------------
##             Statistic Shape Scale  P-Value
## ARCH Lag[2]     1.365 0.500 2.000 0.242605
## ARCH Lag[4]     5.615 1.397 1.611 0.062306
## ARCH Lag[6]    11.820 2.222 1.500 0.004902
## 
## Nyblom stability test
## ------------------------------------
## Joint Statistic:  1.5843
## Individual Statistics:              
## mu     0.23257
## ar1    0.05856
## omega  0.88604
## alpha1 1.19356
## 
## 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.4869 0.6264    
## Negative Sign Bias  0.4839 0.6285    
## Positive Sign Bias  0.1459 0.8840    
## Joint Effect        0.3068 0.9588    
## 
## 
## Adjusted Pearson Goodness-of-Fit Test:
## ------------------------------------
##   group statistic p-value(g-1)
## 1    20     97.55    1.482e-12
## 2    30    109.51    2.783e-11
## 3    40    159.88    1.424e-16
## 4    50    185.71    8.741e-18
## 
## 
## Elapsed time : 0.4414599
spec5 <- ugarchspec(
  variance.model = list(model = "sGARCH", garchOrder = c(0,1)),
  mean.model = list(armaOrder = c(1,0), include.mean = TRUE)
)
fit5 <- ugarchfit(spec5, data = return)
fit5
## 
## *---------------------------------*
## *          GARCH Model Fit        *
## *---------------------------------*
## 
## Conditional Variance Dynamics    
## -----------------------------------
## GARCH Model  : sGARCH(0,1)
## Mean Model   : ARFIMA(1,0,0)
## Distribution : norm 
## 
## Optimal Parameters
## ------------------------------------
##        Estimate  Std. Error    t value Pr(>|t|)
## mu     0.000135    0.000912 1.4826e-01  0.88214
## ar1    0.003898    0.026946 1.4466e-01  0.88498
## omega  0.000002    0.000000 1.2347e+02  0.00000
## beta1  0.997634    0.000015 6.7858e+04  0.00000
## 
## Robust Standard Errors:
##        Estimate  Std. Error    t value Pr(>|t|)
## mu     0.000135    0.001001 1.3507e-01  0.89256
## ar1    0.003898    0.034842 1.1187e-01  0.91092
## omega  0.000002    0.000000 5.4628e+01  0.00000
## beta1  0.997634    0.000044 2.2922e+04  0.00000
## 
## LogLikelihood : 2708.447 
## 
## Information Criteria
## ------------------------------------
##                     
## Akaike       -3.9280
## Bayes        -3.9128
## Shibata      -3.9280
## Hannan-Quinn -3.9223
## 
## Weighted Ljung-Box Test on Standardized Residuals
## ------------------------------------
##                         statistic p-value
## Lag[1]                    0.01037  0.9189
## Lag[2*(p+q)+(p+q)-1][2]   1.59342  0.3872
## Lag[4*(p+q)+(p+q)-1][5]   4.40379  0.1682
## d.o.f=1
## H0 : No serial correlation
## 
## Weighted Ljung-Box Test on Standardized Squared Residuals
## ------------------------------------
##                         statistic   p-value
## Lag[1]                      42.13 8.553e-11
## Lag[2*(p+q)+(p+q)-1][2]     43.15 3.840e-12
## Lag[4*(p+q)+(p+q)-1][5]     51.18 2.909e-14
## d.o.f=1
## 
## Weighted ARCH LM Tests
## ------------------------------------
##             Statistic Shape Scale   P-Value
## ARCH Lag[2]     2.040 0.500 2.000 0.1531788
## ARCH Lag[4]     8.956 1.397 1.611 0.0091304
## ARCH Lag[6]    15.798 2.222 1.500 0.0004752
## 
## Nyblom stability test
## ------------------------------------
## Joint Statistic:  22.0039
## Individual Statistics:            
## mu    0.2575
## ar1   0.3088
## omega 3.9659
## beta1 0.4731
## 
## 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            1.371 1.706e-01    
## Negative Sign Bias   1.915 5.571e-02   *
## Positive Sign Bias   5.250 1.762e-07 ***
## Joint Effect        31.397 7.011e-07 ***
## 
## 
## Adjusted Pearson Goodness-of-Fit Test:
## ------------------------------------
##   group statistic p-value(g-1)
## 1    20     99.96    5.436e-13
## 2    30    153.83    5.980e-19
## 3    40    192.01    4.243e-22
## 4    50    272.13    1.077e-32
## 
## 
## Elapsed time : 0.2318211
# 8. BANDINGKAN MODEL
cat("ARCH(1)    : AIC =", infocriteria(fit1)[1], "\n")
## ARCH(1)    : AIC = -3.954441
cat("ARCH(2)    : AIC =", infocriteria(fit2)[1], "\n")
## ARCH(2)    : AIC = -3.959353
cat("GARCH(1,1) : AIC =", infocriteria(fit3)[1], "\n")
## GARCH(1,1) : AIC = -4.008403
cat("GARCH(1,0) : AIC =", infocriteria(fit4)[1], "\n")
## GARCH(1,0) : AIC = -3.954441
cat("GARCH(0,1) : AIC =", infocriteria(fit5)[1], "\n")
## GARCH(0,1) : AIC = -3.928028
# 9. PERAMALAN VOLATILITAS
forecast <- ugarchforecast(fit3, n.ahead = 10)
forecast
## 
## *------------------------------------*
## *       GARCH Model Forecast         *
## *------------------------------------*
## Model: sGARCH
## Horizon: 10
## Roll Steps: 0
## Out of Sample: 0
## 
## 0-roll forecast [T0=1973-10-09]:
##          Series   Sigma
## T+1  -5.421e-05 0.02686
## T+2  -5.392e-05 0.02732
## T+3  -5.393e-05 0.02774
## T+4  -5.393e-05 0.02814
## T+5  -5.393e-05 0.02851
## T+6  -5.393e-05 0.02885
## T+7  -5.393e-05 0.02917
## T+8  -5.393e-05 0.02947
## T+9  -5.393e-05 0.02975
## T+10 -5.393e-05 0.03002
plot(forecast, which = 1)

# Plot volatilitas bersyarat
plot(fit3, which = 3) 

# INTERPRETASI
# Ambil parameter model terbaik (misal GARCH(1,1))
params <- coef(fit3)
omega <- params["omega"]
alpha <- params["alpha1"]
beta  <- params["beta1"]

cat("=== INTERPRETASI MODEL GARCH(1,1) ===\n")
## === INTERPRETASI MODEL GARCH(1,1) ===
cat("Omega (volatilitas dasar)     :", omega, "\n")
## Omega (volatilitas dasar)     : 6.51144e-05
cat("Alpha (efek kejutan)          :", alpha, "\n")
## Alpha (efek kejutan)          : 0.08898765
cat("Beta  (efek volatilitas lalu) :", beta, "\n")
## Beta  (efek volatilitas lalu) : 0.8551667
cat("Alpha + Beta                  :", alpha + beta, "\n")
## Alpha + Beta                  : 0.9441543
cat("Long-term volatility          :", omega / (1 - alpha - beta), "\n")
## Long-term volatility          : 0.00116597
if (alpha + beta >= 1) {
  cat("Kesimpulan: Volatilitas TIDAK stasioner (shock permanen).\n")
} else if (alpha + beta > 0.9) {
  cat("Kesimpulan: Volatilitas PERSISTEN (shock bertahan lama).\n")
} else {
  cat("Kesimpulan: Volatilitas CEPAT kembali ke rata-rata.\n")
}
## Kesimpulan: Volatilitas PERSISTEN (shock bertahan lama).
# Tampilkan peramalan
cat("\n=== PERAMALAN VOLATILITAS 10 HARI KE DEPAN ===\n")
## 
## === PERAMALAN VOLATILITAS 10 HARI KE DEPAN ===
print(forecast)
## 
## *------------------------------------*
## *       GARCH Model Forecast         *
## *------------------------------------*
## Model: sGARCH
## Horizon: 10
## Roll Steps: 0
## Out of Sample: 0
## 
## 0-roll forecast [T0=1973-10-09]:
##          Series   Sigma
## T+1  -5.421e-05 0.02686
## T+2  -5.392e-05 0.02732
## T+3  -5.393e-05 0.02774
## T+4  -5.393e-05 0.02814
## T+5  -5.393e-05 0.02851
## T+6  -5.393e-05 0.02885
## T+7  -5.393e-05 0.02917
## T+8  -5.393e-05 0.02947
## T+9  -5.393e-05 0.02975
## T+10 -5.393e-05 0.03002