ML4T Models¶
Finance-specific models for asset pricing, prediction, and portfolio learning.
ml4t.models is the modeling layer in the ML4T stack. It packages model families that matter in empirical asset pricing and portfolio construction while keeping the contracts explicit:
- what kind of data each model expects
- what object it estimates
- what must still happen before you have an implementable forecast or tradable weight vector
Start with the bounded CPU Quickstart for a complete forecast and expected result. Use the task guides for your own inputs, the API Reference for exact signatures, and the Book Guide for verified public teaching notebooks.
-
Latent Factors Done Explicitly
Structural extraction, factor-premium forecasting, and asset mapping are separate stages. This keeps PCA, RP-PCA, IPCA, and CAE conceptually clean. Latent-Factor Pipelines
-
No-Arbitrage SDF Modeling
The stochastic discount factor family is weight-native and phase-aware. It is not forced into the same
beta × lambdacontract as latent-factor models. Stochastic Discount Factor -
End-To-End Portfolio Learning
Learn allocations directly with deterministic, LSTM, and DeePM-style portfolio models. Keep allocation objectives separate from return forecasting logic. Portfolio Learning
-
Built For The ML4T Stack
Emit prediction and weight frames for
ml4t-backtestandml4t-diagnosticwithout duplicating evaluation logic inside the model library. Integration
Architecture At A Glance¶
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.
Why This Library Exists¶
Many finance models look similar at the tensor level but behave very differently conceptually:
PCAandRP-PCAestimate persistent-panel latent factorsIPCAandCAEestimate conditional exposures from dated cross-sectionsStochasticDiscountFactorModellearns a no-arbitrage pricing object through weight-native trainingSAEModelis a direct supervised predictor- portfolio models learn allocations directly rather than first forecasting returns
The library reflects those differences instead of hiding them behind one catch-all fit/predict story.
First result¶
The Quickstart runs PCA on a small synthetic panel and checks a
finite forecast with shape (2, 6). It needs only the base package and NumPy.
Three Core Contracts¶
| Contract | Used by | What it represents |
|---|---|---|
PersistentPanelBatch |
PCAModel, RPPCAModel |
stable-entity return panel |
CrossSectionBatch |
IPCAModel, CAEModel, SAEModel, StochasticDiscountFactorModel |
dated observed cross-sections, ragged by construction |
PortfolioSequenceBatch |
LinearFeaturePortfolioModel, LSTMPortfolioModel, DeepPortfolioModel |
sequence-to-allocation learning |
Model Families¶
latent_factors
├── PCAModel
├── RPPCAModel
├── IPCAModel
└── CAEModel
stochastic_discount_factor
└── StochasticDiscountFactorModel
asset_prediction
└── SAEModel
portfolio
├── LinearFeaturePortfolioModel
├── LSTMPortfolioModel
└── DeepPortfolioModel