Ulcer Performance Index (UPI)
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.
It can be used to compare volatilities in different stocks or show stocks go into Ulcer territory. 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.
No programming experience? With the Finance Toolkit MCP server, AI assistants such as Claude and ChatGPT can calculate the Ulcer Performance Index (UPI) for you. Just ask in plain English.
Calculate the Ulcer Performance Index (UPI) in Python
The Ulcer Performance Index (UPI) is available in the Performance module of the open-source Finance Toolkit. Install it with:
pip install financetoolkit -U
Then call get_ulcer_performance_index as shown below.
from financetoolkit import Toolkit
toolkit = Toolkit(["AAPL", "TSLA"], api_key="FINANCIAL_MODELING_PREP_KEY")
toolkit.performance.get_ulcer_performance_index()
Which returns:
| Date | AAPL | TSLA |
|---|---|---|
| 2021 | -0.4626 | -0.2002 |
| 2022 | -4.5193 | -5.0182 |
| 2023 | 13.6486 | 11.6618 |
| 2024 | 7.6983 | 6.3795 |
| 2025 | 0.9945 | 0.7159 |
| 2026 | 2.2021 | -3.5198 |
Parameters
get_ulcer_performance_index accepts the following parameters:
- period (str, optional): The period to use for the calculation. Defaults to “quarterly” if the Toolkit is initialised with quarterly=True, otherwise “yearly”.
- rolling (int): The rolling period to use to calculate the Ulcer Index. Defaults to 14.
- rounding (int, optional): The number of decimals to round the results to. Defaults to 4.
- growth (bool, optional): Whether to calculate the growth of the ratios. Defaults to False.
- lag (int | str, optional): The lag to use for the growth calculation. Defaults to 1.
- standardize (bool, optional): Whether to standardize (Z-Score) the result. When combined with growth=True, standardizes the growth values instead of the raw values. Defaults to False.
Related Performance Metrics
The Performance module page introduces the module, and the sidebar lists all of its functions.