robertmartin8 / PyPortfolioOpt

Financial portfolio optimisation in python, including classical efficient frontier, Black-Litterman, Hierarchical Risk Parity
https://pyportfolioopt.readthedocs.io/
MIT License
4.28k stars 930 forks source link

How to extract minimum variance and maximum sharpe portfolios' variance and expected return? #443

Closed YanLucasGS closed 2 years ago

YanLucasGS commented 2 years ago

Hi!

I'm currently using the PyPortfolioOpt with the CLA model to draw the efficient frontier. However, I wanted to get the weights, variance and expected return for the minimum variance and maximum sharpe portfolios.

The ideia is to bootstrap different optimized portfolios, in order to get the average optimized portfolio. It would be something similar to Michaud's resampling solution here, without recreating the whole frontier, but only getting the bootstrapped min_var and max_sharpe portfolios.

My current code is the following:

paths = [data_raw.pct_change().sample(100,replace=True).to_numpy() for x in range(100)] 

sharpe_list = []
min_var_list = []

for path in paths:
    mu = path.mean(axis=0) * 252
    S = pd.DataFrame(path).cov()*np.sqrt(252)

    test = CLA(mu,S)
    min_var = test.min_volatility()

    test = CLA(mu,S)
    max_sharpe = test.max_sharpe()

    sharpe_list.append(list(min_var.values()))
    min_var_list.append(list(max_sharpe.values()))

Is it possible to achieve that?

Thanks in advance.

YanLucasGS commented 2 years ago

Just adding that with this code I could get the weights, but not the other information.

robertmartin8 commented 2 years ago

If I'm understanding correctly, you can use the portfolio_performance() method, e.g test.portfolio_performance()