Free Tools & Code Worked Examples Home Markets News Equities Quantum Papers Microstructure About
HomeWorked examples › HRP Example: Compare Six Portfolio Allocators

HRP Example: Compare Six Portfolio Allocators

On this synthetic panel, HRP with single linkage has out-of-sample volatility of 0.1419, compared with 0.1489 for unconstrained minimum variance. Other baselines narrow that difference. The comparison is useful precisely because all six results are visible.

Reproduction record
Checked 4 September 2026. Seed: 20260808.
Source
hierarchical-risk-parity at revision 70ae45c.
Environment used
Python 3.11.9, NumPy 2.4.6, pandas 3.0.5, SciPy 1.17.1.
Data
Synthetic. These examples test the implementation and illustrate the method; they do not measure trading performance on real securities.

Set up the experiment

The panel contains 20 assets. The first 120 periods fit the weights; the next 400 evaluate them without refitting. The in-sample mean absolute correlation is 0.240 and the covariance condition number is about 43.

cd quantmedia-research/hierarchical-risk-parity python compare_mvo.py

Compare the output

Volatility is annualized in the example using 252 periods per year. Drift is 100 × (out-of-sample volatility / in-sample volatility − 1), calculated before the displayed volatility figures are rounded.

AllocatorVolatility inVolatility outDrift
HRP (single)0.14010.1419+1.3%
HRP (Ward)0.14190.1425+0.4%
Minimum variance0.13110.1489+13.6%
Minimum variance, clipped to long-only0.13250.1460+10.2%
Minimum variance, shrinkage 0.30.13300.1432+7.7%
Equal weight0.14740.1443−2.1%

The long-only baseline clips negative weights and renormalizes the result. It is a simple comparison, not a constrained optimization solver. The full comparison CSV also includes concentration, short exposure, drawdown and Sharpe. Out-of-sample Sharpe is negative for every allocator in this example.

Read the result carefully

Minimum variance has the lowest fitted volatility and the largest increase outside the fitted sample. Shrinkage reduces that increase. Equal weight has a small decrease; a negative drift is possible and is not an implementation error.

A small drift means the two volatility estimates are similar. It does not by itself imply the highest return, the lowest risk or the best portfolio. HRP single and Ward illustrate that even the linkage choice changes the result.

Check the implementation

The 13 tests include weights summing to one, nonnegative HRP weights, distance-matrix properties, and a two-asset case with a known 80/20 allocation. The implementation copies the correlation array before modifying it and symmetrizes the distance matrix to handle floating-point noise.

# From the repository root: python quantmedia-research/tests/test_hrp.py # Expected: 13 passed

Limits and a useful next experiment

This is one fixed-seed panel with no transaction costs and no weight refitting. It does not establish which allocator wins across assets or market regimes. Vary the training length while retaining a separate evaluation sample to explore how much each method depends on its covariance estimate.