Quant Memo
Core

Optimal Transport

A way of measuring the cheapest way to reshape one distribution of mass into another — like moving piles of dirt to fill holes with minimum total effort — that gives a natural notion of 'distance' between two probability distributions, not just between two points.

Prerequisites: Convex Sets and Convex Functions, Duality and the Dual Problem

You often need to compare two probability distributions — a model's predicted return distribution versus the historically observed one, or a portfolio's factor exposure profile before and after a rebalance. Common tools like KL divergence measure how "surprised" one distribution is by another, but they don't respect the underlying geometry — two distributions that are nearly identical but shifted slightly can register as very different under KL divergence, even though intuitively they're "close." Optimal transport instead asks a physically grounded question: what is the cheapest way to move mass from the shape of one distribution to the shape of the other, given that moving mass a long distance costs more than moving it a short distance?

An analogy: filling holes with piles of dirt

Imagine several piles of dirt scattered across a site, and several holes elsewhere needing exactly that much dirt. There are many ways to assign which pile fills which hole, but moving dirt further takes more work. Optimal transport finds the assignment that minimizes the total distance-weighted effort (mass moved times distance moved) across the whole site. Applied to probability distributions, the "piles" are the mass sitting at each point of one distribution, the "holes" are where the other distribution wants mass to end up, and "distance" is however you measure how far apart two outcomes are (a difference in return, factor exposure, or price).

The framework, one symbol at a time

Given a source distribution μ\mu and target distribution ν\nu, and a cost function c(x,y)c(x,y) for moving one unit of mass from location xx to location yy, the optimal transport problem finds a transport plan π(x,y)\pi(x,y) — a joint distribution describing how much mass moves from each xx to each yy — minimizing

W(μ,ν)=minπc(x,y)π(x,y)dxdy,W(\mu,\nu) = \min_{\pi} \int c(x,y) \, \pi(x,y) \, dx\, dy ,

subject to π\pi's marginals matching μ\mu and ν\nu (all the mass that leaves μ\mu's locations must arrive somewhere, and the total arriving at each location of ν\nu must match what's needed there). In plain English: among every way of matching up the source mass with the target mass, find the one whose total (amount moved) ×\times (distance moved), summed over all mass, is smallest. When c(x,y)=xyc(x,y)=|x-y|, the resulting minimum cost W(μ,ν)W(\mu,\nu) is called the Wasserstein distance (or "earth mover's distance") — a genuine distance metric between two distributions that respects how far apart their masses actually sit in space, unlike divergence measures that only compare probabilities point-by-point without any notion of spatial closeness.

Worked example 1: two discrete piles by hand

Source distribution has mass 0.6 at location 0 and 0.4 at location 10. Target distribution has mass 0.5 at location 2 and 0.5 at location 8. One feasible plan: move 0.5 from source-0 to target-2 (distance 2, cost 0.5×2=1.00.5\times2=1.0), then the remaining 0.1 from source-0 to target-8 (distance 8, cost 0.1×8=0.80.1\times8=0.8), then 0.4 from source-10 to target-8 (distance 2, cost 0.4×2=0.80.4\times2=0.8). Total cost =1.0+0.8+0.8=2.6=1.0+0.8+0.8=2.6. An alternative plan — moving all 0.6 from source-0 toward target-8 and all 0.4 from source-10 toward target-2 — would cost 0.5(0.6×8)+...0.5(0.6\times8) + ... intuitively crossing the mass over itself, giving a clearly larger total (source-0 to target-8 alone costs 0.6×8=4.80.6\times8=4.8, already worse than the entire first plan). Optimal transport formalizes exactly this "don't let the flows cross" intuition and finds the true minimum-cost assignment systematically, which becomes essential once there are many more than two piles.

Worked example 2: comparing a model to reality

A quant compares a model's predicted P&L distribution (mass 0.7 at $0, mass 0.3 at $100) against realized outcomes (mass 0.7 at $10, mass 0.3 at $90). Matching mass-for-mass at the same weights: 0.7 moves from $0 to $10 (distance 10, cost 0.7×10=70.7\times10=7), and 0.3 moves from $100 to $90 (distance 10, cost 0.3×10=30.3\times10=3). Total Wasserstein cost =10=10 (in dollar-mass units). This single number summarizes "how far" the model's distribution sits from reality's, in a way a plain comparison of means ($30 predicted vs $34 realized, barely different) would completely miss, since it captures that entire probability masses are systematically offset even when overall averages look similar.

source: 0.6 source: 0.4 target: 0.5 target: 0.5
Optimal transport finds the mass-to-mass matching between source and target piles that minimizes total (mass × distance) moved — the cheapest, non-crossing assignment wins over naive pairings.

What this means in practice

Optimal transport gives a geometrically meaningful distance between distributions, used in generative modeling (Wasserstein GANs), comparing simulated versus realized return distributions, robust portfolio optimization under distributional uncertainty, and domain adaptation when a model trained on one data regime is applied to another. Its main computational cost is that solving the exact transport plan is itself a linear program that can be expensive for large distributions, which is why fast approximations (like entropy-regularized "Sinkhorn" transport) are common in practice.

Optimal transport measures the distance between two distributions as the minimum total cost of moving all the probability mass of one into the shape of the other — respecting the actual geometric distance mass must travel, unlike divergence measures that compare probabilities point-by-point without any sense of spatial closeness.

It's tempting to reach for KL divergence or another likelihood-based divergence whenever comparing two distributions, but those measures can behave badly (even becoming infinite) when the two distributions have little or no overlapping support — for instance, two nearly identical distributions shifted slightly apart. Optimal transport's Wasserstein distance remains well-behaved and meaningfully small in exactly this case, which is precisely why it's preferred when distributions might be structurally similar but not overlapping, such as comparing a simulated and a realized return distribution over a short window.

Related concepts

Practice in interviews

Further reading

  • Peyré & Cuturi, Computational Optimal Transport
  • Villani, Optimal Transport: Old and New
ShareTwitterLinkedIn