The Math Behind Smarter Diversification
The Three-Step HRP Algorithm, Explained in Order
Step One — Tree Clustering
Begin with the correlation matrix. The goal of this step is to detect which assets move together and which move independently — not by assuming a factor structure, but by letting the data reveal its own geometry. Hierarchical agglomerative clustering groups assets iteratively, merging the most similar pair at each step until a single tree is formed. The choice of linkage method — single, complete, or average — determines how similarity between clusters is measured as they grow. Our team works through each linkage variant and explains why the choice matters for the shape of the resulting tree and, downstream, for the weight distribution. The output of this step is a dendrogram: a tree that encodes the full correlation hierarchy of the asset universe, without discarding any structural information.
Step Two — Quasi-Diagonalization
With the dendrogram in hand, the next step reorders the rows and columns of the covariance matrix so that the most similar assets appear adjacent to one another. This is called quasi-diagonalization, and it produces a matrix whose block structure is visible to the eye — correlated clusters appear as dark squares along the diagonal, and dissimilar groups are pushed toward the corners. The reordering does not discard information or impose a factor model. It simply reorganizes what is already in the data into a form that makes the structure legible. This matters because the next step — recursive bisection — relies on this ordering to split the asset universe into groups that make economic sense, rather than arbitrary subsets. Our team shows the permutation procedure explicitly and connects it to the graph-theoretic concept of minimum spanning tree traversal.
Step Three — Recursive Bisection
The final step assigns portfolio weights. Starting from the full ordered asset list, the algorithm splits it into two halves — left cluster and right cluster — and allocates capital between them in inverse proportion to their respective variance. It then recurses into each half, splitting again and allocating again, until every individual asset has received a weight. At no point does this procedure require inverting the covariance matrix. That is the structural advantage over mean-variance optimization: the weights are determined by the relative variance of sub-clusters, not by the eigenvectors of a matrix that may be poorly conditioned. The result is a portfolio whose diversification follows the actual correlation structure of the data, rather than the artifacts of an unstable numerical solver. Our team traces the full bisection procedure with a worked numerical example so the logic of each allocation step is explicit.
HRP vs. Classical Allocation Approaches
| Key Feature | Cenisadteorvyosa | Mean-Variance Optimization | Equal Risk Contribution |
|---|---|---|---|
| No matrix inversion required | |||
| Stable under estimation error | |||
| Handles large asset universes naturally | |||
| Reflects true correlation hierarchy | |||
| Does not require expected return inputs | |||
| Produces intuitively diversified weights | |||
| Robust out-of-sample Sharpe profile |
Four Properties That Make HRP Structurally Sound
Our team chose to document HRP not because it is fashionable but because its structural properties hold up where classical methods quietly break down.
No Matrix Inversion at Any Step
Graph Theory Reads the Data's Own Structure
Rather than imposing a factor model, HRP uses hierarchical clustering to let the correlation matrix reveal its own groupings. The resulting tree reflects what is actually in the data, not what the analyst assumed in advance.
Scales Gracefully to Large Universes
Diversification Follows Economic Logic
Because weights are assigned along the branches of a correlation tree, assets that are genuinely similar receive allocations that reflect their shared risk. The resulting portfolio is diversified in a way that corresponds to the actual structure of the data, not to a mathematical artifact.
Stronger Out-of-Sample Behavior
Published research by López de Prado and subsequent peer review consistently shows that HRP produces better out-of-sample Sharpe profiles than classical optimizers across a range of asset universes and historical periods — a direct consequence of its lower sensitivity to input estimation error.
Clustering
4Hierarchical Agglomerative Clustering
A bottom-up clustering procedure that begins with each asset as its own cluster and iteratively merges the two most similar clusters until a single tree structure — the dendrogram — encompasses the entire asset universe. The similarity measure used at each merge step is determined by the chosen linkage method.
Linkage Method
Dendrogram
Minimum Spanning Tree
A graph-theoretic construct that connects all assets in a universe using the minimum total edge weight, where edge weights represent pairwise distances derived from correlations. The minimum spanning tree is closely related to the dendrogram and is used in the quasi-diagonalization step to determine the optimal reordering of the covariance matrix.
Matrix Methods
4Covariance Matrix
A square symmetric matrix in which each entry represents the covariance between two assets in a portfolio. The diagonal entries are the individual asset variances. The covariance matrix is central to all risk-based portfolio construction methods, but its reliable estimation requires a sufficiently long data history relative to the number of assets.
Quasi-Diagonalization
Estimation Error
Ill-Conditioned Matrix
A matrix whose condition number — the ratio of its largest to smallest eigenvalue — is very large, indicating that it is close to singular. Ill-conditioned covariance matrices produce numerically unstable results when inverted, which is a common failure mode of classical portfolio optimizers applied to large asset universes or short historical samples.
Recursive Bisection
The third and final step of the HRP algorithm, in which portfolio weights are assigned by repeatedly splitting the ordered asset list into two halves and allocating capital between them in inverse proportion to their cluster variance. The procedure recurses until every asset has received a weight, producing a fully allocated portfolio without any matrix inversion.
Inverse Variance Weighting
Risk Parity
Out-of-Sample Performance
Correlation Structure
Sharpe Ratio
Distance Metric
Common Questions
Does HRP require historical return data to function?
How sensitive is HRP to the choice of linkage method?
Can HRP be combined with factor models or return forecasts?
Yes, though the base HRP algorithm does not require return forecasts at all — it is a purely risk-based method. Extensions exist that incorporate factor-adjusted covariance matrices or tilt the weights toward assets with favorable analytical characteristics, but our materials treat the pure form first before introducing those modifications in Module Five.
Is HRP appropriate for retail investors to apply directly?
The mathematical construction of HRP is accessible to any analyst with a solid grounding in linear algebra and basic statistics. Whether the method is appropriate for a specific financial context depends on many factors outside the scope of this platform. Our materials explain the theory and mechanics, not whether the method suits any individual's circumstances.
How does HRP perform during sharp market downturns?
What Python libraries support HRP implementation?
Several open-source libraries implement HRP or provide the building blocks — SciPy for hierarchical clustering and dendrogram construction, NumPy for matrix operations, and Pandas for return series handling. Our companion notebooks in the curriculum demonstrate a complete implementation from raw return data through to final weights using these standard tools.