Backtesting guide

Downside Risk: Target Return, Samples, and Semi Deviation

Downside risk is exposure to returns below a chosen target. Target downside deviation measures the size and frequency of those shortfalls. With a 1% monthly target, a 0% month is a shortfall even though the account did not lose money. State the target, return interval, and denominator before comparing results.

Read the practical guide

Key Takeaways

  • Standard deviation measures dispersion on both sides of the mean. Target downside deviation measures shortfalls below a specified return.
  • In a full-sample calculation, returns at or above the target contribute zero but remain in the observation count.
  • Dividing by only the below-target count produces a different statistic. At a positive target, that subset can include profitable periods.
  • Trade percentages and monthly account returns are different inputs. Matching the name of a metric does not establish matching calculations.

Choose the target before calculating downside risk

The minimum acceptable return (MAR) defines what counts as underperformance. A zero target measures shortfalls below break-even. A positive target also counts returns that made money but missed the requirement. Choose this hurdle before comparing strategies; changing it changes the question.

  • Match units and intervals: monthly account returns need a monthly target. An effective annual hurdle of 12% converts to (1.12)^(1/12) - 1 = 0.9489% per month under compound conversion.
  • State whether returns include fees and slippage, how external cash flows are handled, and whether equity includes open positions.
  • Semi deviation often means downside deviation about the sample mean. PerformanceAnalytics uses that convention. Other reports use the term for a fixed target, so check the formula instead of assuming the names are interchangeable.
  • A changing benchmark target needs one aligned target per return period. An annual benchmark return cannot be subtracted from every monthly observation.

Downside deviation formula and the denominator

For N valid periodic returns r_t and a fixed target T, define d_t = min(0, r_t - T). Full-sample downside variance is sum(d_t^2) / N; downside deviation is its square root. This page uses that descriptive calculation without an N - 1 correction. Enter returns consistently as decimals, such as 0.01 for 1%.

Downside deviation formula and the denominator
MeasureCalculationWhat enters the denominator
Full-sample target downside deviationsqrt(sum(d_t^2) / N)Every valid return, including zero shortfalls
Below-target conditional RMS shortfallsqrt(sum(d_t^2) / m)Only m observations with r_t < T
Mean-based semi deviation, full sampleUse T = mean(r) in the first formulaEvery valid return; the reference is the sample mean
Population standard deviationsqrt(sum((r_t - mean(r))^2) / N)Every valid return; both sides of the mean contribute
  • For m > 0, full-sample deviation = conditional RMS shortfall × sqrt(m / N). Keeping zero shortfalls makes the first statistic sensitive to how often the target was missed.
  • A return equal to the target contributes zero and stays in N, but is excluded from m. At T = 0, an observed flat period follows the same rule.
  • A missing observation is unknown, not a zero return. Repair the data or disclose exclusions; do not silently convert missing months into successful or flat months.
  • Taking standard deviation of the losing returns around their own mean is another calculation. Identical losses have zero standard deviation but a positive shortfall from a zero target.

Worked calculation: six monthly returns and a 1% target

Assume six hypothetical, equally spaced monthly account returns after costs, no external cash flows, and a fixed 1% monthly target. These are teaching inputs, not a backtest or a forecast. The table uses percentage points for the differences; the calculation below converts them to decimals.

Worked calculation: six monthly returns and a 1% target
MonthReturnShortfall min(0, return - 1%)Squared shortfall in decimal units
14%0 percentage points0
21%0 percentage points0
30%-1 percentage point0.0001
4-2%-3 percentage points0.0009
5-3%-4 percentage points0.0016
66%0 percentage points0
  • Squared shortfalls sum to 0.0026. With all six months, downside variance = 0.0026 / 6 = 0.00043333 and downside deviation = sqrt(0.00043333) = 2.0817% per month.
  • Three months miss the 1% target. Dividing by those three months gives sqrt(0.0026 / 3) = 2.9439%. Dividing by only the two negative-return months would be inconsistent with this positive target.
  • With the same returns and a zero target, squared shortfalls sum to 0.0013. The full-sample result is sqrt(0.0013 / 6) = 1.4720%; the negative-only result is sqrt(0.0013 / 2) = 2.5495%.
  • The mean happens to be 1% here, so mean-based semi deviation equals the 1%-target result for this sample. That equality does not hold for an arbitrary target or another sample.

Equal total volatility can hide different downside outcomes

Consider two more hypothetical four-month return series with a zero target. One has only gains; the other has only losses. Reflection around zero preserves dispersion around each series mean, so their population standard deviations are identical.

Equal total volatility can hide different downside outcomes
Monthly sampleMeanPopulation standard deviationFull-sample downside deviation
A: 1%, 1%, 1%, 7%2.5%2.5981%0%
B: -1%, -1%, -1%, -7%-2.5%2.5981%3.6056%
  • For A, squared deviations from 2.5% sum to 27 percentage-points squared, so standard deviation = sqrt(27 / 4) = 2.5981%. B has the same squared deviations.
  • At the zero target, A has no shortfalls. B has downside deviation sqrt((1 + 1 + 1 + 49) / 4) = 3.6056%. These computations use percentage-point units consistently.
  • Standard deviation does not require normally distributed returns to be calculated. It simply does not distinguish gains from losses when measuring dispersion.

Zero downside deviation and other limits

Zero downside deviation means the observed sample never fell below the chosen target. It does not establish that future losses are impossible. A short history can miss the event that dominates a strategy's risk.

  • With valid observations and m = 0, full-sample deviation is zero. The conditional m-denominator calculation is undefined because its subset is empty. A Sortino ratio with a zero denominator is also mathematically undefined.
  • An empty return series is insufficient data. A single observation can produce a descriptive shortfall, but offers little evidence about the underlying loss distribution.
  • Downside deviation ignores the order of returns. Reordering a series leaves this metric unchanged while changing drawdown and recovery paths; inspect those separately.
  • Report the measured interval. Multiplying monthly deviation by sqrt(12) is a scaling convention, not a direct calculation of shortfalls in compounded annual returns. Dependence and changing exposure can invalidate comparisons.

Reconcile TradingView and Backtest Deep Report inputs

TradingView documents its Sortino input as monthly account returns and identifies N as the total return count. Backtest Deep Report currently uses exported trade P&L percentages for its reported Sortino calculation. Those inputs can disagree even when they come from the same strategy.

  • Export the TradingView List of Trades CSV and retain the test dates, initial capital, position sizing, costs, and risk-free setting. Trade percentages do not reconstruct a complete monthly marked-to-market account return series.
  • The current report squares negative trade percentages and divides by the number of negative trades. Its denominator uses a zero threshold; changing the risk-free input affects the numerator but does not change that threshold.
  • The risk-free field does not specify a return interval. The current trade-based numerator subtracts its value directly, while UPI subtracts the same value from annual CAGR. Do not assume a nonzero annual rate has been converted to a per-trade reference; calculate a consistently defined comparison separately.
  • The overall report scales its trade-based ratio by sqrt(trades per year), using the first entry and latest exit for elapsed time. That convention differs from a monthly account-return calculation.
  • The report exposes Sortino and other supported risk outputs, but does not expose a standalone target-selectable downside-deviation metric. Calculate the full-sample examples above independently when that is the statistic you need.
  • With no negative trades, or with fewer than two trades, the current reported Sortino falls back to zero. Treat this as software behavior rather than a mathematical zero-risk conclusion.

Related Pineify workflow

Review the data behind your downside metrics

Import a TradingView trade CSV into Backtest Deep Report to review its supported return and risk results. Use the definitions above to reconcile its trade-based Sortino with your chosen target and sampling interval.

Backtest Deep Report

Inspect the reported risk metrics alongside the source trade records and their calculation conventions.

Review backtest metrics
Pine Script AI Coding Agent

Draft a custom statistic with a stated return series, target, and denominator. Check the generated calculation against known examples before relying on it.

Draft a custom statistic

Boundary: The report does not provide a configurable full-sample downside-deviation calculator. A custom statistic needs explicit inputs and numerical validation; historical results do not establish future loss limits.

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