Risk Range

Calculate a Range measure: how far the gain tail of the returns of an investment portfolio or asset lies from its loss tail.

The Range is the distance between the best and the worst return. Cajas (2021) generalizes it to the tails: the VaR Range is the distance between the 1 - beta and the alpha quantile, the CVaR Range between the average return in the best beta share and in the worst alpha share of the returns and the Tail Gini Range between the Tail Gini of the gains and of the losses. They measure the width of the distribution where it matters most, without the assumption of symmetry behind the standard deviation, and with beta different from alpha they weigh the gains and the losses differently. The VaR Range at \(\alpha = \beta = 0.25\) is the interquartile range. The EVaR Range does the same with the historic Entropic Value at Risk, the most severe of these tail measures.

The formula is as follows:

\[\text{Range} = \max(\text{Return}) - \min(\text{Return})\] \[\text{VaR Range} = \operatorname{Quantile}(\text{Return},\; 1 - \beta) - \operatorname{Quantile}(\text{Return},\; \alpha)\] \[\text{CVaR Range} = \operatorname{mean}(\text{Return} \geq \operatorname{Quantile}(\text{Return},\; 1 - \beta)) - \operatorname{mean}(\text{Return} \leq \operatorname{Quantile}(\text{Return},\; \alpha))\] \[\text{Tail Gini Range} = \text{Tail Gini of the gains} \;(\beta) - \text{Tail Gini of the losses} \;(\alpha)\] \[\text{EVaR Range} = \text{EVaR of the gains} \;(\beta) - \text{EVaR of the losses} \;(\alpha)\]

Where the quantiles are interpolated linearly and the CVaR is the average of the returns beyond the quantile, as in the historic get_value_at_risk and get_conditional_value_at_risk, the Tail Gini is that of get_tail_gini and the EVaR the historic one of get_entropic_value_at_risk, each measured on the negated returns for the gains. The result is a positive decimal.

Also known as: return range, VaR range, CVaR range, Tail Gini range, EVaR range, tail spread.

Example · AMZN, WMT, COST · 2021 to 2025

Install the Finance Toolkit with pip install financetoolkit -U, then call get_risk_range:

from financetoolkit import Toolkit

toolkit = Toolkit(
    ["AMZN", "WMT", "COST"],
    api_key="FINANCIAL_MODELING_PREP_KEY",
    start_date="2021-01-01",
    end_date="2025-12-31",
)

toolkit.risk.get_risk_range(period="yearly", within_period=True, measure="cvar")

Or, with the Finance Toolkit MCP set up, ask an AI assistant such as Claude or ChatGPT:

How far apart were the 5% conditional Value at Risk of the gains and of the losses of Amazon, Walmart, Costco and the S&P 500 in each year from 2021 to 2025?

Which returns:

Parameters

get_risk_range accepts the following parameters.

ParameterTypeDescriptionExample
periodstrThe data frequency for returns. Options are: “daily”, “weekly”, “monthly”, “quarterly”, “yearly”. Defaults to “daily”."weekly"
measurestrThe range to calculate. Options are: “range” (Range), “var” (VaR Range), “cvar” (CVaR Range), “tail_gini” (Tail Gini Range), “evar” (EVaR Range). Defaults to “range”."range"
alphafloatThe tail probability of the losses, between 0 and 1 (between 0.0001 and 1 for the Tail Gini). Defaults to 0.05.0.01
betafloat | NoneThe tail probability of the gains. Defaults to None, which uses alpha.None, which uses alpha
pointsintThe number of tail probabilities of the Tail Gini Range. Defaults to 100.100
within_periodboolWhether to calculate the Risk Range within the specified period or for the entire period. Thus whether to look at the Risk Range 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
rollingintThe rolling window size to use for the calculation. If set, the Risk Range 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
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 Risk Range values over time. 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
show_columnsstr | list[str] | NoneThe 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 Cajas, D. (2021). “OWA Portfolio Optimization: A Disciplined Convex Programming Framework.” SSRN Electronic Journal.
  • Library Referenced against Riskfolio-Lib’s RG (Range)
  • Library Referenced against Riskfolio-Lib’s TGRG (Tail Gini Range)
  • Library Referenced against Riskfolio-Lib’s EVRG (EVaR Range)
  • Library Shares similar logic as Riskfolio-Lib’s VRG (VaR Range)
  • Library Shares similar logic as Riskfolio-Lib’s CVRG (CVaR Range)
Share