Load Data

library(forecast)
## Warning: package 'forecast' was built under R version 3.4.4
library(vars)
## Loading required package: MASS
## Loading required package: strucchange
## 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: sandwich
## Loading required package: urca
## Loading required package: lmtest
library(readr)
BAC <- read_csv("~/Dropbox/Boston College/Predictive Analytics/Data/BAC.csv")
## Parsed with column specification:
## cols(
##   Date = col_date(format = ""),
##   Open = col_character(),
##   High = col_character(),
##   Low = col_character(),
##   Close = col_character(),
##   `Adj Close` = col_character(),
##   Volume = col_character()
## )
JPM <- read_csv("~/Dropbox/Boston College/Predictive Analytics/Data/JPM.csv")
## Parsed with column specification:
## cols(
##   Date = col_date(format = ""),
##   Open = col_character(),
##   High = col_character(),
##   Low = col_character(),
##   Close = col_character(),
##   `Adj Close` = col_character(),
##   Volume = col_character()
## )
stocks<-data.frame(BAC$`Adj Close`, JPM$`Adj Close`)
stocks<-stocks[-c(1),] #null first value
myts<-ts(stocks, start=c(2013, 5), end=c(2018,4), frequency=12)

Evaluate Time Series

par(mfrow=c(1,1))
plot(myts)

VAR model

myvar<-VARselect(myts, lag.max = 8, type="const")
myvar
## $selection
## AIC(n)  HQ(n)  SC(n) FPE(n) 
##      1      1      1      1 
## 
## $criteria
##                  1           2           3           4            5
## AIC(n)    8.731625    8.869370    8.983451    9.099650     9.249192
## HQ(n)     8.817939    9.013228    9.184852    9.358594     9.565679
## SC(n)     8.956768    9.244609    9.508786    9.775081    10.074718
## FPE(n) 6197.374948 7119.282257 7996.343680 9015.403205 10531.894346
##                   6            7            8
## AIC(n)     9.370237     9.496912     9.628016
## HQ(n)      9.744268     9.928485    10.117133
## SC(n)     10.345859    10.622629    10.903830
## FPE(n) 11990.723491 13775.058527 15960.002376
var<-VAR(myts, p=1, lag.max=8, type="const")
summary(var)
## 
## VAR Estimation Results:
## ========================= 
## Endogenous variables: BAC..Adj.Close., JPM..Adj.Close. 
## Deterministic variables: const 
## Sample size: 59 
## Log Likelihood: -413.951 
## Roots of the characteristic polynomial:
## 0.9086 0.8694
## Call:
## VAR(y = myts, p = 1, type = "const", lag.max = 8)
## 
## 
## Estimation results for equation BAC..Adj.Close.: 
## ================================================ 
## BAC..Adj.Close. = BAC..Adj.Close..l1 + JPM..Adj.Close..l1 + const 
## 
##                     Estimate Std. Error t value Pr(>|t|)    
## BAC..Adj.Close..l1  0.882392   0.068060  12.965   <2e-16 ***
## JPM..Adj.Close..l1 -0.002789   0.066717  -0.042   0.9668    
## const               4.427160   2.553584   1.734   0.0885 .  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## 
## Residual standard error: 8.224 on 56 degrees of freedom
## Multiple R-Squared: 0.773,   Adjusted R-squared: 0.7649 
## F-statistic: 95.37 on 2 and 56 DF,  p-value: < 2.2e-16 
## 
## 
## Estimation results for equation JPM..Adj.Close.: 
## ================================================ 
## JPM..Adj.Close. = BAC..Adj.Close..l1 + JPM..Adj.Close..l1 + const 
## 
##                    Estimate Std. Error t value Pr(>|t|)    
## BAC..Adj.Close..l1 -0.12216    0.07652  -1.597   0.1160    
## JPM..Adj.Close..l1  0.89558    0.07501  11.940   <2e-16 ***
## const               6.68892    2.87098   2.330   0.0234 *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## 
## Residual standard error: 9.246 on 56 degrees of freedom
## Multiple R-Squared: 0.7281,  Adjusted R-squared: 0.7184 
## F-statistic: 74.98 on 2 and 56 DF,  p-value: < 2.2e-16 
## 
## 
## 
## Covariance matrix of residuals:
##                 BAC..Adj.Close. JPM..Adj.Close.
## BAC..Adj.Close.           67.64           32.51
## JPM..Adj.Close.           32.51           85.50
## 
## Correlation matrix of residuals:
##                 BAC..Adj.Close. JPM..Adj.Close.
## BAC..Adj.Close.          1.0000          0.4275
## JPM..Adj.Close.          0.4275          1.0000
serial.test(var, lags.pt=8, type="PT.asymptotic")
## 
##  Portmanteau Test (asymptotic)
## 
## data:  Residuals of VAR object var
## Chi-squared = 5.573, df = 28, p-value = 1

We see a correlation of 0.4275 of the residuals, meaning they are not significantly correlated.

Forecast

forecast<-forecast(var, h=12)
forecast
## BAC..Adj.Close.
##          Point Forecast    Lo 80    Hi 80     Lo 95    Hi 95
## May 2018       54.71235 44.17260 65.25210 38.593187 70.83151
## Jun 2018       52.69568 38.64867 66.74268 31.212638 74.17872
## Jul 2018       50.91713 34.65941 67.17485 26.053090 75.78117
## Aug 2018       49.34792 31.56005 67.13579 22.143716 76.55212
## Sep 2018       47.96280 29.06961 66.85598 19.068164 76.85743
## Oct 2018       46.73963 27.02834 66.45092 16.593813 76.88545
## Nov 2018       45.65900 25.33268 65.98531 14.572583 76.74541
## Dec 2018       44.70386 23.91022 65.49750 12.902730 76.50499
## Jan 2019       43.85925 22.70776 65.01074 11.510832 76.20767
## Feb 2019       43.11204 21.68492 64.53916 10.342085 75.88199
## Mar 2019       42.45068 20.81030 64.09105  9.354582 75.54678
## Apr 2019       41.86504 20.05906 63.67101  8.515681 75.21439
## 
## JPM..Adj.Close.
##          Point Forecast      Lo 80    Hi 80     Lo 95    Hi 95
## May 2018       3.307881  -8.541883 15.15764 -14.81477 21.43053
## Jun 2018       2.967500 -12.621472 18.55647 -20.87378 26.80878
## Jul 2018       2.909027 -14.981062 20.79912 -24.45150 30.26956
## Aug 2018       3.073935 -16.413654 22.56152 -26.72976 32.87763
## Sep 2018       3.413324 -17.265730 24.09238 -28.21256 35.03921
## Oct 2018       3.886487 -17.729067 25.50204 -29.17165 36.94462
## Nov 2018       4.459671 -17.922119 26.84146 -29.77032 38.68966
## Dec 2018       5.105018 -17.922833 28.13287 -30.11304 40.32308
## Jan 2019       5.799662 -17.784754 29.38408 -30.26959 41.86891
## Feb 2019       6.524954 -17.545903 30.59581 -30.28824 43.33815
## Mar 2019       7.265794 -17.234044 31.76563 -30.20348 44.73506
## Apr 2019       8.010071 -16.869944 32.89009 -30.04063 46.06077
plot(forecast)

Looking at the forecasts, we confirm that JPM and BAC are not significantly correlated, which is very surprising.