robertmartin8 / PyPortfolioOpt

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

Get Data in Efficient Frontier #372

Closed pebennett closed 2 years ago

pebennett commented 2 years ago

Hi there, slowly learning how to utilize PyPortfolioOpt. Thanks so much.

What are you trying to do? I need the data underlying the efficient frontier as there additional analytics and plotting I want to do.

What have you tried? tried looking in source file info and trying to pull out various objects.

What data are you using? What asset class, how many assets, how many data points. Preferably provide a sample of the dataset MAS_Returns_Qrtly_2021-06_quad0.csv as a csv attachment.

Thanks, Phil

phschiele commented 2 years ago

@pebennett what data are you talking about specifically? Below you can find an example showing how to get weights and some performance metrics (expected return, volatility and Sharpe ratio) from the optimized portfolio.

ef = EfficientFrontier(mu, S)
raw_weights = ef.max_sharpe()
cleaned_weights = ef.clean_weights()
ef.portfolio_performance(verbose=True)
pebennett commented 2 years ago

Thanks for getting back to me, and sorry for not being specific enough. What I'm trying to get is the data (i.e. vol, return & weights) for all points on an efficient frontier.

BTW, can you please explain the difference between raw weights and cleaned weights.

Thanks, Phil