Architecture¶
The library is organized around finance-native model families and contracts.
Top-Level Design¶
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 The Families Are Separate¶
Latent Factors¶
These families estimate structural state first:
- loadings or conditional betas
- latent factor realizations
- then expected returns through a separate factor-premium forecast
Stochastic Discount Factor¶
This family estimates a weight-native no-arbitrage object:
- asset weights
- SDF series
- optional downstream return projections
Direct Asset Prediction¶
This family predicts signals directly:
- no latent factor state
- no separate premium forecast
Portfolio Learning¶
This family learns allocations directly:
- sequential input windows
- cost-aware or risk-aware objectives
- target-weight outputs
Training Protocol Map¶
PCA and RP-PCA use eigendecomposition. IPCA uses alternating least squares.
These models expose no neural epoch grid; structural output is reported at epoch = 0.
CAE, SAE, and neural portfolio learners train for configured epochs or optimization steps.
Emit interval checkpoints or explicit checkpoint lists. Set default_checkpoint for prediction.
- Unconditional SDF warm-up
- Moment-network fitting
- Conditional SDF refinement
For long SDF runs, use 4-8 explicit structural checkpoints. Beta-head checkpoints have a separate, usually smaller grid.
Models emit configured checkpoints and metadata. Diagnostics and case studies select, score, and compare them.
Use interval checkpoints for short neural runs and explicit checkpoints for long phased runs. Keep prediction-time defaults explicit.
Latent-Factor Pipeline Diagram¶
flowchart LR
A[PersistentPanelBatch or CrossSectionBatch] --> B[Structural Estimator]
B --> C[LatentFactorState]
C --> D[Factor Forecaster]
D --> E[FactorForecastResult]
C --> F[Asset Mapper]
E --> F
F --> G[AssetForecastResult]
G --> H[PredictionsFrame]
H --> I[Backtest / Diagnostic]
Stochastic Discount Factor Flow¶
flowchart LR
A[CrossSectionBatch] --> B[Unconditional SDF Phase]
B --> C[Moment Network Phase]
C --> D[Conditional SDF Phase]
D --> E[StochasticDiscountFactorState]
E --> F[WeightsFrame]
E --> G[Optional Return Projection]
Portfolio Flow¶
flowchart LR
A[PortfolioSequenceBatch] --> B[Portfolio Model]
B --> C[PortfolioWeightsResult]
C --> D[Postprocessor]
D --> E[WeightsFrame]
E --> F[ml4t-backtest]
Package Layout¶
ml4t.models
├── api.py
├── types.py
├── pipelines.py
├── configs/
├── latent_factors/
├── forecasters/
├── mappers/
├── stochastic_discount_factor/
├── asset_prediction/
├── portfolio/
└── integration/
Boundary Rules¶
Belongs Here¶
- model estimation
- batch and result contracts
- checkpoint handling
- results-frame emission
Belongs Elsewhere¶
- feature engineering:
ml4t-engineer - execution and order simulation:
ml4t-backtest - validation and diagnostics:
ml4t-diagnostic