rai-bvar

A worn signal trace: pale and red spikes rising from a dark green field

A Python library for forecasting an economy, and for checking whether a fancier model really forecasts better.

Kind
Research, open source
Stack
Python, JAX
License
Apache-2.0
Written with
Claude

What it does

A vector autoregression forecasts several things at once, such as growth, inflation and interest rates, from their own past. The Bayesian kind gives a range of likely outcomes instead of a single number.

rai-bvar builds these models from three parts you can swap: how the series move on average, how jumpy they are over time, and what you assume before looking at the data.

Why it exists

A more complicated model usually looks better on the data it was fitted to. That says little about whether it forecasts better.

rai-bvar compares two models that differ in exactly one part, on data neither has seen, and gives a verdict: better, worse or inconclusive. If the evidence is not strong enough, it says so.

How we know it is right

The results are checked against established R packages and against tests built to catch mistakes in this kind of code.

Eighteen bugs are planted on purpose before each release. Every one has to be caught before a version ships.

Does stochastic volatility improve the forecasts?
import rai_bvar as rb

res = rb.compare(
    {
        "Constant": rb.BVAR(vol=rb.Constant("ig"), lags=4),
        "SV(outliers)": rb.BVAR(vol=rb.SV(outliers=True), lags=4),
    },
    data,
    origins=rb.Origins(start="2016Q1", step=4),
    window=rb.Rolling(size=120),
    horizons=[1, 4],
)
res.verdict()   # better, worse or inconclusive
All work