Graph Community Detection
Once assets, funds, or counterparties are represented as a network, community detection finds the tightly-connected sub-groups inside it automatically — clusters of nodes that talk to each other far more than they talk to the rest of the graph.
Prerequisites: Graph Theory Basics, Graphs as Data: Adjacency and Node Features
A network of 10,000 hedge funds connected by shared holdings, or 2,000 companies connected by supply-chain links, has structure a single adjacency matrix doesn't show you directly: sub-groups of nodes that connect to each other far more densely than they connect to the rest of the graph. Community detection finds those sub-groups automatically, without being told in advance how many there are or what defines them — a fundamentally different problem from k-means, because there's no coordinate space here, only who is connected to whom.
A good community isn't just "nodes that are close together" — it's a group where the actual number of internal connections clearly exceeds what you'd expect from a same-sized random group in that graph. That comparison against a random baseline, called modularity, is what most community-detection algorithms are directly trying to maximize.
Modularity: comparing against a random baseline
Modularity scores a proposed partition of the graph into communities by comparing observed internal edges to expected internal edges under a random-graph baseline that preserves each node's total number of connections:
In words: for every pair of nodes , check whether an edge actually exists () and subtract off how likely an edge would be there just by chance, given how many connections each node has in total () out of the graph's total edge-endpoints — then only count that comparison if the pair is placed in the same community (). Sum it all up and you get a single score: positive and large when communities have far more internal edges than random chance would produce, near zero when the proposed grouping is no better than a random split.
Because checking every possible partition is computationally hopeless for large graphs, practical algorithms like Louvain and Leiden search greedily: start with every node as its own community, repeatedly merge whichever pair of communities increases modularity the most, and stop when no merge helps — an efficient, if not perfectly optimal, way to climb toward a high-modularity partition.
Worked example
Applying the Louvain algorithm to a graph of 1,200 public companies connected by shared institutional ownership (an edge if two companies share more than 5 major holders in common) finds 14 communities. One community of 60 stocks turns out, on inspection, to correspond almost exactly to companies held heavily by a specific set of large-cap growth funds; another corresponds to regional bank holdings concentrated among a handful of value-oriented funds. Neither grouping was told to the algorithm — sector labels and fund style labels were never inputs — they emerged purely from the pattern of shared ownership, and the resulting partition achieves a modularity of , well above the near-zero score a random same-sized partition would produce.
What this means in practice
Community detection on ownership, supply-chain, or lead-lag networks surfaces groupings that aren't visible from sector classifications alone — a useful cross-check for concentration risk (do my "diversified" holdings actually sit in the same ownership community?) and for building alternative groupings for factor models that go beyond GICS sectors.
Modularity maximization has a known resolution limit: on large graphs it can fail to detect small, genuinely dense communities because merging them into something bigger still scores well against the random baseline. If a suspiciously small or tightly-knit sub-group doesn't show up as its own community, don't assume it isn't there — try a resolution parameter or a different algorithm before concluding it's absent.
Related concepts
Practice in interviews
Further reading
- Newman, 'Modularity and Community Structure in Networks' (PNAS, 2006)
- Blondel et al., 'Fast Unfolding of Communities in Large Networks' (Louvain method, 2008)