Backtesting guide

Value at Risk for Trading Backtests

Value at Risk (VaR) is a loss quantile for a stated horizon and confidence level. A one-day 95% VaR of $3,000 places $3,000 at the modeled 95th percentile of daily losses. Losses can exceed that amount. VaR does not specify the worst possible loss, the average loss beyond the threshold, or a guaranteed stop-loss execution price.

Read the practical guide

Key Takeaways

  • Compare VaR only after matching the return denominator, horizon, confidence and estimation method. A percentage per closed trade is not a percentage of account equity per day.
  • Historical VaR selects an observed or interpolated percentile. Normal parametric VaR uses the mean and standard deviation, so the methods can disagree on identical inputs.
  • A 95% model has a nominal 5% exceedance rate for a continuous distribution. It does not promise exactly five breaches in the next 100 periods.
  • Record subsequent losses against forecasts made before those losses occurred. A quantile fitted and checked on the same sample is not independent validation.

Define the loss, period and confidence before calculating

For a simple return r, define loss L = -r. A return of -3% is a positive 3% loss. VaR at confidence c is the c quantile of L. Keep gains and zero returns in the sample; removing them changes the probability distribution. The confidence level is a quantile level, not a confidence interval for the estimated number.

  • For daily account risk, use daily equity returns with consistent cash-flow adjustments, costs and open-position valuation. State the time zone and closing time.
  • For trade risk, use the closed-trade return series and record its denominator and holding periods. Overlapping trades are not independent daily observations.
  • To express a return threshold in dollars, multiply its decimal value by a stated reference capital. This conversion alone does not model changing position sizes or compounded equity.

Historical and parametric VaR formulas

For historical VaR here, sort N losses from smallest to largest and select the one-based rank ceil(N × c). This is the inverse empirical cumulative-distribution convention. For a normal return model, percentage VaR = z_c × s - mean, where mean and s use the same period and z_c is the standard normal quantile. Use decimal returns before multiplying by capital.

  • The numerical examples use sample standard deviation, s = sqrt(sum((r - mean)^2) / (N - 1)), and rounded z values 1.645 at 95% and 2.326 at 99%.
  • State the percentile convention. A linearly interpolated percentile can differ from an observed-rank percentile, particularly in a short sample.
  • Normal VaR assumes the modeled return distribution is normal. Historical VaR avoids that shape assumption but still relies on the chosen history representing the risk being studied.
  • Reject empty or non-finite input and confidence outside 0 < c < 1. Sample standard deviation requires at least two observations; two observations do not establish reliable tail estimates.

Same 20 daily returns, two VaR methods

Use a hypothetical sample of 20 daily returns: -8%, -3%, -2%, -1%, twelve 0% returns, +1%, +2%, +3% and +8%. The mean is 0%, the squared deviations sum to 156 percentage-points squared, and sample s = sqrt(156 / 19) = 2.865402%. Dollar amounts below use a fixed $100,000 reference. This small sample illustrates arithmetic, not a reliable risk forecast.

Same 20 daily returns, two VaR methods
Method and confidenceCalculationDaily loss threshold
Historical 95%19th of 20 ascending losses3.00% = $3,000
Normal 95%1.645 × 2.865402% - 0%4.713586% ≈ $4,713.59
Historical 99%20th of 20 ascending losses8.00% = $8,000
Normal 99%2.326 × 2.865402% - 0%6.664924% ≈ $6,664.92
  • The normal estimate is higher at 95% but lower at 99%. Neither method is always the more conservative one.
  • With linear interpolation at rank 1 + (N - 1)c, historical 95% VaR is 3% + 0.05 × (8% - 3%) = 3.25%. Historical 99% VaR is 7.05%. The data did not change; the estimator did.
  • At 95%, one sample loss exceeds either threshold. At 99%, none exceeds historical VaR, while one exceeds normal VaR. These in-sample counts do not validate either model.

Keep horizon units consistent

Under independent, identically distributed normal period returns and an additive-return approximation, T-period VaR = z_c × s × sqrt(T) - mean × T. The familiar square-root-of-time shortcut omits the mean term only when mean is assumed zero. It is not a general rule for compounded strategy returns.

  • With assumed daily volatility 2%, zero mean, 95% confidence and $100,000 capital, one-day VaR is $3,290. A ten-day approximation is $3,290 × sqrt(10) = $10,403.89.
  • Daily volatility requires T in days; trade volatility cannot be paired with a day count. Annualized volatility needs an explicit period conversion and trading-day convention.
  • Volatility clustering, serial dependence, changing exposure and option nonlinearities can invalidate simple scaling. Estimate returns over the required horizon or specify a model that handles those effects.

Record VaR breaches on subsequent observations

For each forecast period t, save the VaR estimate made using information available before t, then compare the realized loss L_t with that estimate. Define a breach as L_t > VaR_t and keep equality separate. Observed breach frequency is the number of breaches divided by the number of valid forecast-outcome pairs.

Record VaR breaches on subsequent observations
Illustrative monitoring logCalculationInterpretation
95% VaR, 100 subsequent daily forecasts8 breaches / 100 = 8%Nominal rate is 5%; nominal expected count is 5
99% VaR, 250 subsequent daily forecasts4 breaches / 250 = 1.6%Nominal expected count is 2.5, not a required count
  • Log forecast date, estimation window, confidence, horizon, algorithm, VaR, realized loss and breach size. Investigate missing outcomes rather than counting them as zero losses.
  • Review clustering and severity as well as the total. Eight breaches alone do not prove model failure; inference depends on sample size, dependence and the chosen test.
  • Discrete losses and ties may produce fewer strict breaches than 1 - c. Overlapping multi-day outcomes also create dependence. Document these features before using an independent-trials coverage test.

What VaR leaves out

In the 20-return sample, increasing the worst loss from 8% to 30% leaves inverse-empirical 95% VaR at 3%. The worst 5% tail average rises from 8% to 30%. VaR identifies the cutoff; Expected Shortfall describes the average of the selected tail. Neither is a maximum possible loss.

  • Maximum drawdown measures a chronological peak-to-trough equity decline. VaR discards the ordering of observations, so it cannot replace drawdown analysis.
  • A stop-loss order is an execution instruction. Gaps, slippage and liquidity constraints can produce a fill beyond the stop price; a statistical quantile cannot enforce that price.
  • At 99% confidence, 20 observations supply only 0.2 observations of tail probability. The historical result is pinned to the worst observation under this convention and contains no evidence about unobserved extremes.

Reconcile VaR with Backtest Deep Report

Backtest Deep Report accepts TradingView trade CSV exports and displays VaR (95%) and CVaR (95%). Its current VaR calculation sorts closed-trade percentage returns and selects zero-based index floor(N × 0.05), retaining the return sign. On the 20 values above treated as trade returns, it displays -3% VaR. This matches a positive 3% loss threshold, but describes trades rather than days.

  • The report currently averages every return at or below that cutoff for CVaR. In this example that is (-8% - 3%) / 2 = -5.5%, whereas a fixed worst-5% empirical tail average is an 8% loss. Check boundary inclusion when comparing tools.
  • Keep the CSV filter, row count, return denominator and costs with the result. The report does not make a trade-percentile result into a daily account-risk forecast.
  • Use the report to inspect observed trade risk, then maintain the forecast-and-breach log separately. The normal 95% and 99% comparisons on this page are independent calculations, not claims about report outputs.

Direct Pineify workflow

Inspect the VaR in your TradingView trade sample

Use Backtest Deep Report to review VaR (95%), CVaR (95%) and the trade-return distribution. Match the sign, return units and percentile convention before comparing its results with another calculation.

Backtest Deep Report

Import a TradingView trade CSV and inspect its historical risk statistics.

Review backtest risk

Boundary: The report describes historical closed trades. It does not forecast daily account losses or place an upper bound on future loss.

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