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 dataframall <- 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")