TradingView Backtesting

Ulcer Performance Index: Return Relative to Drawdown Pain

The Ulcer Performance Index (UPI), also called the Martin ratio, divides annualized excess return by the Ulcer Index: UPI = (annualized return - annualized risk-free return) / UI. It measures return relative to the depth and persistence of sampled drawdowns. Use one evaluation window, consistent units and a stated equity sampling frequency. When UI is zero, the ratio has no finite defined value.

See the decision guide

Define the window, equity series and units

Let E₀ be starting equity and Eₜ be each regularly spaced closing valuation. Set Hₜ = max(E₀, E₁, ..., Eₜ), drawdown Dₜ = 100 × (Eₜ/Hₜ - 1), and UI = sqrt(sum(Dₜ²)/n). Include zero drawdowns in n. This page uses the initial value to seed the peak but averages only the n subsequent period-end observations.

  • With no external cash flows, annualized return in percentage points is 100 × ((Eₙ/E₀)^(m/n) - 1), where m is the stated number of periods per year. For weekly samples this example uses m = 52.
  • UPI = (Rannual - Rf,annual)/UI. Enter 12, 2 and 2.941742 together, or 0.12, 0.02 and 0.02941742 together. Mixing percentages and decimal fractions creates a 100-fold error.
  • Use the same dates for return and drawdown. A whole-history CAGR divided by a recent 14-bar UI answers a different question. Keep the peak initialization rule identical when comparing strategies.
  • For an account comparison, use valuations that include open positions, cash and costs. Adjust deposits and withdrawals before calculating returns; a cash deposit is not trading profit.

Calculate UPI from 52 weekly observations

Assume starting equity of $100, no external cash flows, and the following hypothetical weekly closing values after costs. Each grouped row repeats the same equity for every week in its range. The 52-week period counts as one year under the stated convention. The 2% risk-free return is an assumption, not a current market quote.

  • UI = sqrt(450/52) = 2.941742%. Annualized return = 100 × ((112/100)^(52/52) - 1) = 12%.
  • Annual excess return = 12 - 2 = 10 percentage points. UPI = 10/2.941742 = 3.399346, displayed as 3.3993 without a percent sign.
  • The result means 3.3993 units of annual excess return per unit of measured UI. It is not a 339.93% return, a probability or a forecast.
  • If the curve instead spends only one week at $94 and one at $97, with the remaining weeks at peaks and the same $112 finish, UI = sqrt(45/52) = 0.930261% and UPI = 10.749677. Maximum drawdown and terminal return stay unchanged. The different duration changes UPI.
Weekly observationsCountEquity / running peakDrawdownSum of squared drawdowns
Weeks 1 to 1010$100 / $1000%0
Weeks 11 to 2010$94 / $100-6%10 × 36 = 360
Weeks 21 to 3010$97 / $100-3%10 × 9 = 90
Weeks 31 to 5121$100 / $1000%0
Week 521$112 / $1120%0
Total52Starting equity: $100Maximum: 6%450 pp²

Reproduce the weekly example in a spreadsheet

Put the starting value 100 in B2. Expand the grouped table into the 52 weekly equity values in B3:B54. In C3 enter =MAX($B$2:B3), in D3 enter =100*(B3/C3-1), and in E3 enter =D3^2. Fill all three formulas down through row 54. Drawdowns in column D are numeric percentage points, so enter the annual risk-free input as 2 rather than 2%.

  • Require all 52 numeric observations. A missing week is not a zero-return week, and skipping it changes the time weighting.
  • Keep full precision in intermediate cells. If the calculated UI is zero, display undefined before attempting division.
  • This worksheet deliberately excludes the seed row from the UI average. Including its zero drawdown gives sqrt(450/53) = 2.913858% and UPI = 3.431877. Record that convention when reconciling another implementation.
OutputFormulaExpected result
Observation count=COUNT(B3:B54)52
UI in percentage points=SQRT(SUM(E3:E54)/52)2.941742
Annualized return in percentage points=100*((B54/B2)^(52/52)-1)12
UPI with assumed 2% annual reference=(12-2)/SQRT(SUM(E3:E54)/52)3.399346

Annualize returns, not the Ulcer Index

UI is a drawdown level, not a standard deviation of one-period returns. Do not multiply weekly UI by sqrt(52), or apply that factor to a UPI already formed from annualized returns. The weekly observation frequency defines which equity declines enter the denominator; the annual return convention defines the numerator.

  • For a constant 2% effective annual reference, the matching weekly reference is (1.02)^(1/52) - 1 = 0.0380892%. Compounding 52 such weekly returns gives 2%. Subtract the annual figure from annual return, not the weekly figure.
  • For a varying cash benchmark, collect its total returns on the same observation dates, compound them over the evaluation window and annualize using the same convention. A quoted yield is not automatically a realized period return.
  • Document currency, distributions, financing, fees and the assumed cash return. Use the same treatment for each strategy in a comparison.
  • Peter Martin cautions that sampling less often than weekly can miss declines that recover between observations. Even weekly closes can miss intraday losses. A high UPI from sparse data does not demonstrate small executable risk.
  • A few weeks can produce an annualized number but do not provide a year of observed performance. Show the actual dates and sample count, and examine periods beyond the sample used to select the strategy.

Compare UPI with Sharpe and Calmar

These measures penalize different features of a return history. Keep the evaluation dates fixed and label each numerator convention. A large UPI cannot be read against a Sharpe threshold because their denominators measure different quantities.

  • Using the example and the CAGR/max-drawdown Calmar convention, Calmar = 12/6 = 2. The faster-recovery variant also has Calmar 2, while its UPI rises from 3.3993 to 10.7497.
  • The table uses a Calmar convention without risk-free subtraction. Some reports use excess return instead; that variant would give 10/6 = 1.6667 here. Do not compare the two without identifying the difference.
  • For conventional historical Sharpe, use the arithmetic mean and standard deviation of matching periodic excess returns. Substituting CAGR into that formula changes the convention. Square-root annualization requires assumptions about dependence between returns.
MeasureReturn conventionRisk denominatorWhat changes the result
UPI / Martin ratioAnnualized return minus annualized risk-free returnRoot mean square of sampled drawdownsDepth and persistence below earlier peaks
Sharpe ratioMean periodic excess return; annualize consistentlyStandard deviation of periodic excess returnsVariability of both positive and negative excess returns
Calmar ratioAnnualized return in the convention used hereAbsolute maximum drawdown over the windowThe worst sampled peak-to-trough decline

Handle zero drawdown and negative excess return explicitly

If all sampled equity values are at new highs, UI = 0. With positive excess return, division by zero has no finite result; with zero excess return it is 0/0. Report UPI as undefined and show the return, UI and sample count. Do not replace it with an arbitrary large score.

  • When UI > 0 and annual return equals the risk-free return, UPI = 0. This is different from a software fallback that displays zero when UI = 0.
  • If annual return is 1% and the reference is 2%, UI of 2% gives UPI -0.5. Increasing UI to 4% produces -0.25. The numerically higher ratio does not establish an improvement: the return shortfall is unchanged and measured drawdown is worse.
  • Near-zero UI magnifies rounding, missing valuations and selection effects. There is no universal UPI cutoff that establishes skill or profitability.
  • Require positive starting equity and a valid positive terminal value for the CAGR formula used here. A zero or negative equity path, leverage-driven insolvency or a reset account needs separate loss reporting; suppress the normal ratio comparison.

Reconcile a TradingView CSV with Backtest Deep Report

TradingView exports its trade list and strategy summary separately. Import the trade CSV into Backtest Deep Report and check initial capital and Risk-Free Rate (%). The current report displays Ulcer Index and UPI, with UPI calculated as (CAGR - risk-free rate)/UI. Its equity curve starts with initial capital and then adds each imported trade P&L record.

  • The report averages drawdowns across those equity points, including the initial zero-drawdown point. Trade events are not evenly spaced calendar valuations. More events during a drawdown give it more weight, and losses between events may be absent.
  • Its CAGR uses elapsed time from the first trade entry to the latest exit with 365.25 days per year. The example above uses exactly 52 weekly periods per year. Match dates, point counts and annualization before expecting identical UPI values.
  • The current report returns UPI 0 when UI is zero. Treat that display as an implementation fallback, not a defined zero-risk performance ratio.
  • Use the imported report to inspect supported trade results. For a daily or weekly mark-to-market UPI, obtain that equity series and calculate it separately with the stated sampling and cash-return assumptions.
  • For a custom Pine implementation, describe the equity observations, peak seed, annualization and zero-denominator output to Pine Script AI Coding Agent. Review and validate generated code, then compare its results with a known worksheet before relying on it.
Where Pineify fits

Backtest Deep Report

Import a TradingView trade CSV to inspect profit, drawdown and the report UPI. Check its trade-event sampling before comparing it with a regularly sampled account-equity calculation.

Also useful: Pine Script AI Coding Agent. Specify a custom equity statistic and its sampling rules, then review and validate the generated Pine Script against a reproducible calculation.

Explore Backtest Deep Report

Frequently asked questions

Educational information, not investment advice. All worked values and the 2% risk-free reference are hypothetical. Historical ratios and backtests do not guarantee future returns or execution quality.

Sources and verification

Published by Pineify. Pineify is an independent product and is not affiliated with TradingView. Sources support the technical explanations; examples do not establish trading performance.