$\newcommand{\1}{\boldsymbol{1}}$ $\newcommand{\0}{\boldsymbol{0}}$ $\newcommand\Fc{\mathscr{F}}$ $\newcommand{\eps}{\varepsilon}$ $\newcommand{\Var}{\operatorname{Var}}$ $\newcommand{\diag}{\operatorname{diag}}$ $\newcommand{\vec}{\operatorname{vec}}$ $\newcommand{\det}{\operatorname{det}}$ $\newcommand\Cov{\operatorname{Cov}}$ $\newcommand\Corr{\operatorname{Corr}}$ $\newcommand{\sig}{\sigma}$ $\newcommand\Sig{\Sigma}$ $\newcommand{\al}{\alpha}$ $\newcommand{\gam}{\gamma}$ $\newcommand\Gam{\Gamma}$ $\newcommand\lam{\lambda}$ $\newcommand{\Del}{\Delta}$ $\newcommand{\del}{\delta}$ $\newcommand\tht{\theta}$ $\newcommand\ph{\varphi}$ $\newcommand\om{\omega}$ $\newcommand\Om{\Omega}$ $\newcommand\rb{\bar{r}}$ $\newcommand{\Xb}{\bar{X}}$ $\newcommand{\Yb}{\bar{Y}}$ $\newcommand\Eb{\mathbb{E}}$ $\newcommand\Pb{\mathbb{P}}$ $\newcommand\Qb{\mathbb{Q}}$ $\newcommand\Rb{\mathbb{R}}$ $\newcommand\Zb{\mathbb{Z}}$ $\newcommand\Nb{\mathbb{N}}$ $\newcommand\Av{\textbf{A}}$ $\newcommand\av{\mathbf{a}}$ $\newcommand\Bv{\textbf{B}}$ $\newcommand\bv{\mathbf{b}}$ $\newcommand\Ev{\textbf{E}}$ $\newcommand\Dv{\textbf{D}}$ $\newcommand\Fv{\textbf{F}}$ $\newcommand\Gv{\textbf{G}}$ $\newcommand\Hv{\textbf{H}}$ $\newcommand\Kv{\textbf{K}}$ $\newcommand\Iv{\textbf{I}}$ $\newcommand\Pv{\textbf{P}}$ $\newcommand\Ov{\textbf{O}}$ $\newcommand\Sv{\textbf{S}}$ $\newcommand\Xv{\textbf{X}}$ $\newcommand\Yv{\textbf{Y}}$ $\newcommand\Zv{\textbf{Z}}$ $\newcommand\xv{\mathbf{x}}$ $\newcommand\yv{\mathbf{y}}$ $\newcommand\zv{\mathbf{z}}$ $\newcommand\Cv{\mathbf{C}}$ $\newcommand\mv{\mathbf{m}}$ $\newcommand\nv{\mathbf{n}}$ $\newcommand\pv{\mathbf{p}}$ $\newcommand\rv{\mathbf{r}}$ $\newcommand\sv{\mathbf{s}}$ $\newcommand\wv{\mathbf{w}}$ $\newcommand\Wv{\textbf{W}}$ $\newcommand\alv{\boldsymbol{\al}}$ $\newcommand\betav{\boldsymbol{\beta}}$ $\newcommand\etav{\boldsymbol{\eta}}$ $\newcommand\epsv{\boldsymbol{\varepsilon}}$ $\newcommand\delv{\boldsymbol{\delta}}$ $\newcommand\Lamv{\boldsymbol{\Lambda}}$ $\newcommand\lamv{\boldsymbol{\lambda}}$ $\newcommand\muv{\boldsymbol{\mu}}$ $\newcommand\piv{\boldsymbol{\pi}}$ $\newcommand\Piv{\boldsymbol{\Pi}}$ $\newcommand\Gamv{\boldsymbol{\Gam}}$ $\newcommand\Phiv{\boldsymbol{\Phi}}$ $\newcommand\rhov{\boldsymbol{\rho}}$ $\newcommand\Sigv{\boldsymbol{\Sig}}$ $\newcommand\ah{\widehat{a}}$ $\newcommand\Pbh{\widehat{\Pb}}$ $\newcommand\phh{\widehat{\varphi}}$ $\newcommand\Ebh{\widehat{\Eb}}$ $\newcommand\Qh{\widehat{Q}}$ $\newcommand\Ih{\widehat{I}}$ $\newcommand\rh{\widehat{r}}$ $\newcommand\pih{\widehat{\pi}}$ $\newcommand\Pih{\widehat{\Pi}}$ $\newcommand\Sigvh{\widehat{\Sigv}}$ $\newcommand\Wh{\widehat{W}}$ $\newcommand\Fh{\widehat{F}}$ $\newcommand\Yh{\widehat{Y}}$ $\newcommand\Zh{\widehat{Z}}$ $\newcommand\Yvh{\widehat{\Yv}}$ $\newcommand\Ah{\widehat{\Ac}}$ $\newcommand\uh{\widehat{u}}$ $\newcommand\vh{\widehat{v}}$ $\newcommand\fh{\widehat{f}}$ $\newcommand\hh{\widehat{h}}$ $\newcommand\Bh{\widehat{B}}$ $\newcommand\Ovh{\widehat{\Ov}}$ $\newcommand\Xvh{\widehat{\Xv}}$ $\newcommand\rhoh{\widehat{\rho}}$ $\newcommand\omh{\widehat{\om}}$ $\newcommand\nuh{\widehat{\nu}}$ $\newcommand\varphih{\widehat{\varphi}}$ $\newcommand\alh{\widehat{\al}}$ $\newcommand\thetah{\widehat{\theta}}$ $\newcommand\betah{\widehat{\beta}}$ $\newcommand\betavh{\widehat{\boldsymbol\beta}}$ $\newcommand\kaph{\widehat{\kappa}}$ $\newcommand\sigh{\widehat{\sigma}}$ $\newcommand\epsh{\widehat{\eps}}$ $\newcommand\epsvh{\widehat{\epsv}}$ $\newcommand\epst{\widetilde{\eps}}$ $\newcommand\muh{\widehat{\mu}}$ $\newcommand\dd{\mathrm{d}}$ $\newcommand\ee{\mathrm{e}}$
(Adjust Plotting Settings)
sc = .75
options(repr.plot.width=16*sc,
repr.plot.height=7*sc,
repr.plot.pointsize = 13, # Text height in pt
repr.plot.bg = 'white',
repr.plot.antialias = 'gray',
#nice medium-res DPI
repr.plot.res = 300,
#jpeg quality bumped from default
repr.plot.quality = 90,
#vector font family
repr.plot.family = 'serif')
options(warn=-1)
options("getSymbols.warning4.0"=FALSE)
library(quantmod)
getSymbols('KO', from='2007-01-03', to='2018-02-01', auto.assign=TRUE, Warnings=FALSE)
KO = Ad(KO)
head(KO)
dim(KO)
# Let r be percentage daily log returns
r = 100*diff(log(KO))[-1]
head(r)
# Plotting the acf and doing Box-Ljung test for autocorrelation
acf(r, main="sample ACF of KO daily log returns")
Box.test(r, lag=10, type = "Ljung-Box")
Sample ACF and Box-Ljung test show there is autocorrelation in $\{r_t\}$.
# Fit an ARIMA model
library(forecast)
fit=auto.arima(r, max.p = 20, max.q = 20, max.d = 2, ic="bic")
print(fit)
# Inspecting residual's square
par(mfrow=c(2,1));par(mar=c(3,3,3,3))
plot(resid(fit)**2, type="l", col=1, main = expression(residual^2))
smoother = loess((resid(fit)**2) ~ seq(1,length(resid(fit))), span=0.1)
lines(seq(1,length(resid(fit))),fitted(smoother),col=2)
acf((resid(fit)**2), main=expression("sample ACF of "~ residual^2))
# Box-Ljung test
Box.test(resid(fit)**2, lag = 5, type = "Ljung-Box")
There is existence of ARCH effect.
# Fitting
library(fGarch)
fit_magarch = garchFit(~arma(0,1)+garch(1,1), data=r, trace = F)
summary(fit_magarch)
We fit an ARMA(0,1)+GARCH(1,1) model, as follows, $\ $
$$ \left\{\begin{array}{}r_t = 0.057823+a_t-0.029829a_{t-1};\quad a_t=\sig_t\eps_t,\quad\eps_t\overset{i.i.d.}\sim N(0,1)\\\sig_t^2=0.038895+0.100440a_{t-1}^2+0.866927\sig_{t-1}^2\end{array}\right. $$# ACF plot of standardized residuals
plot(fit_magarch, which=10)
The ACF plot of the standardized residual show that the ARMA(0,1) specification is adequate. The Ljung-Box test of standardized residuals for 10 , 15, and 20 lags indicate the model is adequate.
# ACF plot of square standarized residuals
plot(fit_magarch, which=11)
The ACF plot of the squared standardized residual shows that the GARCH(1,1) specification is adequate. $\ $
So do the Ljung-Box tests of standardized residuals$^2$.
# QQ plot
plot(fit_magarch, which=13)
The normal probability plot of the standardized residuals indicates fat-tailed distribution, so we proceed with model modification, using t-distribution residuals.
# Fit the model
fit_magarch_tdist = garchFit(~arma(0,1)+garch(1,1), data=r,
cond.dist = "std",trace = F)
summary(fit_magarch_tdist)
We fit an ARMA(0,1)+GARCH(1,1) model with student-t residuals, as follows, $\ $
$$ \left\{\begin{array}{}r_t = 0.063830+a_t-0.020213a_{t-1};\quad a_t=\sig_t\eps_t,\quad\eps_t\overset{i.i.d.}\sim t_{4.817566}\\\sig_t^2=0.019006+0.076508a_{t-1}^2+0.911551\sig_{t-1}^2\end{array}\right. $$# QQ plot
plot(fit_magarch_tdist, which=13)
We have shown in (b) that ARMA(0,1)+GARCH(1,1) specification is adequate. $\\$
And the t-plot of the standardized residuals is a much better fit.
To detect skewness, we fit an ARMA+GARCH(1,1) model with skew-t-distribution, and do model validation test.
# Fit the model
fit_magarch_stdist = garchFit(~arma(0,1)+garch(1,1), data=r,
cond.dist = "sstd",trace = F)
summary(fit_magarch_stdist)
We fit an ARMA(0,1)+GARCH(1,1) model with skewed student-t residuals, as follows, $\ $
$$ \left\{\begin{array}{}r_t = 0.052696+a_t-0.021578a_{t-1};\quad a_t=\sig_t\eps_t,\quad\eps_t\overset{i.i.d.}\sim t(\nu=4.833,\xi=0.958)\\\sig_t^2=0.019581+0.077416a_{t-1}^2+0.910055\sig_{t-1}^2\end{array}\right. $$# QQ plot
plot(fit_magarch_stdist, which=13)
The skewed t-plot of the standardized residuals is almost the same with the one without skewness. Both models are adequate. $\ $
However, based on the model, the skewness $\xi = 0.958$ is less than 1, which makes it not significant. We conclude that the returns of KO stock is not skewed.
# Fit the model
library('rugarch')
spec = ugarchspec(variance.model=list(garchOrder=c(1,1)),
mean.model=list(armaOrder=c(0,1),
archm=TRUE, archpow=2))
fit_garchm = ugarchfit(data=r, spec=spec)
show(fit_garchm)
We fit an ARMA(0,1)+GARCH(1,1)-M model, as follows, $\ $
$$ \left\{\begin{array}{}r_t = 0.03478+0.0276\sig_t^2+a_t-0.029738a_{t-1};\quad a_t=\sig_t\eps_t,\quad\eps_t\overset{i.i.d.}\sim N(0,1)\\\sig_t^2=0.039521+0.101143a_{t-1}^2+0.865663\sig_{t-1}^2\end{array}\right. $$The estimated risk-premium is 0.0276, which is statistically insignificant. So the return of KO stock has no risk premium.
# Model validation
par(mfrow=c(3,2));par(mar=c(3,3,3,3))
plot(fit_garchm,which=1)
plot(fit_garchm,which=3)
plot(fit_garchm,which=10)
plot(fit_garchm,which=11)
plot(fit_garchm,which=8)
plot(fit_garchm,which=9)
The model seems adequate, the residuals are not normal though.
# Fit the model
spec = ugarchspec(variance.model=list(model="eGARCH", garchOrder=c(1,1)),
mean.model=list(armaOrder=c(0,1)))
fit_egarch = ugarchfit(data=r, spec=spec)
show(fit_egarch)
We fit an ARMA(0,1)+EGARCH(1,1) model, as follows, $\ $
$$ \left\{\begin{array}{}r_t = 0.041052+a_t-0.030159a_{t-1};\quad a_t=\sig_t\eps_t,\quad\eps_t\overset{i.i.d.}\sim N(0,1)\\\ln(\sig_t^2)=0.008262-0.063297\eps_{t-1}+0.189598(|\eps_{t-1}|-\sqrt{2/\pi})+0.966645\ln(\sig_{t-1}^2)\end{array}\right. $$The lag-1 leverage parameter $\alpha_1$=−0.063297 is significant (p-value is 0.000002). So, the model implies leverage effect in the KO stock returns.
# Model validation
par(mfrow=c(3,2));par(mar=c(3,3,3,3))
plot(fit_egarch,which=1)
plot(fit_egarch,which=3)
plot(fit_egarch,which=10)
plot(fit_egarch,which=11)
plot(fit_egarch,which=8)
plot(fit_egarch,which=9)
The model seems adequate, the residuals are not normal though.