Backtesting guide

Tail risk in trading backtests

Tail risk is exposure to rare, extreme outcomes at the edges of a return distribution. For a trading account, the left tail contains unusually large losses. A backtest describes the events in its sample; a quiet history cannot establish that larger losses are impossible.

Read the practical guide

Key Takeaways

  • Define the return series and horizon first. Daily account returns, trade returns and underlying price changes measure different exposures.
  • Negative skewness describes asymmetry; excess kurtosis describes the fourth moment relative to a normal distribution. Neither supplies a future crash probability.
  • At 99% confidence, a 100-observation empirical Expected Shortfall estimate uses only one observation under the equal-weight tail convention used below.
  • Test missing events explicitly: gaps through stops, worse execution, simultaneous losses and higher exposure. State assumptions separately from observed history.

Define the tail before measuring it

Choose a horizon, return denominator and loss threshold before comparing strategies. A three-standard-deviation cutoff is one modeling choice, not a universal definition of tail risk. Fat tails in finance describe more probability in extreme outcomes than a chosen reference model, often the normal distribution. An extreme observation alone does not identify the distribution that generated it.

  • For account risk, use consistent periodic mark-to-market returns, including open positions and cash. Closed trades alone can omit losses that have not yet been realized.
  • Trade returns have variable holding periods and can overlap. A 99% trade loss measure is not a 99% one-day account loss measure.
  • An asset price jump sits in its right tail but can create a left-tail account loss for a short position. Always specify whose returns the chart shows.
  • Record fees, position sizes, data dates and missing sessions. A clean histogram from a short, calm period has limited information about other regimes.

Skewness of returns and excess kurtosis

For returns r and mean m, define mk = average((r - m)^k). Population-moment skewness is m3 / m2^(3/2); kurtosis is m4 / m2^2; excess kurtosis subtracts 3. NIST distinguishes these conventions: normal-distribution kurtosis is 3 and excess kurtosis is 0. Adjusted sample estimators can give different numbers.

  • Negative skewness indicates a longer left tail; positive skewness indicates a longer right tail. Near-zero skewness can still coexist with extreme outcomes on both sides.
  • A large fourth moment is sensitive to outliers. Inspect the actual observations and dates before treating a high kurtosis estimate as a stable property of a strategy.
  • These formulas are undefined when variance m2 is zero. A software display of zero for a constant series does not prove the absence of tail exposure.

A 100-day example: one observation controls the 99% tail

This synthetic example contains 100 equally weighted daily account returns: 95 days at +0.1%, then one day each at -1%, -2%, -3%, -4% and -10%. These are assumed returns, not market data or a Pineify product result. The arithmetic mean is -0.105% per day; moment skewness is about -7.156 and excess kurtosis is about 55.722. A 95% positive-day rate therefore coexists with negative average return.

A 100-day example: one observation controls the 99% tail
Calculation conventionOriginal sampleReplace -10% with -25%
95% Expected Shortfall: mean loss of worst 5 days(1 + 2 + 3 + 4 + 10) / 5 = 4%(1 + 2 + 3 + 4 + 25) / 5 = 7%
99% Expected Shortfall: mean loss of worst 1 day10%25%
Number of observations in the 99% tail1 of 1001 of 100
  • Losses are reported as positive percentages. Sort returns from lowest to highest and average the worst N × (1 - confidence) observations here, where that count is an integer. Other quantile conventions and ties require explicit handling.
  • The replacement is a sensitivity test. It shows dependence on one observation; it does not estimate how likely a 25% loss is.
  • Even if independent days had a fixed 1% event probability, the chance of seeing no such event in 100 days would be 0.99^100, about 36.6%. Independence and a constant probability are illustrative assumptions, not claims about markets.

A reproducible stress-scenario table

Each row starts independently with a hypothetical $100,000 account. For the first three rows, assume 500 long shares bought at $100, a $98 stop and $50,000 cash. Loss = shares × (entry price - exit price) + stated costs. Ignore financing, taxes and dividends. These shocks are chosen test inputs, not forecasts or calibrated probabilities.

A reproducible stress-scenario table
Scenario and assumptionsCalculationAccount loss
Reference: stop fills at $98, no costs500 × ($100 - $98)$1,000 / $100,000 = 1%
Gap: next tradable price is $90, no costs500 × ($100 - $90)$5,000 / $100,000 = 5%
Gap plus execution cost: fill at $89.50, $50 total fees500 × ($100 - $89.50) + $50$5,300 / $100,000 = 5.3%
Common shock: two $40,000 long positions each lose 12%, $20,000 cash, no costs2 × $40,000 × 12%$9,600 / $100,000 = 9.6%
Leverage: $200,000 linear long exposure loses 12%, no costs or forced liquidation modeled$200,000 × 12%$24,000 / $100,000 = 24%
  • TradingView documents that a price-based order crossed in an inter-bar gap fills at the next bar open in its broker emulator. A stop level is therefore not a guaranteed loss cap.
  • The common-shock row imposes joint losses; it does not estimate correlation. The leverage row excludes margin liquidation and financing. Options and other nonlinear exposures require repricing rather than this linear formula.
  • Set an account-loss budget before testing. In the $90 gap scenario, an illustrative $2,000 budget permits at most $2,000 / ($100 - $90) = 200 shares before costs. A deeper gap can still breach that budget.

Historical events expose missing regimes

The Swiss National Bank discontinued its minimum exchange rate of CHF 1.20 per euro on January 15, 2015. That dated policy change is a concrete regime boundary for an EUR/CHF study. A sample ending before it cannot show how a strategy would have traded through the transition. The announcement alone does not supply executable bid/ask prices, fills or a strategy loss.

  • For a historical replay, record the event window, venue, timestamp convention, spreads, data gaps, position held before the event and actual rule version. Extend the window to include the aftermath.
  • If the instrument did not exist or reliable prices are unavailable, label the scenario hypothetical. Do not splice another instrument into the history without describing the proxy and its limits.
  • Ordinary resampling draws from observed values, so it cannot create a more extreme single-period loss than the sample contains. Shuffling can change drawdowns but destroys the original time dependence; block resampling preserves only dependence within the selected blocks.
  • Keep observed replays separate from assumed shocks. The Federal Reserve similarly describes its adverse stress scenarios as hypothetical conditions rather than forecasts; its bank scenarios are not a calibration for this trading example.

Review the TradingView export, then test the assumptions

Export the TradingView trade list and use Backtest Deep Report to inspect its trade-return histogram, skewness and excess kurtosis. Its trade-based distribution is a different input from the daily account-return example above. Record the metric convention before comparing results across tools, especially the tail count and treatment of observations equal to a percentile cutoff.

  • Inspect the largest losses in the original trade list, including open-position exposure that the closed-trade distribution cannot show.
  • Calculate the table scenarios independently. Backtest Deep Report does not automatically reproduce the gap, joint-loss or margin assumptions used on this page.
  • Use Pine Script AI Coding Agent to express a chosen exposure limit or diagnostic in a strategy, then review the generated code and validate its behavior in TradingView. A rule in code cannot guarantee an executable exit price.

Related Pineify workflow

Inspect the losses present in your trade sample

Upload a TradingView trade CSV to Backtest Deep Report to review the return distribution, skewness and excess kurtosis. Compare those historical observations with separately documented stress assumptions.

Backtest Deep Report

Inspect the distribution and extreme observations in your TradingView trade export.

Review trade returns

Boundary: Trade-return statistics do not estimate missing events or guarantee future losses. The daily-return and stress examples on this page use independent assumptions and are not product outputs.

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