Quant Memo
Core

Graph Theory Basics

Representing anything connected to anything else — traders to counterparties, stocks to sectors, orders to fills — as nodes and edges, the shared vocabulary behind network risk, clustering, and shortest-path routing.

Prerequisites: Counting: Permutations and Combinations

A prime broker wants to know: if Counterparty A defaults, which other counterparties are exposed through shared collateral chains, and how many steps away is the contagion? Answering this needs a way to represent "who is connected to whom" that's separate from any specific numbers — just the pattern of connections. Graph theory is exactly that vocabulary: a small set of definitions for talking about things (nodes) and the connections between them (edges), general enough to describe counterparty networks, correlation structures between assets, or the flow of orders through an exchange.

An analogy: a subway map

A subway map is a graph in disguise: stations are nodes, and the tracks connecting adjacent stations are edges. You don't need to know the physical distance or travel time to reason about basic structure — which stations are reachable from which, how many transfers a trip requires, whether the network has a single connected system or several isolated islands. Graph theory strips a network down to exactly this bare connectivity structure, then builds precise tools on top of it.

The vocabulary, one piece at a time

A graph G=(V,E)G = (V, E) consists of a set of vertices (or nodes) VV — the things being connected — and a set of edges EE, each edge a pair of vertices that are linked. If edges have a direction (A owes B, not necessarily the reverse), the graph is directed; otherwise it's undirected. The degree of a vertex is the number of edges touching it — how many direct connections it has. A path is a sequence of edges connecting one vertex to another through intermediate vertices, and the shortest path between two vertices is the path using the fewest edges (or, if edges carry weights like cost or distance, the path with the smallest total weight). A graph is connected if every vertex can reach every other vertex via some path; if not, it splits into separate connected components — isolated islands with no path between them.

A graph can be stored as an adjacency matrix AA, an n×nn \times n grid where Aij=1A_{ij} = 1 if an edge connects vertex ii and vertex jj, and 00 otherwise (for a weighted graph, AijA_{ij} holds the edge's weight instead of just 00/11). In plain English: row ii of the matrix is a complete list of who vertex ii is directly connected to, turning a picture of a network into a table of numbers that algorithms and linear algebra can operate on directly.

Worked example 1: counting components and paths by hand

Five trading desks (A, B, C, D, E) share collateral agreements: A–B, B–C, D–E. As a graph, vertices are the desks and edges are shared agreements. Degree of B is 2 (connected to A and C); degree of D is 1. There are two connected components: {A,B,C}\{A, B, C\} and {D,E}\{D, E\} — a shock hitting D can propagate to E but never reach A, B, or C, because there's no path between the two islands. The shortest path from A to C is A–B–C, length 2 (two edges), even though there's no direct A–C edge.

Worked example 2: the adjacency matrix by hand

For the same five desks in order A, B, C, D, E, the adjacency matrix is:

A=(0100010100010000000100010).A = \begin{pmatrix} 0&1&0&0&0 \\ 1&0&1&0&0 \\ 0&1&0&0&0 \\ 0&0&0&0&1 \\ 0&0&0&1&0 \end{pmatrix} .

Row A has a 1 only in column B, matching "A connects only to B." The block-diagonal structure — zeros everywhere connecting the {A,B,C}\{A,B,C\} block to the {D,E}\{D,E\} block — is a direct visual signature of the two disconnected components.

adjacency matrix, rows/cols A B C D E A,B,C block D,E block off-block entries are all zero
Spotting a block-diagonal pattern like this in a much larger real counterparty matrix is exactly how an analyst identifies that risk cannot propagate between two clusters of firms.
A B C D E no path connects the two clusters
Two connected components with no edges between them: a shock reaching any node in the left cluster can spread only within that cluster, never to D or E.

What this means in practice

Graph theory underlies counterparty and systemic risk mapping (who is exposed to whom, and how far a default propagates), correlation network analysis for spotting clusters of co-moving assets, order-routing and market-microstructure questions phrased as shortest-path or flow problems, and any "who's connected to whom" question that shows up in coding interviews as breadth-first search or connected-components problems. The core payoff is that once a relationship is represented as a graph, a large toolkit of well-understood algorithms — shortest path, connectivity, clustering — becomes directly applicable.

A graph reduces any network of relationships to just two ingredients — vertices (the things) and edges (the connections between them) — and this stripped-down representation is enough to answer connectivity, distance, and clustering questions using standard, well-studied algorithms rather than ad hoc reasoning about the specific domain.

The classic mistake is conflating "connected" (there exists some path between two vertices, however long) with "directly connected" (an edge exists between them). A counterparty two hops away through a shared collateral chain is still exposed to contagion even with zero direct trades between them — treating "no direct edge" as "no risk" misses exactly the indirect exposure graph analysis exists to surface. Always ask whether a question is about an edge or about a path.

Related concepts

Practice in interviews

Further reading

  • West, Introduction to Graph Theory, ch. 1
  • Newman, Networks: An Introduction, ch. 6
ShareTwitterLinkedIn