Wrong-Way Risk (WWR) estimation for counterparty credit risk.
Project description
wayfault
Wrong-Way Risk (WWR) estimation for counterparty credit risk.
wayfault quantifies the adverse dependence between exposure and counterparty
credit quality — the risk that exposure rises precisely when the counterparty
deteriorates (WWR), and its favourable mirror, Right-Way Risk (RWR). It takes a
Monte-Carlo exposure cube and a credit curve as inputs and produces:
- baseline (independence-assumption) exposure metrics and CVA,
- a conditional expected exposure given default under a pluggable dependence model,
- a WWR-adjusted CVA and the empirical alpha multiplier
α = WWR-CVA / independent-CVA, - ML-based calibration of the dependence parameter,
- WWR/RWR classification and diagnostics.
The library does not generate exposures or bootstrap curves — those are inputs.
Architecture
wayfault follows a strict hexagonal (ports & adapters) design. The
dependency rule points inward: adapters → application → ports → domain. The
domain, application, and ports layers import only the standard library
and numpy. Optional adapters import their heavy dependencies lazily and
raise a clear MissingDependencyError if the extra is not installed.
Install
pip install -e . # core (numpy only)
pip install -e '.[io,ml,viz,dev]' # with all optional extras + tooling
Optional extras:
| Extra | Enables | Pulls in |
|---|---|---|
[io] |
CSV/Parquet source adapters | pandas, pyarrow |
[ml] |
scikit-learn survival calibrator | scikit-learn |
[viz] |
diagnostic plots | matplotlib |
[dev] |
tests, type-checking, linting | pytest, mypy, … |
Quickstart
import numpy as np
from wayfault import estimate_wwr
from wayfault.adapters.outbound.exposure_inmemory import InMemoryExposureSource
from wayfault.adapters.outbound.credit_flat import FlatHazardCreditCurveSource
from wayfault.adapters.outbound.dependence_hullwhite import HullWhiteHazardModel
cube = np.random.default_rng(0).normal(size=(10_000, 12)) + 1.0 # scenarios x tenors
tenors = [i / 4 for i in range(1, 13)] # quarterly to 3y
result = estimate_wwr(
exposure=InMemoryExposureSource(cube, tenors),
credit=FlatHazardCreditCurveSource(hazard=0.02, recovery=0.4),
model=HullWhiteHazardModel(b=0.5), # b > 0 -> wrong-way
)
print(result.baseline_cva, result.wwr_cva, result.alpha, result.classification)
A full runnable example lives in examples/quickstart.py
and uses only the in-memory adapters (zero extras).
CLI
python -m wayfault estimate \
--exposure cube.csv --credit curve.csv \
--model hullwhite --b 0.5 --out result.json
(--exposure/--credit CSV ingestion requires the [io] extra.)
Dependence models
| Model | Knob | WWR when | Notes |
|---|---|---|---|
IndependentModel |
— | — | conditional EE ≡ unconditional EE |
HullWhiteHazardModel |
b |
b > 0 |
λ(t) = exp(a(t) + b·V(t)) (Hull–White) |
GaussianCopulaModel |
ρ |
ρ > 0 |
one-factor Gaussian copula |
Calibration
RegressionCalibrator— numpy-only OLS estimate of the Hull–Whiteb.SklearnSurvivalCalibrator—[ml]covariate-hazard surrogate.
Development
pytest # tests
mypy --strict src # type checks
ruff check # lint
Reference: Hull & White, CVA and Wrong-Way Risk (2012).
License
MIT.
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
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 wayfault-0.1.0.tar.gz.
File metadata
- Download URL: wayfault-0.1.0.tar.gz
- Upload date:
- Size: 20.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
733efaec7e33de2adcee5ffbf97f0d67124d030072efbc10b90bf369603d3941
|
|
| MD5 |
105596c362d3e1e35f9d455d8b6d25ae
|
|
| BLAKE2b-256 |
de7cb6e9349ee4426606f384a8ab66d56388d67cf601001da47495494b50ac7f
|
File details
Details for the file wayfault-0.1.0-py3-none-any.whl.
File metadata
- Download URL: wayfault-0.1.0-py3-none-any.whl
- Upload date:
- Size: 30.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
73e70865eeade4cff135b50571d447e3e1b844f0ae46d6daca55b9c3adacdd93
|
|
| MD5 |
df0969730ffa7c36bd7c2033deb25754
|
|
| BLAKE2b-256 |
476fe68dbec82e1d392a27f5398e608ed7e29946cbfb035c64a205e9392af748
|