Upside Deviation
Calculate the Upside Deviation: how widely the returns of an investment portfolio or asset rise above a minimum acceptable return, the volatility an investor welcomes.
The Upside Deviation is the mirror image of the Downside Deviation: it measures the dispersion of the returns above a minimum acceptable return (MAR), the volatility an investor welcomes. Next to the Downside Deviation it shows whether an asset’s volatility comes from its gains or from its losses, and their ratio is the Variability Skewness (get_volatility_skewness).
The formula is as follows:
\[\text{Upside Deviation} = \sqrt{\frac{\sum \max(\text{Return}_{t} - \text{MAR},\; 0)^{2}}{n}}\]Where n is the number of all returns, so returns below the MAR count as zero rather than being left out. Its square is the upside variance and the upper partial moment of order 1 the upside potential (get_partial_moment on the upper side).
Also known as: upside risk, upside volatility, upside semi-deviation.
Example · NEE, DUK, SO · 2021 to 2025
Install the Finance Toolkit with pip install financetoolkit -U, then call get_upside_deviation:
from financetoolkit import Toolkit
toolkit = Toolkit(
["NEE", "DUK", "SO"],
api_key="FINANCIAL_MODELING_PREP_KEY",
start_date="2021-01-01",
end_date="2025-12-31",
)
toolkit.risk.get_upside_deviation(period="yearly", within_period=True)
Or, with the Finance Toolkit MCP set up, ask an AI assistant such as Claude or ChatGPT:
How widely did the daily returns of NextEra Energy, Duke Energy, Southern Company and the S&P 500 rise above zero in each year from 2021 to 2025, measured by the upside deviation?
Which returns:
| Item | NEE | DUK | SO | Benchmark |
|---|---|---|---|---|
| 2021 | 0.0098 | 0.0077 | 0.0072 | 0.0062 |
| 2022 | 0.0140 | 0.0091 | 0.0102 | 0.0105 |
| 2023 | 0.0112 | 0.0081 | 0.0085 | 0.0063 |
| 2024 | 0.0109 | 0.0076 | 0.0081 | 0.0058 |
| 2025 | 0.0124 | 0.0076 | 0.0078 | 0.0092 |
5 rows
Parameters
get_upside_deviation accepts the following parameters.
| Parameter | Type | Description | Example |
|---|---|---|---|
period | str | The data frequency for returns. Options are: “daily”, “weekly”, “monthly”, “quarterly”, “yearly”. Defaults to “daily”. | "weekly" |
minimum_acceptable_return | float | The minimum acceptable return (MAR) per observation of the chosen period (e.g. per day), above which returns count as upside. Defaults to 0.0. | 0.001 |
within_period | bool | Whether to calculate the Upside Deviation within the specified period or for the entire period. Thus whether to look at the Upside Deviation within a specific year (if period = ‘yearly’) or look at the entirety of all years. Defaults to False. Note that this requires intraday data when period = ‘daily’, since a single day only nests observations when intraday data was fetched. | True |
rolling | int | The rolling window size to use for the calculation. If set, the Upside Deviation is calculated over a rolling window of this many periods across the full return history instead of per period. At least 2. Defaults to None. | 4 |
rounding | int | None | The number of decimals to round the results to. Defaults to None, which uses the rounding of the Toolkit (4 unless set otherwise). | 2 |
growth | bool | Whether to calculate the growth of the Upside Deviation values over time. Defaults to False. | True |
lag | int | list[int] | The lag to use for the growth calculation. Defaults to 1. | 4 |
standardize | bool | Whether to standardize (Z-Score) the result. When combined with growth=True, standardizes the growth values instead of the raw values. Defaults to False. | True |
show_columns | str | list[str] | None | The columns to keep, a name or a list of names, matched on every column level, or the rows when no column has those names (such as the line items of a financial statement). Names that do not exist are logged, and when none exist the result is returned in full. Defaults to None, which keeps every column. | None, which keeps every column |
References
- Paper Bacon, C.R. (2008). “Practical Portfolio Performance Measurement and Attribution.” John Wiley & Sons, chapter 4 (upside risk).
- Library Shares similar logic as PerformanceAnalytics (R)’s UpsideRisk