Advanced Statistics with R code 90% doen just check it and make a summary
EXPLORATORY ANALYSIS
nobs 469.000000
NAs 0.000000
Minimum -0.166652
Maximum 0.164808
1. Quartile -0.022391
3. Quartile 0.029000
Mean 0.003843
Median 0.005614
Sum 1.802469
SE Mean 0.002079
LCL Mean -0.000242
UCL Mean 0.007929
Variance 0.002027
Stdev 0.045027
Skewness -0.040829
Kurtosis 1.569306
Title:
Jarque - Bera Normalality Test
Test Results:STATISTIC:X-squared: 49.4632P VALUE:Asymptotic p Value: 1.816e-11
The distribution of log(returns) is not normal distribution, with symmetry close to 0 but kurtosis statistics is 1.5 which is far from normal distribution statistic. The Jarque-Bera test is significant (p-value < 0.05) indicating that hypothesis of normal distribution for log(returns) can be rejected.
The following plot is time series plot of weekly price of Google shares which shows increasing trend.
( Time series Plot of Google Prices )
![]()
Time plot of returns show that google stock returns shows periods of high volatility at various times. Most returns are between +/- 10%. Sample moments show that distribution of log returns is somewhat symmetric with very thin tails (kurtosis = 1.56). There is various times where the returns produce +/-15% with higher volatility also. Volatility doesn’t seem to die down quickly and it continues for a while after a volatile period.
![]()
To check null hypothesis of non stationarity:
Dickey Fuller Test is expressed as H0: φ1=1 vs Ha: φ1<>1 where the null hypothesis indicates unit-root non-stationarity.
The Dickey-Fuller test shows that the earnings time series is unit-root stationary. The test p-values for lags 7 is less than 0.05, therefore the null hypothesis of non stationarity can be rejected (small p-values< 0.05).
Augmented Dickey-Fuller TestTest Results:PARAMETER:Lag Order: 7STATISTIC:Dickey-Fuller: -7.1331P VALUE:0.01alternative hypothesis: stationary
ACF TESTS
The ACF plots below show the Google stock returns are not correlated indicating a constant mean model for rt. Both the squared returns time series and the absolute time series show large autocorrelations. We can conclude that the log returns process has a strong non-linear dependence.
![]()
Ljung Box testing for ARCH effects for Lags of 6-12-18 for squared returns and absolute returns
Box-Ljung testdata: coredata(rets^2)X-squared = 48.3339, df = 6, p-value = 1.013e-08Box-Ljung testdata: coredata(rets^2)X-squared = 71.9976, df = 12, p-value = 1.352e-10Box-Ljung testdata: coredata(rets^2)X-squared = 98.7945, df = 18, p-value = 3.68e-13
The Ljung Box tests confirm that the Ljung Box tests on the squared returns are autocorrelated. The analysis shows a strong ARCH effect. The squared returns are strongly correlated. The Ljung-Box tests on squared residuals are highly significant with p-values < 0.005, and autocorrelation plots shows large autocorrelations for the first 18 lags.
Plot of PACF: There is no correlation till lag 13 which shows there is no AR lag.
![]()
MODEL FITTING
*---------------------------------** GARCH Model Fit **---------------------------------*Conditional Variance Dynamics-----------------------------------GARCH Model : sGARCH(1,1)Mean Model : ARFIMA(0,0,0)Distribution : stdOptimal Parameters------------------------------------Estimate Std. Error t value Pr(>|t|)mu 0.004432 0.001778 2.4924 0.012689omega 0.000103 0.000053 1.9574 0.050295alpha1 0.094169 0.032716 2.8784 0.003997beta1 0.856326 0.044635 19.1850 0.000000shape 6.797338 2.000925 3.3971 0.000681
To fit an ARMA(0,0)-GARCH(2,1) model for the log returns using a normal distribution for the error terms:
Fitted Model:
with 7 degrees of freedom
Residual Analysis
Q-Statistics on Standardized Residuals------------------------------------statistic p-valueLag[1] 0.0339 0.8539Lag[p+q+1][1] 0.0339 0.8539Lag[p+q+5][5] 2.4766 0.7800d.o.f=0H0 : No serial correlationQ-Statistics on Standardized Squared Residuals------------------------------------statistic p-valueLag[1] 0.1274 0.7212Lag[p+q+1][3] 1.4245 0.2327Lag[p+q+5][7] 3.4346 0.6333d.o.f=2Above output shows there is no evidence of autocorrelation in residuals. They behave like white noise. Also, there is no evidence of serial correlation in squared residuals. They also behave like white noise.
Adjusted Pearson Goodness-of-Fit Test:------------------------------------group statistic p-value(g-1)1 20 8465 02 30 13148 03 40 17834 04 50 22521 0
Test for Goodness of fit. Normal Distribution rejected.
To fit ARMA(0,0)-eGARCH(1,1) model with Gaussian distribution:
Conditional Variance Dynamics-----------------------------------GARCH Model : eGARCH(1,1)Mean Model : ARFIMA(0,0,0)Distribution : normOptimal Parameters------------------------------------Estimate Std. Error t value Pr(>|t|)mu 0.004814 0.001837 2.6205 0.008780omega -0.427600 0.165861 -2.5781 0.009936alpha1 -0.086690 0.033886 -2.5583 0.010518beta1 0.931657 0.026273 35.4604 0.000000gamma1 0.177187 0.048248 3.6724 0.000240
Fitted Model is:
Residual Analysis:
Q-Statistics on Standardized Residuals------------------------------------statistic p-valueLag[1] 0.03655 0.8484Lag[p+q+1][1] 0.03655 0.8484Lag[p+q+5][5] 2.73813 0.7403d.o.f=0H0 : No serial correlationQ-Statistics on Standardized Squared Residuals------------------------------------statistic p-valueLag[1] 0.2255 0.6348Lag[p+q+1][3] 2.6812 0.1015Lag[p+q+5][7] 4.1362 0.5300d.o.f=2ARCH LM Tests------------------------------------Statistic DoF P-ValueARCH Lag[2] 2.224 2 0.3290ARCH Lag[5] 4.682 5 0.4559ARCH Lag[10] 7.053 10 0.7204Above output shows there is no evidence of autocorrelation in residuals. They behave like white noise. Also, there is no evidence of serial correlation in squared residuals. They also behave like white noise.
Adjusted Pearson Goodness-of-Fit Test:------------------------------------group statistic p-value(g-1)1 20 26.65 0.11312 30 32.04 0.31793 40 43.67 0.27984 50 47.74 0.5243Above output shows that error terms are normally distributed as all the P values are greater than 0.05.
To fit ARMA(0,0)-tGARCH(1,1) model with Gaussian distribution:
Conditional Variance Dynamics-----------------------------------GARCH Model : gjrGARCH(2,1)Mean Model : ARFIMA(0,0,0)Distribution : normOptimal Parameters------------------------------------Estimate Std. Error t value Pr(>|t|)mu 0.004928 0.001860 2.649926 0.008051omega 0.000120 0.000053 2.257334 0.023987alpha1 0.000000 0.000877 0.000011 0.999991alpha2 0.072854 0.037335 1.951388 0.051011beta1 0.828559 0.053752 15.414339 0.000000gamma1 0.397469 0.144242 2.755564 0.005859gamma2 -0.315459 0.131445 -2.399922 0.016399Fitted Model is:
Residual Analysis:
Q-Statistics on Standardized Residuals------------------------------------statistic p-valueLag[1] 0.2311 0.6307Lag[p+q+1][1] 0.2311 0.6307Lag[p+q+5][5] 2.9412 0.7090d.o.f=0H0 : No serial correlationQ-Statistics on Standardized Squared Residuals------------------------------------statistic p-valueLag[1] 2.137 0.14380Lag[p+q+1][4] 4.191 0.04063Lag[p+q+5][8] 4.680 0.45620d.o.f=3ARCH LM Tests------------------------------------Statistic DoF P-ValueARCH Lag[2] 2.461 2 0.2921ARCH Lag[5] 4.904 5 0.4277ARCH Lag[10] 7.140 10 0.7122Above output shows there is no evidence of autocorrelation in residuals. They behave like white noise. Also, there is no evidence of serial correlation in squared residuals. They also behave like white noise.
Adjusted Pearson Goodness-of-Fit Test:------------------------------------group statistic p-value(g-1)1 20 20.00 0.39472 30 32.43 0.30143 40 30.87 0.82034 50 54.56 0.2714
Above output shows that error terms are normally distributed as all the P values are greater than 0.05.
BEST FIT FOR THE MODEL:
garch11 egarch11 gjrgarch11Akaike -3.479720 -3.455538 -3.474405Bayes -3.435471 -3.411288 -3.412455Shibata -3.479944 -3.455762 -3.474841Hannan-Quinn -3.462310 -3.438127 -3.450030From above output it can be said that AR(0)-EGARCH(1,1) have the (smallest) values for all best fit criterion and hence can be considered as best model.
Forecast Analysis:
RE-FIT MODELS LEAVING 100 OUT-OF-SAMPLE OBSERVATIONS FOR FORECAST and EVALUATE STATISTICS for 5 Step Ahead Forecast.
garch11 egarch11 tgarch21 |
MSE 0.000950199 0.0009498531 0.0009499473 |
MAE 0.02257449 0.0225407 0.02255243 |
DAC 0.6 0.6 0.6 |
Since MSE is smallest for eGARCH model. We should consider this model for forecasting.
CODE:
#Tomas Georgakopoulos CSC 425 Final Project
setwd("C:/Course/CSC425")
# Analysis of Google weekly returns from
library(forecast)
library(TSA)
# import data in R and compute log returns
# import libraries for TS analysis
library(zoo)
library(tseries)
myd= read.table('Weekly-GOOG-TSDATA.csv', header=T, sep=',')
pricets = zoo(myd$price, as.Date(as.character(myd$date), format=c("%m/%d/%Y")))
#log return time series
rets = log(pricets/lag(pricets, -1))
# strip off the dates and just create a simple numeric object
ret = coredata(rets);
#compute statistics
library(fBasics)
basicStats(rets)
#HISTOGRAM
par(mfcol=c(1,2))
hist(rets, xlab="Weekly Returns", prob=TRUE, main="Histogram")
#Add approximating normal density curve
xfit<-seq(min(rets,na.rm=TRUE),max(rets,na.rm=TRUE),length=40)
yfit<-dnorm(xfit,mean=mean(rets,na.rm=TRUE),sd=sd(rets,na.rm=TRUE))
lines(xfit, yfit, col="blue", lwd=2)
#CREATE NORMAL PROBABILITY PLOT
qqnorm(rets)
qqline(rets, col = 'red', lwd=2)
# creates time plot of log returns
par(mfrow=c(1,1))
plot(rets)
#Perform Jarque-Bera normality test.
normalTest(rets,method=c('jb'))
#SKEWNESS TEST
skew_test=skewness(rets)/sqrt(6/length(rets))
skew_test
print("P-value = ")
2*(1-pnorm(abs(skew_test)))
#FAT-TAIL TEST
k_stat = kurtosis(rets)/sqrt(24/length(rets))
print("Kurtosis test statistic")
k_stat
print("P-value = ")
2*(1-pnorm(abs(k_stat)))
#COMPUTE DICKEY-FULLER TEST
library(fUnitRoots)
adfTest(rets, lags=7, type=c("c"))
# Computes Ljung-Box test on squared returns to test non-linear independence at lag 6 and 12
Box.test(coredata(rets^2),lag=6,type='Ljung')
Box.test(coredata(rets^2),lag=12,type='Ljung')
Box.test(coredata(rets^2),lag=18,type='Ljung')
# Computes Ljung-Box test on absolute returns to test non-linear independence at lag 6 and 12
Box.test(abs(coredata(rets)),lag=6,type='Ljung')
Box.test(abs(coredata(rets)),lag=12,type='Ljung')
Box.test(abs(coredata(rets)),lag=18,type='Ljung')
# Plots ACF function of vector data
par(mfrow=c(3,1))
acf(ret)
# Plot ACF of squared returns to check for ARCH effect
acf(ret^2)
# Plot ACF of absolute returns to check for ARCH effect
acf(abs(ret))
#plot returns, square returns and abs(returns)
# Plots ACF function of vector data
par(mfrow=c(3,1))
plot(rets, type='l')
# Plot ACF of squared returns to check for ARCH effect
plot(rets^2,type='l')
# Plot ACF of absolute returns to check for ARCH effect
plot(abs(rets),type='l')
par(mfrow=c(1,1))
# plots PACF of squared returns to identify order of AR model
pacf(coredata(rets),lag=30)
#GARCH Models
library(rugarch)
#Fit AR(0,0)-GARCH(1,1) model
garch11.spec=ugarchspec(variance.model=list(garchOrder=c(1,1)), mean.model=list(armaOrder=c(0,0)),distribution.model = "std")
#estimate model
garch11.fit=ugarchfit(spec=garch11.spec, data=rets)
garch11.fit
#Fit AR(0,0)-eGARCH(1,1) model with Gaussian distribution
egarch11.spec=ugarchspec(variance.model=list(model = "eGARCH",garchOrder=c(1,1)), mean.model=list(armaOrder=c(0,0)))
#estimate model
egarch11.fit=ugarchfit(spec=egarch11.spec, data=rets)
egarch11.fit
#Fit AR(0,0)-TGARCH(1,1) model with norm-distribution
gjrgarch11.spec=ugarchspec(variance.model=list(model = "gjrGARCH",garchOrder=c(2,1)), mean.model=list(armaOrder=c(0,0)), distribution.model = "norm")
#estimate model
gjrgarch11.fit=ugarchfit(spec=gjrgarch11.spec, data=rets)
gjrgarch11.fit
# compare information criteria
model.list = list(garch11 = garch11.fit,
egarch11 = egarch11.fit,
gjrgarch11 = gjrgarch11.fit)
info.mat = sapply(model.list, infocriteria)
rownames(info.mat) = rownames(infocriteria(garch11.fit))
info.mat
# RE-FIT MODELS LEAVING 100 OUT-OF-SAMPLE OBSERVATIONS FOR FORECAST
# EVALUATION STATISTICS
garch11.fit = ugarchfit(spec=garch11.spec, data=rets, out.sample=100)
egarch11.fit = ugarchfit(egarch11.spec, data=rets, out.sample=100)
tgarch11.fit = ugarchfit(spec=gjrgarch11.spec, data=rets, out.sample=100)
garch11.fcst = ugarchforecast(garch11.fit, n.roll=100, n.ahead=1)
egarch11.fcst = ugarchforecast(egarch11.fit, n.roll=100, n.ahead=1)
tgarch11.fcst = ugarchforecast(tgarch11.fit, n.roll=100, n.ahead=1)
fcst.list = list(garch11=garch11.fcst,
egarch11=egarch11.fcst,
tgarch21=tgarch11.fcst)
fpm.mat = sapply(fcst.list, fpm)
fpm.mat