Volatile Model (ARCH & GARCH)
Technique to address irregular fluctuation that cannot be handle by typical time series model such as ARIMA, Moving Average, Exponential Smoothing & others.
R
Import data. (download from https://finance.yahoo.com/quote/005930.KS/history)
X005930_KS <- read_csv("005930.KS.csv")
samsung <- ts(X005930_KS$`Adj Close`)
Check order of differencing.
ndiffs(samsung)
Result:

Stationary check after differencing.
library(tseries)
adf.test( diff(samsung, 1) )
Result:

Check stationary and ARIMA hyperparameter.
tsdisplay( diff(samsung, 1) )
Result:

Train an ARIMA model.
samsung_arima_010 <- Arima(
samsung,
order=c(0,1,0)
)
Check if model adequate.
checkresiduals( samsung_arima_010 )
Result:

Check ARCH effect
library(rugarch)
library(FinTS)
return_samsung <- diff( samsung , 1)
ArchTest( return_samsung )
Result:

Explanation:
p-value = 0.04753 < 0.05, this show the model has ARCH effect.
Check residual after ARIMA, to identify ACF&PACF for residual square.
tsdisplay( samsung_arima_010$residuals^2 )
Result:

Train an ARCH model.
garchSpec <- ugarchspec(
variance.model = list(model="sGARCH", garchOrder=c(1,0)),
mean.model = list(armaOrder=c(0,0)),
distribution.model = "std"
)
garchFit <- ugarchfit(
spec = garchSpec,
data = return_samsung
)
garchFit
Result:

Explanation:
Note that variance.model = list(model="sGARCH", garchOrder=c(1,0)), means that we are training a ARCH model as the value c(1, 0) equivalent to GARCH(p, q). p meant for PACF on residual square, and q meant for ACF on residual square.
If p = q = 0, it actually mean the residual are simply white noise.
Import data. (download from https://finance.yahoo.com/quote/AAPL/history)
AAPL <- read_csv("AAPL.csv")
AAPL <- ts(AAPL$`Adj Close`)
Check stationary and ARIMA hyperparameter.
library(tseries)
adf.test( diff(AAPL, 1) )
Result:

Check stationary and ARIMA hyperparameter.
tsdisplay( diff(AAPL, 1) )
Result:

Train an ARIMA model.
AAPL_arima <- Arima(
AAPL,
order=c(1,1,1)
)
Check residual after ARIMA, to identify ACF&PACF for residual square.
tsdisplay( AAPL_arima$residuals^2 )
Result:

Train an ARCH model.
AAPL_rTS <- ts(diff(AAPL, 1))
garchSpec <- ugarchspec(
variance.model = list(model="sGARCH", garchOrder=c(1,1)),
mean.model = list(armaOrder=c(1,1)),
distribution.model = "std"
)
garchFit <- ugarchfit(
spec = garchSpec,
data = AAPL_rTS
)
garchFit
Result:

Confirm ARCH effect.
library(FinTS)
ArchTest(AAPL)
ArchTest(AAPL_rTS)
Result:

Forecast
forecast_garch <- ugarchforecast(garchFit)
forecast_garch
Result:


Leave a comment