Skip to main content

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

Project description

merton

PyPI version Python versions License CI Docs 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.0.tar.gz (214.8 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.0-py3-none-any.whl (165.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: merton-1.0.0.tar.gz
  • Upload date:
  • Size: 214.8 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.0.tar.gz
Algorithm Hash digest
SHA256 7f1c78d6d01285b3dd700e14de165d819f72e26e66849f3ce61e82a7384ce96a
MD5 1f40b264d4d9f92d5be9609cc8993b76
BLAKE2b-256 fbd27768c635c87c45bf9f9dccc8404b363aa04f9be459c83ae8f7506bf2fd23

See more details on using hashes here.

Provenance

The following attestation bundles were made for merton-1.0.0.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.0-py3-none-any.whl.

File metadata

  • Download URL: merton-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 165.8 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 42d45fbcfc8ce8775e397335d1c9ab1ec2d760d464b65281aa45e050e831e259
MD5 244a44c5b968de742c1cfbda018afe7d
BLAKE2b-256 bb6cf7a1f444e47c094210778f312defbc13757d8b3dec006332a771ce393cd2

See more details on using hashes here.

Provenance

The following attestation bundles were made for merton-1.0.0-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