Backtesting guide

Expected Shortfall and CVaR for Backtests

Expected Shortfall (ES), also called Conditional Value at Risk (CVaR), is the average loss in a specified worst fraction of outcomes. At 95% confidence, it averages the worst 5% of the modeled distribution. VaR gives a loss threshold; ES measures tail severity. In a finite backtest, the boundary weight and return convention determine which observations belong in that average.

Read the practical guide

Key Takeaways

  • Use the same confidence level, horizon and return denominator when comparing ES. A trade-return statistic is not a daily account-loss estimate.
  • For 100 equally weighted observations, empirical 95% ES uses five observations of tail weight. With 30 observations, it uses 1.5, so the boundary observation receives partial weight.
  • Averaging every loss equal to or above VaR can include more than the intended tail. Ties and percentile interpolation must be handled explicitly.
  • A low historical ES cannot rule out losses absent from the sample. Report the tail count and inspect the individual observations.

Set the return series and sign convention first

Let r be a return and L = -r its loss. A return of -6% is a loss of +6%; a return of +2% is a loss of -2%. The examples below report losses, so larger positive ES means a worse tail. They use hypothetical, equally weighted observations rather than market data or product results.

  • Daily account returns should use a consistent equity denominator and include open-position value. Include trading costs in the equity series rather than subtracting them twice.
  • Closed-trade percentage returns can use different holding periods and position sizes. Their ES describes the sampled trades, not the percentage of account equity lost in one day.
  • Keep gains and flat observations in the sample. Deleting them before selecting the tail changes the distribution and the meaning of 95% confidence.

Historical Expected Shortfall formula

Sort N returns from worst to best: r1 <= r2 <= ... <= rN. Choose confidence c with 0 < c < 1, then set m = N × (1 - c), k = floor(m), and f = m - k. The empirical tail-weight formula is ES_c = -(r1 + ... + rk + f × r(k+1)) / m. When f = 0, omit the final term. When k = 0, the sum is empty and the result is the loss on the worst observation.

  • This formula allocates exactly 1 - c of the equal-weight empirical probability to the tail. It is the average of loss quantiles over confidence levels from c to 1.
  • For VaR in the examples, sort losses from smallest to largest and take observation ceil(N × c), using one-based ranks. This is the inverse empirical cumulative-distribution convention.
  • The shortcut E[L | L >= VaR] agrees with ES for suitable continuous distributions. With probability mass at VaR, it can average too much of the distribution. The general CVaR definition accounts for the required boundary weight.

Expected Shortfall vs VaR: the same threshold, different tails

Each hypothetical sample has 100 daily returns. Sample A contains -6%, -5%, -4%, -3%, -2%, -1% and 94 zeros. Sample B contains -20%, -12%, -8%, -6%, -2%, -1% and 94 zeros. At 95% confidence, the 95th of 100 ascending losses is 1% in both samples. The five larger losses determine ES.

Expected Shortfall vs VaR: the same threshold, different tails
MeasureSample ASample B
95% VaR, inverse empirical CDF1%1%
Worst five returns-6%, -5%, -4%, -3%, -2%-20%, -12%, -8%, -6%, -2%
95% ES, fixed 5% tail weight(6 + 5 + 4 + 3 + 2) / 5 = 4%(20 + 12 + 8 + 6 + 2) / 5 = 9.6%
Loss equivalent on a fixed $100,000 reference$4,000$9,600
  • The dollar row multiplies a percentage by a fixed reference amount. It does not reconstruct a compounded equity curve or forecast a future loss.
  • VaR cannot distinguish these tails because the cutoff observation is unchanged. ES rises when losses beyond that cutoff become larger.

Fractional boundaries, interpolation and ties

For 30 hypothetical returns consisting of -12%, -6%, -3% and 27 zeros, 95% ES has m = 1.5 observations of tail weight. Its loss is (12 + 0.5 × 6) / 1.5 = 10%. Rounding down gives 12%; rounding up and averaging two observations gives 9%. Those are different estimators, not rounding errors in the final display.

Fractional boundaries, interpolation and ties
Boundary choiceCalculationResult
Inverse empirical 95% VaR on the 30-return sample29th ascending loss6% loss
Linearly interpolated VaR, h = 1 + (N - 1)ch = 28.55; 3 + 0.55 × (6 - 3)4.65% loss
Fixed tail weight for ES(12 + 0.5 × 6) / 1.510% loss
  • NIST documents several percentile conventions. Interpolating the VaR cutoff is separate from allocating partial weight to a boundary observation for ES; a percentile function alone does not specify the tail average.
  • For a tie example, use 100 returns: one at -20%, nine at -2%, and 90 at 0%. The 95% VaR is 2%, and fixed-weight ES is (20 + 4 × 2) / 5 = 5.6%.
  • Averaging all ten losses at or above the 2% cutoff instead gives (20 + 9 × 2) / 10 = 3.8%. Averaging only losses strictly above it gives 20%. Neither selects the required 5% probability mass.

When the sample cannot support a tail estimate

The relevant count is N × (1 - c), not just the total number of rows. Twenty observations supply one observation of tail weight at 95%; 100 observations supply one at 99%; 1,000 observations supply ten at 99%. These counts describe information available to the estimator, not a minimum sample size that guarantees reliability.

  • If the tail weight is below one observation, this empirical ES equals the worst observed loss. Raising confidence further adds no new tail information.
  • Overlapping trades and clustered losses reduce the independence of the evidence. Changing market conditions also weaken a direct extrapolation from past observations.
  • Reject an empty series, non-finite returns and confidence outside 0 < c < 1. Investigate missing data rather than silently replacing it with zero.
  • Recalculate after removing or worsening the largest loss as a sensitivity check, and record the assumption. Historical ES cannot estimate an unobserved gap, liquidity shock or forced liquidation without an additional model.
  • ES ignores the ordering of returns. Keep maximum drawdown and the original chronology beside it when assessing sequences of losses.

Reconcile the Backtest Deep Report CVaR result

Backtest Deep Report accepts TradingView trade CSV exports and displays VaR (95%) and CVaR (95%). Its current calculation uses closed-trade percentage returns, chooses the return at zero-based index floor(N × 0.05), then averages every return at or below that cutoff. The displayed numbers retain the return sign. This cutoff-inclusive average can differ from the fixed-tail-weight ES above.

  • For Sample A treated as 100 trade returns, the product calculation selects -1% and averages six returns: (-6 - 5 - 4 - 3 - 2 - 1) / 6 = -3.5%. The independent fixed-weight ES is a positive 4% loss.
  • For the tie example, the cutoff-inclusive calculation averages ten returns and gives -3.8%, while the fixed-weight loss estimate is +5.6%. Both the sign and selected tail weight must be reconciled.
  • Check the trade filter, row count, percentage denominator and costs before comparing reports. Use the trade-return distribution and drawdown results to inspect the underlying observations; do not interpret the CVaR display as a validated daily account-risk forecast.

Direct Pineify workflow

Check the tail in your TradingView trade export

Use Backtest Deep Report to inspect CVaR (95%), the trade-return distribution and drawdowns. Reconcile its cutoff-inclusive average with an independent tail-weight calculation when the boundary affects your result.

Backtest Deep Report

Upload a TradingView trade CSV and inspect the reported tail and risk metrics.

Review backtest risk

Boundary: The report uses historical closed-trade returns. Its current CVaR convention can include more than 5% of observations and does not forecast future losses.

This page is educational and does not provide investment advice. Backtests are hypothetical, depend on their data and assumptions, and do not guarantee future results. Trading can result in substantial loss.

Frequently Asked Questions