Skip to content

BUG: Fix CAGR and annualized return calculations#1346

Open
blue-int wants to merge 1 commit intokernc:masterfrom
blue-int:fix/cagr-and-annualized-return
Open

BUG: Fix CAGR and annualized return calculations#1346
blue-int wants to merge 1 commit intokernc:masterfrom
blue-int:fix/cagr-and-annualized-return

Conversation

@blue-int
Copy link

Summary

  • CAGR: time_in_years was computed by dividing calendar days by annual_trading_days (e.g. 252, 52, 12) instead of 365.25. This inflated the time period and underreported CAGR. For weekly/monthly data, results were drastically wrong (e.g. 365/52 = 7 years instead of ~1 year).
  • Return (Ann.): pct_change() produces a leading NaN that geometric_mean() counted in the denominator via fillna(0), slightly diluting the geometric mean and underestimating annualized return.

After the fix, CAGR and Return (Ann.) are now consistent with each other as expected (21.16% vs 21.19% on GOOG SmaCross, previously 14.16% vs 21.18%).

Test plan

  • Updated expected values in test_compute_stats
  • All existing tests pass (74 passed, 1 skipped; test_FractionalBacktest is a pre-existing failure unrelated to this change)

🤖 Generated with Claude Code

CAGR was dividing calendar days by `annual_trading_days` (e.g. 252)
instead of 365.25, inflating the time period and underreporting CAGR.
For weekly/monthly data this was drastically wrong (e.g. 365/52=7 years
instead of 1 year).

Return (Ann.) was slightly underestimated because `pct_change()` produces
a leading NaN that `geometric_mean()` counted in the denominator via
`fillna(0)`, diluting the geometric mean.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.

1 participant