RealizedVolatilityTransformer<T>

Models & Types · AiDotNet.Finance.Volatility

Realized Volatility Transformer for attention-based volatility forecasting.

Inheritance: NeuralNetworkBase<T> → FinancialModelBase<T> → RealizedVolatilityTransformer<T>

Implements: IVolatilityModel<T>

For Beginners

Transformers learn which past time points matter most. This helps the model focus on recent shocks or patterns when predicting volatility.

How It Works

This model applies transformer attention to recent returns to forecast volatility.

Example

// Create a Realized Volatility Transformer for attention-based forecasting
var architecture = new NeuralNetworkArchitecture<double>(
    inputType: InputType.OneDimensional,
    taskType: NeuralNetworkTaskType.Regression,
    inputHeight: 90, inputWidth: 1, inputDepth: 1, outputSize: 5);
var model = new RealizedVolatilityTransformer<double>(architecture);
            
// Or load a pre-trained ONNX model for realized volatility prediction
var onnxModel = new RealizedVolatilityTransformer<double>(architecture, "realizedvol.onnx");

Constructors

Constructor Summary
RealizedVolatilityTransformer(NeuralNetworkArchitecture<T> architecture, RealizedVolatilityTransformerOptions<T> options, IGradientBasedOptimizer<T, Tensor<T>, Tensor<T>> optimizer, ILossFunction<T> lossFunction) Creates a RealizedVolatilityTransformer in native mode for training.
RealizedVolatilityTransformer(NeuralNetworkArchitecture<T> architecture, string onnxModelPath, RealizedVolatilityTransformerOptions<T> options, IGradientBasedOptimizer<T, Tensor<T>, Tensor<T>> optimizer, ILossFunction<T> lossFunction) Creates a RealizedVolatilityTransformer using a pretrained ONNX model.

Methods

Method Summary
Dictionary<string, T> GetFinancialMetrics() Gets overall financial metrics for the model.
Dictionary<string, T> GetVolatilityMetrics()
ModelMetadata<T> GetModelMetadata() Returns metadata describing the model.
Tensor<T> CalculateRealizedVolatility(Tensor<T> highFrequencyReturns) Calculates realized volatility from high-frequency returns.
Tensor<T> ComputeCorrelationMatrix(Tensor<T> returns) Computes the correlation matrix.
Tensor<T> ComputeCovarianceMatrix(Tensor<T> returns) Computes the covariance matrix.
Tensor<T> EstimateCurrentVolatility(Tensor<T> recentReturns) Estimates the current volatility from recent returns.
Tensor<T> ForecastVolatility(Tensor<T> historicalReturns, int horizon) Forecasts future volatility.