NeuralCVaR<T>

Models & Types · AiDotNet.Finance.Risk

A neural network model for estimating Conditional Value at Risk (CVaR), also known as Expected Shortfall.

Inheritance: NeuralNetworkBase<T> → FinancialModelBase<T> → RiskModelBase<T> → NeuralCVaR<T>

For Beginners

CVaR (Conditional Value at Risk) answers the question: “If things get really bad (worse than VaR), how much will I lose on average?”

While VaR (Value at Risk) gives you a threshold (e.g., “I’m 95% sure I won’t lose more than $100”), CVaR tells you the average loss in that remaining 5% of worst-case scenarios (e.g., “$150”).

This model uses a neural network to predict this value based on market conditions. It’s often considered a better risk measure than VaR because it accounts for the magnitude of extreme losses (“fat tails”).

Example

// Define architecture for CVaR estimation (10 risk factors, single CVaR output)
var architecture = new NeuralNetworkArchitecture<double>(
    inputType: InputType.OneDimensional,
    taskType: NeuralNetworkTaskType.Regression,
    inputSize: 10, outputSize: 1);
            
// Training mode: neural network learns expected shortfall from market data
var model = new NeuralCVaR<double>(architecture);
            
// Parameterless constructor with default 10-feature, single-output architecture
var defaultModel = new NeuralCVaR<double>();

Constructors

Constructor Summary
NeuralCVaR() Initializes a new instance with default architecture settings.
NeuralCVaR(NeuralNetworkArchitecture<T> architecture, NeuralCVaROptions<T> options, IGradientBasedOptimizer<T, Tensor<T>, Tensor<T>> optimizer, ILossFunction<T> lossFunction) Initializes a new instance of the NeuralCVaR model.
NeuralCVaR(NeuralNetworkArchitecture<T> architecture, string onnxModelPath, NeuralCVaROptions<T> options, IGradientBasedOptimizer<T, Tensor<T>, Tensor<T>> optimizer, ILossFunction<T> lossFunction) Initializes a new instance of the NeuralCVaR model from a pretrained ONNX model.

Methods

Method Summary
T CalculateRisk(Tensor<T> input) Calculates the Conditional Value at Risk for the given input.
T CalculateVaR(Tensor<T> portfolioReturns, Tensor<T> weights) Calculates VaR as a byproduct of CVaR estimation (using Gaussian assumption or auxiliary output).
Tensor<T> AdjustForRisk(Tensor<T> action, T riskBudget) Adjusts a proposed action to satisfy CVaR constraints.