Load Required Libraries

Load and Prepare Data

data_path <- "financial_Data.csv"
import <- read.csv(data_path)
h <- import$High

log.h <- na.omit(diff(h))
log.h_ts <- ts(log.h)

Exploratory Data Analysis

par(mfrow = c(2, 2))
plot(h, type = "l", main = "Raw High Prices", ylab = "Price")
plot(log.h, type = "l", main = "Log Returns", ylab = "Return")
acf(log.h, main = "ACF of Log Returns")
pacf(log.h, main = "PACF of Log Returns")

par(mfrow = c(1,1))

GARCH(1,1), GARCH(1,2), GARCH(2,1), GARCH(2,2) using fGarch

garch11_model <- garchFit(~ garch(1, 1), data = log.h, trace = FALSE)
## Warning in sqrt(diag(fit$cvar)): NaNs produced
garch12_model <- garchFit(~ garch(1, 2), data = log.h, trace = FALSE)
## Warning in sqrt(diag(fit$cvar)): NaNs produced
garch21_model <- garchFit(~ garch(2, 1), data = log.h, trace = FALSE)
## Warning in sqrt(diag(fit$cvar)): NaNs produced
garch22_model <- garchFit(~ garch(2, 2), data = log.h, trace = FALSE)
## Warning in sqrt(diag(fit$cvar)): NaNs produced
summary(garch11_model)
## 
## Title:
##  GARCH Modelling 
## 
## Call:
##  garchFit(formula = ~garch(1, 1), data = log.h, trace = FALSE) 
## 
## Mean and Variance Equation:
##  data ~ garch(1, 1)
## <environment: 0x0000023546c8e7b0>
##  [data = log.h]
## 
## Conditional Distribution:
##  norm 
## 
## Coefficient(s):
##          mu        omega       alpha1        beta1  
## -0.10302076   0.41140792   0.00000001   0.99999999  
## 
## Std. Errors:
##  based on Hessian 
## 
## Error Analysis:
##          Estimate  Std. Error  t value Pr(>|t|)    
## mu     -1.030e-01   9.894e-01   -0.104    0.917    
## omega   4.114e-01   1.110e+00    0.371    0.711    
## alpha1  1.000e-08         NaN      NaN      NaN    
## beta1   1.000e+00   4.215e-03  237.257   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Log Likelihood:
##  -1030.33    normalized:  -4.171378 
## 
## Description:
##  Mon May  5 20:28:20 2025 by user: victo 
## 
## 
## Standardised Residuals Tests:
##                                    Statistic   p-Value
##  Jarque-Bera Test   R    Chi^2  1.812496e+05 0.0000000
##  Shapiro-Wilk Test  R    W      2.702137e-01 0.0000000
##  Ljung-Box Test     R    Q(10)  1.407700e+00 0.9991952
##  Ljung-Box Test     R    Q(15)  2.281588e+00 0.9999295
##  Ljung-Box Test     R    Q(20)  2.822732e+00 0.9999976
##  Ljung-Box Test     R^2  Q(10)  1.188498e-01 1.0000000
##  Ljung-Box Test     R^2  Q(15)  1.799509e-01 1.0000000
##  Ljung-Box Test     R^2  Q(20)  2.529911e-01 1.0000000
##  LM Arch Test       R    TR^2   1.515726e-01 1.0000000
## 
## Information Criterion Statistics:
##      AIC      BIC      SIC     HQIC 
## 8.375146 8.431978 8.374632 8.398027
summary(garch12_model)
## 
## Title:
##  GARCH Modelling 
## 
## Call:
##  garchFit(formula = ~garch(1, 2), data = log.h, trace = FALSE) 
## 
## Mean and Variance Equation:
##  data ~ garch(1, 2)
## <environment: 0x00000235482614d8>
##  [data = log.h]
## 
## Conditional Distribution:
##  norm 
## 
## Coefficient(s):
##          mu        omega       alpha1        beta1        beta2  
## -0.09197634   0.00025330   0.00000001   0.99999999   0.00153416  
## 
## Std. Errors:
##  based on Hessian 
## 
## Error Analysis:
##          Estimate  Std. Error  t value Pr(>|t|)    
## mu     -9.198e-02   9.881e-01   -0.093 0.925840    
## omega   2.533e-04   1.510e+00    0.000 0.999866    
## alpha1  1.000e-08         NaN      NaN      NaN    
## beta1   1.000e+00   2.611e-01    3.830 0.000128 ***
## beta2   1.534e-03   2.657e-01    0.006 0.995393    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Log Likelihood:
##  -1030.135    normalized:  -4.170587 
## 
## Description:
##  Mon May  5 20:28:20 2025 by user: victo 
## 
## 
## Standardised Residuals Tests:
##                                    Statistic   p-Value
##  Jarque-Bera Test   R    Chi^2  1.783573e+05 0.0000000
##  Shapiro-Wilk Test  R    W      2.715645e-01 0.0000000
##  Ljung-Box Test     R    Q(10)  1.420902e+00 0.9991613
##  Ljung-Box Test     R    Q(15)  2.296993e+00 0.9999264
##  Ljung-Box Test     R    Q(20)  2.842354e+00 0.9999974
##  Ljung-Box Test     R^2  Q(10)  1.204329e-01 1.0000000
##  Ljung-Box Test     R^2  Q(15)  1.824890e-01 1.0000000
##  Ljung-Box Test     R^2  Q(20)  2.566449e-01 1.0000000
##  LM Arch Test       R    TR^2   1.537039e-01 1.0000000
## 
## Information Criterion Statistics:
##      AIC      BIC      SIC     HQIC 
## 8.381660 8.452700 8.380862 8.410261
summary(garch21_model)
## 
## Title:
##  GARCH Modelling 
## 
## Call:
##  garchFit(formula = ~garch(2, 1), data = log.h, trace = FALSE) 
## 
## Mean and Variance Equation:
##  data ~ garch(2, 1)
## <environment: 0x000002354a2a08c8>
##  [data = log.h]
## 
## Conditional Distribution:
##  norm 
## 
## Coefficient(s):
##          mu        omega       alpha1       alpha2        beta1  
## -0.10189597   0.41736275   0.00000001   0.00000001   0.99999999  
## 
## Std. Errors:
##  based on Hessian 
## 
## Error Analysis:
##          Estimate  Std. Error  t value Pr(>|t|)    
## mu     -1.019e-01   9.891e-01   -0.103    0.918    
## omega   4.174e-01   1.116e+00    0.374    0.709    
## alpha1  1.000e-08         NaN      NaN      NaN    
## alpha2  1.000e-08         NaN      NaN      NaN    
## beta1   1.000e+00   4.233e-03  236.257   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Log Likelihood:
##  -1030.29    normalized:  -4.171213 
## 
## Description:
##  Mon May  5 20:28:20 2025 by user: victo 
## 
## 
## Standardised Residuals Tests:
##                                    Statistic   p-Value
##  Jarque-Bera Test   R    Chi^2  1.809666e+05 0.0000000
##  Shapiro-Wilk Test  R    W      2.703369e-01 0.0000000
##  Ljung-Box Test     R    Q(10)  1.408933e+00 0.9991920
##  Ljung-Box Test     R    Q(15)  2.282837e+00 0.9999293
##  Ljung-Box Test     R    Q(20)  2.824183e+00 0.9999976
##  Ljung-Box Test     R^2  Q(10)  1.190041e-01 1.0000000
##  Ljung-Box Test     R^2  Q(15)  1.802002e-01 1.0000000
##  Ljung-Box Test     R^2  Q(20)  2.533500e-01 1.0000000
##  LM Arch Test       R    TR^2   1.517803e-01 1.0000000
## 
## Information Criterion Statistics:
##      AIC      BIC      SIC     HQIC 
## 8.382912 8.453952 8.382114 8.411513
summary(garch22_model)
## 
## Title:
##  GARCH Modelling 
## 
## Call:
##  garchFit(formula = ~garch(2, 2), data = log.h, trace = FALSE) 
## 
## Mean and Variance Equation:
##  data ~ garch(2, 2)
## <environment: 0x000002354b655628>
##  [data = log.h]
## 
## Conditional Distribution:
##  norm 
## 
## Coefficient(s):
##          mu        omega       alpha1       alpha2        beta1        beta2  
## -0.09198733   0.00025330   0.00000001   0.00000001   0.99999999   0.00153417  
## 
## Std. Errors:
##  based on Hessian 
## 
## Error Analysis:
##          Estimate  Std. Error  t value Pr(>|t|)    
## mu     -9.199e-02   9.881e-01   -0.093 0.925831    
## omega   2.533e-04   1.502e+00    0.000 0.999865    
## alpha1  1.000e-08         NaN      NaN      NaN    
## alpha2  1.000e-08         NaN      NaN      NaN    
## beta1   1.000e+00   2.608e-01    3.834 0.000126 ***
## beta2   1.534e-03   2.655e-01    0.006 0.995389    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Log Likelihood:
##  -1030.135    normalized:  -4.170587 
## 
## Description:
##  Mon May  5 20:28:20 2025 by user: victo 
## 
## 
## Standardised Residuals Tests:
##                                    Statistic   p-Value
##  Jarque-Bera Test   R    Chi^2  1.783571e+05 0.0000000
##  Shapiro-Wilk Test  R    W      2.715645e-01 0.0000000
##  Ljung-Box Test     R    Q(10)  1.420903e+00 0.9991612
##  Ljung-Box Test     R    Q(15)  2.296994e+00 0.9999264
##  Ljung-Box Test     R    Q(20)  2.842354e+00 0.9999974
##  Ljung-Box Test     R^2  Q(10)  1.204331e-01 1.0000000
##  Ljung-Box Test     R^2  Q(15)  1.824893e-01 1.0000000
##  Ljung-Box Test     R^2  Q(20)  2.566453e-01 1.0000000
##  LM Arch Test       R    TR^2   1.537041e-01 1.0000000
## 
## Information Criterion Statistics:
##      AIC      BIC      SIC     HQIC 
## 8.389758 8.475006 8.388614 8.424079
predict(garch11_model, n.ahead = 120, plot = TRUE)

##     meanForecast meanError standardDeviation lowerInterval upperInterval
## 1     -0.1030208  18.82311          18.82311     -36.99564      36.78959
## 2     -0.1030208  18.83403          18.83403     -37.01705      36.81101
## 3     -0.1030208  18.84495          18.84495     -37.03845      36.83241
## 4     -0.1030208  18.85586          18.85586     -37.05984      36.85380
## 5     -0.1030208  18.86677          18.86677     -37.08121      36.87517
## 6     -0.1030208  18.87767          18.87767     -37.10258      36.89653
## 7     -0.1030208  18.88856          18.88856     -37.12393      36.91789
## 8     -0.1030208  18.89945          18.89945     -37.14527      36.93922
## 9     -0.1030208  18.91033          18.91033     -37.16659      36.96055
## 10    -0.1030208  18.92121          18.92121     -37.18791      36.98186
## 11    -0.1030208  18.93208          18.93208     -37.20921      37.00317
## 12    -0.1030208  18.94294          18.94294     -37.23050      37.02446
## 13    -0.1030208  18.95379          18.95379     -37.25177      37.04573
## 14    -0.1030208  18.96464          18.96464     -37.27304      37.06700
## 15    -0.1030208  18.97549          18.97549     -37.29429      37.08825
## 16    -0.1030208  18.98632          18.98632     -37.31553      37.10949
## 17    -0.1030208  18.99716          18.99716     -37.33676      37.13072
## 18    -0.1030208  19.00798          19.00798     -37.35798      37.15194
## 19    -0.1030208  19.01880          19.01880     -37.37918      37.17314
## 20    -0.1030208  19.02961          19.02961     -37.40038      37.19434
## 21    -0.1030208  19.04042          19.04042     -37.42156      37.21552
## 22    -0.1030208  19.05122          19.05122     -37.44273      37.23668
## 23    -0.1030208  19.06201          19.06201     -37.46388      37.25784
## 24    -0.1030208  19.07280          19.07280     -37.48503      37.27899
## 25    -0.1030208  19.08358          19.08358     -37.50616      37.30012
## 26    -0.1030208  19.09436          19.09436     -37.52728      37.32124
## 27    -0.1030208  19.10513          19.10513     -37.54839      37.34235
## 28    -0.1030208  19.11589          19.11589     -37.56949      37.36344
## 29    -0.1030208  19.12665          19.12665     -37.59057      37.38453
## 30    -0.1030208  19.13740          19.13740     -37.61164      37.40560
## 31    -0.1030208  19.14815          19.14815     -37.63271      37.42666
## 32    -0.1030208  19.15889          19.15889     -37.65375      37.44771
## 33    -0.1030208  19.16962          19.16962     -37.67479      37.46875
## 34    -0.1030208  19.18035          19.18035     -37.69582      37.48978
## 35    -0.1030208  19.19107          19.19107     -37.71683      37.51079
## 36    -0.1030208  19.20179          19.20179     -37.73784      37.53179
## 37    -0.1030208  19.21250          19.21250     -37.75883      37.55278
## 38    -0.1030208  19.22320          19.22320     -37.77981      37.57376
## 39    -0.1030208  19.23390          19.23390     -37.80077      37.59473
## 40    -0.1030208  19.24459          19.24459     -37.82173      37.61569
## 41    -0.1030208  19.25528          19.25528     -37.84267      37.63663
## 42    -0.1030208  19.26596          19.26596     -37.86360      37.65756
## 43    -0.1030208  19.27663          19.27663     -37.88453      37.67848
## 44    -0.1030208  19.28730          19.28730     -37.90543      37.69939
## 45    -0.1030208  19.29796          19.29796     -37.92633      37.72029
## 46    -0.1030208  19.30862          19.30862     -37.94722      37.74118
## 47    -0.1030208  19.31927          19.31927     -37.96809      37.76205
## 48    -0.1030208  19.32991          19.32991     -37.98896      37.78292
## 49    -0.1030208  19.34055          19.34055     -38.00981      37.80377
## 50    -0.1030208  19.35119          19.35119     -38.03065      37.82461
## 51    -0.1030208  19.36181          19.36181     -38.05148      37.84544
## 52    -0.1030208  19.37243          19.37243     -38.07229      37.86625
## 53    -0.1030208  19.38305          19.38305     -38.09310      37.88706
## 54    -0.1030208  19.39366          19.39366     -38.11390      37.90785
## 55    -0.1030208  19.40426          19.40426     -38.13468      37.92864
## 56    -0.1030208  19.41486          19.41486     -38.15545      37.94941
## 57    -0.1030208  19.42545          19.42545     -38.17621      37.97017
## 58    -0.1030208  19.43604          19.43604     -38.19696      37.99092
## 59    -0.1030208  19.44662          19.44662     -38.21770      38.01166
## 60    -0.1030208  19.45720          19.45720     -38.23842      38.03238
## 61    -0.1030208  19.46777          19.46777     -38.25914      38.05310
## 62    -0.1030208  19.47833          19.47833     -38.27984      38.07380
## 63    -0.1030208  19.48889          19.48889     -38.30054      38.09450
## 64    -0.1030208  19.49944          19.49944     -38.32122      38.11518
## 65    -0.1030208  19.50999          19.50999     -38.34189      38.13585
## 66    -0.1030208  19.52053          19.52053     -38.36255      38.15651
## 67    -0.1030208  19.53106          19.53106     -38.38320      38.17716
## 68    -0.1030208  19.54159          19.54159     -38.40383      38.19779
## 69    -0.1030208  19.55211          19.55211     -38.42446      38.21842
## 70    -0.1030208  19.56263          19.56263     -38.44507      38.23903
## 71    -0.1030208  19.57314          19.57314     -38.46568      38.25964
## 72    -0.1030208  19.58365          19.58365     -38.48627      38.28023
## 73    -0.1030208  19.59415          19.59415     -38.50685      38.30081
## 74    -0.1030208  19.60465          19.60465     -38.52742      38.32138
## 75    -0.1030208  19.61514          19.61514     -38.54798      38.34194
## 76    -0.1030208  19.62562          19.62562     -38.56853      38.36249
## 77    -0.1030208  19.63610          19.63610     -38.58907      38.38303
## 78    -0.1030208  19.64657          19.64657     -38.60960      38.40355
## 79    -0.1030208  19.65704          19.65704     -38.63011      38.42407
## 80    -0.1030208  19.66750          19.66750     -38.65062      38.44458
## 81    -0.1030208  19.67796          19.67796     -38.67111      38.46507
## 82    -0.1030208  19.68841          19.68841     -38.69159      38.48555
## 83    -0.1030208  19.69885          19.69885     -38.71207      38.50602
## 84    -0.1030208  19.70929          19.70929     -38.73253      38.52649
## 85    -0.1030208  19.71973          19.71973     -38.75298      38.54694
## 86    -0.1030208  19.73016          19.73016     -38.77342      38.56738
## 87    -0.1030208  19.74058          19.74058     -38.79385      38.58781
## 88    -0.1030208  19.75100          19.75100     -38.81426      38.60822
## 89    -0.1030208  19.76141          19.76141     -38.83467      38.62863
## 90    -0.1030208  19.77182          19.77182     -38.85507      38.64903
## 91    -0.1030208  19.78222          19.78222     -38.87545      38.66941
## 92    -0.1030208  19.79261          19.79261     -38.89583      38.68979
## 93    -0.1030208  19.80300          19.80300     -38.91619      38.71015
## 94    -0.1030208  19.81339          19.81339     -38.93655      38.73051
## 95    -0.1030208  19.82377          19.82377     -38.95689      38.75085
## 96    -0.1030208  19.83414          19.83414     -38.97722      38.77118
## 97    -0.1030208  19.84451          19.84451     -38.99755      38.79150
## 98    -0.1030208  19.85487          19.85487     -39.01786      38.81182
## 99    -0.1030208  19.86523          19.86523     -39.03816      38.83212
## 100   -0.1030208  19.87558          19.87558     -39.05845      38.85241
## 101   -0.1030208  19.88593          19.88593     -39.07873      38.87269
## 102   -0.1030208  19.89627          19.89627     -39.09900      38.89295
## 103   -0.1030208  19.90661          19.90661     -39.11925      38.91321
## 104   -0.1030208  19.91694          19.91694     -39.13950      38.93346
## 105   -0.1030208  19.92726          19.92726     -39.15974      38.95370
## 106   -0.1030208  19.93758          19.93758     -39.17997      38.97393
## 107   -0.1030208  19.94790          19.94790     -39.20018      38.99414
## 108   -0.1030208  19.95821          19.95821     -39.22039      39.01435
## 109   -0.1030208  19.96851          19.96851     -39.24059      39.03454
## 110   -0.1030208  19.97881          19.97881     -39.26077      39.05473
## 111   -0.1030208  19.98910          19.98910     -39.28095      39.07490
## 112   -0.1030208  19.99939          19.99939     -39.30111      39.09507
## 113   -0.1030208  20.00968          20.00968     -39.32126      39.11522
## 114   -0.1030208  20.01995          20.01995     -39.34141      39.13537
## 115   -0.1030208  20.03023          20.03023     -39.36154      39.15550
## 116   -0.1030208  20.04049          20.04049     -39.38166      39.17562
## 117   -0.1030208  20.05075          20.05075     -39.40178      39.19573
## 118   -0.1030208  20.06101          20.06101     -39.42188      39.21584
## 119   -0.1030208  20.07126          20.07126     -39.44197      39.23593
## 120   -0.1030208  20.08151          20.08151     -39.46205      39.25601
predict(garch12_model, n.ahead = 120, plot = TRUE)

##     meanForecast meanError standardDeviation lowerInterval upperInterval
## 1    -0.09197634  19.19048          19.19048     -37.70463      37.52067
## 2    -0.09197634  19.20518          19.20518     -37.73343      37.54948
## 3    -0.09197634  19.21989          19.21989     -37.76227      37.57831
## 4    -0.09197634  19.23461          19.23461     -37.79112      37.60717
## 5    -0.09197634  19.24934          19.24934     -37.82000      37.63604
## 6    -0.09197634  19.26409          19.26409     -37.84889      37.66494
## 7    -0.09197634  19.27884          19.27884     -37.87781      37.69386
## 8    -0.09197634  19.29361          19.29361     -37.90676      37.72280
## 9    -0.09197634  19.30839          19.30839     -37.93572      37.75177
## 10   -0.09197634  19.32318          19.32318     -37.96471      37.78075
## 11   -0.09197634  19.33798          19.33798     -37.99372      37.80976
## 12   -0.09197634  19.35279          19.35279     -38.02275      37.83879
## 13   -0.09197634  19.36761          19.36761     -38.05180      37.86785
## 14   -0.09197634  19.38245          19.38245     -38.08088      37.89692
## 15   -0.09197634  19.39729          19.39729     -38.10997      37.92602
## 16   -0.09197634  19.41215          19.41215     -38.13909      37.95514
## 17   -0.09197634  19.42702          19.42702     -38.16824      37.98428
## 18   -0.09197634  19.44190          19.44190     -38.19740      38.01345
## 19   -0.09197634  19.45679          19.45679     -38.22659      38.04263
## 20   -0.09197634  19.47169          19.47169     -38.25580      38.07184
## 21   -0.09197634  19.48661          19.48661     -38.28503      38.10107
## 22   -0.09197634  19.50153          19.50153     -38.31428      38.13033
## 23   -0.09197634  19.51647          19.51647     -38.34356      38.15960
## 24   -0.09197634  19.53142          19.53142     -38.37286      38.18890
## 25   -0.09197634  19.54638          19.54638     -38.40218      38.21822
## 26   -0.09197634  19.56135          19.56135     -38.43152      38.24757
## 27   -0.09197634  19.57633          19.57633     -38.46089      38.27693
## 28   -0.09197634  19.59133          19.59133     -38.49027      38.30632
## 29   -0.09197634  19.60633          19.60633     -38.51969      38.33573
## 30   -0.09197634  19.62135          19.62135     -38.54912      38.36517
## 31   -0.09197634  19.63638          19.63638     -38.57857      38.39462
## 32   -0.09197634  19.65142          19.65142     -38.60805      38.42410
## 33   -0.09197634  19.66647          19.66647     -38.63755      38.45360
## 34   -0.09197634  19.68154          19.68154     -38.66708      38.48313
## 35   -0.09197634  19.69661          19.69661     -38.69662      38.51267
## 36   -0.09197634  19.71170          19.71170     -38.72619      38.54224
## 37   -0.09197634  19.72680          19.72680     -38.75578      38.57183
## 38   -0.09197634  19.74190          19.74190     -38.78540      38.60145
## 39   -0.09197634  19.75703          19.75703     -38.81504      38.63108
## 40   -0.09197634  19.77216          19.77216     -38.84469      38.66074
## 41   -0.09197634  19.78730          19.78730     -38.87438      38.69042
## 42   -0.09197634  19.80246          19.80246     -38.90408      38.72013
## 43   -0.09197634  19.81763          19.81763     -38.93381      38.74986
## 44   -0.09197634  19.83281          19.83281     -38.96356      38.77961
## 45   -0.09197634  19.84800          19.84800     -38.99333      38.80938
## 46   -0.09197634  19.86320          19.86320     -39.02313      38.83918
## 47   -0.09197634  19.87841          19.87841     -39.05295      38.86899
## 48   -0.09197634  19.89364          19.89364     -39.08279      38.89884
## 49   -0.09197634  19.90887          19.90887     -39.11265      38.92870
## 50   -0.09197634  19.92412          19.92412     -39.14254      38.95859
## 51   -0.09197634  19.93938          19.93938     -39.17245      38.98850
## 52   -0.09197634  19.95466          19.95466     -39.20238      39.01843
## 53   -0.09197634  19.96994          19.96994     -39.23234      39.04839
## 54   -0.09197634  19.98524          19.98524     -39.26232      39.07837
## 55   -0.09197634  20.00054          20.00054     -39.29232      39.10837
## 56   -0.09197634  20.01586          20.01586     -39.32234      39.13839
## 57   -0.09197634  20.03119          20.03119     -39.35239      39.16844
## 58   -0.09197634  20.04654          20.04654     -39.38246      39.19851
## 59   -0.09197634  20.06189          20.06189     -39.41256      39.22860
## 60   -0.09197634  20.07726          20.07726     -39.44267      39.25872
## 61   -0.09197634  20.09263          20.09263     -39.47281      39.28886
## 62   -0.09197634  20.10802          20.10802     -39.50298      39.31902
## 63   -0.09197634  20.12342          20.12342     -39.53316      39.34921
## 64   -0.09197634  20.13884          20.13884     -39.56337      39.37942
## 65   -0.09197634  20.15426          20.15426     -39.59360      39.40965
## 66   -0.09197634  20.16970          20.16970     -39.62386      39.43991
## 67   -0.09197634  20.18515          20.18515     -39.65414      39.47018
## 68   -0.09197634  20.20061          20.20061     -39.68444      39.50049
## 69   -0.09197634  20.21608          20.21608     -39.71476      39.53081
## 70   -0.09197634  20.23156          20.23156     -39.74511      39.56116
## 71   -0.09197634  20.24706          20.24706     -39.77548      39.59153
## 72   -0.09197634  20.26257          20.26257     -39.80588      39.62192
## 73   -0.09197634  20.27809          20.27809     -39.83630      39.65234
## 74   -0.09197634  20.29362          20.29362     -39.86674      39.68278
## 75   -0.09197634  20.30916          20.30916     -39.89720      39.71325
## 76   -0.09197634  20.32472          20.32472     -39.92769      39.74374
## 77   -0.09197634  20.34028          20.34028     -39.95820      39.77425
## 78   -0.09197634  20.35586          20.35586     -39.98873      39.80478
## 79   -0.09197634  20.37145          20.37145     -40.01929      39.83534
## 80   -0.09197634  20.38706          20.38706     -40.04987      39.86592
## 81   -0.09197634  20.40267          20.40267     -40.08048      39.89652
## 82   -0.09197634  20.41830          20.41830     -40.11110      39.92715
## 83   -0.09197634  20.43394          20.43394     -40.14176      39.95780
## 84   -0.09197634  20.44959          20.44959     -40.17243      39.98848
## 85   -0.09197634  20.46525          20.46525     -40.20313      40.01918
## 86   -0.09197634  20.48092          20.48092     -40.23385      40.04990
## 87   -0.09197634  20.49661          20.49661     -40.26460      40.08064
## 88   -0.09197634  20.51231          20.51231     -40.29536      40.11141
## 89   -0.09197634  20.52802          20.52802     -40.32616      40.14220
## 90   -0.09197634  20.54374          20.54374     -40.35697      40.17302
## 91   -0.09197634  20.55948          20.55948     -40.38781      40.20386
## 92   -0.09197634  20.57522          20.57522     -40.41868      40.23472
## 93   -0.09197634  20.59098          20.59098     -40.44956      40.26561
## 94   -0.09197634  20.60675          20.60675     -40.48047      40.29652
## 95   -0.09197634  20.62254          20.62254     -40.51141      40.32745
## 96   -0.09197634  20.63833          20.63833     -40.54236      40.35841
## 97   -0.09197634  20.65414          20.65414     -40.57335      40.38939
## 98   -0.09197634  20.66996          20.66996     -40.60435      40.42040
## 99   -0.09197634  20.68579          20.68579     -40.63538      40.45143
## 100  -0.09197634  20.70163          20.70163     -40.66643      40.48248
## 101  -0.09197634  20.71749          20.71749     -40.69751      40.51356
## 102  -0.09197634  20.73336          20.73336     -40.72861      40.54466
## 103  -0.09197634  20.74924          20.74924     -40.75973      40.57578
## 104  -0.09197634  20.76513          20.76513     -40.79088      40.60693
## 105  -0.09197634  20.78103          20.78103     -40.82205      40.63810
## 106  -0.09197634  20.79695          20.79695     -40.85325      40.66929
## 107  -0.09197634  20.81288          20.81288     -40.88447      40.70051
## 108  -0.09197634  20.82882          20.82882     -40.91571      40.73176
## 109  -0.09197634  20.84477          20.84477     -40.94698      40.76302
## 110  -0.09197634  20.86074          20.86074     -40.97827      40.79432
## 111  -0.09197634  20.87671          20.87671     -41.00958      40.82563
## 112  -0.09197634  20.89270          20.89270     -41.04092      40.85697
## 113  -0.09197634  20.90870          20.90870     -41.07228      40.88833
## 114  -0.09197634  20.92472          20.92472     -41.10367      40.91972
## 115  -0.09197634  20.94075          20.94075     -41.13508      40.95113
## 116  -0.09197634  20.95678          20.95678     -41.16652      40.98257
## 117  -0.09197634  20.97283          20.97283     -41.19798      41.01402
## 118  -0.09197634  20.98890          20.98890     -41.22946      41.04551
## 119  -0.09197634  21.00497          21.00497     -41.26097      41.07701
## 120  -0.09197634  21.02106          21.02106     -41.29250      41.10855
predict(garch22_model, n.ahead = 120, plot = TRUE)

##     meanForecast meanError standardDeviation lowerInterval upperInterval
## 1    -0.09198733  19.19051          19.19051     -37.70470      37.52073
## 2    -0.09198733  19.20521          19.20521     -37.73351      37.54954
## 3    -0.09198733  19.21992          19.21992     -37.76234      37.57837
## 4    -0.09198733  19.23464          19.23464     -37.79120      37.60722
## 5    -0.09198733  19.24938          19.24938     -37.82007      37.63610
## 6    -0.09198733  19.26412          19.26412     -37.84897      37.66500
## 7    -0.09198733  19.27888          19.27888     -37.87789      37.69392
## 8    -0.09198733  19.29364          19.29364     -37.90683      37.72286
## 9    -0.09198733  19.30842          19.30842     -37.93580      37.75182
## 10   -0.09198733  19.32321          19.32321     -37.96479      37.78081
## 11   -0.09198733  19.33801          19.33801     -37.99380      37.80982
## 12   -0.09198733  19.35282          19.35282     -38.02283      37.83885
## 13   -0.09198733  19.36765          19.36765     -38.05188      37.86791
## 14   -0.09198733  19.38248          19.38248     -38.08096      37.89698
## 15   -0.09198733  19.39733          19.39733     -38.11005      37.92608
## 16   -0.09198733  19.41219          19.41219     -38.13917      37.95520
## 17   -0.09198733  19.42706          19.42706     -38.16832      37.98434
## 18   -0.09198733  19.44194          19.44194     -38.19748      38.01351
## 19   -0.09198733  19.45683          19.45683     -38.22667      38.04269
## 20   -0.09198733  19.47173          19.47173     -38.25588      38.07190
## 21   -0.09198733  19.48664          19.48664     -38.28511      38.10113
## 22   -0.09198733  19.50157          19.50157     -38.31436      38.13039
## 23   -0.09198733  19.51651          19.51651     -38.34364      38.15967
## 24   -0.09198733  19.53146          19.53146     -38.37294      38.18896
## 25   -0.09198733  19.54642          19.54642     -38.40226      38.21829
## 26   -0.09198733  19.56139          19.56139     -38.43160      38.24763
## 27   -0.09198733  19.57637          19.57637     -38.46097      38.27700
## 28   -0.09198733  19.59137          19.59137     -38.49036      38.30639
## 29   -0.09198733  19.60637          19.60637     -38.51977      38.33580
## 30   -0.09198733  19.62139          19.62139     -38.54920      38.36523
## 31   -0.09198733  19.63642          19.63642     -38.57866      38.39469
## 32   -0.09198733  19.65146          19.65146     -38.60814      38.42417
## 33   -0.09198733  19.66651          19.66651     -38.63764      38.45367
## 34   -0.09198733  19.68157          19.68157     -38.66717      38.48319
## 35   -0.09198733  19.69665          19.69665     -38.69671      38.51274
## 36   -0.09198733  19.71174          19.71174     -38.72628      38.54231
## 37   -0.09198733  19.72683          19.72683     -38.75587      38.57190
## 38   -0.09198733  19.74194          19.74194     -38.78549      38.60151
## 39   -0.09198733  19.75707          19.75707     -38.81512      38.63115
## 40   -0.09198733  19.77220          19.77220     -38.84478      38.66081
## 41   -0.09198733  19.78734          19.78734     -38.87447      38.69049
## 42   -0.09198733  19.80250          19.80250     -38.90417      38.72020
## 43   -0.09198733  19.81767          19.81767     -38.93390      38.74993
## 44   -0.09198733  19.83285          19.83285     -38.96365      38.77968
## 45   -0.09198733  19.84804          19.84804     -38.99342      38.80945
## 46   -0.09198733  19.86324          19.86324     -39.02322      38.83925
## 47   -0.09198733  19.87845          19.87845     -39.05304      38.86907
## 48   -0.09198733  19.89368          19.89368     -39.08288      38.89891
## 49   -0.09198733  19.90892          19.90892     -39.11275      38.92877
## 50   -0.09198733  19.92417          19.92417     -39.14263      38.95866
## 51   -0.09198733  19.93943          19.93943     -39.17254      38.98857
## 52   -0.09198733  19.95470          19.95470     -39.20248      39.01850
## 53   -0.09198733  19.96998          19.96998     -39.23243      39.04846
## 54   -0.09198733  19.98528          19.98528     -39.26241      39.07844
## 55   -0.09198733  20.00059          20.00059     -39.29242      39.10844
## 56   -0.09198733  20.01591          20.01591     -39.32244      39.13847
## 57   -0.09198733  20.03124          20.03124     -39.35249      39.16851
## 58   -0.09198733  20.04658          20.04658     -39.38256      39.19858
## 59   -0.09198733  20.06193          20.06193     -39.41265      39.22868
## 60   -0.09198733  20.07730          20.07730     -39.44277      39.25880
## 61   -0.09198733  20.09268          20.09268     -39.47291      39.28894
## 62   -0.09198733  20.10807          20.10807     -39.50307      39.31910
## 63   -0.09198733  20.12347          20.12347     -39.53326      39.34929
## 64   -0.09198733  20.13888          20.13888     -39.56347      39.37950
## 65   -0.09198733  20.15431          20.15431     -39.59370      39.40973
## 66   -0.09198733  20.16974          20.16974     -39.62396      39.43998
## 67   -0.09198733  20.18519          20.18519     -39.65424      39.47026
## 68   -0.09198733  20.20065          20.20065     -39.68454      39.50056
## 69   -0.09198733  20.21612          20.21612     -39.71486      39.53089
## 70   -0.09198733  20.23161          20.23161     -39.74521      39.56124
## 71   -0.09198733  20.24711          20.24711     -39.77558      39.59161
## 72   -0.09198733  20.26261          20.26261     -39.80598      39.62200
## 73   -0.09198733  20.27813          20.27813     -39.83640      39.65242
## 74   -0.09198733  20.29366          20.29366     -39.86684      39.68286
## 75   -0.09198733  20.30921          20.30921     -39.89730      39.71333
## 76   -0.09198733  20.32476          20.32476     -39.92779      39.74382
## 77   -0.09198733  20.34033          20.34033     -39.95830      39.77433
## 78   -0.09198733  20.35591          20.35591     -39.98884      39.80486
## 79   -0.09198733  20.37150          20.37150     -40.01940      39.83542
## 80   -0.09198733  20.38710          20.38710     -40.04998      39.86600
## 81   -0.09198733  20.40272          20.40272     -40.08058      39.89661
## 82   -0.09198733  20.41835          20.41835     -40.11121      39.92724
## 83   -0.09198733  20.43398          20.43398     -40.14186      39.95789
## 84   -0.09198733  20.44964          20.44964     -40.17254      39.98856
## 85   -0.09198733  20.46530          20.46530     -40.20324      40.01926
## 86   -0.09198733  20.48097          20.48097     -40.23396      40.04998
## 87   -0.09198733  20.49666          20.49666     -40.26470      40.08073
## 88   -0.09198733  20.51236          20.51236     -40.29547      40.11150
## 89   -0.09198733  20.52807          20.52807     -40.32627      40.14229
## 90   -0.09198733  20.54379          20.54379     -40.35708      40.17311
## 91   -0.09198733  20.55953          20.55953     -40.38792      40.20395
## 92   -0.09198733  20.57527          20.57527     -40.41879      40.23481
## 93   -0.09198733  20.59103          20.59103     -40.44967      40.26570
## 94   -0.09198733  20.60680          20.60680     -40.48058      40.29661
## 95   -0.09198733  20.62259          20.62259     -40.51152      40.32754
## 96   -0.09198733  20.63838          20.63838     -40.54248      40.35850
## 97   -0.09198733  20.65419          20.65419     -40.57346      40.38948
## 98   -0.09198733  20.67001          20.67001     -40.60446      40.42049
## 99   -0.09198733  20.68584          20.68584     -40.63549      40.45152
## 100  -0.09198733  20.70169          20.70169     -40.66654      40.48257
## 101  -0.09198733  20.71754          20.71754     -40.69762      40.51365
## 102  -0.09198733  20.73341          20.73341     -40.72872      40.54475
## 103  -0.09198733  20.74929          20.74929     -40.75985      40.57587
## 104  -0.09198733  20.76518          20.76518     -40.79099      40.60702
## 105  -0.09198733  20.78109          20.78109     -40.82217      40.63819
## 106  -0.09198733  20.79700          20.79700     -40.85336      40.66939
## 107  -0.09198733  20.81293          20.81293     -40.88458      40.70061
## 108  -0.09198733  20.82887          20.82887     -40.91583      40.73185
## 109  -0.09198733  20.84482          20.84482     -40.94709      40.76312
## 110  -0.09198733  20.86079          20.86079     -40.97838      40.79441
## 111  -0.09198733  20.87677          20.87677     -41.00970      40.82573
## 112  -0.09198733  20.89276          20.89276     -41.04104      40.85706
## 113  -0.09198733  20.90876          20.90876     -41.07240      40.88843
## 114  -0.09198733  20.92477          20.92477     -41.10379      40.91982
## 115  -0.09198733  20.94080          20.94080     -41.13520      40.95123
## 116  -0.09198733  20.95684          20.95684     -41.16664      40.98266
## 117  -0.09198733  20.97289          20.97289     -41.19810      41.01412
## 118  -0.09198733  20.98895          20.98895     -41.22958      41.04561
## 119  -0.09198733  21.00503          21.00503     -41.26109      41.07711
## 120  -0.09198733  21.02112          21.02112     -41.29262      41.10864

eGARCH Models using rugarch

# eGARCH Models using `rugarch`

# Define eGARCH model specifications
egarch_models <- list(
  egarch11 = ugarchspec(
    variance.model = list(model = "eGARCH", garchOrder = c(1, 1)),
    mean.model = list(armaOrder = c(0, 0), include.mean = TRUE),
    distribution.model = "norm"
  ),
  egarch12 = ugarchspec(
    variance.model = list(model = "eGARCH", garchOrder = c(1, 2)),
    mean.model = list(armaOrder = c(0, 0), include.mean = TRUE),
    distribution.model = "norm"
  ),
  egarch21 = ugarchspec(
    variance.model = list(model = "eGARCH", garchOrder = c(2, 1)),
    mean.model = list(armaOrder = c(0, 0), include.mean = TRUE),
    distribution.model = "norm"
  ),
  egarch22 = ugarchspec(
    variance.model = list(model = "eGARCH", garchOrder = c(2, 2)),
    mean.model = list(armaOrder = c(0, 0), include.mean = TRUE),
    distribution.model = "norm"
  )
)

# Fit models to the data (ensure `log.h` is defined and numeric)
fit_egarch <- lapply(egarch_models, function(spec) {
  ugarchfit(spec = spec, data = log.h, solver = "hybrid")
})

# Extract model coefficients
egarch_coefs <- lapply(fit_egarch, coef)
print(egarch_coefs)
## $egarch11
##           mu        omega       alpha1        beta1       gamma1 
##  0.279731070  3.549580822  1.003625132 -0.005222232  1.055261970 
## 
## $egarch12
##         mu      omega     alpha1      beta1      beta2     gamma1 
## -1.4500122  6.4319537  2.4091016  0.3962988 -0.3797081  2.9621385 
## 
## $egarch21
##          mu       omega      alpha1      alpha2       beta1      gamma1 
##  0.08387409 -0.08023885  0.11971505  0.04468266  0.99999999 -0.54928852 
##      gamma2 
##  0.42233103 
## 
## $egarch22
##         mu      omega     alpha1     alpha2      beta1      beta2     gamma1 
##  0.1654386 -0.2142866  0.9316198 -0.2810897  0.6377920  0.4064154  0.5958231 
##     gamma2 
## -0.4636316
# Optional: Forecast using the fitted models
egarch_forecasts <- lapply(fit_egarch, function(fit) ugarchforecast(fit, n.ahead = 10))
# You can inspect a specific forecast like this:
print(egarch_forecasts$egarch11)
## 
## *------------------------------------*
## *       GARCH Model Forecast         *
## *------------------------------------*
## Model: eGARCH
## Horizon: 10
## Roll Steps: 0
## Out of Sample: 0
## 
## 0-roll forecast [T0=1970-09-05]:
##      Series Sigma
## T+1  0.2797 3.848
## T+2  0.2797 5.858
## T+3  0.2797 5.845
## T+4  0.2797 5.845
## T+5  0.2797 5.845
## T+6  0.2797 5.845
## T+7  0.2797 5.845
## T+8  0.2797 5.845
## T+9  0.2797 5.845
## T+10 0.2797 5.845
# Optional: Plot diagnostics
#lapply(fit_egarch, plot)

GJR-GARCH Models using rugarch

gjr_models <- list(
  gjr11 = ugarchspec(variance.model = list(model="gjrGARCH", garchOrder=c(1,1)), mean.model=list(armaOrder=c(0,0)), distribution.model="norm"),
  gjr12 = ugarchspec(variance.model = list(model="gjrGARCH", garchOrder=c(1,2)), mean.model=list(armaOrder=c(0,0)), distribution.model="norm"),
  gjr21 = ugarchspec(variance.model = list(model="gjrGARCH", garchOrder=c(2,1)), mean.model=list(armaOrder=c(0,0)), distribution.model="norm"),
  gjr22 = ugarchspec(variance.model = list(model="gjrGARCH", garchOrder=c(2,2)), mean.model=list(armaOrder=c(0,0)), distribution.model="norm")
)

fit_gjr_models <- lapply(gjr_models, function(spec) ugarchfit(data=log.h, spec=spec, solver="hybrid"))
lapply(fit_gjr_models, coef)
## $gjr11
##          mu       omega      alpha1       beta1      gamma1 
## -0.93841343  0.41903772  0.01262167  0.99557055 -0.01928445 
## 
## $gjr12
##            mu         omega        alpha1         beta1         beta2 
##  7.382630e-02  1.069272e-01  1.036676e-20  3.928563e-01  6.144344e-01 
##        gamma1 
## -1.985695e-02 
## 
## $gjr21
##            mu         omega        alpha1        alpha2         beta1 
##  1.811668e-01  1.664226e-06  1.065664e-10  3.628408e-18  9.885479e-01 
##        gamma1        gamma2 
## -9.252576e-01  9.139672e-01 
## 
## $gjr22
##            mu         omega        alpha1        alpha2         beta1 
##  0.3009698435  0.0003810766  0.0062263714  0.1428815489  0.0476039400 
##         beta2        gamma1        gamma2 
##  0.8234459067 -0.0067442899 -0.1424269253
lapply(fit_gjr_models, summary)
## $gjr11
##    Length     Class      Mode 
##         1 uGARCHfit        S4 
## 
## $gjr12
##    Length     Class      Mode 
##         1 uGARCHfit        S4 
## 
## $gjr21
##    Length     Class      Mode 
##         1 uGARCHfit        S4 
## 
## $gjr22
##    Length     Class      Mode 
##         1 uGARCHfit        S4
# lapply(fit_gjr_models, plot)

Compare GJR-GARCH Models

model_names <- names(fit_gjr_models)
gjr_ic <- sapply(fit_gjr_models, function(fit) infocriteria(fit))
colnames(gjr_ic) <- model_names
gjr_llh <- sapply(fit_gjr_models, function(fit) likelihood(fit))
names(gjr_llh) <- model_names

print("Information Criteria (lower is better):")
## [1] "Information Criteria (lower is better):"
print(round(gjr_ic, 4))
##       gjr11  gjr12  gjr21  gjr22
## [1,] 7.7157 7.4058 6.9727 6.9024
## [2,] 7.7867 7.4910 7.0722 7.0161
## [3,] 7.7149 7.4046 6.9712 6.9004
## [4,] 7.7443 7.4401 7.0128 6.9482
print("Log-Likelihoods (higher is better):")
## [1] "Log-Likelihoods (higher is better):"
print(round(gjr_llh, 4))
##     gjr11     gjr12     gjr21     gjr22 
## -947.8897 -908.6129 -854.1328 -844.4491

GJR-GARCH(2,2) with Different Distributions

fit_gjr_by_dist <- function(distribution) {
  spec <- ugarchspec(
    variance.model = list(model = "gjrGARCH", garchOrder = c(2, 2)),
    mean.model = list(armaOrder = c(0, 0)),
    distribution.model = distribution
  )
  ugarchfit(spec = spec, data = log.h, solver = "hybrid")
}

model_norm <- fit_gjr_by_dist("norm")
model_std  <- fit_gjr_by_dist("std")
model_ged  <- fit_gjr_by_dist("ged")

ic_table <- cbind(
  norm = infocriteria(model_norm),
  std = infocriteria(model_std),
  ged = infocriteria(model_ged)
)
colnames(ic_table) <- c("Normal", "Student-t", "GED")
print(round(ic_table, 4))
##              Normal Student-t     GED
## Akaike       6.8026    5.7560 15.4882
## Bayes        6.9163    5.8839 15.6161
## Shibata      6.8006    5.7535 15.4857
## Hannan-Quinn 6.8484    5.8075 15.5397
llh <- c(
  Normal = likelihood(model_norm),
  Student_t = likelihood(model_std),
  GED = likelihood(model_ged)
)
print(round(llh, 4))
##     Normal  Student_t        GED 
##  -832.1244  -701.8682 -1903.7953

Extra: Built-in Data Extraction and Correlation/Regression Analysis

# Extract and preview data
data2 <- read.csv("financial_Data.csv")
data3 <- data2$Adj.Close

# Visualization
hist(data3)

barplot(data3)

hist(data3, col = "blue")

# Regression and Correlation
d <- data2$Close
h <- data2$High
g <- data2$Low
df <- data.frame(d, h, g)

cor(d, h)
## [1] 0.9996436
cor(d, g)
## [1] 0.9996625
cor(h, g)
## [1] 0.999654
lm_model <- lm(d ~ g + h)
aov(lm_model)
## Call:
##    aov(formula = lm_model)
## 
## Terms:
##                         g         h Residuals
## Sum of Squares  2064833.6     319.3    1075.1
## Deg. of Freedom         1         1       245
## 
## Residual standard error: 2.094752
## Estimated effects may be unbalanced
summary(lm_model)
## 
## Call:
## lm(formula = d ~ g + h)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -7.0668 -1.0546 -0.0468  1.0636  7.2652 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  0.17232    0.34677   0.497     0.62    
## g            0.53490    0.05621   9.517  < 2e-16 ***
## h            0.46548    0.05456   8.531 1.53e-15 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 2.095 on 245 degrees of freedom
## Multiple R-squared:  0.9995, Adjusted R-squared:  0.9995 
## F-statistic: 2.353e+05 on 2 and 245 DF,  p-value: < 2.2e-16
# Plots
hist(d)

hist(h)

hist(g)

plot(lm_model)