library(forecast)
## Warning: package 'forecast' was built under R version 3.4.2
library(tseries)
## Warning: package 'tseries' was built under R version 3.4.3
library(xts)
## Warning: package 'xts' was built under R version 3.4.3
## Loading required package: zoo
## Warning: package 'zoo' was built under R version 3.4.3
##
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
##
## as.Date, as.Date.numeric
library(readr)
fbdata<-read_csv("~/Dropbox/Boston College/Predictive Analytics/FB.csv")
## Parsed with column specification:
## cols(
## Date = col_character(),
## Open = col_double(),
## High = col_double(),
## Low = col_double(),
## Close = col_double(),
## `Adj Close` = col_double(),
## Volume = col_integer()
## )
myts<-ts(fbdata$`Adj Close`, frequency=252, start=c(2013,1))
plot(myts, ylab="Adj Close")
#Train and test set
train<-myts[1:1008]
test<-myts[1009:1260]
We will compare the Garch model to the ARIMA model with no regressor since it performed best last week:
myarima<-auto.arima(train)
forecast<-forecast(myarima, h=252)
accuracy<-accuracy(forecast, test)
accuracy
## ME RMSE MAE MPE MAPE
## Training set -0.0001940347 1.491104 1.038689 -0.0275405 1.363181
## Test set 12.6790085282 15.420789 13.869541 7.2571026 8.019694
## MASE ACF1
## Training set 0.9930499 -0.001307305
## Test set 13.2601279 NA
plot(forecast)
Now fit the Garch model:
library(fGarch)
## Warning: package 'fGarch' was built under R version 3.4.2
## Loading required package: timeDate
## Warning: package 'timeDate' was built under R version 3.4.3
## Loading required package: timeSeries
## Warning: package 'timeSeries' was built under R version 3.4.2
##
## Attaching package: 'timeSeries'
## The following object is masked from 'package:zoo':
##
## time<-
## Loading required package: fBasics
## Warning: package 'fBasics' was built under R version 3.4.2
mygarch<-garch(train, trace=FALSE)
1
## [1] 1
plot(mygarch)
#forecast.garch<-forecast(mygarch, n.ahead=252)
#accuracy2<-accuracy(forecast.garch, test)
#accuracy2
#plot(forecast.garch)
I could not figure out how to forecast this garch model and kept recieving an error when using the forecast function. I will keep working on it later this week and hopefully post my results in here, but for now this is all I have.