Skip to content

[BUG] Compound log returns with exp in expected return estimators - #785

Open
abhnxvj wants to merge 2 commits into
PyPortfolio:mainfrom
abhnxvj:fix/log-returns-compounding
Open

abhnxvj wants to merge 2 commits into
PyPortfolio:mainfrom
abhnxvj:fix/log-returns-compounding

Conversation

@abhnxvj

@abhnxvj abhnxvj commented Dec 1, 2026

Copy link
Copy Markdown

Fixes #784

When prices are converted to log returns (log_returns=True), the compounded annual return is now exp(mean * frequency) - 1 instead of (1 + r) compounding, in mean_historical_return, ema_historical_return and capm_return.

  • With this, mean_historical_return(df, log_returns=True) equals the simple-return CAGR, as it should.
  • compounding=False is unchanged (the mean log return times frequency).
  • The returns_data=True path is unchanged, because the docstring says passed-in returns should not be log returns.

Tests: added three tests (CAGR equality on the bundled data plus a doubling-price case, and EMA and CAPM checked against a manual calculation). They fail on main and pass with this change. The rest of test_expected_returns.py passes, and ruff is clean. The HRP/plotting failures on SciPy 1.18 are already there on main (#754).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

log_returns=True compounds log returns as simple returns in mean_historical_return / ema_historical_return / capm_return

1 participant