Tail-Set Labels

Calculate the tail-set labels: per date, rank the tickers on their volatility-adjusted return over the next horizon periods and label the top quantile 1, the bottom quantile -1 and the rest 0.

A model trained on them learns to tell the best from the worst performers of a universe, the question a long-short portfolio asks, without being distracted by the noisy middle. The labels need a universe of tickers, such as the constituents of an index.

The formula is as follows:

\[\text{Score}_{t} = \frac{p_{t} + \frac{\text{horizon}}{p_{t}} - 1}{\sigma_{t}},\;\; \sigma_{t} \text{ the EWM volatility up to } t \text{ (or the return itself without volatility adjustment)}\] \[q = \frac{\text{rank} - 1}{N - 1},\;\; \text{the percentile rank among the } N \text{ tickers with a score}\] \[\text{Label} = 1 \;\text{when}\; q \geq 1 - \text{quantile},\;\; - 1 \;\text{when}\; q \leq \text{quantile},\;\; \text{else 0}\]

Labels look forward by construction: the score of a date is the return of the horizon periods after it, divided by the volatility known at the date.

The tail sets follow Huerta, Corbacho and Elkan (2013), who label the stocks with the highest and lowest volatility-adjusted returns and leave the middle out.

Also known as: tail sets, tail set labels, cross-sectional quantile labels.

Example · AAPL, MSFT, NVDA, AMZN, 6 more · 2024 to 2025

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

from financetoolkit import Toolkit

toolkit = Toolkit(
    ["AAPL", "MSFT", "NVDA", "AMZN", "GOOGL", "META", "TSLA", "AVGO", "ORCL", "AMD"],
    api_key="FINANCIAL_MODELING_PREP_KEY",
    start_date="2024-01-01",
    end_date="2025-12-31",
)

labels = toolkit.technicals.get_tail_set_labels()

labels["Label"].dropna()

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

On each day of 2025, which of Apple, Microsoft, Nvidia, Amazon, Alphabet, Meta, Tesla, Broadcom, Oracle and AMD ranked among the best or worst performers over the next day?

Which returns:

Parameters

get_tail_set_labels accepts the following parameters.

ParameterTypeDescriptionExample
periodstrThe time period to consider for historical data. Options are: “intraday” (intraday prices), “daily” (daily prices), “weekly” (weekly prices), “monthly” (monthly prices), “quarterly” (quarterly prices), “yearly” (yearly prices). Defaults to “daily”."weekly"
close_columnstrThe column name for closing prices in the historical data. Defaults to “Adj Close”."Close"
horizonintThe number of periods of the forward return. Defaults to 1.5
quantilefloatThe share of the tickers in each tail, up to 0.5. Defaults to 0.1.0.1
volatility_adjustedboolWhether the returns are divided by the volatility. Defaults to True.True
spanintThe span of the exponentially weighted volatility. Defaults to 100.100
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 Huerta, R., Corbacho, F. and Elkan, C. (2013). “Nonlinear Support Vector Machines Can Systematically Identify Stocks with High and Low Future Returns.” Algorithmic Finance, 2(1), 45-58.
  • Paper López de Prado, M. (2020). “Machine Learning for Asset Managers.” Cambridge University Press, chapter 5.
Share