Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion quantstats/reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
20 changes: 20 additions & 0 deletions tests/test_reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down