ml4t
engineer
Python

Feature engineering, labeling, alternative bars, and leakage-safe datasets for financial ML.

Last updated Jul 8, 2026
16
Stars
11
Forks
0
Issues
0
Stars/day
Attention Score
68
Language breakdown
No language data available.
Files click to expand
README

ml4t-engineer

Python 3.12+ PyPI License: MIT

Feature engineering for financial machine learning: validated features, labeling methods, alternative bars, and leakage-safe dataset preparation.

Part of the ML4T Library Ecosystem

This library is one of six interconnected libraries supporting the machine learning for trading workflow described in Machine Learning for Trading:

ML4T Library Ecosystem

Together they cover data infrastructure, feature engineering, modeling, signal evaluation, strategy backtesting, and live deployment.

What This Library Does

Transforming raw price data into predictive features is a core task in quantitative research. ml4t-engineer provides:

  • 120 registry features across 11 categories (momentum, volatility, trend,
microstructure, and more)
  • Triple-barrier, ATR-based, percentile, trend-scanning, and meta-labeling
methods from Advances in Financial Machine Learning
  • Alternative bar sampling (volume bars, dollar bars, tick imbalance bars)
  • Dataset building, preprocessing, and feature discovery for leakage-safe ML
workflows

The library is built on Polars with Numba JIT compilation for numerical operations. 60 features are validated against TA-Lib at 1e-6 tolerance.

ml4t-engineer Architecture

Installation

pip install ml4t-engineer

Optional dependencies:

pip install ml4t-engineer[ta]        # TA-Lib backend
pip install ml4t-engineer[viz]       # Visualization
pip install ml4t-engineer[calendars] # Trading calendars

Quick Start

import polars as pl
from ml4t.engineer import compute_features

df = pl.read_parquet("ohlcv.parquet")

Compute features with default parameters

result = compute_features(df, ["rsi", "macd", "atr", "obv"])

Or with custom parameters

result = compute_features(df, [ {"name": "rsi", "params": {"period": 20}}, {"name": "bollingerbands", "params": {"period": 20, "stddev": 2.0}}, ])

Feature Registry

from ml4t.engineer.core.registry import get_registry

registry = get_registry() print(registry.list_all()) # All 120 features print(registry.listbycategory("momentum")) # 31 momentum indicators print(registry.listtalib_compatible()) # 60 TA-Lib validated features print(registry.list_normalized()) # 37 bounded (0-100, -1 to 1)

Feature Categories

| Category | Count | Examples | |----------|-------|----------| | Momentum | 31 | RSI, MACD, Stochastic, CCI, ADX, MFI | | Microstructure | 15 | Kyle Lambda, VPIN, Amihud, Roll spread | | Volatility | 15 | ATR, Bollinger, Yang-Zhang, Parkinson | | Statistics | 14 | Variance, Linear Regression, Correlation | | ML | 14 | Fractional Diff, Entropy, Lag features | | Trend | 10 | SMA, EMA, WMA, DEMA, TEMA, KAMA | | Risk | 6 | Max Drawdown, Sortino, CVaR | | Price Transform | 5 | Typical Price, Weighted Close | | Regime | 4 | Hurst Exponent, Choppiness Index | | Volume | 3 | OBV, AD, ADOSC | | Math | 3 | MAX, MIN, SUM |

Triple-Barrier Labeling

from ml4t.engineer.config import LabelingConfig
from ml4t.engineer.labeling import triplebarrierlabels, atrtriplebarrier_labels

Fixed barriers

tbconfig = LabelingConfig.triplebarrier( upper_barrier=0.02, # 2% profit target lower_barrier=0.01, # 1% stop loss maxholdingperiod=20, # 20 bars ) labels = triplebarrierlabels( df, config=tb_config, )

ATR-based dynamic barriers

atrconfig = LabelingConfig.atrbarrier( atrtpmultiple=2.0, atrslmultiple=1.0, atr_period=14, maxholdingperiod=20, ) labels = atrtriplebarrier_labels( df, config=atr_config, )

Time-based horizons

tbtimeconfig = LabelingConfig.triple_barrier( upper_barrier=0.02, lower_barrier=0.01, maxholdingperiod="4h", # 4 hours ) labels = triplebarrierlabels( df, config=tbtimeconfig, )

Alternative Bars

from ml4t.engineer.bars import VolumeBarSampler, DollarBarSampler, TickImbalanceBarSampler

Volume bars (equal volume per bar)

vbars = VolumeBarSampler(volumeperbar=1000).sample(tick_data)

Dollar bars (equal dollar volume per bar)

dbars = DollarBarSampler(dollarsperbar=1000000).sample(tick_data)

Tick imbalance bars (information-driven)

ibars = TickImbalanceBarSampler(expectedticksperbar=100).sample(tickdata)

Documentation

workflow map first working feature and labeling workflow 120 features across 11 registry categories 7 labeling methods for supervised learning leakage-safe train/test preparation runnable scripts for complete workflows and focused features

Technical Characteristics

  • Polars-native: All computations use Polars expressions
  • Numba-accelerated: JIT compilation for numerical kernels
  • TA-Lib validated: 60 features validated at 1e-6 tolerance
  • AFML-compliant: Labeling methods verified against Advances in Financial Machine Learning
  • ML-ready outputs: 37 features produce bounded outputs (0-100, -1 to 1) for direct model input; remaining features work with standard preprocessing (returns, z-scores, robust scaling)

Related Libraries

  • ml4t-specs: Shared feed and artifact schema definitions across the ML4T stack
  • ml4t-data: Market data acquisition and storage
  • ml4t-diagnostic: Signal evaluation and statistical validation
  • ml4t-backtest: Event-driven backtesting
  • ml4t-live: Live trading with broker integration

Development

git clone https://github.com/ml4t/engineer.git
cd ml4t-engineer
uv sync
uv run pytest tests/ -q
uv run ty check

References

  • Lopez de Prado, M. (2018). Advances in Financial Machine Learning. Wiley.
  • Lopez de Prado, M. (2020). Machine Learning for Asset Managers. Cambridge.

License

MIT License - see LICENSE for details.

🔗 More in this category

© 2026 GitRepoTrend · ml4t/engineer · Updated daily from GitHub