Basic Prerequisites: 01 · From Zero and Statistics & Inference.
1. Intuition & Practical Objective
The tree is the whole engine of HRP: get it wrong and every weight downstream is wrong. This page builds the tree carefully and shows why the linkage is a modelling choice with measurable consequences.
There are three decisions, and each has a first-principles answer:
- What is “distance”? Correlations are not distances - they are similarities on . The map turns them into a genuine Euclidean metric, so a clustering algorithm that assumes geometry is entitled to run.
- How do clusters measure distance to other clusters? With linkage. Single uses the closest pair (optimistic, chains), complete the farthest pair (conservative, isolates), average the size-weighted mean (the balanced default). These produce different trees.
- How do we order the assets so the covariance is visually and computationally “nearly block-diagonal”? Quasi-diagonalization: read the tree’s leaves in traversal order and permute accordingly. Similar assets become adjacent; the covariance matrix’s signal - its blocks - is exposed and the tiny off-block entries that poison the inverse are demoted to the margin.
The one-sentence essence. “Correlation becomes distance; distance becomes a hierarchy; the hierarchy becomes an ordering; the ordering becomes a covariance matrix whose structure is readable without inverting it.”
2. Mathematical Ground Truth & Derivations
2.1 The correlation distance and its Euclidean embedding
With ,
The triangle inequality holds because is (up to scale) a Euclidean norm. Let be each demeaned return column scaled to unit length. Then
So the “correlation distance” is exactly the distance between the assets’ unit direction vectors - the assets lie in , and the tree is a nearest-neighbour structure in that honest geometry. (Two identical assets sit at ; two uncorrelated ones at ; perfectly anti-correlated ones at .)
2.2 Agglomeration and the Lance–Williams recurrence
Agglomerative clustering repeatedly merges the two closest active clusters. The rule for the distance from a new merged cluster to any other cluster is the general Lance–Williams update
and the four constants define the linkage:
| linkage | cluster distance | character | |
|---|---|---|---|
| single | optimistic; chains through bridge assets | ||
| complete | conservative; isolates outliers, can merge distinct blocks | ||
| average (UPGMA) | size-weighted mean | balanced default; usually highest cophenetic correlation | |
| Ward | variance-minimizing | least-squares merge (see 06 · Advanced) |
The recorded merge heights form the dendrogram. The quality of the tree as a summary of the original distances is the cophenetic correlation: the Pearson correlation between the input distances and the cophenetic distances (the merge height at which two leaves first join). Higher is a better representation - ESL §14.3.12 uses it to choose the linkage.
2.3 Quasi-diagonalization
Given the merge tree, quasi-diagonalize by reading the leaves in order:
After the permutation, entries inside the diagonal blocks are large and entries across blocks are small (for a well-clustered universe). This is the “quasi-diagonal” matrix: not exactly diagonal, but banded into blocks. HRP then bisects the list (contiguous halves), so contiguous ordering ⟺ economically coherent splits.
3. Computational Implementation - the linkage decision in numbers
A chained universe where the linkage genuinely changes the answer: P1–P2 are highly correlated (), P2–P5 moderately so (), and P3–P4 form a clean pair (); everything across the gap is near-. Single linkage should chain P5 into the P1/P2 group; complete should refuse.
What to read:
- The merge heights tell the story. Single linkage merges P5 into the P1/P2 cluster at height - the distance - chaining P5 along the bridge. Complete linkage refuses: its next merge after the two pairs is at height , absorbing P1/P2 and P3/P4 into one block and leaving P5 alone (). Average sits between them.
- The root split flips. Single/average separate the clean pair from ; complete produces versus everything else. Two different trees ⟹ two different HRP weight vectors from the same covariance.
- Cophenetic correlation picks the winner. Average linkage scores , well above single () and complete (): its ultrametric best reproduces the actual distance matrix here. This is the standard, data-driven way to choose a linkage rather than assert one. (On the clean 8-asset block universe of §04 the cophenetic correlations are all , and all three linkages give identical HRP weights - linkage matters when correlations are graded, not when blocks are crisp.)
4. Failure Modes & First-Principles Breakdowns
- Single-linkage chaining. Because it uses the distance, a single bridge asset welds two unrelated clusters together, and every split above the bridge is distorted (here: P5 absorbed into ). Symptom: a long, unbalanced dendrogram. Remedy: average or Ward linkage, or prune by cophenetic correlation.
- Complete-linkage over-merging. Being conservative, complete linkage can fail to separate two genuinely distinct blocks (here: merged) and isolate a marginal asset. Symptom: a small cluster standing alone at a high height.
- The distance is only as good as . inherits every defect of the correlation estimate: short windows, non-stationarity, and noise. Two assets whose sample correlation is spurious noise will be placed close in the tree. Always pair the tree with a denoised/shrunk covariance (→ Covariance Shrinkage & RMT Denoising).
- Quasi-diagonalization is order-sensitive. Recursive bisection splits the ordered list in halves, so the position of an asset in the order matters. A tree that is only marginally better can reorder assets and change the weights; verify with out-of-sample tests, not by eyeballing the dendrogram.
- collapses all distances. In a crisis every pair moves together, every , and the tree carries no information - the clustering analogue of a covariance matrix losing rank. This is a regime risk, not a code bug.
5. References
- Hastie, Tibshirani & Friedman (2009). The Elements of Statistical Learning (2nd ed.)
- López de Prado, M. (2016). “Building Diversified Portfolios that Outperform Out of Sample.” J. Portfolio Management 42(4):59–69
- López de Prado, M. (2018). Advances in Financial Machine Learning
- Raffinot, T. (2017/18). “Hierarchical Clustering-Based Asset Allocation.” J. Portfolio Management 44(2):89–99
6. Connected Graph Bridges
- Back: 02 · Why Quadratic Optimizers Fail · Index Hub
- Continue: 04 · Recursive Bisection
- Related: Covariance Shrinkage & RMT Denoising (the input ) · 05 · Failure Modes · Machine Learning & Alt-Data (clustering machinery)