From c6ea7b40a3bf0d8ea2f629aaee51a55a2fc9a071 Mon Sep 17 00:00:00 2001 From: Pranav-20186017 Date: Fri, 7 Mar 2025 15:24:08 -0500 Subject: [PATCH] Fix dtype warning in HRPOpt: cast weights to float before multiplication --- pypfopt/hierarchical_portfolio.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pypfopt/hierarchical_portfolio.py b/pypfopt/hierarchical_portfolio.py index 52bfa177..74ff22a9 100644 --- a/pypfopt/hierarchical_portfolio.py +++ b/pypfopt/hierarchical_portfolio.py @@ -135,6 +135,7 @@ def _raw_hrp_allocation(cov, ordered_tickers): first_variance = HRPOpt._get_cluster_var(cov, first_cluster) second_variance = HRPOpt._get_cluster_var(cov, second_cluster) alpha = 1 - first_variance / (first_variance + second_variance) + w = w.astype('float64') w[first_cluster] *= alpha # weight 1 w[second_cluster] *= 1 - alpha # weight 2 return w