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

The weight to be assigned to the risk free asset #143

Closed haimsitt closed 4 years ago

haimsitt commented 4 years ago

When i use the max_sharpe function it returns the optimal weight for every asset in my dataframe.

Is there a way to find out the optimal weights when investing in the risk free asset and investing in the market?

robertmartin8 commented 4 years ago

There isn't a builtin way to do that, but you should be able to create a risk free asset and re-run the optimisation

haimsitt commented 4 years ago

Thanks for the quick response. How would you define a risk free asset in pandas?

robertmartin8 commented 4 years ago

You could create a column with constant returns

haimsitt commented 4 years ago

If the time series has a constant daily return than the sharpe ratio is infinite.

robertmartin8 commented 4 years ago

Do you mean conceptually, or this is the result of a numerical attempt?

An asset with constant returns is the definition of a risk-free asset. Also, the Sharpe ratio is not technically infinite because the numerator will also be zero.

On Thu, Jun 25, 2020 at 10:09 PM haimsitt notifications@github.com wrote:

If the time series has a constant daily return than the sharpe ratio is infinite.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/robertmartin8/PyPortfolioOpt/issues/143#issuecomment-649566151, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACZ7ECM27EIY2OTQNFOP2ZDRYNLB7ANCNFSM4OBWD44A .

haimsitt commented 4 years ago

You are correct. If an asset with a risk free asset has returns that are equal to the risk free returns than the Sharpe ratio is 0. Say you have the weights for the portfolio maximizing the Sharpe ratio. If you use leverage you can achieve a higher Sharpe ratio if you also invest in the risk free asset (depending on your loan rate). Maybe you can add leverage to the max_sharpe function ?

haimsitt commented 4 years ago

My feature request is partially theoretical, so I will close it for now. Thanks :D