GraphAttentionPortfolio<T>

Models & Types · AiDotNet.Finance.Portfolio

A time-varying portfolio optimiser over a filtered asset graph, trained directly on the Sharpe ratio (Korangi, Mues and Bravo, arXiv:2407.15532).

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

For Beginners

It works out which companies genuinely move together, keeps only the most informative connections, learns over that network which companies to hold, and is trained to maximize return per unit of risk.

How It Works

The pipeline is: return-volatility series → distance correlation → TMFG planar filtering → graph attention → two feed-forward blocks → sum-normalising allocation layer, trained on -ln(mu_p) + ln(sigma_p). Like SIT it is decision-focused — it emits weights rather than return forecasts — but the two differ in every mechanism: this one uses a filtered graph and a Sharpe objective where SIT uses path signatures and CVaR.

The paper’s own framing of its contribution is that it keeps every firm, including those that later default or leave the mid-cap universe. Studies that drop such firms introduce selection bias, and distance correlation is what makes keeping them practical: it tolerates the short, irregular and partly missing histories those firms have.

Three components, each independently testable: Graph (volatility series, distance correlation, TMFG), Attention (masked graph attention with concatenated heads), and Objective (the Sharpe loss and the sum-normalising allocation layer that replaces a softmax).

Example

var returnPanel = Tensor<double>.CreateRandom(2, 4);
var model = new GraphAttentionPortfolio<double>(
    new GraphAttentionPortfolioOptions<double> { NumAssets = 30 });
Vector<double> weights = model.OptimizePortfolio(returnPanel);

Constructors

Constructor Summary
GraphAttentionPortfolio() Creates the model with the paper’s defaults.
GraphAttentionPortfolio(GraphAttentionPortfolioOptions<T> options, NeuralNetworkArchitecture<T> architecture, ILossFunction<T> lossFunction) Creates the model.

Properties

Property Summary
AssetGraphBuilder<T> Graph { get; } Gets the graph builder: volatility series, distance correlation and TMFG filtering.
GraphAttentionLayerCore<T> Attention { get; } Gets the masked graph-attention core.
SharpeRatioPortfolioObjective<T> Objective { get; } Gets the Sharpe objective and the sum-normalising allocation layer.

Methods

Method Summary
IReadOnlyList<GraphEdge<T>> BuildGraph(Tensor<T> returnPanel) Builds the filtered asset graph for a return panel.
T PortfolioLoss(Vector<T> weights, Tensor<T> assetReturns) The training loss -ln(mu_p) + ln(sigma_p) for an allocation over a return panel.
T RealizedSharpe(Vector<T> weights, Tensor<T> assetReturns) The Sharpe ratio realized by an allocation over a return panel.
Tensor<T> BuildAdjacency(Tensor<T> returnPanel) The graph adjacency (with self-loops) that the attention is masked by.
Vector<T> OptimizePortfolio(Tensor<T> marketData) Produces long-only, fully invested portfolio weights, sparse by construction.