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.
Ulcer Performance Index (UPI) in Python
Install the Finance Toolkit 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
The function accepts the following parameters:
- period (str, optional): The period to use for the calculation. Defaults to “quarterly” if the Toolkit is initialized 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.