I am putting together some portfolios to be auto-traded using a dynamic portfolio asset allocation algo. I had put together a maximum spanning tree (shown in a previous posting) to observe relationships between securities.

In this iteration have gone further:

- Heatmap colors to indicate average volatility levels for a given security relative to others
- Maximum spanning tree clusters to reveal which diversification group a given asset belongs to
- Edge thickness indicates strength of relationship

I am interested in both the diversity and the volatility profile of the asset pool. I will pick the majority of assets from the set with mid-range volatility (oranges), as opposed to low vol (reds), and high vol (yellows). Classifying the asset set into clusters based on correlations provides an automated way of observing the diversification group the asset belongs to.

**Algorithm**

The algorithm is loosely as follows:

- calculate lower-triangular correlation matrix of returns for, say, s&p 500 stocks
- sort in descending order by correlation
- set up graph structure
- loop through correlations selecting pairs of assets
- if neither in graph add as new cluster pair
- if one in graph and other not, attach new to existing
- if both in graph but size of clusters < min cluster size, merge clusters

- repeat until all assets accounted for
**and** all clusters have size >= min cluster size
- annotate & plot

**Clusters (daily returns)**

Here are the clusters the algorithm produced:

Of course this can be applied to any asset set. Thought is a useful visualization, though there are many other dimensions of interest.

### Like this:

Like Loading...

*Related*

Pingback: Regime Discovery « Quantivity

Was this done in R?

Partially. I did the rendering in R, but implemented the algorithm in Java.

Pingback: Optimal number of clusters « Systematic Investor