Expected Quadratic Shortfall (EQS)
Calculate the Expected Quadratic Shortfall (EQS) of an investment portfolio or asset’s returns: the average squared loss in the worst alpha share of the periods.
Where the Conditional Value at Risk averages the worst alpha share of the returns, the Expected Quadratic Shortfall averages the worst alpha share of the squared losses, so a loss twice as deep counts four times. It is the semi-variance restricted to the tail: gains and small losses do not count. It is convex and rises with the losses, which makes it a portfolio objective that a linear program can minimize, but it is not a coherent risk measure: it is in squared returns, so doubling the position quadruples it, and adding cash does not lower it by that amount. Its square root is the root mean square of the tail losses, on the scale of the returns. For a coherent measure that weighs the tail by its second moment, see get_higher_moment_coherent_risk (the Coherent Second Moment).
The formula is as follows (with the default alpha of 0.05):
\[\text{Squared Loss} = \max(- \text{Return},\; 0)^{2}\] \[\text{EQS} = \min \;\text{over}\; \zeta \;\text{of}\; \zeta + \frac{1}{n \cdot \alpha} \cdot \sum \max(\text{Squared Loss} - \zeta,\; 0)\]Where the sum runs over the n returns. The minimum is the average of the n * alpha largest squared losses, the squared loss at the boundary counted with the fraction of it inside the tail (the Conditional Value at Risk of Rockafellar and Uryasev (2002) applied to the squared losses). The result is positive, in squared returns.
Also known as: EQS, expected squared shortfall, tail semi-variance.
Example · GLD, SLV, USO · 2021 to 2025
Install the Finance Toolkit with pip install financetoolkit -U, then call get_expected_quadratic_shortfall:
from financetoolkit import Toolkit
toolkit = Toolkit(
["GLD", "SLV", "USO"],
api_key="FINANCIAL_MODELING_PREP_KEY",
start_date="2021-01-01",
end_date="2025-12-31",
)
toolkit.risk.get_expected_quadratic_shortfall(period="yearly", within_period=True, rounding=6)
Or, with the Finance Toolkit MCP set up, ask an AI assistant such as Claude or ChatGPT:
What was the expected quadratic shortfall, the average squared loss on the worst 5% of days, of the SPDR Gold Shares (GLD), iShares Silver Trust (SLV), United States Oil Fund (USO) and the S&P 500 in each year from 2021 to 2025?
Which returns:
| Item | GLD | SLV | USO | Benchmark |
|---|---|---|---|---|
| 2021 | 0.0005 | 0.0019 | 0.0029 | 0.0004 |
| 2022 | 0.0004 | 0.0012 | 0.0044 | 0.0012 |
| 2023 | 0.0003 | 0.0013 | 0.0020 | 0.0003 |
| 2024 | 0.0005 | 0.0016 | 0.0015 | 0.0004 |
| 2025 | 0.0009 | 0.0025 | 0.0022 | 0.0010 |
5 rows
Parameters
get_expected_quadratic_shortfall 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" |
alpha | float | The tail probability (e.g., 0.05 for the 95% confidence level). Defaults to 0.05. | 0.01 |
within_period | bool | Whether to calculate the EQS within the specified period or for the entire period. Thus whether to look at the EQS 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 EQS 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 EQS 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 Rockafellar, R.T. and Uryasev, S. (2002). “Conditional Value-at-Risk for General Loss Distributions.” Journal of Banking & Finance, 26(7), 1443-1471.
- Library Shares similar logic as PortfolioAnalytics (R)’s extract_risk