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

Feature request: Plot the Efficient Frontier of Mean-Semivariance Model #360

Closed shyen1998 closed 2 years ago

shyen1998 commented 3 years ago

Is your feature request related to a problem? Comparing Efficient Frontiers of Mean-Variance Model and Mean-Semivariance Model

Describe the feature you'd like Plot the Efficient Frontier of Mean-Semivariance Model to compare with the Efficient Frontier of Mean-Variance Model.

Additional context Currently the plotting function only supports the EfficientFrontier and CLA objects.

robertmartin8 commented 3 years ago

@shyen1998

Cheers for the feature request – it's very reasonable.

In the meantime, you can make a plot by looping over target returns and creating EfficientSemivariance portfolios (using efficient_return). For each portfolio, save the standard deviation and expected return into e.g a list, then you can plot these.

shyen1998 commented 3 years ago

Thanks for the tips!

shyen1998 commented 3 years ago

Hey Martin, I tried your suggestion, but the efficient_return method only returns the weight of the portfolio (ordered dict type). May I know how would you calculate the standard deviation and expected return in this case?

robertmartin8 commented 3 years ago

@shyen1998

In each iteration, you can do call exp_return, std, shape = ef.portfolio_performance() after running ef.efficient_return().

shyen1998 commented 3 years ago

image

@robertmartin8 Using for loop to go through the 10 target returns (0, 0.01, 0.02, ..., 0.10), the scatter plot doesn't resemble the usual efficient frontier. And for some reason, the scatter plot changes every time I rerun the for loop.

robertmartin8 commented 3 years ago

@shyen1998

Can you try instantiating the class within the loop, e.g:

for i in range(...):
    es = EfficientSemivariance(...)
    ...
robertmartin8 commented 2 years ago

Closing because stale – feel free to reopen if needed.

In any case, I'll hopefully be pushing some improvements to the plotting functionality so with any luck this problem will be solved