Skip to content

Commit 2043afd

Browse files
hass-nationclaude
andcommitted
feat(hierarchical): add HERCOpt and NCOpt portfolio allocation methods
Extends the hierarchical portfolio module with two additional methods: HERCOpt - Hierarchical Equal Risk Contribution (Raffinot 2018) Equal Risk Contribution (ERC) weights at every level of the hierarchy instead of the inverse-variance weights used by HRP. ERC accounts for within-cluster correlations, producing more balanced risk allocation when intra-cluster correlations are high. Implemented via cyclical coordinate descent (Roncalli 2013). NCOpt - Nested Cluster Optimization (Lopez de Prado 2019) Two-level nested procedure: within-cluster optimization followed by meta-portfolio optimization across clusters. Supports three objectives at each level - min_variance, erc, and equal-weight - giving 9 combinations. The meta-covariance is computed analytically from the full covariance matrix, so no return history is required. Both classes: - Share the same API as HRPOpt (fit from returns or cov_matrix) - Export portfolio_performance() with expected return and Sharpe ratio - Are exported from pypfopt.__init__ and __all__ - Accept all scipy linkage methods Also adds two private helpers: - _erc_weights_ccd: ERC via multiplicative CCD (Roncalli 2013) - _min_var_weights: long-only min-variance with analytic + SLSQP fallback 53 tests across 9 test classes; all existing HRP tests still pass. References ---------- Raffinot, T. (2018). Hierarchical clustering-based asset allocation. Journal of Portfolio Management, 44(2), 89-99. Lopez de Prado, M. (2019). A Robust Estimator of the Efficient Frontier. SSRN Working Paper. https://ssrn.com/abstract=3469961 Roncalli, T. (2013). Introduction to Risk Parity and Budgeting. CRC Press. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent c524c6e commit 2043afd

3 files changed

Lines changed: 997 additions & 1 deletion

File tree

pypfopt/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
EfficientFrontier,
1212
EfficientSemivariance,
1313
)
14-
from .hierarchical_portfolio import HRPOpt
14+
from .hierarchical_portfolio import HRPOpt, HERCOpt, NCOpt
1515
from .risk_models import CovarianceShrinkage
1616

1717
__version__ = "1.6.0"
@@ -28,5 +28,7 @@
2828
"EfficientCVaR",
2929
"EfficientCDaR",
3030
"HRPOpt",
31+
"HERCOpt",
32+
"NCOpt",
3133
"CovarianceShrinkage",
3234
]

0 commit comments

Comments
 (0)