Documentation
Skip to content

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 × lambda contract 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-backtest and ml4t-diagnostic without duplicating evaluation logic inside the model library. Integration

Architecture At A Glance

Model families and native outputs
Latent factors

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.

Stochastic discount factor

StochasticDiscountFactorModel

Input: CrossSectionBatch.

Outputs: asset_weights, sdf_values, and phase-aware checkpoints.

Direct asset prediction

SAEModel

Input: CrossSectionBatch.

Output: cross-sectional signals in AssetSignalResult.

Portfolio learning

LinearFeaturePortfolioModel, LSTMPortfolioModel, DeepPortfolioModel

Input: PortfolioSequenceBatch.

Output: target weights in PortfolioWeightsResult.

Neural learners can include trading costs in their training objective.

Latent-factor return forecasts require three stages
  1. Structural estimation produces LatentFactorState.
  2. A separate factor-premium forecaster produces FactorForecastResult.
  3. An asset mapper combines state and forecast into AssetForecastResult.
Downstream handoff

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:

  • PCA and RP-PCA estimate persistent-panel latent factors
  • IPCA and CAE estimate conditional exposures from dated cross-sections
  • StochasticDiscountFactorModel learns a no-arbitrage pricing object through weight-native training
  • SAEModel is 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

Where To Start