Labeling
finml_core.processing.labeling
TripleBarrierLabeling(col_map, ticker_level, date_level, config=None)
Labels financial time-series using the Triple Barrier Method (TBM).
Unlike standard fixed-horizon labeling, TBM creates dynamic labels based on volatility-adjusted price targets. It effectively captures the path-dependent nature of financial assets by monitoring three concurrent barriers:
- Upper Barrier (Take Profit): Hit when price appreciation reaches \(P_t \cdot (1 + \text{tp}_{\text{mult}} \cdot \sigma_t)\).
- Lower Barrier (Stop Loss): Hit when price depreciation reaches \(P_t \cdot (1 - \text{sl}_{\text{mult}} \cdot \sigma_t)\).
- Vertical Barrier (Time Limit): Hit when neither price barrier is touched within a fixed window \(T\).
Mathematical Outcomes
- 1 (Long): Upper barrier hit first.
- -1 (Short): Lower barrier hit first.
- 0 (Hold): Vertical barrier (Time Limit) reached.
Note
This implementation is optimized for MultiIndex DataFrames (Ticker, Date) and uses vectorized NumPy operations for the internal path-scanning loop.
Parameters:
| Name | Type | Description | Default | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
col_map
|
Dict
|
Mapping for OHLCV columns. Required to compute the labeling:
Example: |
required | ||||||||||||||||||||
ticker_level
|
str
|
MultiIndex level name for asset identifiers (e.g., 'Ticker'). |
required | ||||||||||||||||||||
date_level
|
str
|
MultiIndex level name for timestamps (e.g., 'Date'). |
required | ||||||||||||||||||||
config
|
Dict[str, Any]
|
Hyperparameters for the barriers.
|
None
|
compute_outcomes(df)
Executes the Triple Barrier labeling process across all assets.
This method orchestrates the full pipeline
- Volatility Normalization: Computes dynamic \(\sigma_t\) per ticker.
- MultiIndex Grouping: Isolates price paths by asset to prevent cross-ticker data leakage during barrier scanning.
- Numpy-Vectorized Search: Triggers the internal search engine for first-touch events on future price paths.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
MultiIndex DataFrame containing price series. |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
A DataFrame indexed like
|
Raises:
| Type | Description |
|---|---|
KeyError
|
If required columns or MultiIndex levels are missing. |