AssetGraphBuilder<T>

Helpers & Utilities · AiDotNet.Finance.Portfolio

Builds the filtered asset graph for GraphAttentionPortfolio: distance correlation over return-volatility series, filtered by the Triangulated Maximally Filtered Graph (TMFG) method (Korangi, Mues and Bravo, arXiv:2407.15532).

For Beginners

This works out which companies genuinely move together, then throws away all but the most informative connections so the network is small enough to learn from.

How It Works

Two choices distinguish this from the usual correlation network, and both are load-bearing.

Distance correlation, not Pearson. Pearson captures only LINEAR pairwise dependence, and is zero for plenty of strongly dependent pairs. Distance correlation is zero if and only if the two series are independent, so it detects non-linear co-movement. It also tolerates short, irregular or partly missing history — which is what lets the paper keep every firm, including those that later default, instead of dropping them and introducing selection bias.

Volatility series, not returns. Correlations are computed between return-VOLATILITY series (rolling standard deviation of returns), following Diebold and Yilmaz’s connectedness work. Volatility series co-move sharply during risk-off periods and only weakly in benign conditions, which is the structure the graph is meant to expose.

TMFG, not a minimum spanning tree. TMFG keeps a near-maximal-weight PLANAR subgraph, reducing edges from |V|(|V|-1)/2 to at most 3(|V| - 2) while retaining far more information than an MST, which forbids cycles entirely. It is also parallelizable, unlike PMFG, which is what makes it usable at the paper’s ~5,000-firm scale.

Constructors

Constructor Summary
AssetGraphBuilder(int volatilityLookback) Creates a graph builder.

Properties

Property Summary
int VolatilityLookback { get; } Gets the volatility lookback in days.

Methods

Method Summary
IReadOnlyList<GraphEdge<T>> FilterTmfg(Tensor<T> dependencies) Filters a dense dependency matrix to a near-maximal-weight PLANAR subgraph using TMFG.
T DistanceCorrelation(Vector<T> first, Vector<T> second) Distance correlation between two series, in [0, 1].
Tensor<T> AdjacencyMask(IReadOnlyList<GraphEdge<T>> edges, int nodeCount) Builds a symmetric adjacency mask from an edge list, for use as the GAT’s neighbourhood.
Tensor<T> DistanceCorrelationMatrix(Tensor<T> panel) Dense distance-correlation matrix over a panel of series.
Tensor<T> VolatilitySeries(Tensor<T> returns) Converts a return panel into rolling return-volatility series.
int MaxPlanarEdges(int nodeCount) The maximum edge count of a maximal planar graph on nodeCount nodes: 3(n - 2).

Fields

Field Summary
int PaperVolatilityLookback The paper’s volatility lookback in trading days.