VAR Discussion

Introduction

Chose Tyson and Bunge. Thought commodities would make this a bit more interesting than tech, but I am probably wrong.

#Bring in the data--tried Quantmod for like 30 min and couldnt it to work. Downloaded data from yahoo finance.

tyson <-read.csv("TSN.csv",check.names = FALSE
                 , stringsAsFactors = FALSE
                 , na.strings = "")
bunge <-read.csv("BG.csv",check.names = FALSE
                 , stringsAsFactors = FALSE
                 , na.strings = "")

#create 1 datafram
all <- dplyr::bind_cols(tyson[,c(1,5)], bunge[,5])
## New names:
## * NA -> ...3
names(all) <- c("Date", "tyson", "bunge")

Plot the stocks to see if we can infer any sort of relationship

# Plot the time series of each stock -- horrble time with the dates, so will drop.

all <- data.frame(all$tyson, all$bunge)
all_ts <-ts(all, frequency=52)
all_ts %>% 
  autoplot() +
  labs(title = "Tyson and Bunge Closing"
       , "Price")+
  theme_ipsum_ps()

Run the models, with a max lag of 8

fit1 <- VARselect(all_ts, lag.max=8, type = "const", season = 4)
knitr::kable(fit1, "html")
x
AIC(n) 1
HQ(n) 1
SC(n) 1
FPE(n) 1
1 2 3 4 5 6 7 8
AIC(n) 3.967299 3.982498 4.002621 4.022446 4.038955 4.063238 4.077913 4.082682
HQ(n) 4.042549 4.082832 4.128038 4.172946 4.214539 4.263905 4.303664 4.333517
SC(n) 4.153601 4.230901 4.313125 4.395051 4.473661 4.560045 4.636820 4.703691
FPE(n) 52.843061 53.654433 54.748497 55.849941 56.787095 58.193095 59.066646 59.365726
fit <- VAR(all_ts, lag.max = 8)
fit
## 
## VAR Estimation Results:
## ======================= 
## 
## Estimated coefficients for equation all.tyson: 
## ============================================== 
## Call:
## all.tyson = all.tyson.l1 + all.bunge.l1 + const 
## 
## all.tyson.l1 all.bunge.l1        const 
##   0.95887723   0.01735775   1.90708457 
## 
## 
## Estimated coefficients for equation all.bunge: 
## ============================================== 
## Call:
## all.bunge = all.tyson.l1 + all.bunge.l1 + const 
## 
## all.tyson.l1 all.bunge.l1        const 
##  0.006493759  1.004781511 -0.575840631
summary(fit)
## 
## VAR Estimation Results:
## ========================= 
## Endogenous variables: all.tyson, all.bunge 
## Deterministic variables: const 
## Sample size: 225 
## Log Likelihood: -1079.176 
## Roots of the characteristic polynomial:
## 1.007 0.9565
## Call:
## VAR(y = all_ts, lag.max = 8)
## 
## 
## Estimation results for equation all.tyson: 
## ========================================== 
## all.tyson = all.tyson.l1 + all.bunge.l1 + const 
## 
##              Estimate Std. Error t value Pr(>|t|)    
## all.tyson.l1  0.95888    0.02060   46.56   <2e-16 ***
## all.bunge.l1  0.01736    0.01258    1.38    0.169    
## const         1.90708    1.25462    1.52    0.130    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## 
## Residual standard error: 2.836 on 222 degrees of freedom
## Multiple R-Squared: 0.9365,  Adjusted R-squared: 0.936 
## F-statistic:  1638 on 2 and 222 DF,  p-value: < 2.2e-16 
## 
## 
## Estimation results for equation all.bunge: 
## ========================================== 
## all.bunge = all.tyson.l1 + all.bunge.l1 + const 
## 
##               Estimate Std. Error t value Pr(>|t|)    
## all.tyson.l1  0.006494   0.019551   0.332    0.740    
## all.bunge.l1  1.004782   0.011943  84.129   <2e-16 ***
## const        -0.575841   1.191005  -0.483    0.629    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## 
## Residual standard error: 2.692 on 222 degrees of freedom
## Multiple R-Squared: 0.9791,  Adjusted R-squared: 0.9789 
## F-statistic:  5194 on 2 and 222 DF,  p-value: < 2.2e-16 
## 
## 
## 
## Covariance matrix of residuals:
##           all.tyson all.bunge
## all.tyson     8.041     2.580
## all.bunge     2.580     7.246
## 
## Correlation matrix of residuals:
##           all.tyson all.bunge
## all.tyson     1.000     0.338
## all.bunge     0.338     1.000
VAR_fc <- fit %>% 
  forecast(h=12)

VAR_fc %>% 
  autoplot(tyson)