Generalized Pareto Fit (EVT)

Fit a Generalized Pareto Distribution to the losses above a threshold (Peak-over-Threshold): how heavy the tail of each asset’s losses is, with the shape and scale behind the Extreme Value Theory VaR.

By the Pickands-Balkema-de Haan theorem, the losses above a high threshold follow a Generalized Pareto Distribution (GPD) for a wide class of return distributions. The shape xi says how heavy the tail is: above 0 a power-law tail (as Student-t returns, with tail index 1 / xi; daily stock returns typically give 0.1 to 0.4), 0 an exponential tail (as normal returns) and below 0 a tail with a finite end point. The fitted shape and scale give the Extreme Value Theory VaR and CVaR (get_value_at_risk and get_conditional_value_at_risk with the “evt” method). A shape of 1 or more means the tail has no mean, so the EVT CVaR is NaN. The fit depends on the threshold: get_mean_excess_function helps to choose one.

The formula is as follows:

\[\text{Losses} = - \text{Returns, Excesses}\; y_{i} = \text{Loss}_{i} - u \;\text{for every Loss}_{i} > u\] \[(\xi,\; \beta) \;\text{maximize} \;\sum \ln f(y_{i}) \;\text{with}\; \ln f(y) = - \ln(\beta) - \left(1 + \frac{1}{\xi}\right) \cdot \ln\left(1 + \frac{\xi \cdot y}{\beta}\right)\] \[\text{Shape Standard Error} = \frac{1 + \xi}{\sqrt{\text{Nu}}}\] \[\text{Scale Standard Error} = \beta \cdot \sqrt{\frac{2 \cdot (1 + \xi)}{\text{Nu}}}\] \[\text{Exceedance Probability} = \frac{\text{Nu}}{n}\]

Where u is the threshold_percentile percentile of the losses (linear interpolation) or the given threshold, Nu the number of losses above u and n the number of returns of the asset. The Maximum Likelihood fit maximizes the profile likelihood in \(\theta = \xi / \beta\) (Grimshaw 1993), and the standard errors are the asymptotic ones of Smith (1987), which hold for \(\xi > - 0.5\) (NaN below). The resulting EVT VaR at a tail probability alpha is u + (beta / xi) * ((alpha / p)^(-xi) - 1) as a loss, with the exponential limit u - beta * ln(alpha / p) at \(\xi = 0\).

Also known as: GPD fit, peaks over threshold, POT, extreme value theory tail fit.

Example · BTCUSD, ^GSPC, GCUSD · 2021 to 2025

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

from financetoolkit import Toolkit

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

toolkit.risk.get_generalized_pareto_fit()

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

How heavy was the tail of the daily losses of Bitcoin, the S&P 500 and gold from 2021 to 2025, according to a Generalized Pareto fit on the 5% largest losses?

Which returns:

Parameters

get_generalized_pareto_fit accepts the following parameters.

ParameterTypeDescriptionExample
periodstrThe data frequency for returns. Options are: “daily”, “weekly”, “monthly”, “quarterly”, “yearly”. Defaults to “daily”."weekly"
threshold_percentilefloatThe percentile of losses above which the GPD is fitted (e.g. 0.95 fits the GPD on the worst 5% of losses). Defaults to 0.95.0.9
thresholdfloat | NoneA loss threshold as a positive decimal (0.03 fits the GPD to the losses beyond 3%), which replaces threshold_percentile. Defaults to None.None
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 Smith, R.L. (1987). “Estimating Tails of Probability Distributions.” The Annals of Statistics, 15(3), 1174-1207.
  • Paper Grimshaw, S.D. (1993). “Computing Maximum Likelihood Estimates for the Generalized Pareto Distribution.” Technometrics, 35(2), 185-191.
  • Paper McNeil, A.J. and Frey, R. (2000). “Estimation of Tail-Related Risk Measures for Heteroscedastic Financial Time Series: An Extreme Value Approach.” Journal of Empirical Finance, 7(3-4), 271-300.
  • 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.
  • Library Referenced against scipy’s genpareto
Share