robertmartin8 / PyPortfolioOpt

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

covariance matrix based on logreturns #343

Closed ggerber closed 2 years ago

ggerber commented 3 years ago

Describe the bug expected_returns.py defines a function "returns_from_prices" with args: prices and log_returns(=False).

risk_models.py defines a function "sample_cov" which internally calls "returns_from_prices" without the arg log_returns. Hence, "sample_cov" does not allow for the option to use logreturns.

Expected behavior sample_cov should include the argument log_returns(=True) which gets passed on to the internal call returns_from_prices(prices, log_returns). This will allow covariance matrices to be based on logreturns and not only raw returns

Code sample Add a minimal reproducible example (see here).

Operating system, python version, PyPortfolioOpt version e.g MacOS 10.146, python 3.7.3, PyPortfolioOpt 1.2.6

Additional context Add any other context about the problem here.

robertmartin8 commented 3 years ago

@ggerber good point – I'll fix this in the next release (hopefully this week!)

ggerber commented 3 years ago

The **kwargs and/or "log_returns" arguments are not applied to the "mean_historical_return" function (line 97 in expected_returns.py). This means that the "log_returns" argument is not passed through when "return_model" is called (line 67 in expected_returns.py)

The same issue applies to: ema_historical_return and capm_return

robertmartin8 commented 3 years ago

My mistake – will fix that soon