# Bayesian Vector Autoregression in PyMC

**URL:** <https://discourse.pymc.io/t/bayesian-vector-autoregression-in-pymc/9670>\
**Category:** Sharing\
**Created:** [June 17, 2022, 9:39am UTC](https://discourse.pymc.io/t/bayesian-vector-autoregression-in-pymc/9670 "2022-06-17T09:39:08Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ricardoV94](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/ricardov94/32/5775_2.png) [@ricardoV94](https://discourse.pymc.io/u/ricardoV94)\
**Post date:** [June 17, 2022, 9:39am UTC](https://discourse.pymc.io/t/bayesian-vector-autoregression-in-pymc/9670/1 "2022-06-17T09:39:08Z")

</div>

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

> **[Bayesian Vector Autoregression in PyMC - PyMC Labs](https://www.pymc-labs.io/blog-posts/bayesian-vector-autoregression/)**
>
> It's time to let go of your custom Gibbs sampler

Feedback is more than welcome!

---

<div class="post-metadata">

**Author:** ![jessegrabowski](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/jessegrabowski/32/5010_2.png) [@jessegrabowski](https://discourse.pymc.io/u/jessegrabowski)\
**Post date:** [June 17, 2022, 10:21am UTC](https://discourse.pymc.io/t/bayesian-vector-autoregression-in-pymc/9670/2 "2022-06-17T10:21:28Z")

</div>

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](https://arxiv.org/pdf/2004.09455.pdf). 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?

---

<div class="post-metadata">

**Author:** ![ricardoV94](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/ricardov94/32/5775_2.png) [@ricardoV94](https://discourse.pymc.io/u/ricardoV94)\
**Post date:** [June 17, 2022, 10:51am UTC](https://discourse.pymc.io/t/bayesian-vector-autoregression-in-pymc/9670/3 "2022-06-17T10:51:55Z")

</div>

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 ^^?

---

<div class="post-metadata">

**Author:** ![jessegrabowski](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/jessegrabowski/32/5010_2.png) [@jessegrabowski](https://discourse.pymc.io/u/jessegrabowski)\
**Post date:** [June 17, 2022, 12:41pm UTC](https://discourse.pymc.io/t/bayesian-vector-autoregression-in-pymc/9670/4 "2022-06-17T12:41:44Z")

</div>

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!

```auto
# 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)

```
