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

Change the utility for optimisation #448

Closed qowiews closed 2 years ago

qowiews commented 2 years ago

Hi

I am trying to change the utility function in PyPortfolioOpt.

Package is currently using a utility function that looks like:

Skærmbillede 2022-04-24 kl  11 47 21

would it be possible to implement something like:

Skærmbillede 2022-04-24 kl  11 49 21

With γ being the investors aversion against ESG risk and ESG_all being the ESG risk measured as the standard deviation between the ESG score from the four different providers we have access to. So, the ESG_all variable is a vector with the standard deviation between the different providers ESG score for each company.

i have changed the code so the EfficientFrontiere class and the objective function also contains the vector of ESG_all.

Hope one of you guys can help change the code in the objective function for quadratic_utility

Skærmbillede 2022-04-24 kl  11 54 34 Skærmbillede 2022-04-24 kl  11 55 20 Skærmbillede 2022-04-24 kl  11 55 51
qowiews commented 2 years ago

Basically the idea is to maximise the SR and at the same time the ESG risk aversion

qowiews commented 2 years ago

Hi again,

i will elaborate a bit:

Hi,

I have come up with the following utility function for the portfolio optimisation:

U=(E[r]-r_f)/E[σ^2] -γ·ESG_all

With γ being the investors aversion against ESG risk defined by ESG_all which is the ESG risk measured as the standard deviation between the ESG score from four different providers. So, the ESG_all variable is a vector with the standard deviation between the different providers ESG score for each company.

The point of departure is that for an investor which is not concerned about ESG risk the gamma value would be zero and he would simply seek to invest in the tangency portfolio, under the constraint of being ESG compliant. For the investor who are concerned about the ESG risk the gamma value would increase and we define an investor to be a ESG Risk-concerned investor with a gamma value of XX.

The level of ESG is not a part of the utility but will be a constraint to the portfolio so the investor does not care about the level of ESG if the portfolio is compliant which is defined by the constraint added to the portfolio optimization problem. So, the investor only cares about maximising his utility which is a tradeoff between the return per unit of risk and the ESG Risk.

So fare have I looked at the package PyPortfolioOpt which is great. But I simply can't implement a convex problem that the package can use in the optimisation. Can any one help with formalising a convex objective function the package can use ?

an alternative would be to just use the min volatility portfolio with the implementation of ESG uncertainty utility.

dcelisgarza commented 2 years ago

You have a non-linear objective (you have w in the numerator and denominator, and have a square root in the denominator to boot), it's not a conxex problem. You may be able to try the non-convex optimiser that is part of the base optimiser class. However, I don't know if scipy is capable of using non-linear objectives. You'd have to create a function that uses a solver and constraint structure capable of dealing with non-linear objectives.

You could also try a transformation similar to the one done for the sharpe ratio, if you go to the docs for the max sharpe ratio optimisation there's a link to the paper describing it, where they transform the numerator into a constraint, transform all the constraints, and change the objective function to minimise only the denominator instead of the division. That can let you do away with the square root and division, but I'm not sure how you'd go about dealing with the non-fractional term. It could be that you can expand the division to them as well and apply the same methodology, but i'm not sure.

robertmartin8 commented 2 years ago

Yeah in general it's not easy to modify the Sharpe objective because of the transformation required to make it a convex problem. But this is also addressed in #444, so maybe the solution therein will help!

qowiews commented 2 years ago

Thank you guys!