I decided to use IBM daily closing stock prices for my time series. I will use an ARIMA model, an ETS model, and a neural net model.

library(forecast)
## Warning: package 'forecast' was built under R version 3.4.4
library(fpp)
## Loading required package: fma
## Loading required package: expsmooth
## Loading required package: lmtest
## 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
## Loading required package: tseries
## Warning: package 'tseries' was built under R version 3.4.3
library(caret)
## Warning: package 'caret' was built under R version 3.4.3
## Loading required package: lattice
## Loading required package: ggplot2
library(neuralnet)
library(randomForest)
## randomForest 4.6-12
## Type rfNews() to see new features/changes/bug fixes.
## 
## Attaching package: 'randomForest'
## The following object is masked from 'package:ggplot2':
## 
##     margin
library(psych)
## 
## Attaching package: 'psych'
## The following object is masked from 'package:randomForest':
## 
##     outlier
## The following objects are masked from 'package:ggplot2':
## 
##     %+%, alpha
library(VIM)
## Loading required package: colorspace
## Loading required package: grid
## Loading required package: data.table
## Warning: package 'data.table' was built under R version 3.4.2
## VIM is ready to use. 
##  Since version 4.0.0 the GUI is in its own package VIMGUI.
## 
##           Please use the package to use the new (and old) GUI.
## Suggestions and bug-reports can be submitted at: https://github.com/alexkowa/VIM/issues
## 
## Attaching package: 'VIM'
## The following object is masked from 'package:datasets':
## 
##     sleep
library(mice)
## Warning: package 'mice' was built under R version 3.4.2
library(ResourceSelection)
## ResourceSelection 0.3-2   2017-02-28
library(corrplot)
## Warning: package 'corrplot' was built under R version 3.4.2
## corrplot 0.84 loaded
library(readr)
mydata<-read_csv("~/Dropbox/Boston College/Predictive Analytics/ibm-common-stock-closing-prices-.csv")
## Parsed with column specification:
## cols(
##   Date = col_character(),
##   `IBM common stock closing prices: daily, 29th June 1959 to 30th June 1960 (N=255)` = col_character()
## )
mydata<-mydata[-c(256,257),]
mydata$`IBM common stock closing prices: daily, 29th June 1959 to 30th June 1960 (N=255)`<-as.numeric(mydata$`IBM common stock closing prices: daily, 29th June 1959 to 30th June 1960 (N=255)`)
myts<-ts(mydata$`IBM common stock closing prices: daily, 29th June 1959 to 30th June 1960 (N=255)`,frequency=252, start=c(1959, 6))
plot(myts)

Separate the data

train<-mydata[1:205,]
train.ts<-ts(train$`IBM common stock closing prices: daily, 29th June 1959 to 30th June 1960 (N=255)`, frequency=252, start=c(1959, 06))
plot(train.ts)

test<-mydata[206:255,]
test.ts<-ts(test$`IBM common stock closing prices: daily, 29th June 1959 to 30th June 1960 (N=255)`, frequency=252, start=c(1960, 04))

ARIMA model:

myarima<-auto.arima(train.ts, seasonal=TRUE)
## Warning in value[[3L]](cond): The chosen test encountered an error, so no
## seasonal differencing is selected. Check the time series data.
myarima
## Series: train.ts 
## ARIMA(0,1,0) 
## 
## sigma^2 estimated as 20.73:  log likelihood=-598.69
## AIC=1199.37   AICc=1199.39   BIC=1202.69
forecast.arima<-forecast(myarima, h=50)
plot(forecast.arima)

accuracy(forecast.arima, test.ts)
##                       ME     RMSE      MAE         MPE      MAPE MASE
## Training set  0.05582927 4.542052 3.246073  0.00675572 0.7603812  NaN
## Test set     -1.40000000 4.171331 3.800000 -0.31545538 0.8379540  NaN
##                     ACF1 Theil's U
## Training set -0.03635491        NA
## Test set      0.31658031  1.262641
plot(residuals(forecast.arima))

Neural Net:

mynn<-nnetar(train.ts)
## Warning in nnetar(train.ts): Series too short for seasonal lags
mynn
## Series: train.ts 
## Model:  NNAR(1,1) 
## Call:   nnetar(y = train.ts)
## 
## Average of 20 networks, each of which is
## a 1-1-1 network with 4 weights
## options were - linear output units 
## 
## sigma^2 estimated as 19.64
forecast.nn<-forecast(mynn, h=50)
plot(forecast.nn)

accuracy(forecast.nn, test.ts)
##                         ME     RMSE      MAE         MPE      MAPE MASE
## Training set -1.979192e-05 4.431754 3.237049 -0.01074760 0.7591783  NaN
## Test set      1.988732e-01 3.933947 3.479817  0.03628167 0.7648000  NaN
##                      ACF1 Theil's U
## Training set -0.003471412        NA
## Test set      0.316562912  1.014224
plot(residuals(forecast.nn))

ETS:

myets<-ets(train.ts)
myets
## ETS(M,N,N) 
## 
## Call:
##  ets(y = train.ts) 
## 
##   Smoothing parameters:
##     alpha = 0.956 
## 
##   Initial states:
##     l = 445.1066 
## 
##   sigma:  0.0107
## 
##      AIC     AICc      BIC 
## 1715.973 1716.093 1725.942
forecast.ets<-forecast(myets, h=50)
plot(forecast.ets)

accuracy(forecast.ets, test.ts)
##                      ME     RMSE      MAE          MPE      MAPE MASE
## Training set  0.0573883 4.538119 3.245134  0.006850941 0.7602190  NaN
## Test set     -1.7536724 4.302949 3.870734 -0.393259785 0.8541158  NaN
##                     ACF1 Theil's U
## Training set 0.002178629        NA
## Test set     0.316580311  1.334474
plot(residuals(forecast.ets))

Results: The Neural Net model performed the best in terms of MAE, RMSE, and MAPE. The ETS and ARIMA model were very similar, however. These were rather simple predictive models but it just shows that simple models can still perform well.