Calculate the Ulcer Performance Index (UPI), alternatively called Martin ratio, a measure of risk-adjusted return that evaluates the excess return of an investment portfolio or asset per unit of risk taken.

The formula is as follows:

\[\text{Ulcer Performance Index} = (\text{Period Return} - \text{Risk-Free Rate}) / \text{Ulcer Index}\] \[\text{Ulcer Index} = \sqrt{\operatorname{MEAN}(\text{Drawdown} ^{2})},\;\; \text{with each day's drawdown measured from the highest value of the trailing rolling days within the period}\]

It measures the excess return earned per unit of drawdown pain: the depth and the duration of the declines both weigh in, where the Sharpe Ratio treats upward and downward swings alike. Similar to the Sharpe Ratio, a higher UPI is better than a lower one (since investors prefer more return for less risk).

Also known as: UPI, Martin ratio.

Ulcer Performance Index (UPI) in Python or via the MCP

Install the Finance Toolkit with:

pip install financetoolkit -U

Then call get_ulcer_performance_index as shown below.

from financetoolkit import Toolkit

toolkit = Toolkit(
    ["VZ", "T", "TMUS"],
    api_key="FINANCIAL_MODELING_PREP_KEY",
    start_date="2020-01-01",
    end_date="2025-12-31",
)

toolkit.performance.get_ulcer_performance_index()

Or, after setting up the Finance Toolkit MCP, ask:

What was the Ulcer Performance Index of Verizon, AT&T and T-Mobile US in each year from 2021 to 2025?

Which returns:

Date VZ T TMUS
2021 -3.7069 -2.0886 -3.7462
2022 -4.3869 0.7109 4.3646
2023 -0.3236 -1.4171 3.5546
2024 2.6617 15.933 13.5977
2025 1.4725 2.6824 -2.3337

Parameters

get_ulcer_performance_index accepts the following parameters.

ParameterTypeDescriptionExample
periodstrThe period to use for the calculation. Defaults to “quarterly” if the Toolkit is initialised with quarterly=True, otherwise “yearly”."quarterly"
rollingintThe rolling period to use to calculate the Ulcer Index. Defaults to 14.20
roundingint | NoneThe number of decimals to round the results to. Defaults to None, which uses the rounding of the Toolkit (4 unless set otherwise).2
growthboolWhether to calculate the growth of the ratios. Defaults to False.True
lagint | list[int]The lag to use for the growth calculation. Defaults to 1.4
standardizeboolWhether to standardize (Z-Score) the result. When combined with growth=True, standardizes the growth values instead of the raw values. Defaults to False.True
Share