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

Difference expected return calculated by portfolio_performance() and efficient_return() #435

Closed markm812 closed 2 years ago

markm812 commented 2 years ago

Hello, While reading the documentation for mean-variance optimization, I discovered that efficient_return() is used to 'Calculate the 'Markowitz portfolio,' minimizing volatility for a given goal return.' However, I discovered that the expected return of the portfolio generated by portfolio_performance() after performing efficient_return() differs significantly from the targetted return I specified in the Markowitz portfolio optimization. Could you please assist me with this question?

Code used:

    mu = expected_returns.mean_historical_return(data)
    cov = risk_models.CovarianceShrinkage(data).ledoit_wolf()
    ef = EfficientFrontier(mu, cov)
    try:
        weights = ef.efficient_return(0.05) # <---- tried different ranged from 0.15 - 0.05
        (expect_return, volatilly, sharp) = ef.portfolio_performance(verbose = True) 
    except:

Output:

Expected annual return: 1812.2%
Annual volatility: 6.5%
Sharpe Ratio: 279.51
robertmartin8 commented 2 years ago

Hmmm I'm not entirely sure what's going on here. If you remove the try/except block, is it throwing out an error?

Also can you have a look through your mu to make sure that a return of 0.05 is actually feasible?

Lastly, I'd suggest looking at the weights. ef.portfolio_performance is a relatively simple function that just dots the weights with mu to find expected return, so it should be quite easy to diagnose where the problem is coming from.

robertmartin8 commented 2 years ago

Closing due to inactivity