Minimum Spanning Trees in R

Earlier we posted a correlation heatmap of the S&P 500. An alternative way to visualize the clustered structure of the financial markets is to use Minimum Spanning Trees (MST). The figure below is a MST for components of the S&P 500. Oftentimes this presents a much clearer picture of the clusters (click to enlarge and explore, image is 5k x 5k pixels):

Minimum Spanning Trees provide a simple way to visualize clusters

Minimum Spanning Trees provide a simple way to visualize clusters

Like correlation heatmaps, MSTs can be generated from a correlation matrix. The basic algorithm for constructing a MST is:

  • Sort all pair-wise correlations in the matrix by magnitude
  • Start with the pair that has the highest magnitude correlation, this is your first link
  • Select the next highest magnitude correlation if and only if that doesn’t create a loop in the graph
  • Repeat until every instrument has a vertex on the graph

We can create MST’s easily using the igraph package in R (its also available in python as well).

The above graph was created with the minimum.spanning.tree(…) function in igraph.

Want to explore Minimum Spanning Trees for yourself? Then visit our SliceMatrix signup page. Explore Minimum Spanning Trees and Filtered Correlation Networks for the S&P 400, S&P 500, S&P 600 and NASDAQ 100 indexes.

Network Graph from SliceMatrix

Network Graph from SliceMatrix

7 replies »

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s