Bayesian Vector Autoregression in PyMC

I recently wrote a PyMC Labs blogpost on Bayesian Vector Autoregression (BVAR) using PyMC (duh), which may be of interest to other PyMC-neers!

Feedback is more than welcome!

6 Likes

Very cool! It would be nice if transformations were available to restrict the coefficient matrix to the stationary/invertible region of parameter space, as described for example here. From the results of that paper, forecast performance deteriorates as a function of the number of time series in the VAR without such a transformation.

I assume it would be possible to implement this using aeppl?

That shouldn’t require aeppl, just defining priors in the way they mention in the paper.

Could be fun to try to get it working in PyMC, perhaps for pymc-experimental or a pymc-examples! Would that be something you would be interested in by any chance ^^?

Yes, very interested! Since you’ve basically shown everything you need to set up the BVAR, I’ll put some time into it this weekend and see where I can get.

In the meantime, here’s a block to grab the data for your example that has a 100% HDI to go stale of 0%. Again, awesome blog post, thanks a lot for it!

# T10Y2YM is the 10-year yield minus the 3-month yield -- the best computations are the ones other people do for you!
from pandas_datareader.fred import FredReader

df_fred = (FredReader(symbols=['GDP', 'T10Y2YM'], start='1900-01-01', end=None)
          .read()
          .rename(columns={'T10Y2YM':'TSpread'}))
df_fred = df_fred.resample('Qs').last() # Last because interest rates are rates
df_fred['GDPGrowth'] = df_fred['GDP'].apply(np.log).diff().mul(400)
df_fred.dropna(how='any', axis=0, inplace=True)
1 Like