Libraries

library(vars)
## Loading required package: MASS
## Warning: package 'MASS' was built under R version 3.6.2
## Loading required package: strucchange
## Loading required package: zoo
## Warning: package 'zoo' was built under R version 3.6.2
## 
## 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(knitr)
library(tidyverse)
## ── Attaching packages ──────────────────────────────────────────────────────── tidyverse 1.3.0 ──
## ✓ ggplot2 3.3.2     ✓ purrr   0.3.4
## ✓ tibble  3.0.1     ✓ dplyr   0.8.5
## ✓ tidyr   1.0.2     ✓ stringr 1.4.0
## ✓ readr   1.3.1     ✓ forcats 0.4.0
## Warning: package 'ggplot2' was built under R version 3.6.2
## Warning: package 'tibble' was built under R version 3.6.2
## Warning: package 'purrr' was built under R version 3.6.2
## ── Conflicts ─────────────────────────────────────────────────────────── tidyverse_conflicts() ──
## x stringr::boundary() masks strucchange::boundary()
## x dplyr::filter()     masks stats::filter()
## x dplyr::lag()        masks stats::lag()
## x dplyr::select()     masks MASS::select()
library(quantmod)
## Loading required package: xts
## Registered S3 method overwritten by 'xts':
##   method     from
##   as.zoo.xts zoo
## 
## Attaching package: 'xts'
## The following objects are masked from 'package:dplyr':
## 
##     first, last
## Loading required package: TTR
## Warning: package 'TTR' was built under R version 3.6.2
## Registered S3 method overwritten by 'quantmod':
##   method            from
##   as.zoo.data.frame zoo
## Version 0.4-0 included new data defaults. See ?getSymbols.
library(forecast)
## Warning: package 'forecast' was built under R version 3.6.2

Load Data & Features

I chose Hilton (HLT) and Delta (DAL) as the two stocks to compare. I am not sure about the historical data, but I suspect that after the Covid-induced market crash in March 2020, there will be a clear pattern.

delta = read.csv("/Users/nelsonwhite/Documents/ms applied economics/Predictive Analytics:Forecasting/week 6 discussion/DAL.csv")

hilton = read.csv("/Users/nelsonwhite/Documents/ms applied economics/Predictive Analytics:Forecasting/week 6 discussion/HLT.csv")
delta.ts = ts(delta[,6], frequency=12)

hilton.ts = ts(hilton[,6], frequency=12)

pricediff = (delta.ts-hilton.ts)

prices = cbind(delta.ts,hilton.ts)
autoplot(prices)

There is apparent seasonality in both stocks. We can see at month = 50, there is a significant dip in prices for both.

autoplot(pricediff)

However the price difference has a clear downward trend and it’s defiend as delta-hilton, meaning that even though both stocks becan at similar values in 2015, Hilton has become more valuable than Delta over time.

acf(prices)

VARselect(prices)
## $selection
## AIC(n)  HQ(n)  SC(n) FPE(n) 
##      3      1      1      3 
## 
## $criteria
##                 1          2          3          4          5          6
## AIC(n)   6.375205   6.415769   6.362507   6.468346   6.598901   6.684348
## HQ(n)    6.462578   6.561391   6.566378   6.730466   6.919269   7.062965
## SC(n)    6.604648   6.798174   6.897874   7.156675   7.440191   7.678600
## FPE(n) 587.275277 612.231738 581.848319 649.548198 745.105285 819.571786
##                 7          8           9          10
## AIC(n)   6.813025   6.811270    6.920761    6.994963
## HQ(n)    7.249891   7.306385    7.474124    7.606574
## SC(n)    7.960239   8.111446    8.373898    8.601062
## FPE(n) 944.923327 960.679250 1097.729913 1218.932336

VARselect recommends 3 and 1 equally.

prices.var1 = VAR(prices, lag.max = 3)
prices.var1
## 
## VAR Estimation Results:
## ======================= 
## 
## Estimated coefficients for equation delta.ts: 
## ============================================= 
## Call:
## delta.ts = delta.ts.l1 + hilton.ts.l1 + const 
## 
##  delta.ts.l1 hilton.ts.l1        const 
##  0.888499615 -0.002361582  5.104590111 
## 
## 
## Estimated coefficients for equation hilton.ts: 
## ============================================== 
## Call:
## hilton.ts = delta.ts.l1 + hilton.ts.l1 + const 
## 
##  delta.ts.l1 hilton.ts.l1        const 
##   -0.1265878    0.9732574    8.7209150
forecast(prices.var1)
## delta.ts
##       Point Forecast    Lo 80    Hi 80    Lo 95    Hi 95
## Jan 6       39.32141 33.55557 45.08725 30.50332 48.13950
## Feb 6       39.79120 32.08642 47.49598 28.00775 51.57464
## Mar 6       40.20646 31.26834 49.14459 26.53678 53.87614
## Apr 6       40.57348 30.77414 50.37282 25.58668 55.56028
## May 6       40.89781 30.47100 51.32461 24.95139 56.84423
## Jun 6       41.18436 30.28924 52.07948 24.52172 57.84700
## Jul 6       41.43749 30.18743 52.68755 24.23201 58.64297
## Aug 6       41.66105 30.13914 53.18296 24.03981 59.28229
## Sep 6       41.85845 30.12674 53.59015 23.91635 59.80054
## Oct 6       42.03270 30.13816 53.92724 23.84157 60.22383
## 
## hilton.ts
##       Point Forecast    Lo 80    Hi 80    Lo 95    Hi 95
## Jan 6       106.0513 97.85065 114.2519 93.50950 118.5930
## Feb 6       106.9585 95.81970 118.0973 89.92318 123.9938
## Mar 6       107.7820 94.63423 120.9297 87.67423 127.8897
## Apr 6       108.5309 93.85273 123.2090 86.08259 130.9792
## May 6       109.2133 93.30056 125.1261 84.87686 133.5498
## Jun 6       109.8364 92.88893 126.7839 83.91748 135.7554
## Jul 6       110.4066 92.56707 128.2461 83.12340 137.6898
## Aug 6       110.9295 92.30400 129.5549 82.44427 139.4147
## Sep 6       111.4101 92.08013 130.7400 81.84748 140.9727
## Oct 6       111.8528 91.88285 131.8228 81.31138 142.3943
autoplot(forecast(prices.var1))

prices.var2 = VAR(prices, lag.max=1)
prices.var2
## 
## VAR Estimation Results:
## ======================= 
## 
## Estimated coefficients for equation delta.ts: 
## ============================================= 
## Call:
## delta.ts = delta.ts.l1 + hilton.ts.l1 + const 
## 
##  delta.ts.l1 hilton.ts.l1        const 
##  0.888499615 -0.002361582  5.104590111 
## 
## 
## Estimated coefficients for equation hilton.ts: 
## ============================================== 
## Call:
## hilton.ts = delta.ts.l1 + hilton.ts.l1 + const 
## 
##  delta.ts.l1 hilton.ts.l1        const 
##   -0.1265878    0.9732574    8.7209150
forecast(prices.var2)
## delta.ts
##       Point Forecast    Lo 80    Hi 80    Lo 95    Hi 95
## Jan 6       39.32141 33.55557 45.08725 30.50332 48.13950
## Feb 6       39.79120 32.08642 47.49598 28.00775 51.57464
## Mar 6       40.20646 31.26834 49.14459 26.53678 53.87614
## Apr 6       40.57348 30.77414 50.37282 25.58668 55.56028
## May 6       40.89781 30.47100 51.32461 24.95139 56.84423
## Jun 6       41.18436 30.28924 52.07948 24.52172 57.84700
## Jul 6       41.43749 30.18743 52.68755 24.23201 58.64297
## Aug 6       41.66105 30.13914 53.18296 24.03981 59.28229
## Sep 6       41.85845 30.12674 53.59015 23.91635 59.80054
## Oct 6       42.03270 30.13816 53.92724 23.84157 60.22383
## 
## hilton.ts
##       Point Forecast    Lo 80    Hi 80    Lo 95    Hi 95
## Jan 6       106.0513 97.85065 114.2519 93.50950 118.5930
## Feb 6       106.9585 95.81970 118.0973 89.92318 123.9938
## Mar 6       107.7820 94.63423 120.9297 87.67423 127.8897
## Apr 6       108.5309 93.85273 123.2090 86.08259 130.9792
## May 6       109.2133 93.30056 125.1261 84.87686 133.5498
## Jun 6       109.8364 92.88893 126.7839 83.91748 135.7554
## Jul 6       110.4066 92.56707 128.2461 83.12340 137.6898
## Aug 6       110.9295 92.30400 129.5549 82.44427 139.4147
## Sep 6       111.4101 92.08013 130.7400 81.84748 140.9727
## Oct 6       111.8528 91.88285 131.8228 81.31138 142.3943
autoplot(forecast(prices.var2))