Riadh Mnasri
← Back to blog
3 min read

Counterparty risk, explained to a developer

When I explain what I do in investment banking to developers who have never touched finance, I always reach for the same analogy: counterparty risk is an external dependency problem that can fail at the worst possible time.

The problem, as a distributed systems issue

Imagine a service A that calls a service B to honor a future promise (a payment in six months, for instance). Counterparty risk is the probability that service B is down exactly when A needs it, and the cost that represents if A had relied on it without a safety net.

In finance, that service B is a counterparty: a bank, a fund, a company, with whom you hold a contract (often a derivative). The risk is that it defaults before the contract matures.

EAD, PFE, CVA: three metrics, three questions

  • EAD (Exposure At Default): if the counterparty defaults right now, how much do I lose? A bit like measuring the current state of an open connection.
  • PFE (Potential Future Exposure): in a plausible worst case, how high can my exposure climb before maturity? This is a Monte Carlo simulation across thousands of possible market paths.
  • CVA (Credit Valuation Adjustment): how much does it cost, in today's value, to carry that default risk for the entire life of the contract? It's the price you pay for the uncertainty.
MetricQuestion it answersHorizon
EADIf the counterparty defaults right now, how much do I lose?Today
PFEIn a plausible worst case, how high can my exposure climb?Future (simulated)
CVAWhat does it cost, in today's value, to carry the default risk over the contract's life?Entire contract life

A simplified worked example

Take a counterparty with a current exposure of €10M (EAD), an estimated 1.5% annual probability of default (derived from its rating), and an assumed 40% recovery rate in case of default (you don't lose everything, some of it is usually recoverable):

Loss given default = EAD × (1 - recovery rate)
                    = 10,000,000 × (1 - 0.40)
                    = 6,000,000 €

CVA (simple approximation) = Loss given default × probability of default
                            = 6,000,000 × 0.015
                            ≈ 90,000 €

Those €90,000 represent, in today's value, the cost of carrying that counterparty risk over the year: that's the amount a bank provisions for, or passes on in the derivative's price. A real CVA calculation is far more complex (it factors in the term structure of credit risk and how exposure evolves over time through Monte Carlo simulation), but the intuition stays the same: the higher the exposure or the default probability, the higher the cost of the risk climbs.

Why it's a good playground for a curious developer

What makes the topic technically interesting is that it forces you to combine heavy numerical simulation (thousands of simulated market scenarios) with real performance constraints: these calculations run every night across a bank's entire portfolio, and must finish before markets open the next day.

That intersection between mathematical rigor and engineering constraints is what made me want to build counterparty-risk-lab and kotlin-counterparty-risk: pedagogical, TDD-driven implementations meant to make these concepts approachable for any curious developer, without access to a real banking system.