HRP¶
Defined in fynance.algorithms.allocation
- HRP(X, method='single', metric='euclidean', low_bound=0., up_bound=1.0)[source]
Get weights of the Hierarchical Risk Parity allocation.
Cluster-based allocation that avoids inverting the full covariance matrix. Compared with classical Markowitz solutions, HRP is far more stable when
Nis large or assets are highly correlated, because it groups similar assets first and only allocates risk within and between clusters.Three steps: (1) build a correlation distance and run hierarchical linkage, (2) reorder the covariance matrix into quasi-diagonal form, (3) recursively bisect the ordered tree, allocating weights by inverse variance to each branch.
- Parameters:
- Xarray_like
Each column is a price or return’s asset series. Some errors will happen if one or more series are constant.
- method, metric: str
Parameters for linkage algorithm, default
method='single'andmetric='euclidean'.- low_bound, up_boundfloat
Respectively minimum and maximum value of weights, such that low_bound \(\leq w_i \leq\) up_bound \(\forall i\). Default is 0 and 1.
- Returns:
- np.ndarray
Vector of weights computed by HRP algorithm.
Notes
Hierarchical Risk Parity algorithm is developed by Marco Lopez de Prado [2]. First step is clustering and second step is allocating weights.
References