Skip to main content

Production-grade Merton structural credit-risk model and extensions.

Project description

merton

PyPI version Python versions License CI Docs DOI Code style: ruff Typed

A production-grade Python package for the Merton structural credit-risk model and its industry-standard descendants (KMV, Black-Cox, Geske, Longstaff-Schwartz, CreditGrades, Leland-Toft, jump-diffusion, Vasicek portfolio, climate overlays).

🚀 New in 1.0 — first stable release. API frozen per semver, cold import merton down to ~500 ms (from ~1.1 s), conda-forge feedstock in review. See the announcement post and the migration guide.

Highlights

  • Vectorized core — single-firm and panel-scale (10 000+ firms × decades) with NumPy by default and optional Numba / JAX / CuPy / MLX backends.
  • Multiple calibration methods — Vassalou-Xing iterative MLE, Duan transformed-data MLE (with survivorship-bias correction), Jones-Mason-Rosenfeld, Bharath-Shumway naive, KMV iterative (Crosbie-Bohn).
  • Full extensions library — Black-Cox first-passage, Geske compound options, Longstaff-Schwartz stochastic rates, CreditGrades, Leland-Toft endogenous default, Zhou jump-diffusion, hybrid structural/reduced-form, climate overlays.
  • Portfolio engine — Vasicek single-factor (Basel IRB closed-form), Gaussian / t / Clayton / factor copulas, Monte Carlo loss distribution with VaR / ES / economic capital.
  • Backtesting harness — AUC, Brier, KS, accuracy ratio, reliability / calibration curves, rolling-window and walk-forward validation.
  • Excel integration=MERTON_DD(equity, σE, debt, rf, T) and friends, available in Excel Web, Excel Mac (M365), and Excel Windows via xlwings Server.
  • Climate stress — composable Scenario framework with packaged NGFS Phase V (2024) scenarios (net_zero_2050, delayed_transition, current_policies, fragmented_world); ClimateOverlay wraps any structural model with carbon-price paths and sectoral PD multipliers.
  • OpenTelemetry observability — opt-in via merton.obs.enable(...); pipes spans to any OTLP-compatible backend (Datadog, Honeycomb, Tempo, …).
  • Modern Python — type hints, Pydantic settings, structured logging, Apache-2.0 license, cross-platform wheels for Python 3.11-3.14 (incl. free-threaded).

Quickstart

uv pip install merton          # or: pip install merton
from merton import Firm, fit

firm = Firm(
    equity=100_000_000,        # $100M market cap
    debt_short=20_000_000,
    debt_long=30_000_000,
    equity_vol=0.30,
    rf=0.045,
    horizon=1.0,
)

result = fit(firm, method="vassalou_xing")
print(result.summary())
# MertonResult
#   distance_to_default : 3.142
#   probability_of_default : 0.000839
#   asset_value : 148.6M
#   asset_vol : 0.207
#   implied_spread (LGD=0.6) : 5.0 bps

Excel integration

merton excel install
merton excel server start --port 8000

Then in any Excel workbook (Web / Mac / Windows):

=MERTON_DD(B2, B3, B4+B5, B6, B7)        # distance to default
=MERTON_PD(B2, B3, B4+B5, B6, B7)        # probability of default
=MERTON_SPREAD(B2, B3, B4+B5, B6, B7, 0.6)

See the Excel docs for the full reference.

Performance

  • Single-firm fit: <50 ms
  • 10 000-firm × 10-year daily panel: <60 s on 8 cores (Numba backend)
  • 100 000-sim portfolio VaR: <30 s with GPU (CuPy)

Documentation

Full docs at https://merton.readthedocs.io including:

  • Theory deep-dives (Merton 1974, KMV, Black-Cox, Geske, …)
  • Executable tutorials (AAPL time series, panel backtest, portfolio VaR, climate stress test, GPU acceleration, Excel integration)
  • API reference
  • Performance benchmarks and backend-selection guide

Installation matrix

Goal Command
Minimum (CPU NumPy) pip install merton
Numba JIT (default fast path) pip install merton (Numba is a hard dep)
GPU acceleration pip install "merton[gpu]" (requires CUDA 12)
JAX autodiff calibration pip install "merton[jax]"
Apple Silicon GPU pip install "merton[mlx]"
Excel integration pip install "merton[excel]"
Visualization (matplotlib + plotly) pip install "merton[viz]"
Bayesian MCMC calibration pip install "merton[mcmc]"
OpenTelemetry tracing pip install "merton[obs]"
Everything pip install "merton[all]"

License

Apache-2.0 — see LICENSE.

Citing

If you use merton in academic work, please cite via the CITATION.cff file or the package's Zenodo DOI (assigned on first tagged release).

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

merton-1.0.1.tar.gz (215.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

merton-1.0.1-py3-none-any.whl (165.9 kB view details)

Uploaded Python 3

File details

Details for the file merton-1.0.1.tar.gz.

File metadata

  • Download URL: merton-1.0.1.tar.gz
  • Upload date:
  • Size: 215.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for merton-1.0.1.tar.gz
Algorithm Hash digest
SHA256 68a25e463eac1340de77ef351267748c72b15530ce92e38a3d69b80d181a6a1a
MD5 ccf613b66d363e4b18578776a3f6303e
BLAKE2b-256 b8527f94962948d006bd334f4e06965f8cacf325ebe4dbd7691e769b9dd255f5

See more details on using hashes here.

Provenance

The following attestation bundles were made for merton-1.0.1.tar.gz:

Publisher: wheels.yml on ItsSypher/merton

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file merton-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: merton-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 165.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for merton-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d278046affc89de067030ad3f778ea45d6b58393fe0d55f4ff6f7661aaff2ac4
MD5 590b4d06c49284689c398873d5597e9e
BLAKE2b-256 b6d96d36e750614a2d790709fa7e205132553034f2fe786c17994c2648f01066

See more details on using hashes here.

Provenance

The following attestation bundles were made for merton-1.0.1-py3-none-any.whl:

Publisher: wheels.yml on ItsSypher/merton

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page