AlphaFactorModel<T>
Models & Types · AiDotNet.Finance.Trading.Factors
Neural network model for learning alpha factors from market data.
Inheritance: NeuralNetworkBase<T> → FinancialModelBase<T> → AlphaFactorModel<T>
Implements: IFactorModel<T>
For Beginners
Think of this model as a factor “discoverer.” Instead of manually choosing factors like value or momentum, the model learns hidden drivers of returns from historical data and then uses them to predict performance.
How It Works
AlphaFactorModel learns latent factors that explain and predict excess returns. It discovers these factors directly from data instead of relying on hand-crafted signals.
Reference: Chen et al. (2020). “Deep Learning for Alpha Generation”
Example
// Define architecture for alpha factor discovery (50 stocks, 10 features each, 5 latent factors)
var architecture = new NeuralNetworkArchitecture<double>(
inputType: InputType.OneDimensional,
taskType: NeuralNetworkTaskType.Regression,
inputHeight: 60, inputWidth: 10, inputDepth: 1, outputSize: 5);
// Training mode: learns latent return-predictive factors from market data
var model = new AlphaFactorModel<double>(architecture);
// ONNX inference mode: load pre-trained alpha factor model
var onnxModel = new AlphaFactorModel<double>(architecture, "alpha_factors.onnx");
Constructors
| Constructor | Summary |
|---|---|
AlphaFactorModel(NeuralNetworkArchitecture<T> architecture, AlphaFactorOptions<T> options, IGradientBasedOptimizer<T, Tensor<T>, Tensor<T>> optimizer, ILossFunction<T> lossFunction) |
Initializes a new AlphaFactorModel in native mode for training and inference. |
AlphaFactorModel(NeuralNetworkArchitecture<T> architecture, string onnxModelPath, AlphaFactorOptions<T> options, IGradientBasedOptimizer<T, Tensor<T>, Tensor<T>> optimizer, ILossFunction<T> lossFunction) |
Initializes a new AlphaFactorModel in ONNX mode for inference. |
Properties
| Property | Summary |
|---|---|
bool SupportsTraining { get; } |
Gets whether training is supported in the current mode. |
bool UseNativeMode { get; } |
Gets whether the model is using native layers (true) or ONNX inference (false). |
int NumAssets { get; } |
Gets the number of assets covered by the model. |
int NumFactors { get; } |
Gets the number of latent factors learned by the model. |
int NumFeatures { get; } |
Gets the number of input features per asset. |
int PredictionHorizon { get; } |
Gets the prediction horizon. |
int SequenceLength { get; } |
Gets the input sequence length. |
Methods
| Method | Summary |
|---|---|
Dictionary<string, T> GetFactorMetrics() |
Gets factor model metrics. |
Dictionary<string, T> GetFinancialMetrics() |
Gets financial metrics for the model. |
ModelInputShapeConstraint GetInputShapeConstraint() |
Declares the cross-sectional geometry a factor model accepts. |
ModelMetadata<T> GetModelMetadata() |
Gets metadata describing this model instance. |
Tensor<T> ComputeAlpha(Tensor<T> returns, Tensor<T> factorReturns) |
Computes alpha (excess return) for each asset. |
Tensor<T> ExtractFactors(Tensor<T> returns) |
Extracts latent factors from asset returns. |
Tensor<T> GetFactorCovariance(Tensor<T> returns) |
Computes the factor covariance matrix. |
Tensor<T> GetFactorLoadings(Tensor<T> returns) |
Computes factor loadings for each asset. |
Tensor<T> PredictReturns(Tensor<T> factorExposures) |
Predicts expected returns from factor exposures. |