User Guide¶
ml4t-models is organized around model semantics, not around one generic trainer
abstraction.
The fastest way to understand the library is to ask four questions:
- what data contract does the model require?
- what object does it estimate?
- what is the native output?
- what still has to happen before you can trade or backtest it?
PCAModel, RPPCAModel, IPCAModel, CAEModel
PCA and RP-PCA use PersistentPanelBatch. IPCA and CAE use CrossSectionBatch.
Native outputs are loadings or conditional betas, factor history, and structural state.
StochasticDiscountFactorModel
Input: CrossSectionBatch.
Outputs: asset_weights, sdf_values, and phase-aware checkpoints.
SAEModel
Input: CrossSectionBatch.
Output: cross-sectional signals in AssetSignalResult.
LinearFeaturePortfolioModel, LSTMPortfolioModel, DeepPortfolioModel
Input: PortfolioSequenceBatch.
Output: target weights in PortfolioWeightsResult.
Neural learners can include trading costs in their training objective.
- Structural estimation produces
LatentFactorState. - A separate factor-premium forecaster produces
FactorForecastResult. - An asset mapper combines state and forecast into
AssetForecastResult.
PredictionsFrame carries forecasts or direct signals. WeightsFrame and ContextFrame support backtests and portfolio diagnostics.
The core design choice is simple: do not force structurally different finance models through
one artificial fit/predict story. A latent-factor model, a stochastic discount factor
model, a direct supervised predictor, and an end-to-end portfolio learner may all use neural
networks, but they are not estimating the same object.
The Four Main Workflows¶
1. Latent-Factor Forecasting¶
Used by:
PCAModelRPPCAModelIPCAModelCAEModel
Workflow:
This is the right abstraction for models where:
- exposures and factor realizations are the structural objects
- expected returns come from a separate premium forecast
2. Stochastic Discount Factor Estimation¶
Used by:
StochasticDiscountFactorModel
Workflow:
This family is intentionally separate because the native object is a traded pricing-kernel proxy, not a latent factor plus a premium forecast.
3. Direct Asset Prediction¶
Used by:
SAEModel
Workflow:
This is where the library puts supervised models that predict asset-level signals directly.
4. End-To-End Portfolio Learning¶
Used by:
LinearFeaturePortfolioModelLSTMPortfolioModelDeepPortfolioModel
Workflow:
These models optimize allocation decisions directly rather than first estimating returns.
Design Rules¶
- Stable-ID panel models and ragged cross-sectional models use different contracts.
- Neural checkpoints are configurable rather than hard-coded.
- Forecasting is kept outside structural latent-factor estimation.
- Evaluation belongs in
ml4t-diagnostic, not in this library. - Execution belongs in
ml4t-backtest, not in this library.
Supported and unsupported boundaries¶
The four model families above are supported public workflows. No other model family is designated
experimental in the public API. Modules under ml4t.models._internal can change between releases;
use the public API reference for supported imports. This package does not fetch
market data, compute diagnostic scores, or simulate trades. The Integration guide
describes the frames it can hand to those other steps. Neural models require the deep extra;
their small CPU examples verify contracts, not trained investment performance.
A Good Reading Strategy¶
If you want the economic logic first:
If you want to wire the library into a workflow quickly: