Skip to main content

Module hrp

Module hrp 

Source
Expand description

Hierarchical Risk Parity (HRP) — pure math functions.

Three-phase algorithm:

  1. Compute correlation → distance matrix → agglomerative clustering (average linkage)
  2. Build dendrogram (binary tree of clusters)
  3. Recursive bisection following dendrogram with inverse-variance weighting

All functions are pure math: &[f64] in, f64 out. No domain types, no I/O. The adapter wraps domain types (e.g. LegReturns) into raw slices before calling these functions.

Enums§

ClusterNode
Binary tree node representing hierarchical clustering.

Constants§

MIN_OBSERVATIONS
Minimum number of return observations required to compute a meaningful correlation matrix.

Functions§

build_dendrogram
Build a dendrogram using agglomerative clustering with weighted average linkage.
cluster_variance
Compute average variance for a cluster (sum of leaf variances / leaf count).
cluster_variance_sum
correlation_matrix
Compute the Pearson correlation matrix from return series.
decimal_from_f64
Convert f64 to Decimal with 6 decimal places precision.
distance_matrix
Convert correlation to distance: d(i,j) = sqrt((1 - corr(i,j)) / 2)
find_closest_pair
mean
recursive_bisect
Walk the dendrogram tree, splitting weight between left and right subtrees using inverse-variance allocation at each branch.
variance