The motivation of our study is to analyze the trend in financial data. For this purpose, we collect our data from the daily historical Apple stock prices(open, high, low, close and adjusted prices) from February 1, 2002 to January 31, 2017 extracted from the Yahoo Finance website. The data has logged the prices of the Apple stock everyday and comprises of the open, close, low, high and the adjusted close prices of the stock for the span of 15 years.The goal of the project is to discover an interesting trend in the apple stock prices over the past 15 years (3775 attributes) and to design and develop the best model for forecasting.
Source: http://finance.yahoo.com/quote/AAPL/history?p=AAPL
##############################Load libraries and data########################################
library(rugarch)
library(tseries)
library(fBasics)
library(zoo)
library(lmtest)
library(forecast)
setwd("C:/Users/remya/Desktop/Depaul_4th_quarter/Time Series Analysis/Project")
apple <- read.table("day.csv",header=T, sep=',')
applets <- zoo(apple$Adj.Close, as.Date(as.character(apple$Date), format = c("%Y-%m-%d")))
#log return time series
apple_rets <- log(applets/lag(applets,-1))
#strip off the dates and create numeric object
apple_ret_num <- coredata(apple_rets)
#compute statistics
basicStats(applets)
Looking at the basic statistics of the time series of the apple stock, we observe that the mean value is not zero and the variance is very high. This indicates that the time series is non-stationary with varying mean and variance.Thus, to stationarize the process, we study the log return of the stock price. This is further confirmed by the time series, ACF and PACF plots.
1.1 *Time Series Analysis of the data:*
#Time series plot
plot(applets, type='l', ylab = " adj close price", main="Plot of 2002-2017 daily apple stock prices", col = 'red')
The time series plot appears in clusters, high in certain periods and low in certain periods.It evolves over time in a continuous manner and is thus, volatile. To attain stationarity, we find a fixed range in terms of log return of the stock prices.
#ACF and PACF plot
acf(coredata(applets), main="ACF plot of the 2002-2017 daily apple stock prices")
pacf(coredata(applets), main="PACF plot of the 2002-2017 daily apple stock prices")
From the ACF plot, we observe that the plot decays to zero slowly, meaning the shock affects the process permanently. We can conclude that we need to perform time series analysis on the daily return (log return) of the stock prices.
1.2. Time Series Analysis of log return of Apple Stock Prices:
Computing the basic statistics on applying log return of the stock prices:
#Compute statistics
basicStats(apple_rets)
## x
## nobs 3775.000000
## NAs 0.000000
## Minimum -0.197470
## Maximum 0.130194
## 1. Quartile -0.010006
## 3. Quartile 0.012837
## Mean 0.001149
## Median 0.000947
## Sum 4.336122
## SE Mean 0.000365
## LCL Mean 0.000434
## UCL Mean 0.001864
## Variance 0.000502
## Stdev 0.022410
## Skewness -0.192333
## Kurtosis 5.441411
From the basic statistics of the log return of the stock prices, we observe that the mean is 0 and the distribution of log returns has large kurtosis(fat tails). We observe this further using histogram and Q-Q plot.
#Histogram
hist(apple_rets, xlab="Daily return of stock prices", prob=TRUE, main="Histogram for daily return of stock prices")
xfit<-seq(min(apple_rets),max(apple_rets),length=40)
yfit<-dnorm(xfit,mean=mean(apple_rets),sd=sd(apple_rets))
lines(xfit, yfit, col="blue", lwd=2)
#QQ-plot
qqnorm(apple_rets)
qqline(apple_rets, col = 2)
As seen from the histogram and the QQ-plot, the series has a somewhat normal distribution with fat tails at both ends.
#Time plot of log return of prices
plot(apple_rets, type='l', ylab = "stock price return", main="Plot of 2002-2017 daily apple stock price return")
#Time plot of square of log return of prices
plot(apple_rets^2,type='l', ylab = "square of stock price return", main="Plot of 2002-2017 daily apple stock price squared return")
#Time plot of absolute value of log return of prices
plot(abs(apple_rets),type='l', ylab = "abs value of stock price return", main="Plot of 2002-2017 daily apple stock price abs return")
From the time plot we observe that the returns vary along the zero line with the largest log return of stock prices observed around 2002 having a value of -0.16, around 2009 having a value of -0.19 and around 2013 having a value of 0.13. The period after shows signs of volatility.During the years 2002, 2008-2009 and 2013, there is spike in volility indicating non-constant conditional volatility. The high volatility doesnt decrease as fast because the negative shocks have a effect on the process.
#ACF plot of log return of prices
par(mfrow=c(2,1))
acf(apple_ret_num)
#ACF plot of square of log return of prices
acf(apple_ret_num^2)
#ACF plot of absolute value of log return of prices
acf(abs(apple_ret_num))
The statistics showed that the mean was constant and nearly 0. This is further confirmed by the time series plot. The ACF plot further shows that since, the log stock price returns are not correlated, the mean is constant for the time series. However, both the squared and the absolute stock price return values have high correlation.Thus, we may conclude that the log returns process has a strong non-linear dependence.
#Test of independence
#Compute the Ljung's Box Test on stock price returns
#Ljung Box test on ret
#Box.test(apple_ret_num, lag=2, type="Ljung")
#Box.test(apple_ret_num, lag=4, type="Ljung"
#Box.test(apple_ret_num, lag=6, type="Ljung")
#Ljung Box test on squared values of the stock price returns
Box.test(apple_ret_num^2, lag=2, type="Ljung")
##
## Box-Ljung test
##
## data: apple_ret_num^2
## X-squared = 92.17, df = 2, p-value < 2.2e-16
Box.test(apple_ret_num^2, lag=4, type="Ljung")
##
## Box-Ljung test
##
## data: apple_ret_num^2
## X-squared = 161.84, df = 4, p-value < 2.2e-16
Box.test(apple_ret_num^2, lag=6, type="Ljung")
##
## Box-Ljung test
##
## data: apple_ret_num^2
## X-squared = 282.53, df = 6, p-value < 2.2e-16
#Ljung Box test on absolute values of the stock price returns
Box.test(abs(apple_ret_num), lag=2, type="Ljung")
##
## Box-Ljung test
##
## data: abs(apple_ret_num)
## X-squared = 214.65, df = 2, p-value < 2.2e-16
Box.test(abs(apple_ret_num), lag=4, type="Ljung")
##
## Box-Ljung test
##
## data: abs(apple_ret_num)
## X-squared = 384.2, df = 4, p-value < 2.2e-16
Box.test(abs(apple_ret_num), lag=6, type="Ljung")
##
## Box-Ljung test
##
## data: abs(apple_ret_num)
## X-squared = 569.79, df = 6, p-value < 2.2e-16
The null hypothesis is there exists no autocorrelation. We perform the Ljung Box’s test to test the independence of the stock return prices. From all the above Ljung Box Tests, we observe that the log returns are not correlated as the p-values>>0.05 and hence we cant reject the null hypothesis of no autocorrelation. However, it shows signs of ARCH effect on the log returns of the stock prices since the Ljung Box test on both the squared values of the stock price returns and the absolute values of the stock price returns are significant.
#Determine the order of the model
#PACF plot on the log return of the stock prices
pacf(apple_ret_num, lag=10, main="PACF plot of the log return of the stock prices")
#PACF plot on the squared return of the stock prices
pacf(apple_ret_num^2, lag=10, main="PACF plot of the squared log return of the stock prices")
#PACF plot on the absolute value of the return on the stock prices
pacf(abs(apple_ret_num), lag=10, main="PACF plot of the absolute value of the log return of the stock prices")
2.1. Model 1: AR(0)-GARCH(1,1) with normally distributed errors
garch11.spec=ugarchspec(variance.model=list(garchOrder=c(1,1)), mean.model=list(armaOrder=c(0,0)))
#estimate model
garch11.fit=ugarchfit(spec=garch11.spec, data=apple_rets)
garch11.fit
##
## *---------------------------------*
## * GARCH Model Fit *
## *---------------------------------*
##
## Conditional Variance Dynamics
## -----------------------------------
## GARCH Model : sGARCH(1,1)
## Mean Model : ARFIMA(0,0,0)
## Distribution : norm
##
## Optimal Parameters
## ------------------------------------
## Estimate Std. Error t value Pr(>|t|)
## mu 0.001698 0.000310 5.4817 0.00000
## omega 0.000005 0.000004 1.2845 0.19896
## alpha1 0.055096 0.010629 5.1836 0.00000
## beta1 0.935570 0.015662 59.7334 0.00000
##
## Robust Standard Errors:
## Estimate Std. Error t value Pr(>|t|)
## mu 0.001698 0.000411 4.12923 0.000036
## omega 0.000005 0.000027 0.19693 0.843878
## alpha1 0.055096 0.050056 1.10068 0.271036
## beta1 0.935570 0.090299 10.36084 0.000000
##
## LogLikelihood : 9297.675
##
## Information Criteria
## ------------------------------------
##
## Akaike -4.9238
## Bayes -4.9172
## Shibata -4.9238
## Hannan-Quinn -4.9215
##
## Weighted Ljung-Box Test on Standardized Residuals
## ------------------------------------
## statistic p-value
## Lag[1] 1.607 0.2049
## Lag[2*(p+q)+(p+q)-1][2] 1.953 0.2706
## Lag[4*(p+q)+(p+q)-1][5] 5.020 0.1515
## d.o.f=0
## H0 : No serial correlation
##
## Weighted Ljung-Box Test on Standardized Squared Residuals
## ------------------------------------
## statistic p-value
## Lag[1] 0.6354 0.4254
## Lag[2*(p+q)+(p+q)-1][5] 1.2891 0.7915
## Lag[4*(p+q)+(p+q)-1][9] 2.1298 0.8890
## d.o.f=2
##
## Weighted ARCH LM Tests
## ------------------------------------
## Statistic Shape Scale P-Value
## ARCH Lag[3] 0.08184 0.500 2.000 0.7748
## ARCH Lag[5] 0.86745 1.440 1.667 0.7726
## ARCH Lag[7] 1.04440 2.315 1.543 0.9062
##
## Nyblom stability test
## ------------------------------------
## Joint Statistic: 1.971
## Individual Statistics:
## mu 0.3972
## omega 0.4306
## alpha1 0.7623
## beta1 0.9807
##
## 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.5462 0.5849
## Negative Sign Bias 1.4888 0.1366
## Positive Sign Bias 0.1238 0.9015
## Joint Effect 5.7917 0.1222
##
##
## Adjusted Pearson Goodness-of-Fit Test:
## ------------------------------------
## group statistic p-value(g-1)
## 1 20 132.4 5.126e-19
## 2 30 137.1 5.483e-16
## 3 40 155.4 7.852e-16
## 4 50 160.6 8.461e-14
##
##
## Elapsed time : 0.5677001
Fitted model: r_t = 0.0016 + a_t; a_t= sigma_te_t; sigma2_t=0.00+0.055a2_(t-1)+0.9355sigma^2_(t-1) AIC value = -4.9238, BIC value = -4.9172
Residual diagnostics: Ljung Box test for white noise behaviour in residuals. Since the residuals have p-values>0.05 and we fail to reject the null hypothesis, there is no evidence of autocorrelation in the residuals.Hence, we may conclude that the residuals behave as hite noise.
Test for ARCH beaviour in residuals: Looking at the standaridized squared residuals and ARCH LM Tests, the p-values>0.05 and we fail to reject the null hypothesis hence there is no evidence of serial correlation in squared residuals. This confirms that the residuals behave as a white noise process.
Looking at the output for the goodness of fit test, since the p-values>0.05, the normal distribution assumption is strongly rejected.
#using extractors
#estimated coefficients:
coef(garch11.fit)
## mu omega alpha1 beta1
## 1.698231e-03 5.221849e-06 5.509600e-02 9.355702e-01
#unconditional mean in mean equation
uncmean(garch11.fit)
## [1] 0.001698231
#unconditional varaince: omega/(alpha1+beta1)
uncvariance(garch11.fit)
## [1] 0.000559456
#persistence = alpha1+beta1
persistence(garch11.fit)
## [1] 0.9906662
#Constraints on parameters < 1
#half-life: ln(0.5)/ln(alpha1+beta1)
halflife(garch11.fit)
## [1] 73.91495
#create selection list of plots for garch(1,1) fit
plot(garch11.fit, which = "all")
##
## please wait...calculating quantiles...
#conditional volatility plot
plot.ts(sigma(garch11.fit), ylab="sigma(t)", col="blue")
#Compute information criteria using infocriteria() function for model selecton
infocriteria(garch11.fit)
##
## Akaike -4.923802
## Bayes -4.917194
## Shibata -4.923804
## Hannan-Quinn -4.921452
2.2. Model 2: ARMA(0,0)-GARCH(1,1) model with t-distribution
garch11.t.spec=ugarchspec(variance.model=list(garchOrder=c(1,1)), mean.model=list(armaOrder=c(0,0)), distribution.model = "std")
#estimate model
garch11.t.fit=ugarchfit(spec=garch11.t.spec, data=apple_rets)
garch11.t.fit
##
## *---------------------------------*
## * GARCH Model Fit *
## *---------------------------------*
##
## Conditional Variance Dynamics
## -----------------------------------
## GARCH Model : sGARCH(1,1)
## Mean Model : ARFIMA(0,0,0)
## Distribution : std
##
## Optimal Parameters
## ------------------------------------
## Estimate Std. Error t value Pr(>|t|)
## mu 0.001402 0.000271 5.1761 0.0000
## omega 0.000002 0.000002 1.2157 0.2241
## alpha1 0.047714 0.008791 5.4277 0.0000
## beta1 0.949704 0.009202 103.2104 0.0000
## shape 4.947332 0.349167 14.1690 0.0000
##
## Robust Standard Errors:
## Estimate Std. Error t value Pr(>|t|)
## mu 0.001402 0.000309 4.54399 0.000006
## omega 0.000002 0.000007 0.33929 0.734392
## alpha1 0.047714 0.038015 1.25514 0.209427
## beta1 0.949704 0.038203 24.85936 0.000000
## shape 4.947332 0.737781 6.70569 0.000000
##
## LogLikelihood : 9474.716
##
## Information Criteria
## ------------------------------------
##
## Akaike -5.0171
## Bayes -5.0088
## Shibata -5.0171
## Hannan-Quinn -5.0141
##
## Weighted Ljung-Box Test on Standardized Residuals
## ------------------------------------
## statistic p-value
## Lag[1] 1.589 0.2075
## Lag[2*(p+q)+(p+q)-1][2] 1.893 0.2812
## Lag[4*(p+q)+(p+q)-1][5] 4.884 0.1626
## d.o.f=0
## H0 : No serial correlation
##
## Weighted Ljung-Box Test on Standardized Squared Residuals
## ------------------------------------
## statistic p-value
## Lag[1] 1.434 0.2312
## Lag[2*(p+q)+(p+q)-1][5] 2.105 0.5939
## Lag[4*(p+q)+(p+q)-1][9] 2.899 0.7755
## d.o.f=2
##
## Weighted ARCH LM Tests
## ------------------------------------
## Statistic Shape Scale P-Value
## ARCH Lag[3] 0.009988 0.500 2.000 0.9204
## ARCH Lag[5] 0.596241 1.440 1.667 0.8549
## ARCH Lag[7] 0.757044 2.315 1.543 0.9496
##
## Nyblom stability test
## ------------------------------------
## Joint Statistic: 26.1024
## Individual Statistics:
## mu 0.2208
## omega 1.9510
## alpha1 0.9242
## beta1 1.1120
## shape 1.0248
##
## 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.6262 0.53120
## Negative Sign Bias 1.5749 0.11537
## Positive Sign Bias 0.1119 0.91092
## Joint Effect 6.6928 0.08236 *
##
##
## Adjusted Pearson Goodness-of-Fit Test:
## ------------------------------------
## group statistic p-value(g-1)
## 1 20 30.56 0.04512
## 2 30 32.36 0.30423
## 3 40 54.69 0.04891
## 4 50 50.13 0.42852
##
##
## Elapsed time : 0.98194
#plot of residuals
plot(garch11.t.fit, which = "all")
##
## please wait...calculating quantiles...
persistence(garch11.t.fit)
## [1] 0.997418
#FORECASTS
#compute h-step ahead forecasts for h=1,2,...,10
#garch11.fcst=ugarchforecast(garch11.t.fit, n.ahead=12)
#garch11.fcst
#plot(garch11.fcst)
#rolling forecasts
#garch11.t.fit=ugarchfit(spec=garch11.t.spec, data=apple_rets, out.sample=500)
#garch11.fcst=ugarchforecast(garch11.t.fit, n.ahead=12, n.roll=450)
#plot(garch11.fcst)
Fitted model: 0.0014 + at, at = stet s2t = 0.00 + 0.0477a2t-1 + 0.949 s2t-1 with the t distribution of 5 degrees of freedom (4.97) The shape parameter has p-value = 0<0.05 and hence, is significant. Thus, this model could be significant and a good choice. AIC value = -5.0171 and BIC value = -5 Taking a look at the R output, in particular the weighted Ljung-Box test on squared residuals, there is no evidence of serial correlation as the p-values>0.05 and hence the null hypothesis of serial correlation can be rejected and we may conclude that the residuals behave as a white noise process. Looking at the Goodness-of-fit test, we observe that for group 20 and group 40, the p-value<0.05 and hence we can reject the null hypothesis that this model is adequate for this process.
2.3. Model 3:ARMA(0,0)-GARCH(1,1) model with skewed t-distribution
garch11.skt.spec=ugarchspec(variance.model=list(garchOrder=c(1,1)), mean.model=list(armaOrder=c(0,0)), distribution.model = "sstd")
#estimate model
garch11.skt.fit=ugarchfit(spec=garch11.skt.spec, data=apple_rets)
garch11.skt.fit
##
## *---------------------------------*
## * GARCH Model Fit *
## *---------------------------------*
##
## Conditional Variance Dynamics
## -----------------------------------
## GARCH Model : sGARCH(1,1)
## Mean Model : ARFIMA(0,0,0)
## Distribution : sstd
##
## Optimal Parameters
## ------------------------------------
## Estimate Std. Error t value Pr(>|t|)
## mu 0.001511 0.000295 5.1152 0.0000
## omega 0.000002 0.000002 1.3997 0.1616
## alpha1 0.048402 0.008144 5.9431 0.0000
## beta1 0.949044 0.008574 110.6838 0.0000
## skew 1.020025 0.022674 44.9857 0.0000
## shape 4.926545 0.357817 13.7683 0.0000
##
## Robust Standard Errors:
## Estimate Std. Error t value Pr(>|t|)
## mu 0.001511 0.000346 4.36633 0.000013
## omega 0.000002 0.000005 0.44235 0.658238
## alpha1 0.048402 0.032332 1.49703 0.134385
## beta1 0.949044 0.032329 29.35544 0.000000
## skew 1.020025 0.023980 42.53615 0.000000
## shape 4.926545 0.623423 7.90241 0.000000
##
## LogLikelihood : 9475.112
##
## Information Criteria
## ------------------------------------
##
## Akaike -5.0167
## Bayes -5.0068
## Shibata -5.0168
## Hannan-Quinn -5.0132
##
## Weighted Ljung-Box Test on Standardized Residuals
## ------------------------------------
## statistic p-value
## Lag[1] 1.603 0.2055
## Lag[2*(p+q)+(p+q)-1][2] 1.907 0.2788
## Lag[4*(p+q)+(p+q)-1][5] 4.886 0.1624
## d.o.f=0
## H0 : No serial correlation
##
## Weighted Ljung-Box Test on Standardized Squared Residuals
## ------------------------------------
## statistic p-value
## Lag[1] 1.381 0.2399
## Lag[2*(p+q)+(p+q)-1][5] 2.055 0.6055
## Lag[4*(p+q)+(p+q)-1][9] 2.848 0.7838
## d.o.f=2
##
## Weighted ARCH LM Tests
## ------------------------------------
## Statistic Shape Scale P-Value
## ARCH Lag[3] 0.01353 0.500 2.000 0.9074
## ARCH Lag[5] 0.60986 1.440 1.667 0.8508
## ARCH Lag[7] 0.76960 2.315 1.543 0.9479
##
## Nyblom stability test
## ------------------------------------
## Joint Statistic: 24.7762
## Individual Statistics:
## mu 0.2227
## omega 1.8104
## alpha1 0.9083
## beta1 1.0962
## skew 0.1580
## shape 1.0520
##
## Asymptotic Critical Values (10% 5% 1%)
## Joint Statistic: 1.49 1.68 2.12
## Individual Statistic: 0.35 0.47 0.75
##
## Sign Bias Test
## ------------------------------------
## t-value prob sig
## Sign Bias 0.6011 0.54778
## Negative Sign Bias 1.5568 0.11961
## Positive Sign Bias 0.1387 0.88971
## Joint Effect 6.5338 0.08834 *
##
##
## Adjusted Pearson Goodness-of-Fit Test:
## ------------------------------------
## group statistic p-value(g-1)
## 1 20 28.34 0.07705
## 2 30 28.88 0.47129
## 3 40 50.37 0.10499
## 4 50 54.13 0.28515
##
##
## Elapsed time : 1.481603
Fitted model: rt=0.0015 + at, at=stet s2t = 0.000002 + 0.0484a2t-1 + 0.949s2t-1, with the t-distribution of 5 degrees of freedom (4.92). Looking at the output, we observe that the skewness value has p-value = 0<0.05 and hence, is significant. Since, the skew value>1(1.02), it indicates that the t-distribution is skewed to the right. The shape value has p-value=0<.05 and is significant. We might be interested in this model for the process looking further into the output. AIC value = -5.0167 and BIC value = -5 Residual diagnostics: Ljung Box test for white noise behaviour in residuals. Since the residuals have p-values>0.05 and we fail to reject the null hypothesis, there is no evidence of autocorrelation in the residuals.Hence, we may conclude that the residuals behave as hite noise. Test for ARCH beaviour in residuals: Looking at the standaridized squared residuals and ARCH LM Tests, the p-values>0.05 and we fail to reject the null hypothesis hence there is no evidence of serial correlation in squared residuals. This confirms that the residuals behave as a white noise process. Looking at the output for the goodness of fit test, since the p-values>0.05, the null hypothesis can’t be rejected and hence this model is a good fit.
plot(garch11.skt.fit, which = "all")
##
## please wait...calculating quantiles...
2.4. Model 4: Fit ARMA(0,0)-eGARCH(1,1) model with t-distribution
egarch11.t.spec=ugarchspec(variance.model=list(model = "eGARCH", garchOrder=c(1,1)), mean.model=list(armaOrder=c(0,0)), distribution.model = "std")
#estimate model
egarch11.t.fit=ugarchfit(spec=egarch11.t.spec, data=apple_rets)
egarch11.t.fit
##
## *---------------------------------*
## * GARCH Model Fit *
## *---------------------------------*
##
## Conditional Variance Dynamics
## -----------------------------------
## GARCH Model : eGARCH(1,1)
## Mean Model : ARFIMA(0,0,0)
## Distribution : std
##
## Optimal Parameters
## ------------------------------------
## Estimate Std. Error t value Pr(>|t|)
## mu 0.001257 0.000263 4.7776 2e-06
## omega -0.124376 0.009689 -12.8374 0e+00
## alpha1 -0.051314 0.010297 -4.9832 1e-06
## beta1 0.984111 0.001234 797.5046 0e+00
## gamma1 0.155907 0.018030 8.6469 0e+00
## shape 5.173706 0.431036 12.0030 0e+00
##
## Robust Standard Errors:
## Estimate Std. Error t value Pr(>|t|)
## mu 0.001257 0.000265 4.7519 2e-06
## omega -0.124376 0.004142 -30.0262 0e+00
## alpha1 -0.051314 0.010561 -4.8586 1e-06
## beta1 0.984111 0.000560 1756.8258 0e+00
## gamma1 0.155907 0.021157 7.3690 0e+00
## shape 5.173706 0.454961 11.3718 0e+00
##
## LogLikelihood : 9498.505
##
## Information Criteria
## ------------------------------------
##
## Akaike -5.0291
## Bayes -5.0192
## Shibata -5.0291
## Hannan-Quinn -5.0256
##
## Weighted Ljung-Box Test on Standardized Residuals
## ------------------------------------
## statistic p-value
## Lag[1] 3.490 0.06173
## Lag[2*(p+q)+(p+q)-1][2] 3.703 0.09062
## Lag[4*(p+q)+(p+q)-1][5] 6.191 0.08107
## d.o.f=0
## H0 : No serial correlation
##
## Weighted Ljung-Box Test on Standardized Squared Residuals
## ------------------------------------
## statistic p-value
## Lag[1] 0.369 0.5436
## Lag[2*(p+q)+(p+q)-1][5] 2.180 0.5765
## Lag[4*(p+q)+(p+q)-1][9] 2.825 0.7875
## d.o.f=2
##
## Weighted ARCH LM Tests
## ------------------------------------
## Statistic Shape Scale P-Value
## ARCH Lag[3] 0.7800 0.500 2.000 0.3771
## ARCH Lag[5] 0.9798 1.440 1.667 0.7389
## ARCH Lag[7] 1.2023 2.315 1.543 0.8786
##
## Nyblom stability test
## ------------------------------------
## Joint Statistic: 3.3856
## Individual Statistics:
## mu 0.7760
## omega 2.3660
## alpha1 0.3465
## beta1 2.4276
## gamma1 0.3114
## shape 0.4799
##
## Asymptotic Critical Values (10% 5% 1%)
## Joint Statistic: 1.49 1.68 2.12
## Individual Statistic: 0.35 0.47 0.75
##
## Sign Bias Test
## ------------------------------------
## t-value prob sig
## Sign Bias 0.824117 0.4099
## Negative Sign Bias 0.202642 0.8394
## Positive Sign Bias 0.004475 0.9964
## Joint Effect 1.092633 0.7789
##
##
## Adjusted Pearson Goodness-of-Fit Test:
## ------------------------------------
## group statistic p-value(g-1)
## 1 20 18.56 0.4852
## 2 30 25.00 0.6781
## 3 40 35.02 0.6518
## 4 50 44.35 0.6618
##
##
## Elapsed time : 0.864526
The above R output displays an AR(0) mean model with standard Egarch(1,1) model for variance with t-distribution.We look at the alpha value and since alpha1 < 0, the leverage effect is significant and we may conclude that the volatility reacts more havily to negative shocks.
The fitted model: rt = 0.001257 + at, at=stet ln(s2t) = -0.124376 + (-0.051314et-1 + 0.155907(|et-1|-E(|et-1|)) + 0.984111ln(s2t-1)) with t-dsitribution of nearly 5 (~5.17) degrees of freedom.
The shape parameter is significant as the p-value < 0.05, indicating that the t-distibution is a good choice.
AIC value = -5.0291 and BIC value = -5.0192
Residual diagnostics: All the p-values for the Ljung Box Test of residuals are > 0.05, thus indicating that there is no evidence of serial correlation in the squared residuals and hence, they behave as white noise process.
Looking at the test for goodness-of-fit, since all the p-values > 0.05, we cant reject the null hypothesis, and hence we may conclude that the Egarch model with the t-distribution is a good choice.
plot(egarch11.t.fit, which = "all")
##
## please wait...calculating quantiles...
2.5. Model 5: Fit ARMA(0,0)-fGARCH(1,1) model with t-distribution
fgarch11.t.spec=ugarchspec(variance.model=list(model = "fGARCH", garchOrder=c(1,1), submodel = "APARCH"), mean.model=list(armaOrder=c(0,0)), distribution.model = "std")
#estimate model
fgarch11.t.fit=ugarchfit(spec=fgarch11.t.spec, data=apple_rets)
fgarch11.t.fit
##
## *---------------------------------*
## * GARCH Model Fit *
## *---------------------------------*
##
## Conditional Variance Dynamics
## -----------------------------------
## GARCH Model : fGARCH(1,1)
## fGARCH Sub-Model : APARCH
## Mean Model : ARFIMA(0,0,0)
## Distribution : std
##
## Optimal Parameters
## ------------------------------------
## Estimate Std. Error t value Pr(>|t|)
## mu 0.001260 0.000271 4.6457 0.000003
## omega 0.000296 0.000223 1.3273 0.184422
## alpha1 0.087633 0.015262 5.7419 0.000000
## beta1 0.918550 0.016306 56.3329 0.000000
## eta11 0.346117 0.072834 4.7521 0.000002
## lambda 1.046173 0.166436 6.2857 0.000000
## shape 5.156611 0.420996 12.2486 0.000000
##
## Robust Standard Errors:
## Estimate Std. Error t value Pr(>|t|)
## mu 0.001260 0.000283 4.4441 0.000009
## omega 0.000296 0.000222 1.3335 0.182361
## alpha1 0.087633 0.026790 3.2711 0.001071
## beta1 0.918550 0.029713 30.9138 0.000000
## eta11 0.346117 0.074071 4.6728 0.000003
## lambda 1.046173 0.176215 5.9369 0.000000
## shape 5.156611 0.439322 11.7377 0.000000
##
## LogLikelihood : 9496.813
##
## Information Criteria
## ------------------------------------
##
## Akaike -5.0277
## Bayes -5.0162
## Shibata -5.0277
## Hannan-Quinn -5.0236
##
## Weighted Ljung-Box Test on Standardized Residuals
## ------------------------------------
## statistic p-value
## Lag[1] 3.737 0.05322
## Lag[2*(p+q)+(p+q)-1][2] 3.935 0.07848
## Lag[4*(p+q)+(p+q)-1][5] 6.496 0.06858
## d.o.f=0
## H0 : No serial correlation
##
## Weighted Ljung-Box Test on Standardized Squared Residuals
## ------------------------------------
## statistic p-value
## Lag[1] 0.3369 0.5616
## Lag[2*(p+q)+(p+q)-1][5] 2.4387 0.5190
## Lag[4*(p+q)+(p+q)-1][9] 3.0715 0.7471
## d.o.f=2
##
## Weighted ARCH LM Tests
## ------------------------------------
## Statistic Shape Scale P-Value
## ARCH Lag[3] 0.7869 0.500 2.000 0.3750
## ARCH Lag[5] 0.9211 1.440 1.667 0.7565
## ARCH Lag[7] 1.1295 2.315 1.543 0.8916
##
## Nyblom stability test
## ------------------------------------
## Joint Statistic: 4.453
## Individual Statistics:
## mu 0.8307
## omega 2.8340
## alpha1 2.0986
## beta1 2.5423
## eta11 0.5536
## lambda 2.9911
## shape 1.2977
##
## Asymptotic Critical Values (10% 5% 1%)
## Joint Statistic: 1.69 1.9 2.35
## Individual Statistic: 0.35 0.47 0.75
##
## Sign Bias Test
## ------------------------------------
## t-value prob sig
## Sign Bias 0.7411 0.4587
## Negative Sign Bias 0.4167 0.6769
## Positive Sign Bias 0.1215 0.9033
## Joint Effect 0.9158 0.8216
##
##
## Adjusted Pearson Goodness-of-Fit Test:
## ------------------------------------
## group statistic p-value(g-1)
## 1 20 15.51 0.6896
## 2 30 30.53 0.3877
## 3 40 37.57 0.5353
## 4 50 44.83 0.6429
##
##
## Elapsed time : 3.442473
The shape parameter is significant as the p-value < 0.05, indicating that the t-distibution is a good choice.
AIC value = -5.0277 and BIC value = -5.0162
Residual diagnostics: All the p-values for the Ljung Box Test of residuals are > 0.05, thus indicating that there is no evidence of serial correlation in the squared residuals and hence, they behave as white noise process.
Looking at the test for goodness-of-fit, since all the p-values > 0.05, we cant reject the null hypothesis, and hence we may conclude that the fgarch model with the t-distribution is a good choice.
plot(fgarch11.t.fit, which = "all")
##
## please wait...calculating quantiles...
2.6. Model 6: Igarch model
igarch11.t.spec=ugarchspec(variance.model=list(model = "iGARCH", garchOrder=c(1,1)), mean.model=list(armaOrder=c(0 , 0 )), distribution.model = "std")
igarch11.t.fit=ugarchfit(spec=igarch11.t.spec, data=apple_rets)
igarch11.t.fit
##
## *---------------------------------*
## * GARCH Model Fit *
## *---------------------------------*
##
## Conditional Variance Dynamics
## -----------------------------------
## GARCH Model : iGARCH(1,1)
## Mean Model : ARFIMA(0,0,0)
## Distribution : std
##
## Optimal Parameters
## ------------------------------------
## Estimate Std. Error t value Pr(>|t|)
## mu 0.001399 0.000270 5.1736 0.00000
## omega 0.000002 0.000001 1.3846 0.16616
## alpha1 0.048650 0.006830 7.1234 0.00000
## beta1 0.951350 NA NA NA
## shape 4.806541 0.301195 15.9582 0.00000
##
## Robust Standard Errors:
## Estimate Std. Error t value Pr(>|t|)
## mu 0.001399 0.000275 5.09527 0.000000
## omega 0.000002 0.000002 0.68567 0.492919
## alpha1 0.048650 0.018257 2.66478 0.007704
## beta1 0.951350 NA NA NA
## shape 4.806541 0.328336 14.63908 0.000000
##
## LogLikelihood : 9474.428
##
## Information Criteria
## ------------------------------------
##
## Akaike -5.0174
## Bayes -5.0108
## Shibata -5.0174
## Hannan-Quinn -5.0151
##
## Weighted Ljung-Box Test on Standardized Residuals
## ------------------------------------
## statistic p-value
## Lag[1] 1.617 0.2034
## Lag[2*(p+q)+(p+q)-1][2] 1.904 0.2792
## Lag[4*(p+q)+(p+q)-1][5] 4.830 0.1672
## d.o.f=0
## H0 : No serial correlation
##
## Weighted Ljung-Box Test on Standardized Squared Residuals
## ------------------------------------
## statistic p-value
## Lag[1] 1.516 0.2182
## Lag[2*(p+q)+(p+q)-1][5] 2.194 0.5734
## Lag[4*(p+q)+(p+q)-1][9] 2.955 0.7664
## d.o.f=2
##
## Weighted ARCH LM Tests
## ------------------------------------
## Statistic Shape Scale P-Value
## ARCH Lag[3] 0.01048 0.500 2.000 0.9185
## ARCH Lag[5] 0.58407 1.440 1.667 0.8585
## ARCH Lag[7] 0.73268 2.315 1.543 0.9527
##
## Nyblom stability test
## ------------------------------------
## Joint Statistic: 14.8402
## Individual Statistics:
## mu 0.2183
## omega 3.2994
## alpha1 0.6947
## shape 0.8835
##
## 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.6315 0.5278
## Negative Sign Bias 1.5077 0.1317
## Positive Sign Bias 0.1879 0.8510
## Joint Effect 6.5789 0.0866 *
##
##
## Adjusted Pearson Goodness-of-Fit Test:
## ------------------------------------
## group statistic p-value(g-1)
## 1 20 26.16 0.1258
## 2 30 30.65 0.3823
## 3 40 45.98 0.2055
## 4 50 53.04 0.3212
##
##
## Elapsed time : 0.7192688
The shape parameter is significant as the p-value < 0.05, indicating that the t-distibution is a good choice.
AIC value = -5.0174 and BIC value = -5.0108
Residual diagnostics: All the p-values for the Ljung Box Test of residuals are > 0.05, thus indicating that there is no evidence of serial correlation in the squared residuals and hence, they behave as white noise process.
Looking at the test for goodness-of-fit, since all the p-values > 0.05, we cant reject the null hypothesis, and hence we may conclude that the igarch model with the t-distribution is a good choice.
plot(igarch11.t.fit, which = "all")
##
## please wait...calculating quantiles...
## Warning in FUN(x):
## plot-->: iGARCH newsimpact not available
Comparing results with all the possible models that are a good choice for our model, our final model is selected based on the lowest BIC value.
Model name | BIC value |
---|---|
Model 1 | -4.9172 |
Model 2 | -5 |
Model 3 | -5 |
Model 4 | -5.0192 |
Model 5 | -5.0162 |
Model 6 | -5.0108 |
From the above table, we observe that the best model is Model 4 using Egarch with t-distribution as the model has the lowest BIC value of -5.0192.
#5-step ahead forecast
library(rugarch)
#Fit ARMA(0,0)-eGARCH(1,1) model with t-distribution
egarch11.t.spec=ugarchspec(variance.model=list(model = "eGARCH", garchOrder=c(1,1)), mean.model=list(armaOrder=c(0,0)), distribution.model = "std")
#estimate model
egarch11.t.fit=ugarchfit(spec=egarch11.t.spec, data=apple_rets)
egarch11.t.fit
##
## *---------------------------------*
## * GARCH Model Fit *
## *---------------------------------*
##
## Conditional Variance Dynamics
## -----------------------------------
## GARCH Model : eGARCH(1,1)
## Mean Model : ARFIMA(0,0,0)
## Distribution : std
##
## Optimal Parameters
## ------------------------------------
## Estimate Std. Error t value Pr(>|t|)
## mu 0.001257 0.000263 4.7776 2e-06
## omega -0.124376 0.009689 -12.8374 0e+00
## alpha1 -0.051314 0.010297 -4.9832 1e-06
## beta1 0.984111 0.001234 797.5046 0e+00
## gamma1 0.155907 0.018030 8.6469 0e+00
## shape 5.173706 0.431036 12.0030 0e+00
##
## Robust Standard Errors:
## Estimate Std. Error t value Pr(>|t|)
## mu 0.001257 0.000265 4.7519 2e-06
## omega -0.124376 0.004142 -30.0262 0e+00
## alpha1 -0.051314 0.010561 -4.8586 1e-06
## beta1 0.984111 0.000560 1756.8258 0e+00
## gamma1 0.155907 0.021157 7.3690 0e+00
## shape 5.173706 0.454961 11.3718 0e+00
##
## LogLikelihood : 9498.505
##
## Information Criteria
## ------------------------------------
##
## Akaike -5.0291
## Bayes -5.0192
## Shibata -5.0291
## Hannan-Quinn -5.0256
##
## Weighted Ljung-Box Test on Standardized Residuals
## ------------------------------------
## statistic p-value
## Lag[1] 3.490 0.06173
## Lag[2*(p+q)+(p+q)-1][2] 3.703 0.09062
## Lag[4*(p+q)+(p+q)-1][5] 6.191 0.08107
## d.o.f=0
## H0 : No serial correlation
##
## Weighted Ljung-Box Test on Standardized Squared Residuals
## ------------------------------------
## statistic p-value
## Lag[1] 0.369 0.5436
## Lag[2*(p+q)+(p+q)-1][5] 2.180 0.5765
## Lag[4*(p+q)+(p+q)-1][9] 2.825 0.7875
## d.o.f=2
##
## Weighted ARCH LM Tests
## ------------------------------------
## Statistic Shape Scale P-Value
## ARCH Lag[3] 0.7800 0.500 2.000 0.3771
## ARCH Lag[5] 0.9798 1.440 1.667 0.7389
## ARCH Lag[7] 1.2023 2.315 1.543 0.8786
##
## Nyblom stability test
## ------------------------------------
## Joint Statistic: 3.3856
## Individual Statistics:
## mu 0.7760
## omega 2.3660
## alpha1 0.3465
## beta1 2.4276
## gamma1 0.3114
## shape 0.4799
##
## Asymptotic Critical Values (10% 5% 1%)
## Joint Statistic: 1.49 1.68 2.12
## Individual Statistic: 0.35 0.47 0.75
##
## Sign Bias Test
## ------------------------------------
## t-value prob sig
## Sign Bias 0.824117 0.4099
## Negative Sign Bias 0.202642 0.8394
## Positive Sign Bias 0.004475 0.9964
## Joint Effect 1.092633 0.7789
##
##
## Adjusted Pearson Goodness-of-Fit Test:
## ------------------------------------
## group statistic p-value(g-1)
## 1 20 18.56 0.4852
## 2 30 25.00 0.6781
## 3 40 35.02 0.6518
## 4 50 44.35 0.6618
##
##
## Elapsed time : 1.025902
#plot(egarch11.t.fit)
f=ugarchforecast(egarch11.t.fit, n.ahead=20)
f
##
## *------------------------------------*
## * GARCH Model Forecast *
## *------------------------------------*
## Model: eGARCH
## Horizon: 20
## Roll Steps: 0
## Out of Sample: 0
##
## 0-roll forecast [T0=2017-01-31]:
## Series Sigma
## T+1 0.001257 0.007904
## T+2 0.001257 0.008022
## T+3 0.001257 0.008139
## T+4 0.001257 0.008255
## T+5 0.001257 0.008372
## T+6 0.001257 0.008488
## T+7 0.001257 0.008605
## T+8 0.001257 0.008720
## T+9 0.001257 0.008836
## T+10 0.001257 0.008951
## T+11 0.001257 0.009066
## T+12 0.001257 0.009180
## T+13 0.001257 0.009294
## T+14 0.001257 0.009408
## T+15 0.001257 0.009521
## T+16 0.001257 0.009634
## T+17 0.001257 0.009746
## T+18 0.001257 0.009857
## T+19 0.001257 0.009969
## T+20 0.001257 0.010079
#plot(f, which="all")
#rolling forecasts
rff=ugarchfit(spec=egarch11.t.spec, data=apple_rets, out.sample=500)
rf=ugarchforecast(rff, n.ahead=20, n.roll=450)
rf
##
## *------------------------------------*
## * GARCH Model Forecast *
## *------------------------------------*
## Model: eGARCH
## Horizon: 20
## Roll Steps: 450
## Out of Sample: 20
##
## 0-roll forecast [T0=2015-02-05]:
## Series Sigma
## T+1 0.001529 0.01984
## T+2 0.001529 0.01986
## T+3 0.001529 0.01988
## T+4 0.001529 0.01991
## T+5 0.001529 0.01993
## T+6 0.001529 0.01995
## T+7 0.001529 0.01998
## T+8 0.001529 0.02000
## T+9 0.001529 0.02002
## T+10 0.001529 0.02004
## T+11 0.001529 0.02006
## T+12 0.001529 0.02008
## T+13 0.001529 0.02010
## T+14 0.001529 0.02012
## T+15 0.001529 0.02014
## T+16 0.001529 0.02016
## T+17 0.001529 0.02018
## T+18 0.001529 0.02020
## T+19 0.001529 0.02022
## T+20 0.001529 0.02024
#plot(rf, which="all")
The sigma of the forecast, is the predicted conditional volatility at time t+h and series represents the conditional mean at time t+h. The predicted mean is observed to be constant because the mean model on rt is constant. Predicted volatility converges to overall (unconditional) standard deviation of time series.
## Backtesting method to validate EGARCH model:
mod_egarch = ugarchroll(egarch11.t.spec, data = apple_rets, n.ahead = 1,
n.start = 2500, refit.every = 200, refit.window = "recursive")
mod_egarch
##
## *-------------------------------------*
## * GARCH Roll *
## *-------------------------------------*
## No.Refits : 7
## Refit Horizon : 200
## No.Forecasts : 1275
## GARCH Model : eGARCH(1,1)
## Distribution : std
##
## Forecast Density:
## Mu Sigma Skew Shape Shape(GIG) Realized
## 2012-01-06 0.0016 0.0145 0 5.8637 0 0.0104
## 2012-01-09 0.0016 0.0143 0 5.8637 0 -0.0016
## 2012-01-10 0.0016 0.0140 0 5.8637 0 0.0036
## 2012-01-11 0.0016 0.0135 0 5.8637 0 -0.0016
## 2012-01-12 0.0016 0.0132 0 5.8637 0 -0.0027
## 2012-01-13 0.0016 0.0131 0 5.8637 0 -0.0038
##
## ..........................
## Mu Sigma Skew Shape Shape(GIG) Realized
## 2017-01-24 0.0013 0.0085 0 5.2459 0 -0.0009
## 2017-01-25 0.0013 0.0084 0 5.2459 0 0.0158
## 2017-01-26 0.0013 0.0088 0 5.2459 0 0.0005
## 2017-01-27 0.0013 0.0086 0 5.2459 0 0.0001
## 2017-01-30 0.0013 0.0083 0 5.2459 0 -0.0026
## 2017-01-31 0.0013 0.0084 0 5.2459 0 -0.0023
##
## Elapsed: 12.34349 secs
# type=VaR shows VaR at 1% level: this is the tail probability.
report(mod_egarch, type="VaR", VaR.alpha = 0.01, conf.level = 0.95)
## VaR Backtest Report
## ===========================================
## Model: eGARCH-std
## Backtest Length: 1275
## Data:
##
## ==========================================
## alpha: 1%
## Expected Exceed: 12.8
## Actual VaR Exceed: 14
## Actual %: 1.1%
##
## Unconditional Coverage (Kupiec)
## Null-Hypothesis: Correct Exceedances
## LR.uc Statistic: 0.12
## LR.uc Critical: 3.841
## LR.uc p-value: 0.729
## Reject Null: NO
##
## Conditional Coverage (Christoffersen)
## Null-Hypothesis: Correct Exceedances and
## Independence of Failures
## LR.cc Statistic: NaN
## LR.cc Critical: 5.991
## LR.cc p-value: NaN
## Reject Null: NA
#risk
f
##
## *------------------------------------*
## * GARCH Model Forecast *
## *------------------------------------*
## Model: eGARCH
## Horizon: 20
## Roll Steps: 0
## Out of Sample: 0
##
## 0-roll forecast [T0=2017-01-31]:
## Series Sigma
## T+1 0.001257 0.007904
## T+2 0.001257 0.008022
## T+3 0.001257 0.008139
## T+4 0.001257 0.008255
## T+5 0.001257 0.008372
## T+6 0.001257 0.008488
## T+7 0.001257 0.008605
## T+8 0.001257 0.008720
## T+9 0.001257 0.008836
## T+10 0.001257 0.008951
## T+11 0.001257 0.009066
## T+12 0.001257 0.009180
## T+13 0.001257 0.009294
## T+14 0.001257 0.009408
## T+15 0.001257 0.009521
## T+16 0.001257 0.009634
## T+17 0.001257 0.009746
## T+18 0.001257 0.009857
## T+19 0.001257 0.009969
## T+20 0.001257 0.010079
p01=qt(0.01, 5)
p01
## [1] -3.36493
r01=100000*exp(0.001257-p01*0.007904)
r01
## [1] 102824.5