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

Trying to print the value of self._max_return() #379

Closed Originn closed 2 years ago

Originn commented 2 years ago

Hi,

I am quite new with PyPortfolioOpt and Python in general so please bare with me.

I am trying to print the value of self._max_return() in line 373 from efficient_frontier.py if target_return > self._max_return(): raise ValueError( "target_return must be lower than the maximum possible return" )

Becasue if I input 12% target_return in my portfolio and run the following

ef = EfficientFrontier(mu, S, weight_bounds=(None, None))
ef.add_objective(objective_functions.L2_reg)
ef.efficient_return(target_return=0.12, market_neutral=True)

I get the following ValueError "target_return must be lower than the maximum possible return"

As I don't want to guess the maximum possible return, I would like to print it. Is there a way to do it?

Thanks!

robertmartin8 commented 2 years ago

Hi @Originn,

You should be able to just call ef._max_return(), as per below:

ef = EfficientFrontier(mu, S, weight_bounds=(None, None))
ef.add_objective(objective_functions.L2_reg)
print(ef._max_return())

Let met know if that doesn't work!