Packaging
library(readxl)
library(TSA)
##
## Attaching package: 'TSA'
## The following objects are masked from 'package:stats':
##
## acf, arima
## The following object is masked from 'package:utils':
##
## tar
library(tseries)
## Registered S3 method overwritten by 'quantmod':
## method from
## as.zoo.data.frame zoo
library(forecast)
## Warning: package 'forecast' was built under R version 4.0.3
## Registered S3 methods overwritten by 'forecast':
## method from
## fitted.Arima TSA
## plot.Arima TSA
library(lattice)
library(ggplot2)
library(lattice)
library(StatDA)
## Loading required package: sgeostat
##
## Attaching package: 'sgeostat'
## The following object is masked from 'package:TSA':
##
## lagplot
## Registered S3 method overwritten by 'geoR':
## method from
## plot.variogram sgeostat
library(rugarch)
## Warning: package 'rugarch' was built under R version 4.0.3
## Loading required package: parallel
##
## Attaching package: 'rugarch'
## The following object is masked from 'package:stats':
##
## sigma
Data Import
#Import from excel
Data<- read_excel("C:/Users/User/Documents/BAS/SEM 7 (AUG 2020)/MAT 2014 Time Series & Forecasting/Assesment/NINTENDO data.xlsx")
View(Data)
Stock_data<-Data[,c(1,6)]
View(Stock_data)
#Obtaining Daily Returns
returns <- diff(log(Stock_data$`Adj Close`))
DATA ANALYSIS
Data Visualisation
NINTENDO Stock Price Movements
ggplot(data = Stock_data, aes(x = Date, y = `Adj Close`)) + geom_line(colour = "blue", size = 0.5) + labs(title = "Daily NINTENDO Index Prices from 2015 to 2020", x = "Date", y = "Adjusted Closing Price")

NINTENDO Daily Returns
ts.plot(returns, gpars = list(xlab="Time", ylab = "Daily Returns (%)", main = "Daily APPLE Stock Returns from 2015 to 2020"))

Density of NINTENDO Daily Returns
hist(returns, col = "lightblue", border = "black", prob = TRUE, ylim = c(0, 25), xlab = "Daily Returns (%)", main = "Density of Daily NINTENDO Stock Returns")
lines(density(returns), lwd = 2, col = "red")

Analysis of Annual Data Pattern
#Format Conversion for Dates
Stock_data$Date <- as.Date (Stock_data$Date, formal = "%d/%m/%y")
str(Stock_data)
## tibble [1,258 x 2] (S3: tbl_df/tbl/data.frame)
## $ Date : Date[1:1258], format: "2015-10-28" "2015-10-29" ...
## $ Adj Close: num [1:1258] 22.3 19.7 18.5 18.7 18.6 ...
#Formatting Date for Grouping Collective Purpose
Year <- format(Stock_data$Date, "%y")
Day <- format(Stock_data$Date, "%d")
Date <- data.frame(Day, Year, c(returns,NA))
Boxplot for NINTENDO Daily Returns in Annual Terms
Date %>%
ggplot(aes(x = frequency(c(returns,NA)),y = c(returns,NA))) + geom_boxplot(fill = "Blue") +
facet_wrap( ~ Year) +
labs(y = "Daily Returns (%)", x = "Day") +
theme_bw(base_size = 10) +
scale_x_discrete(breaks = 0)
## Warning: Removed 1 rows containing non-finite values (stat_boxplot).

Scatterplot for NINTENDO Daily Returns in Annual Terms
Date %>%
ggplot(aes(x = Day, y = c(returns,NA))) + geom_point(color = "blue") +
facet_wrap( ~ Year) +
labs(y = "Daily Returns (%)", x = "Day") +
theme_bw(base_size = 10) +
scale_x_discrete(breaks = c(0,50,100,150,200,250,300))
## Warning: Removed 1 rows containing missing values (geom_point).

Density of NINTENDO Daily Returns in Annual Terms
Date %>%
ggplot(aes(x = c(returns,NA)), y = frequency(c(returns,NA))) + geom_density(fill = "lightblue") +
facet_wrap( ~ Year) +
labs(x = "Daily Returns (%)", y = "Density") +
theme_bw(base_size = 10)
## Warning: Removed 1 rows containing non-finite values (stat_density).

QQ-Plot of NINTENDO Daily Returns
qqplot.das(returns, distribution = "norm", ylab = "Sample quantiles",
xlab = "Theoretical Quantiles", main = "Normal Q-Q Plot NINTENDO Daily Returns (2015 - 2020)", las = par("las"),
datax = FALSE, envelope = 0.95, labels = FALSE, col = "red",
lwd = 2, pch = 20,line = c("quartiles","robust","none"), cex = 1,
xaxt = "s", add.plot = FALSE, xlim = NULL, ylim = NULL)

LINEAR MODELLING
Test of Stationarity
Observation on Initial Data
Method 1: Analysis of Sample ACF and PACF
acf(log(Stock_data$`Adj Close`), main="ACF of Stock Returns")

pacf(log(Stock_data$`Adj Close`), main="PACF of Stock Returns")

Method 2: Statistical Analysis
Augmented Dicky-Fuller Test
#H0: Data is non-stationary
#H1: Data is stationary
adf.test(log(Stock_data$`Adj Close`))
##
## Augmented Dickey-Fuller Test
##
## data: log(Stock_data$`Adj Close`)
## Dickey-Fuller = -1.9546, Lag order = 10, p-value = 0.5975
## alternative hypothesis: stationary
Kwiatkowski–Phillips–Schmidt–Shin (KPSS) Test
#H0: Data is stationary
#H1: Data is non-stationary
kpss.test(log(Stock_data$`Adj Close`))
## Warning in kpss.test(log(Stock_data$`Adj Close`)): p-value smaller than printed
## p-value
##
## KPSS Test for Level Stationarity
##
## data: log(Stock_data$`Adj Close`)
## KPSS Level = 11.127, Truncation lag parameter = 7, p-value = 0.01
Observation on First Order Differenced Data
Method 1: Analysis of Sample ACF and PACF
diff.data <- diff(log(Stock_data$`Adj Close`))
acf(diff.data, main="ACF of Differenced Stock Returns")

pacf(diff.data, main="PACF of Differenced Stock Returns")

Method 2: Statistical Analysis
Augmented Dicky-Fuller Test
#H0: Data is non-stationary
#H1: Data is stationary
adf.test(diff.data)
## Warning in adf.test(diff.data): p-value smaller than printed p-value
##
## Augmented Dickey-Fuller Test
##
## data: diff.data
## Dickey-Fuller = -11.78, Lag order = 10, p-value = 0.01
## alternative hypothesis: stationary
Kwiatkowski–Phillips–Schmidt–Shin (KPSS) Test
#H0: Data is stationary
#H1: Data is non-stationary
kpss.test(diff.data)
## Warning in kpss.test(diff.data): p-value greater than printed p-value
##
## KPSS Test for Level Stationarity
##
## data: diff.data
## KPSS Level = 0.052507, Truncation lag parameter = 7, p-value = 0.1
Model Building with Estimation of Parameters (Box-Jenkins)
Modelling with Stationary Time Series Model
Model X : ARMA(3,3)/ARIMA(3,0,3)
ModelX <- Arima(diff.data, order = c(3,0,3), method = "ML")
summary(ModelX)
## Series: diff.data
## ARIMA(3,0,3) with non-zero mean
##
## Coefficients:
## ar1 ar2 ar3 ma1 ma2 ma3 mean
## -0.4475 0.3452 0.0828 0.4680 -0.3228 -0.0167 9e-04
## s.e. 0.8709 0.2432 0.5559 0.8693 0.2645 0.5659 8e-04
##
## sigma^2 estimated as 0.0006703: log likelihood=2812.78
## AIC=-5609.57 AICc=-5609.45 BIC=-5568.48
##
## Training set error measures:
## ME RMSE MAE MPE MAPE MASE ACF1
## Training set -2.105835e-05 0.02581891 0.01727354 NaN Inf 0.698422 0.0004579641
Casuality and Invertibility Test for Model X
#The coefficients of Autoregressive Models and Moving Average models should fall within the unit root, |z| </= 1
autoplot(ModelX)

Modelling with Non-Stationary Time Series Model
Model Y : ARIMA(3,1,3)
ModelY <- Arima(log(Stock_data$`Adj Close`), order = c(3,1,3), method = "ML")
summary(ModelY)
## Series: log(Stock_data$`Adj Close`)
## ARIMA(3,1,3)
##
## Coefficients:
## ar1 ar2 ar3 ma1 ma2 ma3
## -0.4947 0.3119 0.0853 0.5169 -0.2842 -0.0181
## s.e. 0.5996 0.2713 0.3737 0.6011 0.2851 0.3821
##
## sigma^2 estimated as 0.0006704: log likelihood=2812.27
## AIC=-5610.55 AICc=-5610.46 BIC=-5574.59
##
## Training set error measures:
## ME RMSE MAE MPE MAPE MASE
## Training set 0.0007751898 0.02581927 0.01725727 0.01884125 0.4961705 1.002079
## ACF1
## Training set -0.001702803
Casuality and Invertibility Test for Model Y
#The coefficients of Autoregressive Models and Moving Average models should fall within the unit root, |z| </= 1
autoplot(ModelY)

Statistical Comparison for Both Models
Statistics <- c("Log-likelihood", "AICc")
Statistics
## [1] "Log-likelihood" "AICc"
#Statistics obtained ffrom Model X
ModelX.stats <- c(ModelX$loglik, ModelX$aicc)
ModelX.stats
## [1] 2812.784 -5609.452
##Statistics obtained ffrom Model Y
ModelY.stats <- c(ModelY$loglik, ModelY$aicc)
ModelY.stats
## [1] 2812.274 -5610.458
Model.Statistics <- data.frame(Statistics, ModelX.stats, ModelY.stats)
View(Model.Statistics)
NON-LINEAR MODELLING
Test of Non-Linearlity
Residual Check for ARIMA(3,1,3)
checkresiduals(ModelY)

##
## Ljung-Box test
##
## data: Residuals from ARIMA(3,1,3)
## Q* = 14.462, df = 4, p-value = 0.005957
##
## Model df: 6. Total lags used: 10
White Noise Modelling
Model_w.noise <- Arima(returns, order = c(0,0,0))
Model_w.noise.stats <- c(Model_w.noise$loglik, Model_w.noise$aicc)
Model_w.noise.stats
## [1] 2808.007 -5612.005
Residual Check for White Noise Model [ARIMA(0,1,0)]
checkresiduals(Model_w.noise)

##
## Ljung-Box test
##
## data: Residuals from ARIMA(0,0,0) with non-zero mean
## Q* = 25.52, df = 9, p-value = 0.002447
##
## Model df: 1. Total lags used: 10
Analysis of Properties of White Noise Model
Residual Plots
#Ordinary Residuals
plot(Model_w.noise$residuals, main="Residuals Plot")

#Squared Residuals
plot(Model_w.noise$residuals^2, main = "Squared Residuals Plot")

Test of IID Properties of White Noise (Independence and Identical Distribution)
Sample ACF & PACF of Absolute Residuals
residuals.abs <- abs(Model_w.noise$residuals)
acf(residuals.abs, main="ACF of Absolute Residuals")

pacf(residuals.abs, main="PACF of Absolute Residuals")

Sample ACF & PACF of Squared Residuals
residuals.squared <- (Model_w.noise$residuals^2)
acf(residuals.squared, main="ACF of Squared Residuals")

pacf(residuals.squared, main="PACF of Squared Residuals")

Modelling of Varying Volatility
ARCH Modelling
Model A: ARCH(1)
arch1 <- ugarchspec(variance.model=list(model = "sGARCH", garchOrder=c(1,0)), mean.model=list(armaOrder=c(0,0)), distribution.model = "std")
ModelA <- ugarchfit(spec=arch1, data=log(Stock_data$`Adj Close`))
ModelA
##
## *---------------------------------*
## * GARCH Model Fit *
## *---------------------------------*
##
## Conditional Variance Dynamics
## -----------------------------------
## GARCH Model : sGARCH(1,0)
## Mean Model : ARFIMA(0,0,0)
## Distribution : std
##
## Optimal Parameters
## ------------------------------------
## Estimate Std. Error t value Pr(>|t|)
## mu 3.813183 0.004268 893.3513 0.000000
## omega 0.000327 0.000056 5.8433 0.000000
## alpha1 0.999000 0.043680 22.8708 0.000000
## shape 99.999997 31.792539 3.1454 0.001659
##
## Robust Standard Errors:
## Estimate Std. Error t value Pr(>|t|)
## mu 3.813183 0.022844 166.9238 0.00000
## omega 0.000327 0.000086 3.8268 0.00013
## alpha1 0.999000 0.013872 72.0136 0.00000
## shape 99.999997 3.698647 27.0369 0.00000
##
## LogLikelihood : 338.6632
##
## Information Criteria
## ------------------------------------
##
## Akaike -0.53206
## Bayes -0.51572
## Shibata -0.53208
## Hannan-Quinn -0.52592
##
## Weighted Ljung-Box Test on Standardized Residuals
## ------------------------------------
## statistic p-value
## Lag[1] 1045 0
## Lag[2*(p+q)+(p+q)-1][2] 1535 0
## Lag[4*(p+q)+(p+q)-1][5] 2949 0
## d.o.f=0
## H0 : No serial correlation
##
## Weighted Ljung-Box Test on Standardized Squared Residuals
## ------------------------------------
## statistic p-value
## Lag[1] 0.02204 0.88198
## Lag[2*(p+q)+(p+q)-1][2] 0.27251 0.81121
## Lag[4*(p+q)+(p+q)-1][5] 7.39883 0.04146
## d.o.f=1
##
## Weighted ARCH LM Tests
## ------------------------------------
## Statistic Shape Scale P-Value
## ARCH Lag[2] 0.4993 0.500 2.000 0.4797884
## ARCH Lag[4] 0.8543 1.397 1.611 0.7532674
## ARCH Lag[6] 17.5924 2.222 1.500 0.0001621
##
## Nyblom stability test
## ------------------------------------
## Joint Statistic: 130.3439
## Individual Statistics:
## mu 1.89882
## omega 0.05847
## alpha1 0.83625
## shape 74.07729
##
## 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.4368 0.6624
## Negative Sign Bias 0.2069 0.8361
## Positive Sign Bias 0.2444 0.8070
## Joint Effect 0.1912 0.9790
##
##
## Adjusted Pearson Goodness-of-Fit Test:
## ------------------------------------
## group statistic p-value(g-1)
## 1 20 4486 0
## 2 30 5671 0
## 3 40 6743 0
## 4 50 5947 0
##
##
## Elapsed time : 1.200736
GARCH Modelling
Model B: GARCH(1,1)
garch11 <- ugarchspec(variance.model=list(model = "sGARCH", garchOrder=c(1,1)), mean.model=list(armaOrder=c(0,0)), distribution.model = "std")
ModelB <- ugarchfit(spec=garch11, data=log(Stock_data$`Adj Close`))
ModelB
##
## *---------------------------------*
## * 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 3.815347 0.004050 942.0154 0.000000
## omega 0.000206 0.000059 3.5080 0.000451
## alpha1 0.844693 0.086563 9.7581 0.000000
## beta1 0.154307 0.080892 1.9076 0.056446
## shape 99.999992 31.383686 3.1864 0.001441
##
## Robust Standard Errors:
## Estimate Std. Error t value Pr(>|t|)
## mu 3.815347 0.021458 177.8087 0.000000
## omega 0.000206 0.000092 2.2375 0.025256
## alpha1 0.844693 0.106328 7.9442 0.000000
## beta1 0.154307 0.109879 1.4043 0.160217
## shape 99.999992 3.739829 26.7392 0.000000
##
## LogLikelihood : 340.8123
##
## Information Criteria
## ------------------------------------
##
## Akaike -0.53388
## Bayes -0.51346
## Shibata -0.53391
## Hannan-Quinn -0.52621
##
## Weighted Ljung-Box Test on Standardized Residuals
## ------------------------------------
## statistic p-value
## Lag[1] 1052 0
## Lag[2*(p+q)+(p+q)-1][2] 1540 0
## Lag[4*(p+q)+(p+q)-1][5] 2945 0
## d.o.f=0
## H0 : No serial correlation
##
## Weighted Ljung-Box Test on Standardized Squared Residuals
## ------------------------------------
## statistic p-value
## Lag[1] 2.762 9.653e-02
## Lag[2*(p+q)+(p+q)-1][5] 13.094 1.433e-03
## Lag[4*(p+q)+(p+q)-1][9] 30.466 3.254e-07
## d.o.f=2
##
## Weighted ARCH LM Tests
## ------------------------------------
## Statistic Shape Scale P-Value
## ARCH Lag[3] 1.128 0.500 2.000 2.882e-01
## ARCH Lag[5] 25.797 1.440 1.667 7.342e-07
## ARCH Lag[7] 33.400 2.315 1.543 2.039e-08
##
## Nyblom stability test
## ------------------------------------
## Joint Statistic: 107.9688
## Individual Statistics:
## mu 1.77809
## omega 0.14371
## alpha1 1.04921
## beta1 0.05608
## shape 69.97415
##
## 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.10186 0.9189
## Negative Sign Bias 0.28435 0.7762
## Positive Sign Bias 0.01684 0.9866
## Joint Effect 0.08156 0.9940
##
##
## Adjusted Pearson Goodness-of-Fit Test:
## ------------------------------------
## group statistic p-value(g-1)
## 1 20 4461 0
## 2 30 5910 0
## 3 40 6811 0
## 4 50 6399 0
##
##
## Elapsed time : 0.9855351
ARMA-GARCH Modelling
Model C: ARMA(1,0) - GARCH(1,1)
arma10.garch11 <- ugarchspec(variance.model=list(model = "sGARCH", garchOrder=c(1,1)), mean.model=list(armaOrder=c(1,0)), distribution.model = "std")
ModelC <- ugarchfit(spec=arma10.garch11, data=log(Stock_data$`Adj Close`))
ModelC
##
## *---------------------------------*
## * GARCH Model Fit *
## *---------------------------------*
##
## Conditional Variance Dynamics
## -----------------------------------
## GARCH Model : sGARCH(1,1)
## Mean Model : ARFIMA(1,0,0)
## Distribution : std
##
## Optimal Parameters
## ------------------------------------
## Estimate Std. Error t value Pr(>|t|)
## mu 3.104350 0.026843 115.6497 0.000000
## ar1 1.000000 0.000831 1203.2255 0.000000
## omega 0.000114 0.000035 3.2691 0.001079
## alpha1 0.183092 0.048659 3.7628 0.000168
## beta1 0.619956 0.087614 7.0760 0.000000
## shape 4.755350 0.629239 7.5573 0.000000
##
## Robust Standard Errors:
## Estimate Std. Error t value Pr(>|t|)
## mu 3.104350 0.001380 2249.6600 0.000000
## ar1 1.000000 0.000801 1248.1748 0.000000
## omega 0.000114 0.000047 2.4166 0.015668
## alpha1 0.183092 0.056670 3.2308 0.001234
## beta1 0.619956 0.113539 5.4603 0.000000
## shape 4.755350 0.756975 6.2820 0.000000
##
## LogLikelihood : 3042.344
##
## Information Criteria
## ------------------------------------
##
## Akaike -4.8273
## Bayes -4.8028
## Shibata -4.8273
## Hannan-Quinn -4.8180
##
## Weighted Ljung-Box Test on Standardized Residuals
## ------------------------------------
## statistic p-value
## Lag[1] 0.02456 0.8755
## Lag[2*(p+q)+(p+q)-1][2] 0.24194 0.9975
## Lag[4*(p+q)+(p+q)-1][5] 0.47909 0.9945
## d.o.f=1
## H0 : No serial correlation
##
## Weighted Ljung-Box Test on Standardized Squared Residuals
## ------------------------------------
## statistic p-value
## Lag[1] 0.01551 0.9009
## Lag[2*(p+q)+(p+q)-1][5] 0.07057 0.9991
## Lag[4*(p+q)+(p+q)-1][9] 0.18143 1.0000
## d.o.f=2
##
## Weighted ARCH LM Tests
## ------------------------------------
## Statistic Shape Scale P-Value
## ARCH Lag[3] 0.001369 0.500 2.000 0.9705
## ARCH Lag[5] 0.044385 1.440 1.667 0.9958
## ARCH Lag[7] 0.128103 2.315 1.543 0.9989
##
## Nyblom stability test
## ------------------------------------
## Joint Statistic: 2.1246
## Individual Statistics:
## mu 0.2318
## ar1 0.1758
## omega 0.8854
## alpha1 0.2503
## beta1 0.4886
## shape 0.2254
##
## 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.06642 0.9471
## Negative Sign Bias 0.80626 0.4202
## Positive Sign Bias 0.36356 0.7162
## Joint Effect 0.86489 0.8339
##
##
## Adjusted Pearson Goodness-of-Fit Test:
## ------------------------------------
## group statistic p-value(g-1)
## 1 20 32.33 0.02865
## 2 30 30.09 0.40941
## 3 40 43.05 0.30207
## 4 50 46.77 0.56402
##
##
## Elapsed time : 0.884037
Model D: ARMA(0,1) - GARCH(1,1)
arma01.garch11 <- ugarchspec(variance.model=list(model = "sGARCH", garchOrder=c(1,1)), mean.model=list(armaOrder=c(0,1)), distribution.model = "std")
ModelD <- ugarchfit(spec=arma01.garch11, data=log(Stock_data$`Adj Close`))
ModelD
##
## *---------------------------------*
## * GARCH Model Fit *
## *---------------------------------*
##
## Conditional Variance Dynamics
## -----------------------------------
## GARCH Model : sGARCH(1,1)
## Mean Model : ARFIMA(0,0,1)
## Distribution : std
##
## Optimal Parameters
## ------------------------------------
## Estimate Std. Error t value Pr(>|t|)
## mu 3.807522 0.005027 757.4728 0.000000
## ma1 0.877761 0.011041 79.4979 0.000000
## omega 0.000049 0.000020 2.5046 0.012258
## alpha1 0.315749 0.042231 7.4767 0.000000
## beta1 0.683251 0.040095 17.0408 0.000000
## shape 99.999969 33.355639 2.9980 0.002718
##
## Robust Standard Errors:
## Estimate Std. Error t value Pr(>|t|)
## mu 3.807522 0.022539 168.9269 0.000000
## ma1 0.877761 0.013378 65.6128 0.000000
## omega 0.000049 0.000021 2.2767 0.022805
## alpha1 0.315749 0.033174 9.5181 0.000000
## beta1 0.683251 0.033497 20.3974 0.000000
## shape 99.999969 3.290185 30.3934 0.000000
##
## LogLikelihood : 970.968
##
## Information Criteria
## ------------------------------------
##
## Akaike -1.5341
## Bayes -1.5096
## Shibata -1.5342
## Hannan-Quinn -1.5249
##
## Weighted Ljung-Box Test on Standardized Residuals
## ------------------------------------
## statistic p-value
## Lag[1] 615.4 0
## Lag[2*(p+q)+(p+q)-1][2] 1134.2 0
## Lag[4*(p+q)+(p+q)-1][5] 2306.2 0
## d.o.f=1
## H0 : No serial correlation
##
## Weighted Ljung-Box Test on Standardized Squared Residuals
## ------------------------------------
## statistic p-value
## Lag[1] 85.8 0
## Lag[2*(p+q)+(p+q)-1][5] 344.2 0
## Lag[4*(p+q)+(p+q)-1][9] 418.7 0
## d.o.f=2
##
## Weighted ARCH LM Tests
## ------------------------------------
## Statistic Shape Scale P-Value
## ARCH Lag[3] 48.06 0.500 2.000 4.142e-12
## ARCH Lag[5] 116.90 1.440 1.667 0.000e+00
## ARCH Lag[7] 143.78 2.315 1.543 0.000e+00
##
## Nyblom stability test
## ------------------------------------
## Joint Statistic: 160.8115
## Individual Statistics:
## mu 6.1208
## ma1 2.0742
## omega 0.1985
## alpha1 0.3140
## beta1 0.2284
## shape 104.8517
##
## 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.8092 0.41856
## Negative Sign Bias 1.3096 0.19056
## Positive Sign Bias 1.9999 0.04573 **
## Joint Effect 5.8217 0.12061
##
##
## Adjusted Pearson Goodness-of-Fit Test:
## ------------------------------------
## group statistic p-value(g-1)
## 1 20 1782 0
## 2 30 2099 0
## 3 40 2128 0
## 4 50 2184 0
##
##
## Elapsed time : 1.363618
Model E: ARMA(1,1) - GARCH(1,1)
arma11.garch11 <- ugarchspec(variance.model=list(model = "sGARCH", garchOrder=c(1,1)), mean.model=list(armaOrder=c(1,1)), distribution.model = "std")
ModelE <- ugarchfit(spec=arma11.garch11, data=log(Stock_data$`Adj Close`))
ModelE
##
## *---------------------------------*
## * GARCH Model Fit *
## *---------------------------------*
##
## Conditional Variance Dynamics
## -----------------------------------
## GARCH Model : sGARCH(1,1)
## Mean Model : ARFIMA(1,0,1)
## Distribution : std
##
## Optimal Parameters
## ------------------------------------
## Estimate Std. Error t value Pr(>|t|)
## mu 3.103531 0.026622 116.57921 0.000000
## ar1 1.000000 0.000814 1228.47772 0.000000
## ma1 -0.025256 0.030778 -0.82058 0.411888
## omega 0.000115 0.000035 3.26978 0.001076
## alpha1 0.181501 0.048753 3.72286 0.000197
## beta1 0.619634 0.088017 7.03992 0.000000
## shape 4.712446 0.623977 7.55227 0.000000
##
## Robust Standard Errors:
## Estimate Std. Error t value Pr(>|t|)
## mu 3.103531 0.002221 1397.65539 0.000000
## ar1 1.000000 0.000807 1239.59264 0.000000
## ma1 -0.025256 0.034911 -0.72343 0.469416
## omega 0.000115 0.000047 2.43288 0.014979
## alpha1 0.181501 0.056686 3.20189 0.001365
## beta1 0.619634 0.112970 5.48493 0.000000
## shape 4.712446 0.760499 6.19652 0.000000
##
## LogLikelihood : 3042.682
##
## Information Criteria
## ------------------------------------
##
## Akaike -4.8262
## Bayes -4.7976
## Shibata -4.8263
## Hannan-Quinn -4.8155
##
## Weighted Ljung-Box Test on Standardized Residuals
## ------------------------------------
## statistic p-value
## Lag[1] 0.6897 0.4063
## Lag[2*(p+q)+(p+q)-1][5] 1.1614 0.9999
## Lag[4*(p+q)+(p+q)-1][9] 3.4792 0.8055
## d.o.f=2
## H0 : No serial correlation
##
## Weighted Ljung-Box Test on Standardized Squared Residuals
## ------------------------------------
## statistic p-value
## Lag[1] 0.01605 0.8992
## Lag[2*(p+q)+(p+q)-1][5] 0.07952 0.9988
## Lag[4*(p+q)+(p+q)-1][9] 0.18890 0.9999
## d.o.f=2
##
## Weighted ARCH LM Tests
## ------------------------------------
## Statistic Shape Scale P-Value
## ARCH Lag[3] 0.0008337 0.500 2.000 0.9770
## ARCH Lag[5] 0.0449409 1.440 1.667 0.9958
## ARCH Lag[7] 0.1254713 2.315 1.543 0.9990
##
## Nyblom stability test
## ------------------------------------
## Joint Statistic: 2.0346
## Individual Statistics:
## mu 0.0004837
## ar1 0.1946883
## ma1 0.1095580
## omega 0.8838482
## alpha1 0.2598446
## beta1 0.4925559
## shape 0.2341833
##
## 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.06104 0.9513
## Negative Sign Bias 0.78312 0.4337
## Positive Sign Bias 0.39157 0.6954
## Joint Effect 0.83564 0.8409
##
##
## Adjusted Pearson Goodness-of-Fit Test:
## ------------------------------------
## group statistic p-value(g-1)
## 1 20 21.05 0.3343
## 2 30 29.00 0.4653
## 3 40 38.53 0.4909
## 4 50 52.73 0.3319
##
##
## Elapsed time : 1.557701
Model F: ARMA(2,2) - GARCH(1,1)
arma22.garch11 <- ugarchspec(variance.model=list(model = "sGARCH", garchOrder=c(1,1)), mean.model=list(armaOrder=c(2,2)), distribution.model = "std")
ModelF <- ugarchfit(spec=arma22.garch11, data=log(Stock_data$`Adj Close`))
ModelF
##
## *---------------------------------*
## * GARCH Model Fit *
## *---------------------------------*
##
## Conditional Variance Dynamics
## -----------------------------------
## GARCH Model : sGARCH(1,1)
## Mean Model : ARFIMA(2,0,2)
## Distribution : std
##
## Optimal Parameters
## ------------------------------------
## Estimate Std. Error t value Pr(>|t|)
## mu 2.990271 0.019590 152.64627 0.000000
## ar1 1.337361 0.000588 2272.92847 0.000000
## ar2 -0.337038 0.000529 -637.07460 0.000000
## ma1 -0.366366 0.029907 -12.25018 0.000000
## ma2 -0.018627 0.028237 -0.65968 0.509460
## omega 0.000104 0.000033 3.16766 0.001537
## alpha1 0.177396 0.047805 3.71081 0.000207
## beta1 0.641773 0.085617 7.49589 0.000000
## shape 4.793445 0.643167 7.45287 0.000000
##
## Robust Standard Errors:
## Estimate Std. Error t value Pr(>|t|)
## mu 2.990271 0.007575 394.74831 0.000000
## ar1 1.337361 0.000407 3284.64493 0.000000
## ar2 -0.337038 0.000273 -1232.82972 0.000000
## ma1 -0.366366 0.033765 -10.85042 0.000000
## ma2 -0.018627 0.026667 -0.69852 0.484849
## omega 0.000104 0.000045 2.30909 0.020939
## alpha1 0.177396 0.057231 3.09965 0.001937
## beta1 0.641773 0.113901 5.63450 0.000000
## shape 4.793445 0.786664 6.09339 0.000000
##
## LogLikelihood : 3047.191
##
## Information Criteria
## ------------------------------------
##
## Akaike -4.8302
## Bayes -4.7934
## Shibata -4.8303
## Hannan-Quinn -4.8164
##
## Weighted Ljung-Box Test on Standardized Residuals
## ------------------------------------
## statistic p-value
## Lag[1] 0.5697 0.45036
## Lag[2*(p+q)+(p+q)-1][11] 7.3122 0.01932
## Lag[4*(p+q)+(p+q)-1][19] 12.9835 0.11073
## d.o.f=4
## H0 : No serial correlation
##
## Weighted Ljung-Box Test on Standardized Squared Residuals
## ------------------------------------
## statistic p-value
## Lag[1] 0.0243 0.8761
## Lag[2*(p+q)+(p+q)-1][5] 0.1091 0.9978
## Lag[4*(p+q)+(p+q)-1][9] 0.2469 0.9999
## d.o.f=2
##
## Weighted ARCH LM Tests
## ------------------------------------
## Statistic Shape Scale P-Value
## ARCH Lag[3] 4.324e-06 0.500 2.000 0.9983
## ARCH Lag[5] 4.921e-02 1.440 1.667 0.9952
## ARCH Lag[7] 1.619e-01 2.315 1.543 0.9982
##
## Nyblom stability test
## ------------------------------------
## Joint Statistic: 1.8201
## Individual Statistics:
## mu 0.0005568
## ar1 0.0794009
## ar2 0.0783156
## ma1 0.0910450
## ma2 0.0688264
## omega 0.8313086
## alpha1 0.3028205
## beta1 0.4870160
## shape 0.2218937
##
## Asymptotic Critical Values (10% 5% 1%)
## Joint Statistic: 2.1 2.32 2.82
## Individual Statistic: 0.35 0.47 0.75
##
## Sign Bias Test
## ------------------------------------
## t-value prob sig
## Sign Bias 0.2140 0.8306
## Negative Sign Bias 0.7041 0.4815
## Positive Sign Bias 0.6252 0.5320
## Joint Effect 1.1126 0.7740
##
##
## Adjusted Pearson Goodness-of-Fit Test:
## ------------------------------------
## group statistic p-value(g-1)
## 1 20 21.90 0.28903
## 2 30 35.86 0.17758
## 3 40 53.29 0.06332
## 4 50 64.97 0.06286
##
##
## Elapsed time : 1.203249
Statistical Analysis on Non-Linear Modellings
#Model A: GARCH(1,0)
#Model B: GARCH(1,1)
#Model C: ARMA(1,0)-GARCH(1,1)
#Model D: ARMA(0,1)-GARCH(1,1)
#Model E: ARMA(1,1)-GARCH(1,1)
#Model F: ARMA(2,2)-GARCH(1,1)
nonlinear.statistics <- data.frame("Statistics" = c("Akaike", "Bayes", "Shibata", "Hannan-Quinn"),"ModelA" = c(infocriteria(ModelA)),"ModelB" = c(infocriteria(ModelB)),"ModelC" = c(infocriteria(ModelC)),"ModelD" = c(infocriteria(ModelD)), "ModelE" = c(infocriteria(ModelE)), "ModelF" = c(infocriteria(ModelF)))
nonlinear.statistics
## Statistics ModelA ModelB ModelC ModelD ModelE ModelF
## 1 Akaike -0.5320559 -0.5338829 -4.827256 -1.534130 -4.826204 -4.830192
## 2 Bayes -0.5157212 -0.5134644 -4.802754 -1.509628 -4.797618 -4.793439
## 3 Shibata -0.5320760 -0.5339143 -4.827302 -1.534176 -4.826265 -4.830293
## 4 Hannan-Quinn -0.5259171 -0.5262093 -4.818048 -1.524922 -4.815461 -4.816379
View(nonlinear.statistics)
FORECASTING
Forecasting Linear Time Series Model (Model Y)
#Forecast of ModelY - ARIMA (3,1,3)
ModelY_f.cast <- forecast::forecast(ModelY, h = 10)
ModelY_f.cast
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## 1259 4.181208 4.148027 4.214389 4.130462 4.231954
## 1260 4.179460 4.132011 4.226909 4.106893 4.252027
## 1261 4.180084 4.121433 4.238735 4.090385 4.269783
## 1262 4.179211 4.110046 4.248375 4.073432 4.284989
## 1263 4.179689 4.101801 4.257576 4.060570 4.298807
## 1264 4.179233 4.093021 4.265445 4.047383 4.311083
## 1265 4.179533 4.085984 4.273082 4.036462 4.322604
## 1266 4.179283 4.078712 4.279854 4.025473 4.333094
## 1267 4.179461 4.072465 4.286458 4.015824 4.343098
## 1268 4.179321 4.066156 4.292486 4.006250 4.352391
#Graph of Forecast for ARIMA (3,1,3)
plot(ModelY_f.cast, xlim = c(1250, 1270), ylim = c(3.75, 4.75))

Forecasting Non-Linear Time Series Model (Model C)
ModelC_f.cast <- ugarchboot(ModelC, n.ahead = 10, method = c("Partial", "Full")[1])
ModelC_f.cast
##
## *-----------------------------------*
## * GARCH Bootstrap Forecast *
## *-----------------------------------*
## Model : sGARCH
## n.ahead : 10
## Bootstrap method: partial
## Date (T[0]): 1973-06-12 07:30:00
##
## Series (summary):
## min q.25 mean q.75 max forecast[analytic]
## t+1 4.0784 4.1720 4.1816 4.1908 4.2938 4.1814
## t+2 4.0669 4.1678 4.1835 4.1973 4.3755 4.1814
## t+3 4.0635 4.1667 4.1850 4.2035 4.4419 4.1814
## t+4 4.0362 4.1616 4.1852 4.2092 4.4350 4.1814
## t+5 3.9988 4.1554 4.1838 4.2107 4.4943 4.1814
## t+6 4.0115 4.1514 4.1835 4.2118 4.5571 4.1814
## t+7 3.9923 4.1514 4.1860 4.2167 4.5492 4.1814
## t+8 3.9198 4.1494 4.1873 4.2196 4.5938 4.1814
## t+9 3.8835 4.1497 4.1879 4.2207 4.5635 4.1814
## t+10 3.8832 4.1470 4.1874 4.2227 4.4884 4.1814
## .....................
##
## Sigma (summary):
## min q0.25 mean q0.75 max forecast[analytic]
## t+1 0.019084 0.019084 0.019084 0.019084 0.019084 0.019084
## t+2 0.018436 0.018522 0.019832 0.020044 0.051478 0.020164
## t+3 0.018024 0.018477 0.020718 0.020997 0.086860 0.020990
## t+4 0.017764 0.018618 0.021145 0.021801 0.074812 0.021631
## t+5 0.017612 0.018752 0.021556 0.022413 0.059939 0.022133
## t+6 0.017605 0.019096 0.022050 0.022690 0.094756 0.022527
## t+7 0.017525 0.019249 0.022114 0.023045 0.076371 0.022839
## t+8 0.017499 0.019245 0.022218 0.023255 0.065319 0.023087
## t+9 0.017500 0.019322 0.022384 0.023283 0.083414 0.023283
## t+10 0.017621 0.019338 0.022367 0.023487 0.066554 0.023440
## .....................
plot(ModelC_f.cast, which = 2)

Forecasting Non-Linear Time Series Model (Model E)
ModelE_f.cast <- ugarchboot(ModelE, n.ahead = 10, method = c("Partial", "Full")[1])
ModelE_f.cast
##
## *-----------------------------------*
## * GARCH Bootstrap Forecast *
## *-----------------------------------*
## Model : sGARCH
## n.ahead : 10
## Bootstrap method: partial
## Date (T[0]): 1973-06-12 07:30:00
##
## Series (summary):
## min q.25 mean q.75 max forecast[analytic]
## t+1 4.0781 4.1719 4.1821 4.1934 4.2380 4.1815
## t+2 4.0149 4.1678 4.1851 4.2018 4.2893 4.1815
## t+3 4.0110 4.1650 4.1848 4.2052 4.3063 4.1815
## t+4 4.0115 4.1620 4.1866 4.2101 4.3791 4.1815
## t+5 3.9831 4.1582 4.1867 4.2141 4.3920 4.1815
## t+6 3.9724 4.1563 4.1878 4.2177 4.3971 4.1815
## t+7 3.9646 4.1545 4.1893 4.2262 4.6387 4.1815
## t+8 3.9509 4.1491 4.1907 4.2295 4.7295 4.1815
## t+9 3.9456 4.1510 4.1923 4.2311 4.8034 4.1815
## t+10 3.9485 4.1501 4.1926 4.2323 4.7852 4.1815
## .....................
##
## Sigma (summary):
## min q0.25 mean q0.75 max forecast[analytic]
## t+1 0.019170 0.019170 0.019170 0.019170 0.019170 0.019170
## t+2 0.018518 0.018618 0.019961 0.020326 0.047770 0.020239
## t+3 0.018104 0.018716 0.020833 0.021386 0.053659 0.021057
## t+4 0.017851 0.018874 0.021165 0.021875 0.057849 0.021690
## t+5 0.017709 0.018875 0.021761 0.022406 0.083694 0.022184
## t+6 0.017683 0.019136 0.021999 0.023266 0.069637 0.022572
## t+7 0.017609 0.019201 0.021959 0.023295 0.057533 0.022878
## t+8 0.017581 0.019162 0.022563 0.023479 0.164250 0.023120
## t+9 0.017620 0.019321 0.022914 0.023762 0.136604 0.023312
## t+10 0.017620 0.019276 0.023102 0.023867 0.112865 0.023465
## .....................
plot(ModelE_f.cast, which = 2)

Forecasting Non-Linear Time Series Model (Model F)
ModelF_f.cast <- ugarchboot(ModelF, n.ahead = 10, method = c("Partial", "Full")[1])
ModelF_f.cast
##
## *-----------------------------------*
## * GARCH Bootstrap Forecast *
## *-----------------------------------*
## Model : sGARCH
## n.ahead : 10
## Bootstrap method: partial
## Date (T[0]): 1973-06-12 07:30:00
##
## Series (summary):
## min q.25 mean q.75 max forecast[analytic]
## t+1 4.1234 4.1721 4.1833 4.1927 4.2946 4.1829
## t+2 4.0774 4.1674 4.1849 4.2005 4.3833 4.1838
## t+3 4.0625 4.1643 4.1858 4.2064 4.4532 4.1845
## t+4 4.0770 4.1625 4.1867 4.2071 4.5588 4.1851
## t+5 4.0465 4.1615 4.1884 4.2123 4.5602 4.1857
## t+6 4.0168 4.1583 4.1879 4.2136 4.5984 4.1863
## t+7 3.9802 4.1580 4.1885 4.2193 4.5558 4.1869
## t+8 3.9437 4.1559 4.1901 4.2250 4.6196 4.1874
## t+9 3.9432 4.1554 4.1916 4.2249 4.6710 4.1880
## t+10 3.8847 4.1562 4.1925 4.2317 4.6163 4.1886
## .....................
##
## Sigma (summary):
## min q0.25 mean q0.75 max forecast[analytic]
## t+1 0.019177 0.019177 0.019177 0.019177 0.019177 0.019177
## t+2 0.018451 0.018553 0.020004 0.020564 0.050561 0.020141
## t+3 0.017970 0.018522 0.020874 0.021311 0.092904 0.020898
## t+4 0.017654 0.018594 0.021286 0.022004 0.092263 0.021498
## t+5 0.017456 0.018630 0.021552 0.022020 0.100293 0.021978
## t+6 0.017399 0.018717 0.021684 0.022472 0.090527 0.022363
## t+7 0.017327 0.018830 0.021793 0.022722 0.074106 0.022673
## t+8 0.017430 0.018910 0.021827 0.022736 0.062410 0.022925
## t+9 0.017303 0.019222 0.022228 0.023281 0.090581 0.023129
## t+10 0.017315 0.019186 0.022389 0.023218 0.086243 0.023294
## .....................
plot(ModelF_f.cast, which = 2)
