PortfolioOptimizerBase<T>

Base Classes · AiDotNet.Finance.Base

Base class for portfolio optimization models.

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

Implements: IPortfolioOptimizer<T>

Known derived types: BlackLittermanNeural<T>, DeepPortfolioManager<T>, GraphAttentionPortfolio<T>, HierarchicalRiskParity<T>, SignatureInformedTransformer<T>

For Beginners

This is the foundation for models that manage investment portfolios. It provides the basic tools needed to decide how much money to put into different assets (stocks, bonds, etc.) to achieve the best balance of risk and return.

How It Works

This abstract base class implements the IPortfolioOptimizer interface and provides common functionality for neural portfolio optimization. It handles asset tracking, metric calculation, and integration with the financial model hierarchy.

Properties

Property Summary
IMeanVarianceOptimizer<T> AnalyticOptimizer { get; set; } Closed-form analytic mean-variance optimizer available as a training-free baseline / warm start alongside the learned weights.
int NumAssets { get; } Gets the number of assets in the portfolio universe.

Methods

Method Summary
Dictionary<string, T> GetFinancialMetrics() Gets overall financial metrics for the model.
Dictionary<string, T> GetPortfolioMetrics() Gets metrics for portfolio optimizer evaluation.
ModelInputShapeConstraint GetInputShapeConstraint() Declares the market-data panel geometry a portfolio optimizer accepts.
T CalculateExpectedReturn(Tensor<T> weights, Tensor<T> expectedReturns) Calculates the expected return of the portfolio.
T CalculateSharpeRatio(Tensor<T> weights, Tensor<T> expectedReturns, Tensor<T> covariance, T riskFreeRate) Calculates the Sharpe Ratio of the portfolio.
T CalculateVolatility(Tensor<T> weights, Tensor<T> covariance) Calculates the volatility (standard deviation) of the portfolio.
Tensor<T> ComputeRiskContribution(Tensor<T> weights, Tensor<T> covariance) Computes the risk contribution of each asset to the total portfolio risk.
Tensor<T> OptimizeWeights(Tensor<T> expectedReturns, Tensor<T> covariance) Calculates optimal weights given expected returns and covariance (Traditional optimization).
Vector<T> OptimizePortfolio(Tensor<T> marketData) Optimizes the portfolio to determine the best asset allocation.