robertmartin8 / PyPortfolioOpt

Financial portfolio optimisation in python, including classical efficient frontier, Black-Litterman, Hierarchical Risk Parity
https://pyportfolioopt.readthedocs.io/
MIT License
4.51k stars 955 forks source link

Functions only accept prices data not returns data #26

Closed robertmartin8 closed 5 years ago

robertmartin8 commented 5 years ago

This was originally what I intended, but a user has notified me that some data sources (e.g the Fama and French 30) only provide returns. If you are having a problem with this, a quick workaround is to construct a new series of "prices" by adding a row of 1s to your dataset then using df.Series.cumprod() to get the cumulative product. This works because most methods first take the percentage change to make a returns series, and this percentage change does not care about the starting value.

Would love to hear any opinions on whether this is an issue, and if so, what would be the cleanest way to implement optionally providing returns instead of prices. I guess I could do it by having a boolean parameter price_data=True; if False then the data passed in will be interpreted as returns. However, I don't want to clutter the API without good reason.

schneiderfelipe commented 5 years ago

Hi Robert,

I believe you could create a function called prices_from_returns (in the same fashion as returns_from_prices, which is a very useful function that's not mentioned in the docs at all!).

This would allow anyone to use either input with no API change at all.

robertmartin8 commented 5 years ago

@schneiderfelipe thank you for the feedback, I’ll do this soon