Mean Excess Function

Calculate the Mean Excess Function of the losses: the average amount by which the losses exceed a range of thresholds, the plot used to choose the threshold of a Generalized Pareto fit.

Above a threshold where the losses follow a Generalized Pareto Distribution, the mean excess is a straight line in the threshold with slope xi / (1 - xi): rising for a heavy (power-law) tail, flat for an exponential tail and falling for a tail with an end point. A good threshold for get_generalized_pareto_fit and the Extreme Value Theory VaR is the lowest one above which the line is close to straight; the last points rest on a handful of losses and are noisy.

The formula is as follows:

\[\text{Losses} = - \text{Returns}\] \[e(u) = \frac{\sum(\text{Loss}_{i} - u) \cdot 1 \{\text{Loss}_{i} > u\}}{\sum 1 \{\text{Loss}_{i} > u\}}\]

Where u is the quantile of each asset’s losses at each of quantiles (linear interpolation).

Also known as: mean excess plot, mean residual life plot, ME plot.

Example · BTCUSD, ^GSPC · 2021 to 2025

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

from financetoolkit import Toolkit

toolkit = Toolkit(
    ["BTCUSD", "^GSPC"],
    api_key="FINANCIAL_MODELING_PREP_KEY",
    start_date="2021-01-01",
    end_date="2025-12-31",
)

toolkit.risk.get_mean_excess_function(quantiles=[0.9, 0.95, 0.975, 0.99], show_columns="Mean Excess")

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

By how much did the daily losses of Bitcoin and the S&P 500 from 2021 to 2025 exceed their 90%, 95%, 97.5% and 99% quantiles on average?

Which returns:

Parameters

get_mean_excess_function accepts the following parameters.

ParameterTypeDescriptionExample
periodstrThe data frequency for returns. Options are: “daily”, “weekly”, “monthly”, “quarterly”, “yearly”. Defaults to “daily”."weekly"
quantileslist[float] | NoneThe quantiles of the losses to use as thresholds, each between 0 and 1. Defaults to None, which uses 0.80, 0.81, …, 0.99.[0.05, 0.5, 0.95]
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
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 Davison, A.C. and Smith, R.L. (1990). “Models for Exceedances over High Thresholds.” Journal of the Royal Statistical Society, Series B, 52(3), 393-442.
  • Paper McNeil, A.J., Frey, R. and Embrechts, P. (2015). “Quantitative Risk Management: Concepts, Techniques and Tools.” Revised Edition, Princeton University Press, Section 5.2.
Share