FinancialModelBase<T>

Base Classes · AiDotNet.Finance.Base

Base class for all financial AI models, providing dual ONNX/native mode support.

Inheritance: NeuralNetworkBase<T> → FinancialModelBase<T>

Implements: IFinancialModel<T>

Known derived types: AlphaFactorModel<T>, CrossSectionalGraphModelBase<T>, FactorVAE<T>, FinancialNLPModelBase<T>, ForecastingModelBase<T>, NeuralGARCH<T>, PortfolioOptimizerBase<T>, RealizedVolatilityTransformer<T>, RiskModelBase<T>

For Beginners

Think of this as a “foundation” class that all financial models build upon.

It provides common functionality that every financial model needs:

  • Making predictions (inference)
  • Training on data (learning)
  • Saving/loading models (persistence)
  • Computing gradients (for optimization)
  • Integration with the AiDotNet ecosystem

The dual-mode design means you can choose:

  • Native mode: More control, can train, uses more memory
  • ONNX mode: Faster inference, pretrained, read-only

How It Works

This abstract class provides the core infrastructure for financial models, following the BLIP-2/RealESRGAN dual-mode pattern from the broader AiDotNet library. It supports both:

Native Mode: Full training capabilities using pure C# neural network layers. Use the native constructor when you need to train models from scratch or fine-tune.

ONNX Mode: Fast inference using pretrained ONNX models. Use the ONNX constructor for production deployment with pretrained models.

Properties

Property Summary
T LastTrainingLoss { get; } Gets the last recorded training loss.
bool SupportsTraining { get; }
bool UseNativeMode { get; }
int NumFeatures { get; }
int PredictionHorizon { get; }
int SequenceLength { get; }

Methods

Method Summary
Dictionary<string, T> GetFinancialMetrics()
InputContractManifest GetInputContract(int[] inputShape) Generated public model-boundary contract.
LayerInputDomain GetInputDomain(int[] inputShape) Generated from the primary [TensorPort] declaration.
LayerInputDomain GetOutputDomain(int[] outputShape) Gets the value domain of this model’s public output.
ModelInputShapeConstraint GetInputShapeConstraint() Declares the [batch, sequence, features] geometry this model actually accepts.
ModelMetadata<T> GetModelMetadata()
Tensor<T> Forecast(Tensor<T> input, double[] quantiles)
Tensor<T> ForwardForTraining(Tensor<T> input) Tape-aware forward pass used by NeuralNetworkBase.TrainWithTape.
Tensor<T> Predict(Tensor<T> input)
void Train(Tensor<T> input, Tensor<T> expectedOutput)