Back to Projects
2026 // CREDIT RISK & PORTFOLIO LOSS

CREDIT RISK ENGINE

A portfolio credit loss engine that turns a book of obligor exposures into a full loss distribution, not just an expected-loss number, covering both default risk (exact Panjer recursion) and migration risk (Merton/CreditMetrics-style single-factor stress) as separate, additively-combined capital components.

Go to Repo
Credit Risk Engine (aggregate default loss distribution)
Role
Researcher & Developer
Stack
Python / NumPy / Matplotlib
Domain
Credit Risk / Portfolio Loss
Scopes
3 Sequential Pipelines

THE IDEA

A one-number expected loss hides everything a risk manager actually needs: how fat the tail is, how much a handful of names drive the whole book's capital, and how much worse things get in a downturn. This engine builds the full loss distribution instead, anchored to three real market-data points already retrieved from live IG quotes (PFE volatility shock, collateral haircut, and the risk-free curve), with everything credit-specific (ratings, PD, recovery, transition matrix, correlation) simulated from public-style reference tables and fully documented in a PROVENANCE dict.

Default risk and migration risk are modelled as genuinely separate mechanisms and combined additively into total credit capital, rather than folded into one blended number.

THE THREE SCOPES

ScopeMethodOutput
1. ExposureUltimate-parent aggregation, EAD incl. derivative PFE add-on, downturn LGDPer-obligor EAD, PD, LGD, expected loss
2. Default LossBanding, negative-binomial frequency, exact Panjer recursionFull aggregate loss distribution, default capital (99.5%), HHI, marginal capital
3. MigrationMerton-style single-factor stressed transition matrixMigration capital, reverse stress, combined marginal capital

DEFAULT LOSS (EXACT, NOT SIMULATED)

Rather than approximating the aggregate default loss distribution with Monte Carlo noise, Scope 2 computes it exactly via Panjer recursion on a Poisson-Gamma (negative-binomial) frequency model, validated against brute-force enumeration to floating-point precision. On an example 18-obligor, $21.0m EAD book, that yields a portfolio EL of $0.96m and a 99.5% default capital of $5.29m.

CONCENTRATION IS CONVEX

A worked example makes diversification tangible: the same $10m of total exposure concentrated in a single name costs roughly 7x more capital per dollar of EAD than the identical exposure spread across 20 obligors, the concentration-convexity result that motivates the leave-one-out marginal capital reported per obligor.

MIGRATION UNDER STRESS

The single-factor Merton stress shifts mass from stay/upgrade toward downgrade/default across the entire transition matrix. On the reference matrix, a CCC-rated obligor's one-year default probability moves from 20% unconditional to 64% under the 99.5% stress, the kind of nonlinearity a static, unconditional transition matrix can't show.

KEY RESULTS

$5.96m
Total credit capital on the example 18-obligor, $21.0m EAD book
7x
Capital-per-dollar cost of single-name concentration vs. spreading across 20 names
64%
Stressed 1-year default probability for a CCC obligor, up from 20% unconditional
Exact
Panjer recursion for the aggregate default loss distribution, no Monte Carlo noise