ƒxyzƒxyz Network
Algorithms

FX Correlation Algorithms

Pearson correlation, ultrametric distance, MST, PMFG, and core-periphery detection on FX rate data

FX Correlation and Topology

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/src/services/fx-correlation.ts, 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 distance

Complexity: 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

// graph-analysis.ts:637
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, /cartography.


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 correlation

Planarity 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

// graph-analysis.ts (buildPMFG) + fx-correlation.ts (buildFXPMFG)
// GraphQL: fxPMFG query

Status: 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

// graph-analysis.ts + fx-correlation.ts
// detectCorePeriphery() / detectFXCorePeriphery()
// GraphQL: fxCorePeriphery query

Status: 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

// graph-analysis.ts:747
getAlgebraicConnectivity(): number
fiedlerVector(): number[]  // graph-analysis.ts:335

Status: LIVE — Algebraic connectivity is computed and displayed on the dashboard via algebraicConnectivity GraphQL query.


Paper References

PaperTitleRelevance
C1PMFG ConstructionTumminello 2005 planar filtering
C2Mantegna-Stanley FX DistanceUltrametric d_ij = sqrt(2(1-rho))
C3DTW DistanceTime-lagged correlation (planned)
C4FX Correlation NetworksEmpirical market structure
C5FX Dynamic CommunitiesRolling-window community detection
C7FX Core-Periphery StructureBorgatti-Everett model
A1Spectral Graph TheoryAlgebraic connectivity, Fiedler vector