Quant Memo
Core

Quantile (Pinball) Loss for Neural Forecasting

A model trained on squared error can only output one number — its best guess at the mean; quantile loss trains a network to output an entire range of outcomes, like a 90% confidence band, by penalizing over- and under-prediction asymmetrically.

Prerequisites: Loss Functions for Regression

A model trained with mean squared error learns to output one number: its best estimate of the average outcome. But a risk manager doesn't just want the average next-day return — they want to know "what's the worst plausible outcome I should size for," a specific quantile like the 5th percentile, not the mean. Getting a network to output a chosen quantile instead of the mean requires a different loss function that penalizes over-prediction and under-prediction by different amounts, in a ratio set by which quantile you want.

The analogy: a delivery company hedging against being late

A delivery company promising a "90% on-time" estimate isn't promising the average delivery time — it's promising a time that 90% of deliveries beat. To find that number, being early is barely penalized (arriving early is fine), but being late is penalized heavily and often (it should only happen 10% of the time). Tune that penalty ratio and you get a different promised time: a "50% on-time" estimate penalizes early and late symmetrically, landing back on the median. Quantile loss (also called pinball loss) is exactly this asymmetric penalty, made precise with a number.

The formula

For a target quantile τ(0,1)\tau \in (0,1) (e.g. τ=0.9\tau = 0.9 for the 90th percentile), residual r=yy^r = y - \hat{y}:

Lτ(r)={τrr0(τ1)rr<0L_\tau(r) = \begin{cases} \tau \cdot r & r \ge 0 \\ (\tau - 1) \cdot r & r < 0 \end{cases}

In words: when the model under-predicts (r=yy^0r = y - \hat{y} \ge 0, the true value came in above the forecast), the penalty is τ\tau times the gap. When the model over-predicts (r<0r < 0), the penalty is (1τ)(1-\tau) times the gap (since τ1\tau - 1 is negative, multiplying it by a negative rr gives a positive loss). For τ=0.9\tau = 0.9, under-predicting is penalized 9 times more heavily than over-predicting by the same amount — which pushes the model's optimal output up, away from the mean, until only 10% of outcomes exceed it. That is exactly the defining property of the 90th percentile.

Worked example 1: computing pinball loss by hand at τ=0.9\tau = 0.9

Suppose the model forecasts y^=100\hat{y} = 100 and the true outcome is y=108y = 108 (an under-prediction, r=80r = 8 \ge 0): loss =0.9×8=7.2= 0.9 \times 8 = 7.2. Now suppose instead the true outcome is y=95y = 95 (an over-prediction, r=5<0r = -5 < 0): loss =(0.91)×(5)=0.5= (0.9 - 1) \times (-5) = 0.5. The same roughly-sized miss costs 14 times more when the model under-shot than over-shot — exactly the asymmetry needed to push the trained forecast upward toward the 90th percentile.

τ=0.9 τ=0.5 (median) τ=0.1
Three quantile heads trained at τ=0.1, 0.5, 0.9 on the same inputs produce a full forecast band around the median from one network.

Worked example 2: recovering the median at τ=0.5\tau = 0.5

At τ=0.5\tau = 0.5: under-prediction penalty is 0.5×r0.5 \times r, over-prediction penalty is (0.51)×r=0.5r(0.5-1)\times r = -0.5r, which for negative rr gives 0.5r0.5|r| — the two cases are now penalized identically per unit of error. This symmetric case is exactly the ordinary mean absolute error loss, and minimizing it is well known to recover the median of the target distribution, not the mean. This confirms the formula behaves correctly at the one point where the answer is already familiar: τ=0.5\tau=0.5 is the special case of quantile loss that everyone already knows by another name.

τ = 0.9 steep: under-predict shallow: over-predict τ = 0.5 symmetric V
At τ=0.9 the loss punishes under-prediction far more steeply than over-prediction, pulling the trained forecast up toward the 90th percentile; at τ=0.5 the two slopes match and the loss reduces to mean absolute error.

Quantile (pinball) loss penalizes under- and over-prediction asymmetrically — by τ\tau and 1τ1-\tau respectively — so minimizing it trains a network to output the τ\tau-th quantile of the target distribution instead of its mean; training several output heads at different τ\tau values gives a full predictive interval from one model.

What this means in practice

Several parallel output heads at different τ\tau values, as above, give a full predictive interval from a single architecture — exactly what's needed for VaR-style risk estimates, execution cost bands, or any forecast where the tail matters as much as the center. A subtlety worth watching: quantile heads trained independently can cross (the 0.9 head predicting below the 0.5 head) since nothing in the loss enforces monotonicity across separately-trained quantiles.

The common confusion is treating a quantile forecast as if it were still an unbiased estimate of the mean, and averaging several quantile predictions together expecting to recover it. A model's τ=0.9\tau=0.9 output is deliberately biased above the mean by construction — that's the entire point — so feeding it into code that expects a mean forecast (like a standard PnL simulation) silently introduces a systematic upward bias that has nothing to do with a modeling error.

Related concepts

Practice in interviews

Further reading

  • Koenker & Bassett, Regression Quantiles (1978)
ShareTwitterLinkedIn