Skip to content

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

Backlog

Description

@abhnxvj

When log_returns=True (and the default compounding=True), the expected-return estimators annualise log returns with (1 + r).prod() ** (frequency / n) - 1. That formula is for simple returns. Log returns add up over time, so the annual figure should be exp(mean(r) * frequency) - 1.

The result is a large downward bias that grows with volatility, and it flows straight into the optimiser.

Minimal example with the bundled data:

import pandas as pd
from pypfopt import expected_returns

df = pd.read_csv("tests/resources/stock_prices.csv", parse_dates=True, index_col="date")
simple = expected_returns.mean_historical_return(df)
log = expected_returns.mean_historical_return(df, log_returns=True)
print(pd.DataFrame({"simple": simple, "log_returns=True": log}).loc[["AMZN", "AMD", "BBY"]])
ticker simple returns log_returns=True
AMZN 37.1% 14.4%
AMD 3.3% -15.5%
BBY 23.9% 7.2%

Both should be the same CAGR, since they come from the same prices. On this data, the gap is 9.6 pp on average and up to 22.8 pp, and max_sharpe weights change (AAPL, AMZN, BBY, SBUX drop out).

ema_historical_return and capm_return (the market return) use the same (1 + r) step. test_log_return_passthrough only checks that the two outputs differ, so this wasn't caught.

Happy to open a PR.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions