Market Behavior

From Correlation Matrices to Stock Networks

Do stocks really diversify each other? An accessible, data-driven look at how 203 companies moved together, what network diagrams reveal, and where those diagrams can mislead.


Owning twenty stocks does not necessarily mean holding twenty independent bets. If most of those stocks tend to rise and fall on the same days, a portfolio that looks diversified may still depend on a few shared forces.

Consider two portfolios: one holds several banks; the other mixes banks with companies from other industries. Both may contain the same number of stocks, yet their exposure to the same market shocks could be quite different. To understand why, we need to look beyond the companies’ names and ask which stock prices actually tend to move together.

A useful starting point is correlation: a number that summarizes how closely two stocks’ daily percentage changes move together. We can calculate it for any pair of stocks. But once we have hundreds of companies, there are thousands of pairs, and a large table of numbers becomes hard to interpret.

That is where a network can help. Imagine a map in which every stock is a dot (a vertex) and a line (an edge) connects two stocks whose movements are relatively similar. We can look for groups, important connecting points, and links between different parts of the map. The idea comes from the mathematics of networks, which is also used to study things like friendships, transport routes and communication systems. Applied to relationships between people it is called social network analysis, and much of its vocabulary carries over to stocks.

There is a catch: the map depends on the rules used to draw it. Keep only a few connections and one picture emerges; allow more connections and it may look quite different. Even small changes in the estimated relationships can alter which lines appear. A line represents a statistical association, not a channel through which one company influences another.

I explored these questions using historical daily prices for 203 US large-cap stocks, from 2003 through 2024. The aim is not to find a magic stock-picking signal. It is to understand what these maps genuinely reveal, which features are artifacts of the method, and how much confidence we should place in the results.

Why turn stock movements into a map?

A correlation table tells us about one pair at a time: did these two stocks tend to move together? A network lets us step back and look at the relationships across many stocks at once.

For example, we can ask which stocks have many close neighbors, whether distinct groups form, and which links are needed to connect otherwise separate groups. These are useful descriptive questions, but they are not predictions or explanations of cause and effect.

The article builds the idea in stages: first the correlations themselves, then several ways of turning them into a network, and finally tests of how much of each network is dependable. The mathematical details are there for readers who want them; the main conclusions do not require prior knowledge of graph theory.

The data, and what it cannot tell us

Source. Daily closing prices from Yahoo Finance, split- and dividend-adjusted, 2 January 2003 to 30 December 2024 (5,536 trading days). The files do not record whether the export was adjusted, so I checked the convention by comparing against Interactive Brokers raw closes for a sample stock (consistent with dividend and split adjustment; a spot check, not a vendor audit). Returns are simple daily returns; no gaps were filled.

Universe. I started from the S&P 500 membership history (a public GitHub dataset of historical constituents) and took the 458 stocks in the index on 6 January 2003. A stock enters the analysis panel only if it was a continuous index member through 2024 and has a complete, plausible price history. That leaves 203 stocks.

Throughout, a window means the most recent 252 trading days (about one year) of returns, and the “headline” window ends on 30 December 2024. Each figure and table is generated by code and CSV files in the repository (see the reproducibility section at the end).

First, measure how stocks move together

Before we draw any lines, we need to measure how stock movements are related. A daily return is simply the percentage change in a stock’s value from one trading day to the next. Pearson correlation compares two such sequences: +1 indicates that their fluctuations follow the same pattern, 0 indicates no linear relationship, and −1 indicates opposite patterns. A high correlation does not mean the stocks have the same price or earn the same return.

With 203 stocks there are 203 × 202 / 2 = 20,503 distinct pairs. Figure 1 shows those relationships as a color-coded grid, known as a correlation matrix. Each small square represents one pair; companies are grouped by industry so broader patterns are easier to spot.

Figure 1. The correlation matrix behind everything that follows: Pearson correlation of daily returns for 203 stocks over the 252 trading days ending 30 December 2024, grouped by sector (thin lines mark sector boundaries; hover for stock pairs). Blue is positive, orange negative. Source: Yahoo Finance adjusted daily closes, survivor panel; sector labels are GICS sectors as of December 2024.

The pattern is already visible: blocks of higher correlation along the diagonal (Financials, Utilities, Energy), a market-wide positive tint everywhere, and a distinct set of orange cells where semiconductor stocks moved against consumer staples and utilities during 2024. The average pairwise correlation in this window is 0.197, which is low compared with the stress windows shown later (the equal-weighted market’s annualized volatility over the window is about 10.7%).

A matrix with 20,503 numbers is too much to read, and many of those numbers are small differences that are mostly noise from a 252-day sample. This is why people filter it into a graph.

From a table of relationships to a network

To draw a map, we need to decide which stocks should appear close to each other. Correlation measures similarity, but network algorithms often work with distance: a smaller number means two stocks behaved more alike. One standard way to turn correlation into a distance, introduced in financial networks by Mantegna (1999), is

dij=2 (1−ρij)d_{ij}=\sqrt{2\,(1-\rho_{ij})}

where ρij\rho_{ij} is the correlation of stocks ii and jj⁠. Perfectly correlated stocks are at distance 0, uncorrelated stocks at 2≈1.41\sqrt{2}\approx 1.41⁠, and perfectly opposite stocks at 2. This is not an arbitrary choice: if you standardize each return series, dijd_{ij} is exactly the ordinary geometric (Euclidean) distance between the two series, divided by T\sqrt{T} for TT days.

The formula is useful if you want to reproduce the calculation; the essential idea is simply that more similar daily movements give a shorter distance. But even with every distance calculated, we still have to decide which of the 20,503 possible connections to draw. Here are three different ways to simplify the same set of relationships.

  1. Minimum spanning tree (MST): connect everyone with as few lines as possible. Find the set of connections with the smallest total distance that still allows a path between every pair of stocks. This produces a tree: a connected diagram with no loops. For 203 stocks it has exactly 202 lines. It is a common starting point in financial-network research (Mantegna, 1999).
  2. Planar maximally filtered graph (PMFG): keep more connections, but limit the complexity. Add the strongest pairs one by one, provided the growing diagram can still be drawn on a flat surface without edges crossing. This keeps up to $3(N-2)=603$ lines for 203 stocks, including the MST’s lines, while allowing loops and triangles (Tumminello and co-authors, 2005). This is a greedy construction, not a globally optimal planar subgraph.
  3. Fixed-density graph: just keep the strongest 603 pairs. This uses exactly the same number of lines as the PMFG, but imposes no rule that the whole map must stay connected or planar.
Figure 2. The same 203 stocks and the same 252-day window drawn three ways. Node color is sector and node size grows with the number of links; on the interactive version use the buttons to switch graphs and hover for tickers. The fixed-density graph (right panel) is shown with its largest piece on top and its 80 smaller pieces on a grid below. Layouts are drawing aids only: positions carry no meaning beyond who is linked to whom. Source: Yahoo Finance adjusted daily closes, survivor panel, window ending 30 December 2024.
Property (headline window)MSTPMFGFixed density
Edges202603603
Triangles (three mutually linked stocks)06012,314
Connected pieces1181
Share of stocks in the largest piece100%100%46%
Highest number of links on one stock112626
Same-sector share of edges71%59%90%
Expected same-sector share if sectors were shuffled11%11%11%

What is imposed by construction, and what is a finding? Read the table with that question in mind.

  • The MST has no triangles and one path between any two stocks. That is a theorem about trees, not a market fact. In a tree, every edge is a bridge: removing it disconnects the network. Any measure built on loops or clustering is zero or meaningless on an MST.
  • The fixed-density graph shatters into 81 pieces. That is not a failure of the method, it is information: the strongest 603 correlations sit among stocks of a few sectors, so most stocks have none of their links in that top group. Fixed-density graphs can be disconnected; MST and PMFG are connected by design.
  • Same-sector shares differ across filters partly by design. The MST forces connections to the isolated stocks, so it must use some cross-sector edges. The fixed-density graph includes only the strongest pairs, which are mostly within sectors, hence 90%. The PMFG sits between. “The network is highly sectoral” is therefore only meaningful relative to the filter, and relative to the 11% baseline.

The point of showing three filters is that they are three views of one matrix, each answering a different question. None is “the” network.

Try it: every year, every filter

The explorer below draws the same 203 stocks for any year from 2004 to 2024 (each year is the 252 trading days ending at its last trading day). Switch between the minimum spanning tree, the PMFG and a correlation threshold, and follow the four measures beside the map: how many edges are kept, how many separate pieces the network falls into, what share of edges join two stocks of the same sector (next to the share expected if sectors were shuffled), and which stock carries the most edges. With the threshold, lowering the slider joins the pieces; the button sets it to keep about as many edges as the PMFG (a few more when correlations tie after rounding), which is the fixed-density graph of the table above. Colouring by community shows the groups that a modularity algorithm finds in that year’s tree or PMFG, which need not follow sectors. Tap a stock to see its strongest correlations. Sector labels are those in force in each year (before 2012 the earliest available list, from December 2012), so a few stocks change colour between years. The map positions are computed once for each year and change gradually, so a stock stays roughly in place as the years go by. The same tool is available on its own page.

What the tree shows (and what it does not)

Sectors. 71% of the MST’s 202 edges join two stocks of the same sector. When I shuffled sector labels 1,000 times, no shuffle matched that share (the 11% baseline is the average over shuffles). This test is conditional on the sector labels (GICS as of December 2024): it shows that these labels line up with the tree far better than chance, not that the classification is the only meaningful grouping. Sector membership also gives the tree a high assortativity (the tendency of stocks to link to similar stocks): 0.67 on a scale where 1 is perfect same-with-same linking.

Hubs. A hub is a stock with many links (a high degree). In the MST for the headline window, the highest-degree stocks are PPL (a utility, 11 links), CAT (industrials, 10) and PH (industrials, 7). But the stocks with the highest average correlation to everything else are different: USB, ITW, PNC, L and FITB (average correlation 0.305 to 0.323). A tree hub is a stock that happens to be the nearest neighbor of many others, which is a local statement. It is not the same as being the stock most tied to the market as a whole. In this tree, 99 of the 203 stocks are leaves with one link.

Bridges. In a tree, a stock on the path between two clusters has a high betweenness (the share of shortest paths passing through it). In this window PH, CAT, PPG, EMN and ITW score highest. This says these stocks lie between groups in the tree. I would not read it as a statement that they transmit anything to other stocks; correlation says only that returns moved together, and the direction and cause are not recoverable from this data.

Communities. A community is a group of stocks with relatively many links within the group. Running a standard community-detection algorithm (greedy modularity maximization) on the MST finds 13 groups, but their agreement with the sector labels is modest: adjusted Rand index 0.26 (0 means no better than random, 1 means identical). Fixed-density communities agree more (0.48), partly because that filter keeps only the sector-heavy edges (and leaves 80 small pieces). Sectors are real, but they are not a clean partition: financials include insurers and banks that behave differently, “information technology” mixes semiconductor and software stocks, and so on.

Does the choice of correlation measure matter?

Pearson correlation has a known weakness: a few extreme days can dominate it. Two popular alternatives use only the ranking of returns. Spearman correlation compares the ranks of the returns. Kendall correlation asks how often two stocks’ returns move in the same direction on pairs of days, and I convert it to the same scale with ρ=sin⁡(πτ/2)\rho=\sin(\pi\tau/2) (valid for elliptical distributions, and an approximation otherwise). As a fourth variant, I removed the common market factor (the equal-weighted average return of all 203 stocks) from every stock before computing Pearson correlation, so only the stock-specific co-movement remains. These are four different quantities, not four estimates of one thing, but they are used interchangeably in practice, so it is useful to see how much they differ on identical data.

Figure 3. Four correlation measures on identical data (headline window). Top: how closely the pairwise values agree. Bottom: how many minimum spanning tree edges the resulting networks share. The matrices look alike; the trees much less so. Jaccard counts shared edges against all distinct edges of the two trees, so 0.42 corresponds to about 59% of each 202-edge tree. Source: Yahoo Finance adjusted daily closes, survivor panel of 203 stocks.

On the 20,503 pairs, the four measures agree well: the Pearson-Spearman pairwise correlation is 0.93, and Spearman and Kendall are almost identical (0.9996). Removing the market factor changes the matrix more (0.73 to 0.80 against the others). But the networks are much less stable than the matrices. Pearson and Spearman trees have about 120 of their 202 edges in common. That is 59% of each tree’s edges, but only 0.42 on the Jaccard index (edges in both, divided by edges in either) that the figures and tables use, because the denominator counts each differing edge from both trees. Spearman and Kendall trees share about 190 edges (94% of each tree, Jaccard 0.89). The no-market version shares about 149 edges with Pearson (74%, Jaccard 0.58). The fixed-density graphs agree much better (Jaccard 0.75 for Pearson versus Spearman, about 86% of their 603 edges) because the strongest correlations are strong under any measure.

All four measures share one more limitation: a correlation of zero does not mean that two returns are unrelated. A textbook case is a variable XX that is symmetric around zero, for example a standard normal one, and Y=X2Y = X^2⁠: YY is completely determined by XX⁠, yet their correlation is exactly zero, because YY rises both when XX is very negative and when it is very positive. Stock returns can depend on each other in ways of this kind, for example by falling together in crashes more than they rise together in rallies, which an average linear measure can miss. Nothing in this article measures that kind of dependence; it is a limitation of every network built from a correlation matrix, including the ones here.

The lesson is that a tree amplifies small differences. Two matrices whose pairwise values are 93% correlated can produce trees that differ in about two of every five edges, because the MST depends on the ordering of nearby distances, which noise reshuffles.

What changes when markets get stressed?

I recomputed the MST every 21 trading days from 2004 to 2024 (252 monthly windows, each using the previous 252 days of returns).

Figure 4. Rolling 252-day windows, recomputed every 21 trading days, 2004–2024. Top: average pairwise correlation. Middle: share of MST edges joining same-sector stocks (sector labels as of December 2024 for every window; with dated labels the series moves by at most 5.4 points). Bottom: edge overlap (Jaccard index) of each month's MST with the previous month's tree. Consecutive windows overlap heavily, so these series are smooth by construction. Source: Yahoo Finance adjusted daily closes, survivor panel of 203 stocks.
Window endingMarket volatility (annualized)Average correlationFirst component shareTop MST degreeMST same-sector share
29 Jun 2007 (low volatility)10.6%0.2628%965%
31 Dec 2008 (financial crisis)42.1%0.5556%1174%
29 Dec 2017 (low volatility)6.8%0.1417%1177%
30 Jun 2020 (COVID)37.3%0.5960%965%
30 Dec 2022 (rates)20.9%0.4244%1973%
30 Dec 2024 (latest)10.7%0.2022%1171%

(Market volatility is that of the equal-weighted average of the 203 stocks over each 252-day window, and the labels in brackets are mine, chosen from it. The “first component share” is the share of variance on the first principal component, the single dominant direction of joint movement; when it explains a large share of variance, the stocks are moving mostly as one block.) Average correlation ranges from 0.14 to 0.60 across these windows and tracks annualized market volatility closely (a correlation of 0.80 between the two monthly series; overlapping windows, so this is descriptive and not a formal test). Two things stand out.

First, when the whole market moves together, the tree’s same-sector share does not behave simply. It was lowest (57%) in a window ending in November 2007, before the 2008 crisis peaked, and highest (80%) in a window ending in February 2019. In the 2008 and 2020 stress windows it is 74% and 65%. So “everything correlates in a crisis, therefore sectors vanish” is too simple. These shares, and the same-sector column of the table, use the end-2024 sector labels for every window. Recomputing them with the label each stock had at each window’s end date (dated lists exist from December 2012, so the 144 windows from 2013 on are truly dated) changes the same-sector share by at most 5.4 percentage points and by 0.7 points on average in those windows. The lowest window stays at 57% (November 2007) and the highest becomes 79% instead of 80% (February 2019); in the table, 2008 and 2024 are unchanged and 2017, 2020 and 2022 rise by 0.5 to 1 point.

Second, the stability of the tree does not follow the correlation level. The median month-to-month edge overlap is 0.61 (but consecutive windows share 92% of their days, so this is mostly shared data, a trap discussed below), and across the 252 windows the correlation between average correlation and consecutive-window overlap is 0.07, essentially zero. High-correlation regimes do not make the tree visibly more or less persistent.

Two different questions: resampling stability and persistence over time

“Is the network stable?” can mean two quite different things, and mixing them up is one of the easiest ways to overstate what a network shows.

  1. Resampling stability (also called algorithmic stability). Hold the data fixed and ask: if the same year had unfolded with its days arranged a little differently, would the same procedure pick the same edges? This measures sampling noise in this particular sample. It says nothing about whether next year’s network will look the same, and it does not say that an edge is “true”.
  2. Temporal persistence (out-of-sample stability). Build the network from one window and compare it with the network from a different window that shares no days with it. This measures how much of the structure survives the passage of time. It mixes two sources of difference: sampling noise in both windows, and genuine change in the market.

The first can be measured with a bootstrap, which re-draws the data. The second needs a chronological comparison, and the comparison is only informative if the two windows do not share data. I measured both.

Resampling stability: how much of the tree is noise?

A correlation estimated from 252 days has sampling error. A tree built from it inherits that error, magnified by the winner-takes-all nature of the MST.

Method. Keep the 252 daily return vectors, but resample them together (the same days for all 203 stocks, so cross-stock dependence is preserved) in blocks of 21 consecutive days (a moving-block bootstrap, which keeps short-range time dependence; see Politis and Romano 1994 for a close relative). Rebuild the correlation matrix and the graph. Repeat 300 times. For each edge of the original graph, record the share of resamples in which it reappears (its inclusion frequency; the idea comes from Tumminello and co-authors, 2007).

Figure 5. How often each edge of the headline graph reappears when the same year of returns is resampled 300 times in 21-day blocks (all stocks resampled together). Top: MST. Bottom: fixed-density graph. Colors split same-sector and cross-sector edges. Source: Yahoo Finance adjusted daily closes, survivor panel; bootstrap code and seeds in the repository.

How to read this: an inclusion frequency measures algorithmic stability, not the probability that an edge is “true”. A stable edge is one this particular method recovers from many re-draws of this particular year.

  • MST. Median inclusion 0.56. Only 18% of edges appear in at least 90% of resamples, and 14% appear in fewer than a quarter. Within-sector edges are more stable (median 0.66) than cross-sector edges (0.32). Stability correlates with edge length (−0.59 between distance and inclusion): the shortest, strongest edges are the most reliable.
  • Fixed density. Median inclusion 0.93; 54% of edges are in at least 90% of resamples, none are below a quarter. Its selected edges reappear more often under this resampling procedure. But this filter keeps three times as many lines as the MST, favors the very strongest pairs, and leaves many stocks disconnected. The higher inclusion rate is not, by itself, proof that this is a more accurate picture of the market.
  • Communities. The agreement between the original communities and those from resampled data (adjusted Rand index) has median 0.39 for the MST (middle 80% between 0.32 and 0.49) and 0.62 for the fixed-density graph (0.50 to 0.72), computed on the first 100 of the 300 resamples.

I did not bootstrap the PMFG: the greedy planarity check costs about 100 seconds per graph on this panel, and an underpowered bootstrap would be misleading.

Watching the trees change. The lab below plays the 300 resampled trees of the headline year, or of 2008, one after another on one map. Blue lines are edges of the original tree that the resample kept, dashed red lines are original edges it lost, and orange lines are edges that appear only in that resample. The second view replaces the animation with a summary: line thickness grows with how often each original edge survives, and the cards compare edges inside one sector with edges between sectors. The 2008 tree is not more stable than the 2024 tree: its edges survive in 53% of the resamples on average, against 57% in 2024. The same tool is available on its own page.

Temporal persistence: does a different year look the same?

Compare the MST of the headline window (252 days ending 30 December 2024) with MSTs built from windows shifted back in time by k trading days. A shift of one day shares 251 of 252 days with the original; a shift of 252 days shares none.

Shifted back byDays sharedEnd 2008End 2017End 2024
1 day99.6%0.941.000.95
21 days91.7%0.660.650.68
63 days75%0.290.390.42
126 days50%0.200.320.31
252 days (no shared days)0%0.130.170.22
Two bootstrap resamples of one windowdrawn from the same window0.270.320.31
One bootstrap resample vs the originaldrawn from the same window0.360.430.39

All entries are edge-overlap (Jaccard) values between two MSTs: 1 means identical edge sets, 0 means no shared edge. Three points follow.

  • Overlap inflates persistence. A tree that shares 251 of its 252 days with its neighbor of course looks stable (0.95, and exactly 1.00 for the window ending in 2017). That number says nothing about next year. The usual monthly rolling-window plots (Figure 4, bottom) are in this regime.
  • The honest comparison is the no-overlap row. Against the immediately preceding year, the trees have a Jaccard overlap of 0.13 to 0.22, which means that about 23% to 36% of each tree’s 202 edges also appear in the other tree. Across all 2004–2024 windows the median Jaccard overlap at gaps of 12, 24 and 60 months is 0.18, 0.16 and 0.15 (Figure 6): the overlap settles at a floor rather than falling to zero, which I read as a persistent sector skeleton underneath a changing fine structure.
  • A same-window bootstrap reference, with limits. For context, two resamples drawn (with replacement, in 21-day blocks) from the same 252-day window have a Jaccard overlap of 0.27 to 0.32 (about 43% to 49% of each tree’s edges). The year-to-year Jaccard values (0.13 to 0.22) are lower, which is consistent with the market’s structure changing between years. But this comparison alone cannot tell genuine change from ordinary sampling variation: the bootstrap pair comes from one estimated window, which is not a calibrated null for two independently observed years, and each end date gives a single comparison. Establishing change would need a separately calibrated stationary-null simulation, which I did not run, so I do not claim a statistically established change of regime.
Figure 6. How long minimum spanning tree edges last: median edge overlap (Jaccard index: shared edges divided by all distinct edges of the two trees) between two 252-day windows separated by 1 to 60 months, with the 10th to 90th percentile band. Blue markers: windows share days; orange markers: no shared days. Dashed line: for reference, the median overlap between two bootstrap resamples of the single window ending 30 December 2024 (same-window bootstrap overlap; it is not a statistical null for two separate years, and it does not depend on the gap). Source: Yahoo Finance adjusted daily closes, survivor panel of 203 stocks, 2004–2024.

One more caution: the shifted windows end at different dates, so they differ in market regime as well as in overlap. The table shows why adjacent-window persistence is mechanically inflated; it does not isolate a pure effect of sample reuse.

What not to conclude. High resampling stability within a year does not mean that the tree will persist, and low persistence across years does not mean that the tree is “wrong” in any year. They answer different questions.

Window length and recoverability

How long a window do you need? On the same 203 stocks and the same end date, I compared the MST built from 126, 252 and 504 days.

Figure 7. Top (real data): edge overlap (Jaccard index) of MSTs built from different window lengths ending on the same date. Bottom (SYNTHETIC mechanism experiment, not market data): how well planted correlation blocks (ten of 19 stocks, one of 13) are recovered from an MST-based community search as the number of days grows; within- and between-block correlations are set to the real matrices' averages for three windows; mean over 20 simulated panels per point. Top source: Yahoo Finance adjusted daily closes, survivor panel. Bottom: simulation code in the repository.

In the top panel of Figure 7 (real data), a half-year and a one-year window have an MST edge overlap (Jaccard) of only 0.34 for the window ending 2024, 0.41 for 2017 and 0.55 for 2008; one year and two years give 0.45, 0.32 and 0.55. Longer is not a fix by itself: a longer window averages over different market regimes and so can build a different tree for a different reason.

The bottom panel is a synthetic mechanism experiment (a small Monte Carlo simulation), not a market result. I generate artificial returns from a Gaussian (normally distributed) model in which the 203 stocks belong to 11 blocks (ten of 19 stocks and one of 13), with one correlation inside blocks and another between them, set to the real matrices’ within-sector and between-sector averages for three windows. With a known answer, I can ask how many days are needed to recover the planted blocks from an MST-based community search. At 252 days the adjusted Rand index is about 0.84 to 0.87, at 126 days 0.62 to 0.81, and at 63 days 0.29 to 0.59; beyond 1,000 days it plateaus near 0.9. In this idealized setting about a year of data is enough to recover clean blocks, and at 252 days 95% of tree edges join stocks of the same block (the maximum possible with 11 blocks, since a tree must contain at least 10 edges between blocks). The real tree at 252 days has 71% same-sector edges and an adjusted Rand index against the sector labels of only 0.26. The gap is consistent with financial dependencies being less clean than the planted Gaussian blocks, but does not identify why: heterogeneity, changes over time, imperfect sector labels and the synthetic assumptions could all contribute. Treat the synthetic curve as how clean the world would have to be for a year of data to suffice, not as a power calculation for the real market.

A narrower question: how does a handful of stocks connect?

So far the questions were about the whole network. A different, smaller question is: given a few specific stocks, what is the cheapest way to connect them? In graph language this is a Steiner tree problem. The chosen stocks are the terminals. A Steiner tree is the cheapest tree that links all terminals, and it may route through other stocks, called intermediate nodes, if that shortens the total. “Cheapest” here means the smallest sum of correlation distances dij=2(1−ρij)d_{ij}=\sqrt{2(1-\rho_{ij})} along the tree’s edges. The cost is in distance units, with no dollar or return meaning.

I fixed the terminals before running anything: one widely known large company from each of eight sectors that are well represented in the panel: AAPL (information technology), JPM (financials), XOM (energy), JNJ (health care), PG (consumer staples), CAT (industrials), HD (consumer discretionary) and SO (utilities). I compare three trees on the same 252-day window, plus a reference:

  1. MST subtree. The smallest part of the minimum spanning tree that contains all eight terminals. Because a tree has exactly one path between any two nodes, this is the exact Steiner tree within the MST.
  2. Steiner tree on the PMFG. The exact cheapest tree using only PMFG edges.
  3. Steiner tree on the full graph. The exact cheapest tree allowed to use any pair of stocks as an edge.
  4. Terminals only. The minimum spanning tree of the eight terminals alone, with no intermediates allowed.

The exact solutions come from the Dreyfus–Wagner dynamic program (Dreyfus and Wagner, 1971), which searches over any number of intermediate stocks. This matters: a common shortcut, the shortest-path approximation, can miss a useful intermediate on a complete distance graph, because every direct edge is already a shortest path. The repository’s tests check the exact solver against brute-force enumeration on small graphs and on a toy correlation matrix (three terminals correlated 0.4 with each other and 0.75 with one extra stock) where the extra stock really does shorten the tree, so the method can detect an intermediate when one helps.

Figure 8. Four ways to connect the same eight terminal stocks (diamonds: AAPL, JPM, XOM, JNJ, PG, CAT, HD, SO) in the headline window. Circles are intermediate stocks; colors are sectors; total correlation distance is shown for each tree (use the buttons in the interactive version). The tree restricted to the MST needs 26 intermediate stocks, the PMFG tree 9, and the tree on the full distance graph none. Layout is a drawing aid only, and the static image labels the terminals only (hover in the interactive version for all names). Source: Yahoo Finance adjusted daily closes, survivor panel; exact Steiner trees by the Dreyfus–Wagner algorithm.
Window endingTreeTotal distanceEdgesIntermediate stocks
30 Dec 2024MST subtree26.583326
Steiner on PMFG14.10169
Steiner on full graph7.9470
Terminals only7.9470
29 Dec 2017MST subtree26.802922
Steiner on PMFG17.451811
Steiner on full graph8.6970
31 Dec 2008MST subtree12.412013
Steiner on PMFG9.21147
Steiner on full graph5.4170

What is imposed by construction. The MST is contained in the PMFG, which is contained in the full graph, so the cheapest tree can only get cheaper as more edges are allowed: full graph at most PMFG at most MST subtree. The ordering of the costs is therefore guaranteed, not discovered. What is informative is the size of the gaps and the number of intermediates.

What the data show. On the full graph, the best tree never used an intermediate stock: it was always the minimum spanning tree of the eight terminals themselves. That held in all three windows, in each of the 600 random terminal sets described below, in all eight leave-one-out sets, and in all 200 bootstrap resamples. This is a result for this panel and these windows, not a general law. A plausible reason, which I did not test further, is that all stocks are roughly equally far from each other (a typical distance is about 1.26 when average correlation is 0.20), so no real stock sits close enough to several terminals at once to act as a hub. The detours through 9 or 26 intermediate stocks in the PMFG and the MST are therefore best read as routing constraints from sparsification: the sparser the graph, the longer the way around. They are not evidence of a chain of influence between AAPL and JPM, and I do not read them that way.

Sensitivity to the choice of terminals (headline window; code and tables in the repository).

  • 300 random sets of 8 stocks: the PMFG tree costs a median 0.56 of the MST subtree (10th to 90th percentile 0.51 to 0.61), and the full-graph tree 0.27 (0.23 to 0.32). Intermediates: MST subtree median 28 (range 13 to 43), PMFG median 11 (range 5 to 17), full graph 0 in every set.
  • 300 sets with one random stock from each of the eight named sectors: the same picture (MST subtree median 32 intermediates, PMFG 13, full graph 0).
  • Dropping each of my eight terminals in turn: MST subtree 22 to 27 intermediates, PMFG 7 to 10, full graph 0.

Sensitivity to sampling noise. Re-drawing the year 200 times in 21-day blocks, the MST-subtree edges overlap only 0.28 (median Jaccard) with the original, and its total distance ranges from 22.7 to 30.2 (10th to 90th percentile; original 26.6). But some intermediates recur: LOW appears in 98% of resamples, PH in 94%, MSFT in 91%, DVN in 90% and PPL in 87%. So the identity of the routing stocks is partly stable even though the exact edge set is not. The full-graph tree (the eight terminals’ own MST) overlaps the original by 0.75, with total distance 7.7 to 8.0.

What this experiment supports is narrow: a Steiner tree is another summary of one estimated distance matrix, and how many intermediates it needs depends mostly on how sparse a graph you allow. It supports no claim about contagion, causality, hedging or investment performance.

Choosing other terminals. The explorer from the network section also has a second mode for this question: choose two to eight stocks and the edges the tree may use, and it computes the exact Steiner tree in the browser with the same Dreyfus–Wagner method. Below it starts with the eight terminals in the headline year; switch to “PMFG links only” or “Tree links only (MST)” to see the intermediates appear, or change the year. The tool works from correlations rounded to three decimals, which reproduces the costs in the table to within 0.01; in the 2017 full-graph tree one of two nearly tied edges differs from the published tree.

Does a network help build a portfolio? A narrow, risk-only check

The idea that diversification can be read from a network is the most tempting use of these graphs, and the one most easily oversold. The honest test is a walk-forward one: at each month-end use only the previous 252 days to set the weights, then hold them going forward. I compared four rules on the survivor panel, from January 2005 to December 2024 (239 monthly rebalances, 5,012 trading days):

  • Equal weight: 1/203 in every stock, the benchmark any fancier rule has to beat (DeMiguel, Garlappi and Uppal, 2009).
  • Shrinkage minimum variance: the long-only portfolio with the smallest estimated variance, using a Ledoit and Wolf style shrunk covariance matrix.
  • Hierarchical risk parity (HRP): a clustering-based rule from López de Prado (2016) that needs no matrix inversion.
  • MST inverse degree: the network rule: weight proportional to 1 divided by a stock’s number of links in the MST, so peripheral stocks receive more.

Three timing and accounting rules guard against the common errors. Weights are computed at the month-end close but traded at the next close, and the day in between is earned by the old weights (an earlier version that traded at the same close it observed was optimistic and is not implementable). Every trading day is accounted for, so skipped rebalances do not drop returns. Costs are charged on the traded amount, here 10 basis points (0.10%) per unit traded.

RuleVolatilityWorst fallVol. vs equal weight (95% range)Names heldEffective namesTurnover per year
Equal weight19.7%−53.4%(benchmark)20320331%
Shrinkage minimum variance13.2%−35.9%−6.6 pts (−7.7 to −5.6)11416226%
HRP16.3%−46.0%−3.4 pts (−4.0 to −2.9)203136154%
MST inverse degree19.5%−53.1%−0.3 pts (−0.3 to −0.2)20317096%

Here volatility means the annualized size of day-to-day return fluctuations; worst fall (the drawdown) is the largest historical decline from a portfolio peak to a subsequent low. The table is for 10 basis points of cost and next-close trading. Ranges in parentheses are 95% bootstrap intervals for the difference in annualized volatility (2,000 resamples of 21-day blocks of the daily return series; they quantify sampling variation in this one history, not model risk). The effective number of names is 1 divided by the sum of squared weights: 203 for equal weight, and much smaller when a rule concentrates. In the 2008–2009 crisis the annualized volatilities were 37.1% (equal weight), 21.6% (minimum variance), 28.9% (HRP) and 36.6% (MST inverse degree). The sign and approximate size of the three volatility differences did not change when the bootstrap used blocks of 5 to 126 trading days instead of 21 (an independent re-implementation, 600 resamples per block length): the 95% range for the network rule’s difference stayed between about −0.36 and −0.23 points for every block length.

What this does and does not show.

  • On risk, the network rule produces only a small reduction relative to equal weight (about 0.29 percentage points lower annualized volatility, with a similar drawdown), while the two covariance-based rules cut volatility substantially. The paired bootstrap interval excludes zero in this fixed history, but that does not make the small reduction economically substantial. In this panel, the matrix-based tools did the diversification work and the graph representation did not.
  • The risk reduction of minimum variance is bought with concentration (about 16 effective names) and heavy trading (226% one-way turnover per year); at 25 basis points its drawdown deepens further (−36.5% versus −35.5% at zero cost under next-close trading).
  • I deliberately report no returns or Sharpe ratios. The panel contains only stocks that survived 22 years in the index, which flatters returns for every rule, and I have no delisting returns. Risk is less distorted by that selection than return, but it is not immune either: the survivors had no stock that went to zero.
  • Same-close trading, the idealized convention, changes volatilities by under 0.1 percentage point but makes the drawdowns look somewhat better (for example −34.2% against −35.5% for minimum variance at zero cost), which is the kind of optimism the next-close rule removes.
  • This is one universe, one lookback (252 days), one rebalance frequency and four rules. It is not a claim that network-based portfolios cannot work (see Pozzi and co-authors, 2013, and Peralta and Zareei, 2016, for positive results, and Millington, 2022, for filtering that did not help in a classification task), only that on this evidence the network rule adds little risk reduction over simply equal weighting.

A descriptive check of a basket. Behind every network diversification rule sits a simpler question: do the stocks in a basket really move separately? The checker below takes any basket of the 203 stocks and a year, and reports how many communities of that year’s PMFG or MST the basket spans, how many sectors, the average correlation between its stocks, and the effective number of independent bets, N/(1+(N−1)ρˉ)N/(1+(N-1)\bar\rho)⁠: the number of unrelated stocks that would give an equal-weight basket of the same NN stocks the same volatility (ρˉ\bar\rho is the average correlation between pairs). A section to open adds a version that uses the whole correlation matrix, the participation ratio of its eigenvalues. The article’s eight terminals, one from each of eight sectors, were worth about 3.9 unrelated stocks in 2024 but only 1.6 in 2008, when correlations rose across the market; eight technology stocks were worth 2.3 in 2024. This describes past co-movement only. It is not a recommendation, and the survivor panel makes every basket look steadier than one chosen at the time. The same tool is available on its own page.

What I would and would not conclude

Supported by the data here:

  • In this survivor panel, the networks show substantial clustering under GICS sector labels as of December 2024. The 2024 MST has 71% same-sector edges versus approximately 11% under the stated label-permutation procedure; this is conditional on those labels, and the rolling same-sector shares of earlier years use the same end-2024 labels (dated labels change them by at most 5.4 points).
  • Which edges appear in a minimum spanning tree depends heavily on the correlation measure, the window and sampling noise. The tree’s coarse features (sector clustering) are far more reliable than its fine structure (who links to whom).
  • Network properties such as no triangles, a single path between any two stocks, or fragmentation into many pieces are properties of the filter, and should not be reported as market findings.
  • Average correlation and tree stability are different things: across the rolling windows they were essentially uncorrelated.
  • Resampling stability and temporal persistence answer different questions; persistence measured on overlapping windows is mechanically inflated.
  • On this panel, the number of intermediate stocks in the Steiner trees was driven mostly by how sparse the graph was.
  • On risk, the two covariance-based rules reduced volatility much more than the network rule did, in this one survivor panel and setup.

Not supported, and I would not claim:

  • That a central or high-degree stock “drives” or “transmits risk to” others. Correlation is symmetric and contemporaneous; it carries no direction.
  • That the network outperforms or beats simpler methods for building portfolios, unless it is evaluated on data without survivorship and with realistic costs.
  • That any of this describes the whole market, since the panel contains only stocks that stayed in the index.
  • That a Steiner path or a bootstrap-stable edge is a channel of contagion, a hedge, or a trading signal.

Limitations to keep in mind. The panel is a survivor panel (203 of 458). Sector labels are the GICS sectors at the end of 2024, verified against a dated constituents list; dated lists exist only from December 2012, so windows before 2013 cannot be checked with the labels of their own time. Yahoo Finance adjusted prices are a convenient, not an institutional-grade, source (no delisted names, vendor adjustments not independently audited beyond the sample checks described). The bootstrap resamples within one window and so quantifies sampling noise, not model risk or regime change. The synthetic experiment is a mechanism check, not a market result. The membership history file’s redistribution licence is unverified, so the raw price panel is not committed to the repository. The Steiner experiment uses one predetermined set of eight terminals plus random sets, in one 252-day window per date, and was not repeated on other universes. The PMFG was not bootstrapped, and community stability used only the first 100 resamples.

Reproducibility

The code, data documentation and result tables are public in the companion repository dvirross/stock-correlation-networks. The analysis is a small Python package with its own tests: the stocknet code (data checks, correlation measures, the three filters, bootstrap, Steiner solver, portfolio rules and walk-forward accounting), scripts that run each part, a notebook that runs the whole analysis from the saved price panel to the figures, and the result tables (CSV and JSON) that every number in the text is read from. The 49 unit tests use small hand-made inputs with known answers, not market data; they include a brute-force check of the exact Steiner solver and a check that the walk-forward accounting trades at the next close. The portfolio check also records the optimizer status of every minimum-variance rebalance.

Two independent checks were run on the saved results rather than on the prices. One recomputed every number of the portfolio table from the saved daily return series. The other is the block-length sensitivity mentioned under the table; it also tests the claims in the text against the result files. Neither re-estimates the networks from prices, and the notebook has not yet been re-run end to end by a second person.

The raw Yahoo Finance files and the membership file are not redistributed (the membership file’s licence is unverified). The repository’s data documentation lists the excluded tickers with the reason for each exclusion and the steps to rebuild the panel from the raw files.

Further reading

Sources I checked against the publisher or author record; one annotation each on what it supports. Access to some full texts was limited to abstracts and author manuscripts, so I cite each only for what that record supports.

The maps themselves

  • Rosario N. Mantegna (1999), “Hierarchical structure in financial markets,” The European Physical Journal B 11, 193–197 (DOI 10.1007/s100510050929). The distance transformation and the minimum spanning tree for stock returns.
  • Jukka-Pekka Onnela, Anirban Chakraborti, Kimmo Kaski, János Kertész and Antti Kanto (2003), “Dynamics of market correlations: Taxonomy and portfolio analysis,” Physical Review E 68, 056110 (DOI 10.1103/PhysRevE.68.056110). How the tree changes with market conditions.
  • Michele Tumminello, Tomaso Aste, Tiziana Di Matteo and Rosario N. Mantegna (2005), “A tool for filtering information in complex systems,” PNAS 102, 10421–10426 (DOI 10.1073/pnas.0500298102). The planar maximally filtered graph; planarity is itself an imposed property, and the greedy construction is not a globally optimal planar subgraph.
  • Naoki Masuda, Michiko Sakaki, Takahiro Ezaki and Takamitsu Watanabe (2018), “Clustering coefficients for correlation networks,” Frontiers in Neuroinformatics 12, 7 (DOI 10.3389/fninf.2018.00007). Why correlation networks contain many triangles for purely mathematical reasons (the correlations are not independent of one another). The application is neuroscience, not stocks.
  • Mel MacMahon and Diego Garlaschelli (2015), “Community detection for correlation matrices,” Physical Review X 5, 021006 (DOI 10.1103/PhysRevX.5.021006). Community detection needs a baseline that respects the structure of correlation matrices.
  • Nicolò Musmeci, Vincenzo Nicosia, Tomaso Aste, Tiziana Di Matteo and Vito Latora (2017), “The multiplex dependency structure of financial markets,” Complexity, article 9586064 (DOI 10.1155/2017/9586064). Different dependence measures connect different pairs of stocks.

Can we trust the map?

  • Laurent Laloux, Pierre Cizeau, Jean-Philippe Bouchaud and Marc Potters (1999), “Noise dressing of financial correlation matrices,” Physical Review Letters 83, 1467–1470 (DOI 10.1103/PhysRevLett.83.1467). Much of a sample correlation matrix looks like noise when stocks are many and days are few.
  • Michele Tumminello, Claudia Coronnello, Fabrizio Lillo, Salvatore Miccichè and Rosario N. Mantegna (2007), “Spanning trees and bootstrap reliability estimation in correlation-based networks,” International Journal of Bifurcation and Chaos 17(7), 2319–2329 (DOI 10.1142/S0218127407018415). Bootstrap reliability of tree links. Inclusion frequency measures stability of a procedure, not the probability that a link is real.
  • Dimitris N. Politis and Joseph P. Romano (1994), “The stationary bootstrap,” Journal of the American Statistical Association 89, 1303–1313 (DOI 10.1080/01621459.1994.10476870). Resampling blocks of days to respect time dependence; the fixed-length moving blocks used here are a close relative.
  • V. A. Kalyagin, A. P. Koldanov and P. A. Koldanov (2022), “Reliability of maximum spanning tree identification in correlation-based market networks,” Physica A 599, 127482 (DOI 10.1016/j.physa.2022.127482). Under stated models, different correlation estimators target the same population tree but identify it with different sampling error.

Portfolios, and why I stop short of claiming them

  • Olivier Ledoit and Michael Wolf (2004), “Honey, I shrunk the sample covariance matrix,” The Journal of Portfolio Management 30(4), 110–119 (DOI 10.3905/jpm.2004.110). Shrinkage as a serious alternative to changing the graph. (The estimator used here shrinks toward a scaled identity with an analytic intensity.)
  • Marcos López de Prado (2016), “Building diversified portfolios that outperform out of sample,” The Journal of Portfolio Management 42(4), 59–69 (DOI 10.3905/jpm.2016.42.4.059). Hierarchical risk parity; its favorable results come from the paper’s own simulation setting.
  • Victor DeMiguel, Lorenzo Garlappi and Raman Uppal (2009), “Optimal versus naive diversification: How inefficient is the 1/N portfolio strategy?” The Review of Financial Studies 22(5), 1915–1953 (DOI 10.1093/rfs/hhm075). Why equal weighting is a hard benchmark.
  • Francesco Pozzi, Tiziana Di Matteo and Tomaso Aste (2013), “Spread of risk across financial markets: better to invest in the peripheries,” Scientific Reports 3, 1665 (DOI 10.1038/srep01665). Reports better diversification from peripheral stocks, but stocks are eligible only if they have prices in the year after investment, a look-ahead that this article’s survivor panel shares in spirit.
  • Gustavo Peralta and Abalfazl Zareei (2016), “A network approach to portfolio selection,” Journal of Empirical Finance 38, 157–180 (DOI 10.1016/j.jempfin.2016.06.003). Network centrality as a portfolio-selection rule.
  • Tristan Millington and Mahesan Niranjan (2020), “Partial correlation financial networks,” Applied Network Science 5, 11 (DOI 10.1007/s41109-020-0251-z). Conditioning on other stocks changes the picture but in that study made the networks less stable, not more reliable.
  • Tristan Millington (2022), “An investigation into the effects and effectiveness of correlation network filtration methods with financial returns,” PLoS ONE 17(10), e0273830 (DOI 10.1371/journal.pone.0273830). In a classification experiment across markets, filtering simplified graphs but did not improve accuracy over the full correlation network.

Steiner trees

  • Stuart E. Dreyfus and Robert A. Wagner (1971), “The Steiner problem in graphs,” Networks 1(3), 195–207 (DOI 10.1002/net.3230010302). The exact dynamic-programming algorithm used here for the minimum connecting tree of a small terminal set.

Data

  • Historical S&P 500 constituents: hanshof/sp500_constituents on GitHub, used to build the January 2003 membership list (redistribution licence unverified).
  • GICS sectors: datasets/s-and-p-500-companies on GitHub, a dated history of the S&P 500 constituents table on Wikipedia, used to verify the sector labels against the list of 27 December 2024 and to find the reclassifications since 2012.

Provenance

This article expands a series of LinkedIn posts: