- Published on
Sample Weights
Sample Weights
This chapter addresses a critical problem in financial machine learning: observations are not Independent and Identically Distributed (IID). This violation of a core ML assumption stems from overlapping outcomes, and this summary explains how to quantify and correct for it using sample weights.
The Problem: Overlapping Outcomes
In finance, the outcome (label) for a feature is determined over a time interval . If the time intervals of two different labels and overlap (i.e., for ), they will both depend on a common set of returns.
- Concurrency: This overlap means the labels are not independent. Standard ML algorithms will be overfit on the redundant information, and bagging methods (like Random Forests) will produce unreliable OOB (out-of-bag) scores because the OOB samples are not truly independent of the in-bag samples.
Quantifying Label Uniqueness
To solve this, we must first quantify the degree of overlap (concurrency) for each label.
Number of Concurrent Labels (): This measures how many labels are "active" (i.e., depend on the return) at a specific time . It is the sum of all indicator functions (where if label is active at ).
Average Uniqueness (): This provides a single uniqueness score for each label . It is the average of its uniqueness () over its entire lifespan.
A high means the label is highly unique, while a low means it shares information with many other labels.

Solution 1: Sequential Bootstrap
This method addresses the flawed sampling in bagging. Instead of sampling with uniform probability (which oversamples redundant data), the Sequential Bootstrap updates the sampling probabilities at each draw.
- Draw 1: Sample with uniform probability .
- Draw 2: Re-calculate the uniqueness of all labels given that sample was drawn. The probability of drawing sample for the second draw, , is now proportional to its new average uniqueness .
This process makes it less likely to draw samples that heavily overlap with those already in the bag, resulting in a bootstrapped set that is closer to IID.

Solution 2: Sample Weights
This section provides methods for weighting observations during model training, giving more importance to "better" samples.
Return Attribution
Weights are assigned based on both uniqueness and absolute return. The idea is to give more weight to unique labels that were associated with a significant market move. The weight is the absolute sum of all returns during the label's life, with each return divided by its concurrency .
- Un-normalized weight:
- Normalized weight (to sum to ):
Time Decay
To account for adaptive markets, older data should be less relevant. A time-decay factor is applied to the sample weights.
- Key Concept: The decay is not based on calendar time, but on cumulative uniqueness . This prevents the model from rapidly discarding many recent, but redundant, observations.
- A parameter controls the decay rate, where is no decay, and "forgets" the oldest portion of the data.

Class Weights
Finally, the text distinguishes sample weights (for uniqueness) from class weights.
- Class Weights: These are used to address imbalanced classes, not label overlap. If a model is trained to detect rare events (like a flash crash), class weights are applied to increase the penalty for misclassifying the rare event, forcing the model to pay more attention to it. A common setting for this is
class_weight='balanced'.
Implementation: Uniqueness and Other Sample Weights
In our RiskLabAI.data.weights.sample_weights module, we implement the core functions for calculating sample weights to address the non-IID nature of financial data.
Concurrency and Uniqueness
We provide functions to measure the uniqueness of each label based on event concurrency.
- Concurrency: First, we compute the number of concurrent events active at each timestamp. This function expands the event start/end times into a time series of active event counts.
- Average Uniqueness: Using the concurrency data, we calculate the average uniqueness of each label, , as the average of over the label's lifespan. This
index_matrixis an indicator matrix (T x N) representing active events, which can be derived fromexpand_label_for_meta_labeling.
Return-Based Sample Weights
We also implement the return attribution method to weight samples based on their associated market impact. The weight is calculated as the sum of absolute log-returns during the event, normalized by the concurrency at each step.
Time-Decay Weights
Finally, we provide a function to apply a time-decay factor to any set of weights. This allows us to give more importance to recent observations, with the clf_last_weight parameter controlling how much the oldest observations are discounted (linearly).
API reference
RiskLabAI implements these in Python and Julia (signatures auto-generated from the package source):
| Python | Julia |
|---|---|
| |
| |
| |
| |