From 0b7d9ef6ee6c3747bb45c4952bbc6cd250018ec7 Mon Sep 17 00:00:00 2001 From: luuhongyii <72600702+luuhongyii@users.noreply.github.com> Date: Sat, 13 Jun 2026 09:06:17 +0200 Subject: [PATCH] Fix 10Y annualized return window --- quantstats/reports.py | 2 +- tests/test_reports.py | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/quantstats/reports.py b/quantstats/reports.py index f0d8a9ad..b82bf0d4 100644 --- a/quantstats/reports.py +++ b/quantstats/reports.py @@ -1555,7 +1555,7 @@ def metrics( _get_stats().cagr(df[df.index >= d], 0.0, compounded, win_year) * pct ) - d = today - relativedelta(years=10) + d = today - relativedelta(months=119) metrics["10Y (ann.) %"] = ( _get_stats().cagr(df[df.index >= d], 0.0, compounded, win_year) * pct ) diff --git a/tests/test_reports.py b/tests/test_reports.py index e03bcc97..2001e031 100644 --- a/tests/test_reports.py +++ b/tests/test_reports.py @@ -174,6 +174,26 @@ def test_metrics_with_rf(self, sample_returns): # Results should be different assert not result_no_rf.equals(result_with_rf) + def test_metrics_10y_annualized_return_uses_partial_month_offset(self): + """Test 10Y annualized return uses the same partial-month offset as 3Y/5Y.""" + dates = pd.date_range("2016-01-31", periods=121, freq="ME") + returns = pd.Series(0.01, index=dates, name="Strategy") + returns.iloc[0] = -0.50 + + result = reports.metrics( + returns, + display=False, + prepare_returns=False, + periods_per_year=12, + ) + + assert result.loc["10Y (ann.)", "Strategy"] == result.loc[ + "3Y (ann.)", "Strategy" + ] + assert result.loc["10Y (ann.)", "Strategy"] == result.loc[ + "5Y (ann.)", "Strategy" + ] + class TestMatchDates: """Test date matching functionality."""