Hanyue Kuang
for this discussion, I intend to look at the relationship between airline stock and oil stock. I choose jetblue and U.S.oil Fund to compare.
## Warning: package 'forecast' was built under R version 3.5.2
jblu <- read.csv("JBLU.csv")
uso <- read.csv("USO.csv")
stock <- data.frame(jblu$Adj.Close, uso$Adj.Close)
stock.ts <- ts(stock, start = c(2014,5), frequency=12)
jblu.ts <- ts(jblu$Adj.Close,start = c(2014,5), frequency=12)
uso.ts <- ts(uso$Adj.Close, start = c(2014,5), frequency=12)
autoplot(stock.ts)
par(mar=c(2.5,2.5,2.5,2.5))
acf(stock.ts)
autoplot(acf(diff(stock.ts)))
there is obvious autocorrelation existing and thus differencing is on demand.
stock.ts_diff <- diff(stock.ts)
VARselect(stock.ts_diff, lag.max = 8, type="const")$selection
## AIC(n) HQ(n) SC(n) FPE(n)
## 1 1 1 1
var <- VAR(stock.ts_diff, p=1)
summary(var)
##
## VAR Estimation Results:
## =========================
## Endogenous variables: jblu.Adj.Close, uso.Adj.Close
## Deterministic variables: const
## Sample size: 58
## Log Likelihood: -212.039
## Roots of the characteristic polynomial:
## 0.3816 0.1815
## Call:
## VAR(y = stock.ts_diff, p = 1)
##
##
## Estimation results for equation jblu.Adj.Close:
## ===============================================
## jblu.Adj.Close = jblu.Adj.Close.l1 + uso.Adj.Close.l1 + const
##
## Estimate Std. Error t value Pr(>|t|)
## jblu.Adj.Close.l1 -0.19288 0.13457 -1.433 0.157
## uso.Adj.Close.l1 -0.18578 0.13003 -1.429 0.159
## const 0.06818 0.21383 0.319 0.751
##
##
## Residual standard error: 1.573 on 55 degrees of freedom
## Multiple R-Squared: 0.05813, Adjusted R-squared: 0.02388
## F-statistic: 1.697 on 2 and 55 DF, p-value: 0.1926
##
##
## Estimation results for equation uso.Adj.Close:
## ==============================================
## uso.Adj.Close = jblu.Adj.Close.l1 + uso.Adj.Close.l1 + const
##
## Estimate Std. Error t value Pr(>|t|)
## jblu.Adj.Close.l1 0.03517 0.13145 0.268 0.7900
## uso.Adj.Close.l1 0.39301 0.12701 3.094 0.0031 **
## const -0.26792 0.20886 -1.283 0.2050
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
##
## Residual standard error: 1.536 on 55 degrees of freedom
## Multiple R-Squared: 0.1502, Adjusted R-squared: 0.1193
## F-statistic: 4.859 on 2 and 55 DF, p-value: 0.01139
##
##
##
## Covariance matrix of residuals:
## jblu.Adj.Close uso.Adj.Close
## jblu.Adj.Close 2.474 -0.361
## uso.Adj.Close -0.361 2.361
##
## Correlation matrix of residuals:
## jblu.Adj.Close uso.Adj.Close
## jblu.Adj.Close 1.0000 -0.1494
## uso.Adj.Close -0.1494 1.0000
autoplot(forecast(var, h=12))
seeing from the forecasting result, i think there is a relationship between this two. Also from the ts plot of the two, the data before 2015 deserves further analyzing.