ARCH GARCH Data Kurs

Library

library("prettydoc")
library("rmdformats")
library(fGarch)
library(aTSA)
library(FinTS) 
library(lmtest)
library(forecast)
library(TSA)
library(tseries)
library(xts)
library(readxl)
library(tidyverse)
library("dygraphs")

Input Data

Data Kurs adalah nilai tukar rupiah terhadap dolar Amerika Serikat (USD to IDR). Kurs diamati dari 1 Januari 2018 hingga 31 Maret 2020 dalam harian yang ditentukan oleh Bank Indonesia. Sebanyak 548 observasi dicatat. Data berikut diperoleh dari website JISDOR BI dan digunakan Khairunnisa dalam artikel penelitian untuk memodelkan GARCH.

kurs <- read.csv("https://raw.githubusercontent.com/Rifqiaulya/poladatawaktu/main/Informasi%20Kurs%20Jisdor.csv",header=T)
head(kurs)
  NO              Tanggal  Kurs
1  1 1/2/2018 12:00:00 AM 13542
2  2 1/3/2018 12:00:00 AM 13498
3  3 1/4/2018 12:00:00 AM 13474
4  4 1/5/2018 12:00:00 AM 13405
5  5 1/8/2018 12:00:00 AM 13397
6  6 1/9/2018 12:00:00 AM 13428
tail(kurs)
     NO               Tanggal  Kurs
543 543 3/23/2020 12:00:00 AM 16608
544 544 3/24/2020 12:00:00 AM 16486
545 545 3/26/2020 12:00:00 AM 16328
546 546 3/27/2020 12:00:00 AM 16230
547 547 3/30/2020 12:00:00 AM 16336
548 548 3/31/2020 12:00:00 AM 16367

Visualisasi

Plot data dan acf memperlihatkan data tidak stasioner pada rataan, namun perlu pengujian secara formal dengan adf test.

Terima H0 dan menerima bahwa data tidak stasioner. Akibatnya, data perlu dilakukan pemebedaan.

kurs.ts<-ts(kurs$Kurs)
adf.test(kurs.ts)

    Augmented Dickey-Fuller Test

data:  kurs.ts
Dickey-Fuller = -1.0975, Lag order = 8, p-value = 0.923
alternative hypothesis: stationary

Pembedaan d=1

Plot dan uji ADF menyatakan data pembedaan d=1 telah stasioner.

dif1.kurs<-diff(kurs.ts)
plot(dif1.kurs,ylab="Kurs")

adf.test(dif1.kurs)

    Augmented Dickey-Fuller Test

data:  dif1.kurs
Dickey-Fuller = -6.216, Lag order = 8, p-value = 0.01
alternative hypothesis: stationary

Identifikasi Model ARIMA

#ACF menunjukkan kandidat model ARIMA(0,1,2)
acf(dif1.kurs, lag.max = 7)

#PACF menunjukkan kandidat model ARIMA(1,1,0)
pacf(dif1.kurs, lag=6)

#EACF menunjukkan kandidat model ARIMA(0,1,2)
eacf(dif1.kurs)
AR/MA
  0 1 2 3 4 5 6 7 8 9 10 11 12 13
0 x x o o x o o o o o o  o  o  x 
1 x o o o x o o o x o o  x  o  x 
2 x o x o o o o o x o o  o  o  x 
3 x x x o x o o o o o o  o  o  x 
4 x x x o o o o x o o o  o  o  x 
 [ reached getOption("max.print") -- omitted 3 rows ]
#auto ARIMA menunjukkan kandidat model ARIMA(1,1,0)
auto.arima(kurs.ts,trace = T,d = 1)

 Fitting models using approximations to speed things up...

 ARIMA(2,1,2) with drift         : 6091.573
 ARIMA(0,1,0) with drift         : 6136.04
 ARIMA(1,1,0) with drift         : 6086.548
 ARIMA(0,1,1) with drift         : 6094.638
 ARIMA(0,1,0)                    : 6137.337
 ARIMA(2,1,0) with drift         : 6088.108
 ARIMA(1,1,1) with drift         : 6087.186
 ARIMA(2,1,1) with drift         : 6089.748
 ARIMA(1,1,0)                    : 6086.399
 ARIMA(2,1,0)                    : 6087.806
 ARIMA(1,1,1)                    : 6086.846
 ARIMA(0,1,1)                    : 6094.866
 ARIMA(2,1,1)                    : 6089.423

 Now re-fitting the best model(s) without approximations...

 ARIMA(1,1,0)                    : 6094.328

 Best model: ARIMA(1,1,0)                    
Series: kurs.ts 
ARIMA(1,1,0) 

Coefficients:
         ar1
      0.3049
s.e.  0.0407

sigma^2 estimated as 4015:  log likelihood=-3045.15
AIC=6094.31   AICc=6094.33   BIC=6102.92

Pemilihan Model

modelarima012<-arima(kurs.ts, order=c(0,1,2), method="ML")
modelarima110<-arima(kurs.ts, order=c(1,1,0), method="ML")
(modelarima012)

Call:
arima(x = kurs.ts, order = c(0, 1, 2), method = "ML")

Coefficients:
         ma1     ma2
      0.2933  0.1466
s.e.  0.0423  0.0432

sigma^2 estimated as 3990:  log likelihood = -3043.96,  aic = 6091.92
(modelarima110)

Call:
arima(x = kurs.ts, order = c(1, 1, 0), method = "ML")

Coefficients:
         ar1
      0.3049
s.e.  0.0407

sigma^2 estimated as 4008:  log likelihood = -3045.15,  aic = 6092.31
#Model Terbaik pada AIC terkecil model ARIMA(0,1,2)

Signifikansi Koefisien

coeftest(modelarima012)

z test of coefficients:

    Estimate Std. Error z value  Pr(>|z|)    
ma1 0.293312   0.042262  6.9404 3.911e-12 ***
ma2 0.146573   0.043222  3.3911  0.000696 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
coeftest(modelarima110)

z test of coefficients:

    Estimate Std. Error z value  Pr(>|z|)    
ar1 0.304912   0.040683  7.4948 6.638e-14 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#Semua Koefisien Model ARIMA(0,1,2) siginfikan

Plot data dan Fitted Value

fit<-kurs$Kurs-modelarima012$residuals
plot(kurs$Kurs,type="l")
lines(fit,col="Red")

Analisis Residual

Sisaan terlihat acak dan bebas.

tsdiag(modelarima012)

checkresiduals(modelarima012$residuals)

Tolak H0, akibatnya sisaan tidak menyebar normal

jarque.bera.test(residuals(modelarima012))

    Jarque Bera Test

data:  residuals(modelarima012)
X-squared = 1774.7, df = 2, p-value < 2.2e-16

Terlihat ada korelasi pada sisaan kuadrat yang menandakan terdapat heteroskedastis. LM test dan PQ test semua lag p value observasinya dibawah garis maka ada indikasi heteroskedastisitas. Berdasarkan plot sisaan kuadrat terdapat titik titik yang melebihi nilai kebanyakannya sehingga terjadi heteroskedastisitas.

acf(modelarima012$residuals^2,main="ACF Squared Residual")

#atau
arch.test(modelarima012)
ARCH heteroscedasticity test for residuals 
alternative: heteroscedastic 

Portmanteau-Q test: 
     order  PQ p.value
[1,]     4 263       0
[2,]     8 323       0
[3,]    12 341       0
[4,]    16 365       0
[5,]    20 365       0
[6,]    24 365       0
Lagrange-Multiplier test: 
     order    LM  p.value
[1,]     4 254.1 0.00e+00
[2,]     8 111.5 0.00e+00
[3,]    12  67.4 3.83e-10
[4,]    16  29.0 1.62e-02
[5,]    20  20.8 3.51e-01
[6,]    24  16.7 8.22e-01

Pemeriksaan efek ARCH

Tolak H0 untuk uji LM test dari lag 1 hingga 5. Akibatnya terdapat efek ARCH jangka panjang atau GARCH.

for (i in 1:5) {
  ArchTest <- ArchTest(modelarima012$residuals, lags=i, demean=TRUE)
  cat("P Value LM Test lag ke", i,"adalah" , ArchTest$p.value, "\n") }
P Value LM Test lag ke 1 adalah 9.601294e-28 
P Value LM Test lag ke 2 adalah 1.218508e-29 
P Value LM Test lag ke 3 adalah 2.931241e-29 
P Value LM Test lag ke 4 adalah 2.312342e-28 
P Value LM Test lag ke 5 adalah 1.739022e-29 

Pemodelan GARCH

#alpha1 unsur ARCH 1 nya di lag residual kuadrat
#LM Archtestnya p value siginifikan, yg mau kita tuju adalah tidak signfikan, terdapat efek masih
arch1<-garchFit(~arma(0,2)+garch(1,0),data = dif1.kurs, trace = F)
summary(arch1)

Title:
 GARCH Modelling 

Call:
 garchFit(formula = ~arma(0, 2) + garch(1, 0), data = dif1.kurs, 
    trace = F) 

Mean and Variance Equation:
 data ~ arma(0, 2) + garch(1, 0)
<environment: 0x0000000025ac1748>
 [data = dif1.kurs]

Conditional Distribution:
 norm 

Coefficient(s):
        mu         ma1         ma2       omega      alpha1  
   1.21476     0.11216     0.12915  1837.09768     0.52789  

Std. Errors:
 based on Hessian 

Error Analysis:
        Estimate  Std. Error  t value Pr(>|t|)    
mu     1.215e+00   2.514e+00    0.483  0.62892    
ma1    1.122e-01   4.250e-02    2.639  0.00832 ** 
ma2    1.291e-01   3.242e-02    3.984 6.78e-05 ***
omega  1.837e+03   1.613e+02   11.391  < 2e-16 ***
alpha1 5.279e-01   8.914e-02    5.922 3.18e-09 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Log Likelihood:
 -2957.233    normalized:  -5.406275 

Description:
 Fri May 07 22:51:34 2021 by user: DK0158AU 


Standardised Residuals Tests:
                                Statistic p-Value     
 Jarque-Bera Test   R    Chi^2  85.48614  0           
 Shapiro-Wilk Test  R    W      0.9778342 2.273594e-07
 Ljung-Box Test     R    Q(10)  16.1978   0.09410852  
 Ljung-Box Test     R    Q(15)  31.59991  0.007295258 
 Ljung-Box Test     R    Q(20)  36.92794  0.01193701  
 Ljung-Box Test     R^2  Q(10)  54.29062  4.283436e-08
 Ljung-Box Test     R^2  Q(15)  78.84286  1.136172e-10
 Ljung-Box Test     R^2  Q(20)  87.39625  2.107072e-10
 LM Arch Test       R    TR^2   56.64841  9.147279e-08

Information Criterion Statistics:
     AIC      BIC      SIC     HQIC 
10.83083 10.87018 10.83067 10.84621 
#beta 1 garch atau lag variansnya sendiri, p-value LM besar, AIC lebih kecil, tidak terdapat efek
garch11<-garchFit(~arma(0,2)+garch(1,1),data = dif1.kurs, trace = F)
summary(garch11)

Title:
 GARCH Modelling 

Call:
 garchFit(formula = ~arma(0, 2) + garch(1, 1), data = dif1.kurs, 
    trace = F) 

Mean and Variance Equation:
 data ~ arma(0, 2) + garch(1, 1)
<environment: 0x0000000020b61ff0>
 [data = dif1.kurs]

Conditional Distribution:
 norm 

Coefficient(s):
        mu         ma1         ma2       omega      alpha1       beta1  
  1.678450    0.096288    0.047817  165.468900    0.191526    0.772454  

Std. Errors:
 based on Hessian 

Error Analysis:
        Estimate  Std. Error  t value Pr(>|t|)    
mu       1.67845     2.21700    0.757    0.449    
ma1      0.09629     0.04803    2.005    0.045 *  
ma2      0.04782     0.04591    1.042    0.298    
omega  165.46890    81.35917    2.034    0.042 *  
alpha1   0.19153     0.04621    4.145  3.4e-05 ***
beta1    0.77245     0.05995   12.885  < 2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Log Likelihood:
 -2928.937    normalized:  -5.354548 

Description:
 Fri May 07 22:51:34 2021 by user: DK0158AU 


Standardised Residuals Tests:
                                Statistic p-Value     
 Jarque-Bera Test   R    Chi^2  35.09304  2.396868e-08
 Shapiro-Wilk Test  R    W      0.9857588 3.493584e-05
 Ljung-Box Test     R    Q(10)  16.4892   0.08645869  
 Ljung-Box Test     R    Q(15)  26.13412  0.03663633  
 Ljung-Box Test     R    Q(20)  31.9502   0.04383181  
 Ljung-Box Test     R^2  Q(10)  6.446059  0.7764995   
 Ljung-Box Test     R^2  Q(15)  15.74557  0.3991598   
 Ljung-Box Test     R^2  Q(20)  22.77047  0.3002051   
 LM Arch Test       R    TR^2   11.07645  0.5223783   

Information Criterion Statistics:
     AIC      BIC      SIC     HQIC 
10.73103 10.77825 10.73080 10.74949 
garch12<-garchFit(~arma(0,2)+garch(1,2),data = dif1.kurs, trace = F)
summary(garch12)

Title:
 GARCH Modelling 

Call:
 garchFit(formula = ~arma(0, 2) + garch(1, 2), data = dif1.kurs, 
    trace = F) 

Mean and Variance Equation:
 data ~ arma(0, 2) + garch(1, 2)
<environment: 0x000000002695bfe8>
 [data = dif1.kurs]

Conditional Distribution:
 norm 

Coefficient(s):
        mu         ma1         ma2       omega      alpha1       beta1  
  1.570774    0.090214    0.051667  188.588790    0.223673    0.547426  
     beta2  
  0.188204  

Std. Errors:
 based on Hessian 

Error Analysis:
        Estimate  Std. Error  t value Pr(>|t|)    
mu       1.57077     2.21547    0.709  0.47832    
ma1      0.09021     0.04882    1.848  0.06464 .  
ma2      0.05167     0.04540    1.138  0.25513    
omega  188.58879    90.67619    2.080  0.03754 *  
alpha1   0.22367     0.05632    3.972 7.14e-05 ***
beta1    0.54743     0.19176    2.855  0.00431 ** 
beta2    0.18820     0.16114    1.168  0.24283    
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Log Likelihood:
 -2928.631    normalized:  -5.353987 

Description:
 Fri May 07 22:51:35 2021 by user: DK0158AU 


Standardised Residuals Tests:
                                Statistic p-Value     
 Jarque-Bera Test   R    Chi^2  35.85958  1.633775e-08
 Shapiro-Wilk Test  R    W      0.9857627 3.503186e-05
 Ljung-Box Test     R    Q(10)  16.57499  0.08431343  
 Ljung-Box Test     R    Q(15)  26.45063  0.03354461  
 Ljung-Box Test     R    Q(20)  32.2248   0.0409611   
 Ljung-Box Test     R^2  Q(10)  5.831729  0.8291969   
 Ljung-Box Test     R^2  Q(15)  15.13517  0.4417249   
 Ljung-Box Test     R^2  Q(20)  22.49684  0.3141704   
 LM Arch Test       R    TR^2   10.64375  0.5596704   

Information Criterion Statistics:
     AIC      BIC      SIC     HQIC 
10.73357 10.78865 10.73325 10.75510 
garch21<-garchFit(~arma(0,2)+garch(2,1),data = dif1.kurs, trace = F)
summary(garch21)

Title:
 GARCH Modelling 

Call:
 garchFit(formula = ~arma(0, 2) + garch(2, 1), data = dif1.kurs, 
    trace = F) 

Mean and Variance Equation:
 data ~ arma(0, 2) + garch(2, 1)
<environment: 0x0000000020e4ee08>
 [data = dif1.kurs]

Conditional Distribution:
 norm 

Coefficient(s):
        mu         ma1         ma2       omega      alpha1      alpha2  
1.7173e+00  9.6406e-02  4.8124e-02  1.6890e+02  1.9297e-01  1.0000e-08  
     beta1  
7.6987e-01  

Std. Errors:
 based on Hessian 

Error Analysis:
        Estimate  Std. Error  t value Pr(>|t|)    
mu     1.717e+00   2.226e+00    0.771  0.44049    
ma1    9.641e-02   4.874e-02    1.978  0.04795 *  
ma2    4.812e-02   4.630e-02    1.039  0.29867    
omega  1.689e+02   9.492e+01    1.779  0.07517 .  
alpha1 1.930e-01   5.927e-02    3.256  0.00113 ** 
alpha2 1.000e-08   7.635e-02    0.000  1.00000    
beta1  7.699e-01   7.796e-02    9.875  < 2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Log Likelihood:
 -2929.205    normalized:  -5.355037 

Description:
 Fri May 07 22:51:35 2021 by user: DK0158AU 


Standardised Residuals Tests:
                                Statistic p-Value     
 Jarque-Bera Test   R    Chi^2  35.60396  1.856515e-08
 Shapiro-Wilk Test  R    W      0.9856454 3.222841e-05
 Ljung-Box Test     R    Q(10)  16.49147  0.08640154  
 Ljung-Box Test     R    Q(15)  26.12109  0.03676898  
 Ljung-Box Test     R    Q(20)  32.03505  0.0429263   
 Ljung-Box Test     R^2  Q(10)  6.467754  0.7745541   
 Ljung-Box Test     R^2  Q(15)  15.7345   0.3999132   
 Ljung-Box Test     R^2  Q(20)  22.85614  0.2959133   
 LM Arch Test       R    TR^2   11.01519  0.5276174   

Information Criterion Statistics:
     AIC      BIC      SIC     HQIC 
10.73567 10.79075 10.73535 10.75720 
#kandidat model lain ketika ARIMA(0,1,1) GARCH(1,1) karena ada koefisien tak siginfikan di garch11
garch11k<-garchFit(~arma(0,1)+garch(1,1),data = dif1.kurs, trace = F)
summary(garch11k)

Title:
 GARCH Modelling 

Call:
 garchFit(formula = ~arma(0, 1) + garch(1, 1), data = dif1.kurs, 
    trace = F) 

Mean and Variance Equation:
 data ~ arma(0, 1) + garch(1, 1)
<environment: 0x0000000025931370>
 [data = dif1.kurs]

Conditional Distribution:
 norm 

Coefficient(s):
        mu         ma1       omega      alpha1       beta1  
  1.734972    0.090323  167.654611    0.192608    0.771104  

Std. Errors:
 based on Hessian 

Error Analysis:
        Estimate  Std. Error  t value Pr(>|t|)    
mu       1.73497     2.12681    0.816   0.4146    
ma1      0.09032     0.04561    1.980   0.0477 *  
omega  167.65461    82.09439    2.042   0.0411 *  
alpha1   0.19261     0.04618    4.171 3.04e-05 ***
beta1    0.77110     0.05998   12.857  < 2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Log Likelihood:
 -2929.521    normalized:  -5.355615 

Description:
 Fri May 07 22:51:35 2021 by user: DK0158AU 


Standardised Residuals Tests:
                                Statistic p-Value     
 Jarque-Bera Test   R    Chi^2  35.99119  1.529723e-08
 Shapiro-Wilk Test  R    W      0.9855314 2.972663e-05
 Ljung-Box Test     R    Q(10)  18.53264  0.04661644  
 Ljung-Box Test     R    Q(15)  27.96422  0.02179408  
 Ljung-Box Test     R    Q(20)  34.30147  0.02415621  
 Ljung-Box Test     R^2  Q(10)  5.940365  0.8202483   
 Ljung-Box Test     R^2  Q(15)  15.56604  0.4114636   
 Ljung-Box Test     R^2  Q(20)  23.55279  0.2624729   
 LM Arch Test       R    TR^2   10.83636  0.5429924   

Information Criterion Statistics:
     AIC      BIC      SIC     HQIC 
10.72951 10.76886 10.72935 10.74489 
#AIC terkecil pada ARIMA(0,1,1) GARCH(1,1)

Plot Simpangan Baku

#plot simpangan baku
sb<-garch11k@sigma.t
ragam<-garch11k@sigma.t^2
#sequense kurg 1 obs sehingga harus dimodifikasi
dates2<-kurs$Tanggal[-1]
stdv=xts(sb,order.by = dates2)
vragam=xts(ragam,order.by = dates2)
plot(stdv, main="Simpangan Baku")

plot(vragam, main="Ragam")

Sumber :

  1. Website JISDOR BI : https://www.bi.go.id/id/statistik/informasi-kurs/jisdor/default.aspx

  2. Khairunnisa, dan Siti Sunendiari.2020.Perbandingan Model Exponential GARCH dan Glosten Jaganathan Runkle GARCH dalam Meramalkan Nilai Tukar Rupiah terhadap Dolar Amerika Serikat.Prosiding Statistika Universitas Islam Bandung.Vol 6 No2 Hal 96-104