FX Correlation Algorithms
Pearson correlation, ultrametric distance, MST, PMFG, and core-periphery detection on FX rate data
The FX correlation pipeline transforms raw exchange rate time series into a filtered network that reveals the hierarchical structure of the FX market. The pipeline runs in four stages: compute log-return correlations, convert to distances, build a spanning tree, and extend to the PMFG for richer topology. A core-periphery analysis then identifies systematically important currencies.
Implementation: packages/neo4j-network/src/services/fx-correlation.ts, packages/neo4j-network/src/services/graph-analysis.ts
Data source: ECB rates via frankfurter-api.ts (30 currencies, daily)
Paper references: C1-C5, C7
Pearson Correlation on Log-Returns
Overview
Raw FX rates are non-stationary. To measure co-movement, the pipeline first converts rates to log-returns:
r_i(t) = log(P_i(t) / P_i(t-1))Pearson correlation is then computed over a rolling window (typically 252 trading days):
rho_ij = cov(r_i, r_j) / (sigma_i * sigma_j)
= E[(r_i - mu_i)(r_j - mu_j)] / (sigma_i * sigma_j)The result is an N×N symmetric correlation matrix where rho_ij = 1 means the two currencies move in perfect lockstep, rho_ij = -1 means they move in opposite directions, and rho_ij = 0 means no linear relationship.
Properties
- Range: [-1, 1]
- Symmetric: rho_ij = rho_ji
- Time-varying: computed over rolling windows to capture regime changes
- Not a metric: does not satisfy triangle inequality (distance conversion required)
Status: PLANNED - computeFXDistanceMatrix() and FX correlation service are new. Data infrastructure (Frankfurter ECB rates) is already live. GraphQL query: fxCorrelationNetwork.
FX Ultrametric Distance
Overview
The Pearson correlation matrix cannot be used directly for MST construction because correlation is not a proper distance metric. The Mantegna-Stanley formula (Paper C2) converts correlation to a distance that satisfies the ultrametric inequality:
d_ij = sqrt(2 * (1 - rho_ij))Properties
- Range: [0, 2]
- d_ij = 0 when rho_ij = 1 (perfectly correlated)
- d_ij = sqrt(2) ≈ 1.414 when rho_ij = 0 (uncorrelated)
- d_ij = 2 when rho_ij = -1 (perfectly anti-correlated)
- Satisfies ultrametric inequality: d_ij ≤ max(d_ik, d_kj)
The ultrametric inequality is stronger than the triangle inequality and is what enables the MST to serve as a meaningful hierarchical representation.
Interpretation
In FX markets, low distance (high correlation) typically indicates:
- Same regional economy (e.g. EUR, CHF, DKK)
- Commodity-linked currencies moving together (e.g. AUD, CAD, NOK on oil prices)
- Safe-haven co-movement during crises (e.g. JPY, CHF, USD)
Minimum Spanning Tree
Overview
The Minimum Spanning Tree (MST) on the FX distance matrix is the maximal connected subgraph that uses the minimum total distance while connecting all N currencies with exactly N-1 edges. The MST is the backbone of the FX market's hierarchical structure.
Algorithm: Kruskal's Method
Sort all N*(N-1)/2 edges by d_ij ascending
Initialize: N singleton components (one per currency)
For each edge (i, j) in sorted order:
if i and j are in different components:
add edge (i, j) to MST
merge components (union-find)
if MST has N-1 edges: stop
Result: MST with N-1 edges, minimum total distanceComplexity: O(N^2 log N) for the sort; union-find is near-linear.
Interpretation
The MST reveals:
- Hub currencies: High-degree nodes are the most central (USD, EUR typically sit at the core)
- Currency clusters: Subtrees represent groups of co-moving currencies
- Market hierarchy: The tree structure encodes which currencies drive others
Implementation
// kruskalMST() in packages/neo4j-network/src/services/graph-analysis.ts
kruskalMST(
distanceMatrix: Map<string, Map<string, number>>
): { edges: MSTEdge[]; totalWeight: number }
// GraphQL:
query GetMinimumSpanningTree {
minimumSpanningTree {
edges { from to weight }
totalWeight
}
}Status: WIRED - kruskalMST() is implemented and exposed via minimumSpanningTree GraphQL query. Target UIs: /currencies/fiat-fx, /graph?mode=advanced.
PMFG
Overview
The MST uses only N-1 edges, discarding much of the correlation structure. The Planar Maximally Filtered Graph (PMFG), introduced by Tumminello et al. (2005), extends the MST by adding more edges while maintaining planarity.
A planar graph can be drawn on a sphere without edge crossings. By the Euler formula for planar graphs, a planar graph on N nodes has at most 3(N-2) edges. The PMFG uses all of these available edges.
Algorithm
Start with MST (N-1 edges)
Sort all remaining edges by d_ij ascending
For each edge (i, j) in sorted order:
Tentatively add edge (i, j) to graph
Test planarity (Boyer-Myrvold or similar O(N) algorithm)
if graph remains planar: keep the edge
else: remove the edge
if |edges| == 3*(N-2): stop
Result: PMFG with 3(N-2) edges, maximum filtered correlationPlanarity criterion: Kuratowski's theorem - a graph is planar iff it contains no subdivision of K5 or K3,3.
Why PMFG
The PMFG captures triangular and quadrangular relationships between currencies that the MST misses. These additional edges often correspond to:
- Cross-rate arbitrage triangles (EUR/USD, USD/JPY, EUR/JPY)
- Regional currency blocs with internal triangular structure
- Safe-haven clustering in stress regimes
Implementation
// buildPMFG() in packages/neo4j-network/src/services/graph-analysis.ts
// buildFXPMFG() in packages/neo4j-network/src/services/fx-correlation.ts
// GraphQL: fxPMFG queryStatus: WIRED - buildPMFG() implemented in graph-analysis.ts, buildFXPMFG() in fx-correlation.ts, exposed via fxPMFG GraphQL query.
Core-Periphery Detection
Overview
The Borgatti-Everett core-periphery model partitions currencies into two groups:
- Core: Densely connected currencies that trade heavily with each other and with the periphery
- Periphery: Sparsely connected currencies that connect mainly through the core
In FX markets, the core typically contains the major reserve currencies (USD, EUR, GBP, JPY, CHF) plus regional hubs.
Algorithm: Borgatti-Everett Approximation
The optimization objective is to find a binary partition (core/periphery) that maximizes:
R = sum_ij A_ij * delta(c_i, core) * delta(c_j, core)where A_ij is the correlation matrix entry and delta is 1 if the node is in the core.
The approximation used in production is the geometric mean of degree and betweenness centrality, which provides a fast proxy for the full optimization:
core_score(v) = sqrt(degree(v) * betweenness(v))Currencies above the score median are classified as core.
Interpretation
Core membership is a proxy for systematic importance in the FX market. A currency that loses its core position may indicate reduced market activity, regulatory changes, or a shift in global trade patterns.
Implementation
// detectCorePeriphery() in packages/neo4j-network/src/services/graph-analysis.ts
// detectFXCorePeriphery() in packages/neo4j-network/src/services/fx-correlation.ts
// GraphQL: fxCorePeriphery queryStatus: WIRED - detectCorePeriphery() is implemented. GraphQL query fxCorePeriphery is available. Target UIs: /currencies/fiat-fx, /network.
Algebraic Connectivity
Overview
The algebraic connectivity (Fiedler value) is the second-smallest eigenvalue of the graph Laplacian - denoted lambda_2. It measures how well-connected the entire network is.
Graph Laplacian: L = D - A
D = diagonal degree matrix
A = adjacency matrix
lambda_2 = min_{x perp 1, x != 0} (x^T L x) / (x^T x)A higher lambda_2 means:
- The network is harder to disconnect (more resilient)
- Information and shocks propagate faster across the network
- There is no obvious bottleneck currency that, if removed, fragments the graph
The corresponding eigenvector (Fiedler vector) provides an optimal 2-partitioning of the network.
Implementation
// getAlgebraicConnectivity() in packages/neo4j-network/src/services/graph-analysis.ts
getAlgebraicConnectivity(): number
// fiedlerVector() in packages/neo4j-network/src/services/graph-analysis.ts
fiedlerVector(): number[]Status: LIVE - Algebraic connectivity is computed and displayed on the dashboard via algebraicConnectivity GraphQL query.
Planned Extensions
Numeraire-Invariant Partial Correlations (Paper C9)
Standard Pearson correlations on FX returns are numeraire-dependent: the correlation between EUR/USD and GBP/USD changes depending on which currency is used as the base. Partial correlations remove this spurious dependency by conditioning on all other currencies:
rho_ij|rest = -P_ij / sqrt(P_ii * P_jj)
Where P = Sigma^{-1} (precision matrix, inverse of the covariance matrix)The partial correlation rho_ij|rest measures the direct linear relationship between currencies i and j after removing the effect of all other currencies. This reveals true bilateral relationships that are masked in the full correlation matrix. Planned as an extension to fx-correlation.ts.
TDA / Persistent Homology Clustering (Paper C10, arXiv:2510.19306)
Topological Data Analysis (TDA) uses persistent homology to identify topological features (connected components, loops, voids) in the FX correlation network that persist across multiple distance thresholds. Unlike MST or PMFG, which use a single filtration, TDA tracks how features are born and die as the distance threshold varies:
Filtration: d_threshold = 0 → 2
- At d=0: N isolated points
- As d increases: connected components merge (0-dim homology)
- Loops appear and disappear (1-dim homology)
- Features that persist across a wide range of d are topologically significantLong-lived 1-dimensional features (loops) in the FX persistence diagram correspond to currency triangles with stable cross-rate relationships. Planned as a new analysis in graph-analysis.ts.
Paper References
| Paper | Title | Relevance |
|---|---|---|
| C1 | PMFG Construction | Tumminello 2005 planar filtering |
| C2 | Mantegna-Stanley FX Distance | Ultrametric d_ij = sqrt(2(1-rho)) |
| C3 | DTW Distance | Time-lagged correlation (planned) |
| C4 | FX Correlation Networks | Empirical market structure |
| C5 | FX Dynamic Communities | Rolling-window community detection |
| C7 | FX Core-Periphery Structure | Borgatti-Everett model |
| C9 | Numeraire-Invariant Partial Correlations | Precision matrix partial correlations (planned) |
| C10 | TDA Persistent Homology (arXiv:2510.19306) | Topological clustering of FX networks (planned) |
| A1 | Spectral Graph Theory | Algebraic connectivity, Fiedler vector |