A modular Python framework for the BAM agent-based macroeconomic model
Project description
A Modular Python Framework for the BAM Agent-Based Macroeconomic Model
A Python implementation of the BAM (Bottom-Up Adaptive Macroeconomics) model from Macroeconomics from the Bottom-up (Delli Gatti et al., 2011). It runs simulations of individual workers, firms, and banks making decisions and interacting in labor, credit and goods markets, letting macroeconomic patterns (growth, unemployment, inflation, business cycles) emerge from the bottom up, instead of assuming them with aggregate equations.
bamengine.org • Documentation • Getting Started • Examples
Note: This release is feature-complete for the core BAM model but APIs may change in future releases before v1.0.0.
Quick Start
pip install bamengine
Requirements: Python 3.11+. NumPy and PyYAML are installed automatically.
import bamengine as bam
# Initialize and run simulation
sim = bam.Simulation.init(n_firms=100, n_households=500, seed=42)
results = sim.run(n_periods=100)
# Access results
results["Economy.inflation"] # 1D array (n_periods,)
results.Producer.price # 2D array (n_periods, n_firms)
# Export to pandas DataFrame
df = results.to_dataframe()
# Add extensions with one call
from extensions.rnd import RND
sim = bam.Simulation.init(seed=42)
sim.use(RND)
results = sim.run(n_periods=1000)
See the Getting Started guide for a complete walkthrough.
Features
- Complete BAM Implementation: Baseline model from Macroeconomics from the Bottom-up, Chapter 3 (firms, households, and banks across labor, credit, and goods markets), three built-in extensions (R&D / Growth+, buffer-stock consumption, taxation), and a robustness analysis suite (internal validity, sensitivity, structural experiments).
- Vectorized Performance: Agent state lives in parallel NumPy arrays and behavior is expressed as array transformations, not Python loops over agent objects. Simulations scale to large populations and long horizons.
- Pluggable Extension System: Add custom roles, events, and pipeline hooks via decorators without modifying the engine. The same mechanism powers the built-in extensions.
- Parameter Calibration: Automated pipeline for tuning model parameters against validation targets.
Architecture
BAM Engine uses an ECS (Entity-Component-System) architecture: agents are lightweight entities, state lives in Role components stored as parallel NumPy arrays, and behavior is defined by Event systems composed into a YAML-configurable pipeline. New roles, events, and relationships can be added through decorators, without modifying core code.
The trade-off is a mindset shift: you write agent rules as systems that transform whole arrays of state at once, not as methods on per-agent objects. ECS itself does not demand vectorization, but BAM Engine treats it as the default. Every built-in system processes all agents at once, with the goods market's sequential matching rounds as the deliberate exception where strict per-agent ordering matters.
See the User Guide for a full walkthrough of the model and its architecture.
Documentation
Full documentation is available at bam-engine.readthedocs.io.
| Section | Description |
|---|---|
| Getting Started | Installation, first simulation, data collection |
| User Guide | Model overview, configuration, custom roles/events, pipelines, best practices |
| API Reference | Complete reference for all components and operations |
| Examples | 16 runnable examples: basic, advanced, and extensions |
| Extensions | R&D / Growth+, buffer-stock consumption, taxation |
| Validation | Scenario validation, scoring, robustness analysis |
| Calibration | Morris screening, grid search, stability testing |
Development
git clone https://github.com/kganitis/bam-engine.git
pip install -e ".[dev]"
pytest
ruff format . && ruff check --fix . && mypy
This project is part of ongoing MSc thesis research at the University of Piraeus, Greece. Code contributions will be welcome after thesis submission. In the meantime, bug reports, feedback, and documentation suggestions are appreciated via the issue tracker.
See the Development Guide for more on testing, linting, benchmarking, and contributing.
Citation
If you use BAM Engine in your research, please cite:
- This software - Use
CITATION.cffor GitHub's "Cite this repository" - The original BAM model - Delli Gatti, D., Desiderio, S., Gaffeo, E., Cirillo, P., & Gallegati, M. (2011). Macroeconomics from the Bottom-up. Springer. DOI: 10.1007/978-88-470-1971-3
License
MIT License - see LICENSE for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file bamengine-0.10.0.tar.gz.
File metadata
- Download URL: bamengine-0.10.0.tar.gz
- Upload date:
- Size: 285.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0fbad9796500decf69e4c55e7e6494d50ca3a96a446c1cb9ccb4f0a2a26959c6
|
|
| MD5 |
1a11d97ee93f5b435eac11f7b4f6abf5
|
|
| BLAKE2b-256 |
d3af48db84a5b49a490888c505e7eacacecda99e4bada93c1f6460994e10081b
|
Provenance
The following attestation bundles were made for bamengine-0.10.0.tar.gz:
Publisher:
publish.yml on kganitis/bam-engine
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
bamengine-0.10.0.tar.gz -
Subject digest:
0fbad9796500decf69e4c55e7e6494d50ca3a96a446c1cb9ccb4f0a2a26959c6 - Sigstore transparency entry: 2085097779
- Sigstore integration time:
-
Permalink:
kganitis/bam-engine@0454866418b01c3fb0a344c9ed93a2cdc6c6a73c -
Branch / Tag:
refs/tags/v0.10.0 - Owner: https://github.com/kganitis
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@0454866418b01c3fb0a344c9ed93a2cdc6c6a73c -
Trigger Event:
release
-
Statement type:
File details
Details for the file bamengine-0.10.0-py3-none-any.whl.
File metadata
- Download URL: bamengine-0.10.0-py3-none-any.whl
- Upload date:
- Size: 338.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
37348b54a7e7f51a1d5762da2fa0c33e1e161e643e7b9347fe1ea6ff6082a6c7
|
|
| MD5 |
261c8f3cf897b5172fe80c0a859f305f
|
|
| BLAKE2b-256 |
72961e9f53ee4a60b17d6907f55cc56c19a6cbf1fbfc39da98989386dcd70442
|
Provenance
The following attestation bundles were made for bamengine-0.10.0-py3-none-any.whl:
Publisher:
publish.yml on kganitis/bam-engine
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
bamengine-0.10.0-py3-none-any.whl -
Subject digest:
37348b54a7e7f51a1d5762da2fa0c33e1e161e643e7b9347fe1ea6ff6082a6c7 - Sigstore transparency entry: 2085097792
- Sigstore integration time:
-
Permalink:
kganitis/bam-engine@0454866418b01c3fb0a344c9ed93a2cdc6c6a73c -
Branch / Tag:
refs/tags/v0.10.0 - Owner: https://github.com/kganitis
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@0454866418b01c3fb0a344c9ed93a2cdc6c6a73c -
Trigger Event:
release
-
Statement type: