I am currently using R and vector autoregressions in the vars package to construct a data model for predicting the prices of multiple commodities using historical data which includes oil, a commodity that has strong relationships with the prices of multiple other commodities. What I want to do is use the existing data and relationships to predict what the price of all the other goods with strong relationships to oil will be if the price of oil drops to a specified price.
Here is a sample of my code and data used for constructing the VAR for oil and US wheat:
Data:
Date coa wuh
1 Dec 2003 29.97 165.57
2 Jan 2004 31.37 166.33
3 Feb 2004 31.33 161.39
4 Mar 2004 33.67 166.28
5 Apr 2004 33.71 166.58
6 May 2004 37.56 163.73
Code:
#Packages
library(AER)
library(urca)
library(vars)
#Set time series
COA <- ts(Clean_Pink_Sheet_Data$coa,
start = c(1960, 1),
end = c(2023, 12),
frequency = 12)
WUH <- ts(Clean_Pink_Sheet_Data$wuh,
start = c(1960, 1),
end = c(2023, 12),
frequency = 12)
#Set spread
COA_WUH_Spread <- COA - WUH
#Set up data for estimation
COA_WUH_VAR <- window(ts.union(WUH, COA_WUH_Spread), start = c(1960, 1), end = c(2023, 12))
#Estimate model coefficients
COA_WUH_est <- VAR(y = COA_WUH_VAR, p = 2)
#Forecast based on model coefficients
COA_WUH_forecast <- predict(COA_WUH_est)