Daniel RG

12/2/2020

Series: Exxon (XOM), Royal Dutch Shell (RDS)

library(fpp2)
library(ggplot2)
library(ggthemes)
library(tidyverse)
library(kableExtra)
library(quantmod)
library(vars)
symbols <- c("BP", "XOM")
getSymbols(symbols, return.class="ts", from="2010-01-01", to="2020-12-01", auto.assign = TRUE)
## [1] "BP"  "XOM"
XOM.ts <- ts(XOM[,6], start=c(2010,1),end=c(2020,365),frequency=365)
BP.ts <- ts(BP[,6], start=c(2010,1),end=c(2020,365),frequency=365)
autoplot(BP.ts, series = "BP") + autolayer(XOM.ts, series = "XOM") + ylab("Price") + ggtitle("Price of BP and XOM")

round(cor(BP.ts, XOM.ts),3) %>% kable(caption = "Correlation Value") %>% kable_classic(full_width = F) 
Correlation Value
x
0.576

There’s a clear common pattern, with a correlation value of 0.6.

The series is not stationary, and therefore we take the differences.

Differences

autoplot(diff(BP.ts), series = "BP") + autolayer(diff(XOM.ts), series = "XOM") + ylab("Price")

round(cor(diff(BP.ts), diff(XOM.ts)),3) %>% kable(caption = "Correlation Value of Differences") %>% kable_classic(full_width = F)
Correlation Value of Differences
x
0.67

Differences are even more correlated.

checkresiduals(diff(BP.ts))

ggPacf(diff(BP.ts))

checkresiduals(diff(XOM.ts)) 

ggPacf(diff(XOM.ts))

VAR

VARselect(c(diff(BP.ts), diff(XOM.ts)), lag.max = 14) %>% kable(caption = "VAR Select Lag Selection") %>% kable_classic(full_width = F)
VAR Select Lag Selection
x
AIC(n) 14
HQ(n) 3
SC(n) 1
FPE(n) 14
1 2 3 4 5 6 7 8 9 10 11 12 13 14
AIC(n) -0.8558543 -0.8562299 -0.8567551 -0.8565696 -0.8563281 -0.8563245 -0.8562615 -0.8566667 -0.8566374 -0.8579819 -0.8577394 -0.8579352 -0.8582867 -0.8583815
HQ(n) -0.8552574 -0.8553344 -0.8555612 -0.8550772 -0.8545373 -0.8542352 -0.8538737 -0.8539805 -0.8536527 -0.8546987 -0.8541577 -0.8540550 -0.8541080 -0.8539044
SC(n) -0.8541102 -0.8536136 -0.8532667 -0.8522092 -0.8510956 -0.8502199 -0.8492847 -0.8488179 -0.8479165 -0.8483889 -0.8472743 -0.8465980 -0.8460774 -0.8453001
FPE(n) 0.4249200 0.4247605 0.4245374 0.4246162 0.4247187 0.4247203 0.4247470 0.4245749 0.4245874 0.4240169 0.4241198 0.4240367 0.4238877 0.4238475

I’ll use 14 lags.

data.ts <- ts(data.frame(diff(BP.ts), diff(XOM.ts)), start=c(2010,1),end=c(2020,365),frequency=365)
var1 <- VAR(data.ts, p=14)
var2 <- VAR(data.ts, p=3)
var3 <- VAR(data.ts, p=1)
summary(var1)
## 
## VAR Estimation Results:
## ========================= 
## Endogenous variables: diff.BP.ts., diff.XOM.ts. 
## Deterministic variables: const 
## Sample size: 4001 
## Log Likelihood: -6317.543 
## Roots of the characteristic polynomial:
## 0.8562 0.8562 0.8295 0.8295 0.8231 0.8231 0.8189 0.8189 0.7806 0.7806  0.78  0.78 0.7715 0.7715 0.768 0.768 0.7399 0.7399 0.7201 0.7201 0.7123 0.7123 0.7034 0.7034 0.6949 0.6949 0.5888 0.1228
## Call:
## VAR(y = data.ts, p = 14)
## 
## 
## Estimation results for equation diff.BP.ts.: 
## ============================================ 
## diff.BP.ts. = diff.BP.ts..l1 + diff.XOM.ts..l1 + diff.BP.ts..l2 + diff.XOM.ts..l2 + diff.BP.ts..l3 + diff.XOM.ts..l3 + diff.BP.ts..l4 + diff.XOM.ts..l4 + diff.BP.ts..l5 + diff.XOM.ts..l5 + diff.BP.ts..l6 + diff.XOM.ts..l6 + diff.BP.ts..l7 + diff.XOM.ts..l7 + diff.BP.ts..l8 + diff.XOM.ts..l8 + diff.BP.ts..l9 + diff.XOM.ts..l9 + diff.BP.ts..l10 + diff.XOM.ts..l10 + diff.BP.ts..l11 + diff.XOM.ts..l11 + diff.BP.ts..l12 + diff.XOM.ts..l12 + diff.BP.ts..l13 + diff.XOM.ts..l13 + diff.BP.ts..l14 + diff.XOM.ts..l14 + const 
## 
##                    Estimate Std. Error t value Pr(>|t|)   
## diff.BP.ts..l1    3.735e-03  2.136e-02   0.175  0.86119   
## diff.XOM.ts..l1  -1.935e-02  1.394e-02  -1.388  0.16524   
## diff.BP.ts..l2   -1.235e-02  2.134e-02  -0.579  0.56291   
## diff.XOM.ts..l2   2.485e-02  1.394e-02   1.782  0.07479 . 
## diff.BP.ts..l3    6.038e-02  2.136e-02   2.827  0.00472 **
## diff.XOM.ts..l3  -3.503e-02  1.395e-02  -2.511  0.01209 * 
## diff.BP.ts..l4    2.358e-03  2.138e-02   0.110  0.91220   
## diff.XOM.ts..l4   7.434e-03  1.399e-02   0.532  0.59508   
## diff.BP.ts..l5    6.678e-02  2.137e-02   3.125  0.00179 **
## diff.XOM.ts..l5  -2.560e-02  1.398e-02  -1.832  0.06706 . 
## diff.BP.ts..l6    5.512e-02  2.139e-02   2.577  0.00999 **
## diff.XOM.ts..l6  -1.627e-02  1.398e-02  -1.164  0.24450   
## diff.BP.ts..l7   -2.880e-02  2.138e-02  -1.347  0.17798   
## diff.XOM.ts..l7   2.731e-02  1.399e-02   1.953  0.05090 . 
## diff.BP.ts..l8   -6.001e-02  2.138e-02  -2.807  0.00503 **
## diff.XOM.ts..l8  -5.937e-03  1.399e-02  -0.424  0.67139   
## diff.BP.ts..l9    2.307e-02  2.136e-02   1.080  0.28027   
## diff.XOM.ts..l9   7.064e-03  1.398e-02   0.505  0.61345   
## diff.BP.ts..l10  -5.179e-05  2.133e-02  -0.002  0.99806   
## diff.XOM.ts..l10  2.666e-02  1.398e-02   1.907  0.05656 . 
## diff.BP.ts..l11  -1.202e-02  2.134e-02  -0.563  0.57339   
## diff.XOM.ts..l11  1.692e-02  1.398e-02   1.210  0.22628   
## diff.BP.ts..l12  -2.119e-02  2.133e-02  -0.993  0.32053   
## diff.XOM.ts..l12 -1.815e-02  1.396e-02  -1.300  0.19378   
## diff.BP.ts..l13  -6.141e-04  2.131e-02  -0.029  0.97701   
## diff.XOM.ts..l13 -2.125e-02  1.394e-02  -1.524  0.12752   
## diff.BP.ts..l14   5.396e-02  2.132e-02   2.531  0.01141 * 
## diff.XOM.ts..l14 -1.262e-02  1.395e-02  -0.905  0.36538   
## const            -1.451e-03  7.940e-03  -0.183  0.85502   
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## 
## Residual standard error: 0.5014 on 3972 degrees of freedom
## Multiple R-Squared: 0.02124, Adjusted R-squared: 0.01434 
## F-statistic: 3.078 on 28 and 3972 DF,  p-value: 9.705e-08 
## 
## 
## Estimation results for equation diff.XOM.ts.: 
## ============================================= 
## diff.XOM.ts. = diff.BP.ts..l1 + diff.XOM.ts..l1 + diff.BP.ts..l2 + diff.XOM.ts..l2 + diff.BP.ts..l3 + diff.XOM.ts..l3 + diff.BP.ts..l4 + diff.XOM.ts..l4 + diff.BP.ts..l5 + diff.XOM.ts..l5 + diff.BP.ts..l6 + diff.XOM.ts..l6 + diff.BP.ts..l7 + diff.XOM.ts..l7 + diff.BP.ts..l8 + diff.XOM.ts..l8 + diff.BP.ts..l9 + diff.XOM.ts..l9 + diff.BP.ts..l10 + diff.XOM.ts..l10 + diff.BP.ts..l11 + diff.XOM.ts..l11 + diff.BP.ts..l12 + diff.XOM.ts..l12 + diff.BP.ts..l13 + diff.XOM.ts..l13 + diff.BP.ts..l14 + diff.XOM.ts..l14 + const 
## 
##                   Estimate Std. Error t value Pr(>|t|)    
## diff.BP.ts..l1    0.009675   0.032746   0.295  0.76766    
## diff.XOM.ts..l1  -0.035448   0.021375  -1.658  0.09732 .  
## diff.BP.ts..l2    0.077446   0.032718   2.367  0.01798 *  
## diff.XOM.ts..l2  -0.001974   0.021379  -0.092  0.92645    
## diff.BP.ts..l3    0.106530   0.032747   3.253  0.00115 ** 
## diff.XOM.ts..l3  -0.093720   0.021394  -4.381 1.21e-05 ***
## diff.BP.ts..l4   -0.016208   0.032779  -0.494  0.62100    
## diff.XOM.ts..l4   0.010940   0.021443   0.510  0.60994    
## diff.BP.ts..l5    0.048907   0.032767   1.493  0.13563    
## diff.XOM.ts..l5  -0.034809   0.021430  -1.624  0.10439    
## diff.BP.ts..l6   -0.012155   0.032786  -0.371  0.71086    
## diff.XOM.ts..l6   0.012575   0.021435   0.587  0.55746    
## diff.BP.ts..l7   -0.052120   0.032776  -1.590  0.11188    
## diff.XOM.ts..l7   0.042272   0.021441   1.972  0.04873 *  
## diff.BP.ts..l8   -0.063868   0.032780  -1.948  0.05144 .  
## diff.XOM.ts..l8   0.014043   0.021453   0.655  0.51275    
## diff.BP.ts..l9    0.016274   0.032750   0.497  0.61928    
## diff.XOM.ts..l9  -0.001463   0.021437  -0.068  0.94561    
## diff.BP.ts..l10   0.056832   0.032704   1.738  0.08233 .  
## diff.XOM.ts..l10  0.020622   0.021430   0.962  0.33597    
## diff.BP.ts..l11  -0.023480   0.032721  -0.718  0.47305    
## diff.XOM.ts..l11  0.008104   0.021438   0.378  0.70545    
## diff.BP.ts..l12  -0.012233   0.032704  -0.374  0.70839    
## diff.XOM.ts..l12 -0.014987   0.021404  -0.700  0.48386    
## diff.BP.ts..l13   0.030299   0.032676   0.927  0.35385    
## diff.XOM.ts..l13 -0.033959   0.021375  -1.589  0.11220    
## diff.BP.ts..l14   0.043292   0.032682   1.325  0.18537    
## diff.XOM.ts..l14 -0.011504   0.021379  -0.538  0.59054    
## const             0.007112   0.012172   0.584  0.55907    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## 
## Residual standard error: 0.7687 on 3972 degrees of freedom
## Multiple R-Squared: 0.01535, Adjusted R-squared: 0.008406 
## F-statistic: 2.211 on 28 and 3972 DF,  p-value: 0.0002511 
## 
## 
## 
## Covariance matrix of residuals:
##              diff.BP.ts. diff.XOM.ts.
## diff.BP.ts.       0.2514       0.2583
## diff.XOM.ts.      0.2583       0.5909
## 
## Correlation matrix of residuals:
##              diff.BP.ts. diff.XOM.ts.
## diff.BP.ts.       1.0000       0.6702
## diff.XOM.ts.      0.6702       1.0000
summary(var2)
## 
## VAR Estimation Results:
## ========================= 
## Endogenous variables: diff.BP.ts., diff.XOM.ts. 
## Deterministic variables: const 
## Sample size: 4012 
## Log Likelihood: -6384.143 
## Roots of the characteristic polynomial:
## 0.4196 0.3981 0.3981 0.3037 0.3037 0.2794
## Call:
## VAR(y = data.ts, p = 3)
## 
## 
## Estimation results for equation diff.BP.ts.: 
## ============================================ 
## diff.BP.ts. = diff.BP.ts..l1 + diff.XOM.ts..l1 + diff.BP.ts..l2 + diff.XOM.ts..l2 + diff.BP.ts..l3 + diff.XOM.ts..l3 + const 
## 
##                  Estimate Std. Error t value Pr(>|t|)  
## diff.BP.ts..l1   0.004204   0.021285   0.197   0.8435  
## diff.XOM.ts..l1 -0.018227   0.013950  -1.307   0.1914  
## diff.BP.ts..l2  -0.020505   0.021261  -0.964   0.3349  
## diff.XOM.ts..l2  0.027836   0.013934   1.998   0.0458 *
## diff.BP.ts..l3   0.052099   0.021294   2.447   0.0145 *
## diff.XOM.ts..l3 -0.030649   0.013942  -2.198   0.0280 *
## const           -0.001987   0.007971  -0.249   0.8032  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## 
## Residual standard error: 0.5047 on 4005 degrees of freedom
## Multiple R-Squared: 0.003347,    Adjusted R-squared: 0.001854 
## F-statistic: 2.242 on 6 and 4005 DF,  p-value: 0.03665 
## 
## 
## Estimation results for equation diff.XOM.ts.: 
## ============================================= 
## diff.XOM.ts. = diff.BP.ts..l1 + diff.XOM.ts..l1 + diff.BP.ts..l2 + diff.XOM.ts..l2 + diff.BP.ts..l3 + diff.XOM.ts..l3 + const 
## 
##                  Estimate Std. Error t value Pr(>|t|)    
## diff.BP.ts..l1   0.009635   0.032425   0.297  0.76637    
## diff.XOM.ts..l1 -0.034847   0.021252  -1.640  0.10115    
## diff.BP.ts..l2   0.061197   0.032389   1.889  0.05891 .  
## diff.XOM.ts..l2  0.003557   0.021227   0.168  0.86695    
## diff.BP.ts..l3   0.100430   0.032440   3.096  0.00198 ** 
## diff.XOM.ts..l3 -0.091966   0.021240  -4.330 1.53e-05 ***
## const            0.006352   0.012142   0.523  0.60092    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## 
## Residual standard error: 0.7689 on 4005 degrees of freedom
## Multiple R-Squared: 0.007589,    Adjusted R-squared: 0.006103 
## F-statistic: 5.105 on 6 and 4005 DF,  p-value: 3.121e-05 
## 
## 
## 
## Covariance matrix of residuals:
##              diff.BP.ts. diff.XOM.ts.
## diff.BP.ts.       0.2547       0.2601
## diff.XOM.ts.      0.2601       0.5912
## 
## Correlation matrix of residuals:
##              diff.BP.ts. diff.XOM.ts.
## diff.BP.ts.       1.0000       0.6703
## diff.XOM.ts.      0.6703       1.0000
summary(var3)
## 
## VAR Estimation Results:
## ========================= 
## Endogenous variables: diff.BP.ts., diff.XOM.ts. 
## Deterministic variables: const 
## Sample size: 4014 
## Log Likelihood: -6405.145 
## Roots of the characteristic polynomial:
## 0.03134 0.0004623
## Call:
## VAR(y = data.ts, p = 1)
## 
## 
## Estimation results for equation diff.BP.ts.: 
## ============================================ 
## diff.BP.ts. = diff.BP.ts..l1 + diff.XOM.ts..l1 + const 
## 
##                  Estimate Std. Error t value Pr(>|t|)
## diff.BP.ts..l1   0.001411   0.021272   0.066    0.947
## diff.XOM.ts..l1 -0.017099   0.013934  -1.227    0.220
## const           -0.002038   0.007972  -0.256    0.798
## 
## 
## Residual standard error: 0.505 on 4011 degrees of freedom
## Multiple R-Squared: 0.000634,    Adjusted R-squared: 0.0001357 
## F-statistic: 1.272 on 2 and 4011 DF,  p-value: 0.2803 
## 
## 
## Estimation results for equation diff.XOM.ts.: 
## ============================================= 
## diff.XOM.ts. = diff.BP.ts..l1 + diff.XOM.ts..l1 + const 
## 
##                  Estimate Std. Error t value Pr(>|t|)
## diff.BP.ts..l1   0.003589   0.032469   0.111    0.912
## diff.XOM.ts..l1 -0.033217   0.021268  -1.562    0.118
## const            0.005557   0.012168   0.457    0.648
## 
## 
## Residual standard error: 0.7709 on 4011 degrees of freedom
## Multiple R-Squared: 0.001004,    Adjusted R-squared: 0.000506 
## F-statistic: 2.016 on 2 and 4011 DF,  p-value: 0.1333 
## 
## 
## 
## Covariance matrix of residuals:
##              diff.BP.ts. diff.XOM.ts.
## diff.BP.ts.       0.2551       0.2609
## diff.XOM.ts.      0.2609       0.5942
## 
## Correlation matrix of residuals:
##              diff.BP.ts. diff.XOM.ts.
## diff.BP.ts.       1.0000       0.6701
## diff.XOM.ts.      0.6701       1.0000
serial.test(var1, lags.pt=14, type="PT.asymptotic")
## 
##  Portmanteau Test (asymptotic)
## 
## data:  Residuals of VAR object var1
## Chi-squared = 0.89941, df = 0, p-value < 2.2e-16
serial.test(var2, lags.pt=14, type="PT.asymptotic")
## 
##  Portmanteau Test (asymptotic)
## 
## data:  Residuals of VAR object var2
## Chi-squared = 102.27, df = 44, p-value = 1.543e-06
serial.test(var3, lags.pt=14, type="PT.asymptotic")
## 
##  Portmanteau Test (asymptotic)
## 
## data:  Residuals of VAR object var3
## Chi-squared = 140.19, df = 52, p-value = 4.965e-10
f1 <- forecast(var1, h=365)
f2 <- forecast(var2, h=365)
f3 <- forecast(var3, h=365)

autoplot(f1)

autoplot(f2)

autoplot(f3)

Forecasts have some variability in the short term, but converges to 0.006.