PyPortfolioOpt icon indicating copy to clipboard operation
PyPortfolioOpt copied to clipboard

Feature request: Upgrade HRPOpt to prefer supplied covariance matrix

Open RobertWSmith opened this issue 5 months ago • 1 comments

Is your feature request related to a problem? I was looking at the source code for HRPOpt and noticed that it prefers to compute the covariance as opposed to using the constructor supplied covariance matrix. I read through the earlier discussion, and was reading the code because I was interested in the implementation.

Describe the feature you'd like I believe the following change to HRPOpt.optimize would allow users to supply both returns and a pre-shrunk covariance matrix and get the expected results:

        if self.cov_matrix is not None:
            cov = self.cov_matrix
            corr = risk_models.cov_to_corr(self.cov_matrix).round(6)
        else:
            corr, cov = self.returns.corr(), self.returns.cov()

I'm testing out this change locally and if I can get all your unit tests to pass I'd like to submit a pull request.

RobertWSmith avatar Jul 03 '25 02:07 RobertWSmith

I don't think HRP should compute the covariance matrix at all. We will give access to a few methods to compute a Dendrogram. The covariance matrix is one such route.... Otherwise, we keep repeating the same functionality/code at different places in this package.

tschm avatar Nov 16 '25 13:11 tschm