Skip to content

PyMetrix

Applied macroeconometrics in Python, from data to forecast report. Estimate equations and systems, test them, solve models, run scenarios, manage forecast rounds and export reports, from Python scripts, Jupyter notebooks or a desktop app with guided forms. Every action becomes Python you can read and rerun.

pymetrix is for economists in policy institutions, teaching and research who want Python's openness without assembling their work from notebooks, spreadsheets, GUI packages and one-off scripts. It covers much of what EViews and MATLAB/IRIS are used for, and it is open source (BSD-3-Clause).

Status: development build (0.1.0a23, on PyPI as a pre-release). One developer so far; public and open source (BSD-3-Clause), and reviews, bug reports and contributions are welcome ahead of 0.1 (CONTRIBUTING.md). The core works and is tested on Windows and Linux; see known gaps for what is missing or rough, and the changelog.

What's new since 0.1.0a8: DSGE estimation with the No-U-Turn sampler, the particle filter, DSGE-VAR and OccBin with regimes; zero and sign restrictions and historical decompositions with bands for VARs; conditional forecasts with ranges and structural scenarios; applied microeconometrics (double machine learning, shift-share IV, interactive fixed effects, conditional logits); copulas and more in the finance plugin; the FRB/US example; and in the app, Redo, a series browser and figures annotated by dragging. The changelog has every detail.

Why pymetrix

  • One workflow. Data and transformations, estimation and diagnostics, model solving and scenarios, forecast rounds with judgement, backtests and reports live together and pass results to each other.
  • Reproducible by design. Every dialog records the Python it runs. A project saves the data and the steps and rebuilds the results when opened, and results know their sample, method and data vintage. Typed code in a project runs only once you trust it.
  • Numbers you can check. Wherever a mature library exists (statsmodels, linearmodels, arch, SciPy), pymetrix uses it; its own code is checked against libraries, published tables, other packages and hand formulas. Validation lists the checks, and defaults (also a help page in the app) says where pymetrix's defaults differ from EViews' and Stata's.
  • Python first, guided when you want it. Write scripts and notebooks for control; use forms for guidance and teaching. Plugins add estimators, tests, data sources and course material, and they appear in the forms, the help and the scripts automatically.
  • Coming from EViews. The pymetrix-eviews plugin (experimental, packages/pymetrix-eviews) reads workfiles through a bundle its export program writes, and translates EViews programs into readable pymetrix scripts with a report on every line: data work, estimation, tests, models and control flow (loops, ifs, subroutines), in code or with File → Translate EViews program… and its panel.
  • R scripts. The pymetrix-r plugin (experimental, packages/pymetrix-r, pip install -e packages/pymetrix-r in a clone) translates R scripts into readable pymetrix scripts with a report on every line, without R: data work with dplyr, lm and glm, sandwich's covariances, feols, plm, unit-root tests and vars, in code or from the command line.
  • Debt sustainability analysis. The pymetrix-fiscal plugin (experimental, packages/pymetrix-fiscal, pip install -e packages/pymetrix-fiscal in a clone) does the deterministic DSA, PyMetrix's implementation of the published guidance. It has the debt-dynamics identity with local- and foreign-currency debt, the SRDSF and 2013 MAC DSA decompositions, gross financing needs, the debt-stabilising primary balance and the Debt Dynamics Tool's stress tests, in code or from the Fiscal menu.
  • Heterogeneous-agent models. The pymetrix-ha plugin (experimental, packages/pymetrix-ha, pip install -e packages/pymetrix-ha in a clone) solves models with households that differ in income and wealth, such as Krusell-Smith, by wrapping sequence-jacobian. It gives steady states, Jacobians, impulse responses and nonlinear transitions as pymetrix results, in code.

Install

On PyPI as a pre-release: pip install --pre "pymetrix[all]" (0.1.0a23; the plugins too: pymetrix-eviews and pymetrix-finance 0.1.0a2, -seasonal, -guide, -labbook and -assistant 0.1.0a1). Reviewers: installing pymetrix covers PyPI, the wheel attached to each release, installing from this repository, and Codespaces. From a clone, with Python 3.11 or later:

pip install -e ".[all]"

[all] adds linearmodels, arch, scikit-learn, the desktop app (PySide6), Jupyter forms and report writers, and the plugins published on PyPI (finance, EViews, seasonal adjustment, lab book, guide and assistant); the core needs NumPy, pandas, SciPy, statsmodels, matplotlib and pyarrow. In a clone, [all] takes the plugins from PyPI: add -e packages/pymetrix-finance (and so on) to the same command to work on the clone's own.

Try it in your browser, with nothing to install: open this repository in GitHub Codespaces (open a codespace, or Code → Codespaces → Create codespace). The codespace installs pymetrix and opens the desktop app with the Lab 3 demo on a desktop in your browser: in the Ports tab, open pymetrix desktop (port 6080), then connect with the password vscode. Notebooks run there too. It uses your GitHub account's free monthly Codespaces allowance; see .devcontainer/README.md.

Quick start

from pymetrix import OLS, Dataset, Equation, Model, Scenario

data = Dataset.example("sample_macro")            # a simulated quarterly economy, installed with pymetrix
cons = Equation("c ~ y + c[-1]").fit(data, method=OLS(cov="hac"))
print(cons.summary())
print(cons.test("breusch_godfrey", lags=4))

model = Model([cons, Equation("i ~ y[-1]").fit(data), Equation("y = c + i + g")])
base = model.solve(data, ("2020Q1", "2024Q4"))
more_g = model.solve(data, ("2020Q1", "2024Q4"), scenario=Scenario(shift={"g": 5.0}))
print(((more_g["y"] - base["y"]) / 5).loc["2020Q1":"2020Q4"])   # the spending multiplier, building up

The desktop app is pymetrix-gui: start with Load example data (or your own file), then the Estimate, Test, Model and Forecast menus. File → Export script shows what you did as Python. pymetrix-gui project.pymx opens a project, and pymetrix-gui --demo forecast_round a demo (also File → Open demo project…); --maximized fills the screen.

Try the demos

Three demos, on one simulated economy installed with pymetrix:

  • Teaching: Lecture 1, a consumption function linked into the help (OLS against IV: simultaneity bias, and the true parameters recovered), and the Lab 2 exercise: estimate, test, model and a fiscal scenario. The instructor's solution is in examples/solutions.
  • Python: Lab 4, pymetrix as a library:
  • estimators side by side, and a cross-check against statsmodels;
  • a new estimator added as a plugin;
  • dialog steps as plain Python;
  • a New Keynesian model estimated from data by maximum likelihood, and what is weakly identified.
  • Modelling: building and estimating models for Dynare and IRIS users, and two demo projects in the app (pymetrix-gui --demo nk_estimation, --demo policy_and_nonlinear): Bayesian estimation, identification, the lower bound, optimal policy and second order.
  • Policy: Lab 3, a quarterly forecast round:
  • VAR forecast, judgement and revisions;
  • a backtest against a Bayesian VAR;
  • a structural fiscal scenario;
  • a report with provenance, also from the forecast_round template in the policy theme;
  • the project reopened;
  • a nowcast of the quarter in progress from monthly indicators (bridge equation and dynamic factor model), with the news as the quarter's figures arrive.
  • Forecasting course: six labs following the topics of Elliott and Timmermann's Economic Forecasting:
  • loss functions, forecast comparison, combination, densities, many predictors, and breaks;
  • each on simulated data with known answers, and checked against an independent calculation;
  • with a chapter-by-chapter coverage map.

The teaching and policy demos also run from the desktop app's menus. Every notebook runs in the test suite, so the demos are tested on every change, and none of them uses AI.

Documentation

  • Start here: building and estimating models: for Dynare and IRIS users, equations to an estimated, forecasting model in one runnable script
  • User guide: every area by topic, with short examples
  • How do I…: task pages, each one task start to finish, in the app and in code (also Help → How do I… in the app)
  • Features: what works and what is planned
  • Validation: what the numbers are checked against
  • Known gaps: what is missing or rough
  • Concepts: the objects and verbs pymetrix is built from, and what is planned
  • Design: architecture, decisions and the build log
  • Adding features: how a method, test or command is added so it works in scripts, forms, notebooks, projects and reports alike
  • Wrapping another library: the general form of a wrapper, with a worked example
  • Writing a case study: for lecturers, a lab the app's Guide panel takes trainees through
  • An MCP server: pymetrix for AI assistants (pip install pymetrix[mcp]), every step recorded and replayable
  • In the app, Help (F1) has a page for every dialog, method and test, and links to the wrapped libraries' documentation

The project

pymetrix is founder-led and open to review before its 0.1 release:

  • Pitch: where pymetrix is going, on one page, for reviewers and collaborators;
  • Status: what exists today against the design objectives, and the gaps;
  • How to help: replications, testing, teaching and plugins that need an owner;
  • Roadmap: the stages from the first demos to 0.1 and after;
  • Governance: roles, decisions, intellectual property and AI-assisted work;
  • Contributing: what a change needs, and the DCO sign-off;
  • Security: project trust, plugins, and reporting problems.

Background notes: - Positioning: where pymetrix sits among open-source workbenches; - AI-assisted development: the reasoning behind the AI rules; - AI in the UI: the planned design for an assistant.

Contributing

See CONTRIBUTING.md.

pip install -e ".[dev,jupyter]"
pytest

Licence

BSD-3-Clause (see LICENSE). The name PyMetrix™ and the PyMetrix logo are trademarks, not covered by the licence: see TRADEMARKS.md for how they may be used. Bundled datasets and test fixtures from elsewhere, and what pymetrix downloads when asked, are listed with their sources and licences in THIRD-PARTY-NOTICES.md.