Integration¶
ml4t-models integrates with the rest of the ML4T stack at boundaries. It does not try to absorb execution or evaluation logic.
Boundary Design¶
This Library Owns¶
- model estimation
- typed input contracts
- typed result objects
- prediction and weight frames
This Library Does Not Own¶
- execution simulation
- portfolio diagnostics
- statistical validation reports
Those belong in:
ml4t-backtestml4t-diagnostic
Long-Frame To Batch Adapters¶
Use:
persistent_panel_batch_from_long_framecross_section_batch_from_long_frameresolve_dataset_schema
These help when your data starts as:
- a pandas frame
- a polars frame
- a long-format table with ML4T-style schema metadata
Frame Adapters¶
The frame helpers normalize model outputs into standard long-format tables.
Predictions Frames¶
predictions_frame_from_asset_forecastpredictions_frame_from_asset_signal
Output columns:
timestampassetprediction_value
Weight And Signal Frames¶
signals_frame_from_portfolio_weightssignals_frame_from_asset_weightsweights_frame_from_portfolio_weightsweights_frame_from_asset_weightscontext_frame_from_weights
Backtest Handoff¶
Use:
backtest_datafeed_inputsbacktest_inputs_from_asset_forecastbacktest_inputs_from_asset_signalbacktest_inputs_from_weights
These construct:
- standardized signal frames
- optional context frames
FeedSpec-compatible metadata forml4t-backtest
Artifact Writing¶
Use:
to emit:
predictions.parquetweights.parquet
in the artifact conventions expected downstream.
Example¶
from ml4t.models import (
backtest_inputs_from_asset_forecast,
predictions_frame_from_asset_forecast,
write_backtest_frames,
)
frame = predictions_frame_from_asset_forecast(asset_forecast)
write_backtest_frames("artifacts/run_001", predictions=frame)
inputs = backtest_inputs_from_asset_forecast(
asset_forecast,
prices_path="prices.parquet",
timestamp_col="timestamp",
entity_col="asset",
close_col="close",
)
Rule Of Thumb¶
If you find yourself computing:
- IC summaries
- tearsheets
- execution PnL
- trade analytics
inside ml4t-models, you are probably crossing the intended library boundary.