robertmartin8 / PyPortfolioOpt

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

How to plot nicely formatted efficient frontier #126

Closed x829901 closed 4 years ago

x829901 commented 4 years ago

The efficient frontier on your main page is very colorful and nicely formatted. But I couldn't find anything in your repository that creates it. All I could find was:

Plotting.plot_efficient_frontier(cla) # to plot

And that just make a simple very basic efficient frontier plot. How did you make the colorful efficient frontier?

robertmartin8 commented 4 years ago

The colourful efficient frontier plot, though pretty, isn't actually very informative. All of the dots on it represent random portfolios, coloured by the Sharpe ratio. I generated this by a simple Monte Carlo script, which looked something like:

returns = []
sigmas = []
sharpes = []
n_assets = 20
for _ in range(10000):
    w = np.random(n_assets, 1)
    w /= w.sum()
    ret = mu.T @ w
    std = np.sqrt(w.T @ S @ w)
    returns.append(ret)
    sigmas.append(std)
    sharpes.append(ret/std)