GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - pablo-reyes8/bayesian-var: Standard Bayesian VAR with conjugate priors and Minnesota dummy-observation priors (unit-root and cointegration dummies) for analyzing shock transmission between U.S. 5-year and 3-year T-Bills and Colombian 5-year TES.

BranchesTags
Open more actions menu

Latest commit

 

History

23 Commits
23 Commits

Folders and files

NameName
Last commit message
Last commit date
data/raw
data/raw
 
 
notebooks
notebooks
 
 
outputs
outputs
 
 
scripts
scripts
 
 
src/bvar
src/bvar
 
 
tests
tests
 
 
.gitattributes
.gitattributes
 
 
.gitignore
.gitignore
 
 
Dockerfile
Dockerfile
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
pyproject.toml
pyproject.toml
 
 
requirements.txt
requirements.txt
 
 

Repository files navigation

Bayesian VAR (BVAR) with Conjugate Priors

Repo size Last commit Open issues Contributors Stars

A Python implementation of a standard Bayesian Vector Autoregression (VAR) with conjugate Normal–Inverse–Wishart priors and Minnesota hyperparameter structure. This repository provides routines for:

  • Specifying and estimating a VAR($p$) model
  • Constructing Minnesota priors with five hyperparameters ($\lambda_0$ – $\lambda_5$)
  • Sampling from the Normal–Inverse–Wishart posterior
  • Computing Monte Carlo impulse response functions (IRFs)
  • Performing forecast error variance decomposition (FEVD)

Table of Contents

  • Project Layout
  • Data
  • Quickstart
  • Results
  • Convergence Diagnostics
  • API (FastAPI)
  • Features
  • Contributing
  • License

Project Layout

  • data/raw/: raw source data (Excel)
  • data/processed/: cleaned/resampled CSVs
  • notebooks/: exploratory notebooks
  • scripts/: CLI entrypoints
  • src/bvar/: package modules (including the FastAPI service)
  • outputs/: generated model outputs
  • tests/: pytest suite

Data

The data used to run the model (to recreate the results) is located at:

  • data/raw/Tes-Bills Final.xlsx

The code should work with more variables and different types of time series without major complication.

Quickstart

Install in editable mode:

pip install -e .

Prepare the quarterly data:

python - <<'PY'
import pandas as pd
df = pd.read_excel('data/raw/Tes-Bills Final.xlsx')
df['Fecha'] = pd.to_datetime(df['Fecha'])
df = df.set_index('Fecha').resample('QE').mean().reset_index()
df[['DGS5','DGS1','TES 5 años']].to_csv('data/processed/tes_bills_quarterly.csv', index=False)
PY

Fit the model and draw posterior samples:

python scripts/bvar_fit.py \
  --data data/processed/tes_bills_quarterly.csv \
  --lags 3 \
  --draws 2000 \
  --output outputs/fit.npz

Compute IRFs, FEVD, and plots:

python scripts/bvar_infer.py \
  --fit outputs/fit.npz \
  --irf-horizon 35 \
  --output-dir outputs \
  --plots-dir outputs/plots

Run tests:

pytest

Results

Examples of outputs generated using the included data:

Impulse Response Functions (IRFs) Impulse Response Functions (IRFs) Forecast Error Variance Decomposition (FEVD) Forecast Error Variance Decomposition (FEVD)
Posterior densities Posterior densities MCMC trace plots MCMC trace plots

Convergence Diagnostics

Run diagnostics from an existing fit:

python scripts/bvar_diagnostics.py --fit outputs/fit.npz

Run diagnostics directly from data (pipeline + at least 2 chains):

python scripts/bvar_diagnostics.py \
  --data data/processed/tes_bills_quarterly.csv \
  --lags 3 \
  --draws 2000 \
  --chains 2

The diagnostics use ArviZ/PyMC to compute R-hat, effective sample sizes (ESS), and a full summary table.

API (FastAPI)

Start the API:

uvicorn bvar.api:app --reload --host 0.0.0.0 --port 8000

Example request (upload CSV and set lags):

curl -X POST "http://localhost:8000/estimate" \
  -F "file=@data/processed/tes_bills_quarterly.csv" \
  -F "lags=3" \
  -F "draws=2000" \
  -F "irf_horizon=35"

Features

  • Hyperparameter optimization via marginal likelihood
  • Posterior sampling of coefficients and covariance draws
  • IRF & FEVD routines with companion-form and Cholesky factorization
  • Flexible handling of lag order $p$ and variable ordering

References:

J. Jacobo, Una introducción a los métodos de máxima entropía y de inferencia bayesiana en econometría

Contributing

Contributions are welcome! Please open issues or submit pull requests at https://github.com/pablo-reyes8

License

This project is licensed under the Apache License 2.0.

About

Standard Bayesian VAR with conjugate priors and Minnesota dummy-observation priors (unit-root and cointegration dummies) for analyzing shock transmission between U.S. 5-year and 3-year T-Bills and Colombian 5-year TES.

Topics

bayesian-varbvarfevdgibbs-samplingimpulse-response-functionsmacroeconomicsminnesota-priormultivariate-time-seriesreproducible-research

Resources

Readme
Apache-2.0 license
Activity

Stars

8 stars

Watchers

1 watching

Forks

1 fork
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.