Skip to main content

ml4t-diagnostic

Python 3.12-3.14 PyPI License: MIT

Signal diagnostics, statistical validation, and backtest evaluation for quantitative trading workflows.

Use ml4t-diagnostic to evaluate cross-sectional signals, construct purged time-series validation folds, correct strategy statistics for selection bias, analyze feature and trade behavior, and produce backtest reports.

ML4T Library Ecosystem

ml4t-diagnostic is one of seven libraries supporting the workflow described in Machine Learning for Trading.

ML4T library ecosystem

It accepts engineered features, predictions, and backtest results from the other ML4T libraries, but the primary signal-analysis workflow below has no external service or special hardware requirement.

Installation and Support

The supported Python versions are 3.12, 3.13, and 3.14 on Linux, macOS, and Windows.

uv add ml4t-diagnostic

Python 3.15 is not currently supported because required dependency wheels are still being qualified. Progress is tracked in issue #45.

Quick Start

This example creates a synthetic cross-sectional factor whose score affects the next price change, then measures its information coefficient and quantile spread.

import numpy as np
import polars as pl

from ml4t.diagnostic import analyze_signal

rng = np.random.default_rng(42)
dates = pl.date_range(pl.date(2025, 1, 1), pl.date(2025, 2, 28), eager=True)[:40]
assets = [f"asset_{index:02d}" for index in range(20)]

factor_rows = []
price_rows = []
prices = np.full(len(assets), 100.0)
for date in dates:
    scores = rng.normal(size=len(assets))
    factor_rows.extend(
        {"date": date, "asset": asset, "factor": score}
        for asset, score in zip(assets, scores, strict=True)
    )
    price_rows.extend(
        {"date": date, "asset": asset, "price": price}
        for asset, price in zip(assets, prices, strict=True)
    )
    prices *= 1 + 0.002 * scores + rng.normal(scale=0.005, size=len(assets))

result = analyze_signal(
    factor=pl.DataFrame(factor_rows),
    prices=pl.DataFrame(price_rows),
    periods=(1, 5),
)

assert result.ic["1D"] > 0.1
print(f"IC (1D): {result.ic['1D']:.4f}")
print(f"IC t-stat (1D): {result.ic_t_stat['1D']:.2f}")
print(f"Q5-Q1 spread (1D): {result.spread['1D']:.2%}")

analyze_signal returns information coefficients, significance statistics, quantile returns, spreads, turnover, and related diagnostics for each requested forward period. See the executable quickstart tutorial for the input schema and a multiple-testing example.

Main Capabilities

Area Public workflows
Signal analysis analyze_signal, HAC-adjusted IC, quantile profiles, turnover
Cross-validation WalkForwardCV, CombinatorialCV, ValidatedCrossValidation
Selection bias Deflated Sharpe Ratio, PBO, RAS, FDR control, White's Reality Check
Feature analysis FeatureDiagnostics, importance, interactions, drift, causality audit
Backtest analysis BacktestProfile, portfolio metrics, factor attribution, trade diagnostics
Reporting Plotly charts, dashboards, HTML tearsheets, static export

Optional Features

Install only the integrations needed by your workflow:

uv add 'ml4t-diagnostic[viz]'       # Plotly charts and static export
uv add 'ml4t-diagnostic[ml]'        # LightGBM, XGBoost, and supported SHAP builds
uv add 'ml4t-diagnostic[perf]'      # Optional Numba acceleration
uv add 'ml4t-diagnostic[backtest]'  # ml4t-backtest result bridge
uv add 'ml4t-diagnostic[data]'      # ml4t-data integration
uv add 'ml4t-diagnostic[factors]'   # Factor-data sourcing through ml4t-data
uv add 'ml4t-diagnostic[dashboard]' # Streamlit dashboard
uv add 'ml4t-diagnostic[all]'       # All supported optional features

LightGBM requires an OpenMP runtime on macOS. SHAP and Numba are excluded on Intel macOS with Python 3.14 because compatible wheels are unavailable. Static Plotly image and PDF export through current Kaleido releases may require a local Chrome or Chromium installation. Core signal analysis does not require these optional runtimes.

Documentation

Development

git clone https://github.com/ml4t/diagnostic.git
cd diagnostic
uv sync --all-extras --dev
uv run ruff check src/ tests/
uv run ruff format --check src/ tests/
uv run ty check
uv run pytest tests/ -q -n auto --timeout 120
uv run mkdocs build --strict
pre-commit run --all-files

Pull requests should identify an owning issue and state any compatibility or release impact.

License

MIT License

Metadata

Release files for ml4t-diagnostic 0.1.9

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ml4t-diagnostic 0.1.9
File Size Uploaded
ml4t_diagnostic-0.1.9.tar.gz 6.8 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for ml4t-diagnostic 0.1.9
File Interpreter ABI Platform
ml4t_diagnostic-0.1.9-py3-none-any.whl Python 3 none any Details

Total release size: 7.7 MB

Release files / ml4t_diagnostic-0.1.9.tar.gz

Download URL ml4t_diagnostic-0.1.9.tar.gz
Size 6.8 MB
Tags Source
SHA-256 checksum
How to use checksums
12709cd007a16c86ade0d4a96cd6332d951d6370fd0d78c8e9a7b61994c164e4
BLAKE2b-256 checksum
How to use checksums
40b8a498679051921581ba48da6a94611fc88af5da0cc217d0fffbc4c7080e8b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 15, 2026.

Transparency log

Release files / ml4t_diagnostic-0.1.9-py3-none-any.whl

Download URL ml4t_diagnostic-0.1.9-py3-none-any.whl
Size 942.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9ef2dab764200c087619a3f972d063961b9370077c7cf33c1eb2c7f566e36f8c
BLAKE2b-256 checksum
How to use checksums
0bc8e797f2d29765e4148cb638f02ad8a78fb61b6b194792a911e4b696c59860
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 15, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.9 This release

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page