Skip to content
ml4tPublic

Repository files navigation

ml4t-data

CI PyPI Python Downloads

Market data acquisition, storage, and update workflows for machine learning for trading.

Use ml4t-data to fetch and validate market data, keep local datasets current, and provide repeatable inputs to research and trading workflows. It includes adapters for equities, futures, foreign exchange, crypto assets, macroeconomic series, factors, and prediction markets.

The ML4T library ecosystem

Six libraries cover one workflow, from raw market data to a strategy running against a broker. They share the data, artifact, and lifecycle contracts in ml4t-specs, and they are the libraries used throughout Machine Learning for Trading, 3rd Edition.

The six ML4T libraries arranged as one left-to-right workflow: market data, feature and label engineering, modeling, signal and strategy evaluation, backtesting, and live deployment

Stage Library What it does
Data ml4t-data (this repository) Market data acquisition from 19+ providers behind one interface
Signal ml4t-engineer Features, labels, alternative bars, and leakage-safe datasets
Models ml4t-models Finance-native latent factors, SDFs, prediction, and portfolio learning
Evaluation ml4t-diagnostic Feature validation, strategy diagnostics, and the Deflated Sharpe Ratio
Strategy ml4t-backtest Event-driven backtesting with realistic execution
Deployment ml4t-live Live trading with broker integrations and risk checks

Installation

ml4t-data supports CPython 3.12 through 3.15 on Linux, macOS, and Windows.

pip install ml4t-data

Provider-specific integrations are optional. Install ml4t-data[yahoo], ml4t-data[databento], ml4t-data[oanda], or ml4t-data[cot] when those adapters are needed. Some providers require network access, an account, credentials, or metered data. The provider guide records each boundary.

Quick start

The synthetic provider exercises the public OHLCV interface without network access or credentials.

from ml4t.data.providers import SyntheticProvider

provider = SyntheticProvider(seed=42)
data = provider.fetch_ohlcv("SYNTH", "2024-01-01", "2024-01-10", "daily")

assert not data.is_empty()
assert {"timestamp", "symbol", "open", "high", "low", "close", "volume"} <= set(data.columns)

Set ML4T_DATA_PATH to choose the root directory for local datasets. Without an explicit path, the library uses ./data in the current working directory.

Migration from QLDM names

Existing deployments may continue to use QLDM_DATA_ROOT and import QldmError. Both names emit DeprecationWarning and will not be removed before version 1.0.

  • Replace QLDM_DATA_ROOT with ML4T_DATA_PATH.
  • Replace QldmError with ML4TDataError from ml4t.data.core.exceptions.

Documentation and support

The library supplies data to ml4t-engineer feature workflows and ml4t-backtest simulations. Neither package is required to use ml4t-data.

Development

git clone https://github.com/ml4t/data.git
cd data
uv sync --all-extras --all-groups
uv run pre-commit install
uv run ruff check src/ tests/
uv run ruff format --check src/ tests/
uv run ty check
uv run pytest tests/ -q -ra --cov=ml4t.data --cov-report=term-missing
uv run mkdocs build --strict
uv build

Pull requests must preserve offline deterministic tests. Provider contract tests that require credentials run in explicit integration lanes.

Releases

Packages

Used by

Contributors

Languages