Skip to content

Commit f76ef15

Browse files
committed
feat: add compounded flag to calmar() for non-compounded return streams
Pass a `compounded` parameter through to the underlying CAGR calculation so that intraday and arithmetic return streams get the correct annualized return in the numerator instead of geometric CAGR. Fixes #507
1 parent 9d255e6 commit f76ef15

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

quantstats/reports.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1435,7 +1435,9 @@ def metrics(
14351435
metrics["Volatility (ann.) %"] = ret_vol
14361436

14371437
# Additional risk and return metrics
1438-
metrics["Calmar"] = _get_stats().calmar(df, prepare_returns=False, periods=win_year)
1438+
metrics["Calmar"] = _get_stats().calmar(
1439+
df, prepare_returns=False, periods=win_year, compounded=compounded
1440+
)
14391441
metrics["Skew"] = _get_stats().skew(df, prepare_returns=False)
14401442
metrics["Kurtosis"] = _get_stats().kurtosis(df, prepare_returns=False)
14411443

quantstats/stats.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1643,6 +1643,7 @@ def calmar(
16431643
returns: Returns,
16441644
prepare_returns: bool = True,
16451645
periods: int = 252,
1646+
compounded: bool = True,
16461647
) -> float:
16471648
"""
16481649
Calculate the Calmar ratio (CAGR / Maximum Drawdown).
@@ -1655,6 +1656,9 @@ def calmar(
16551656
returns (pd.Series): Return series to analyze
16561657
prepare_returns (bool): Whether to prepare returns first (default: True)
16571658
periods (int): Periods per year for annualization (default: 252)
1659+
compounded (bool): Whether to use compounded (geometric) returns
1660+
for the CAGR calculation (default: True). Set to False for
1661+
intraday or non-compounded return streams.
16581662
16591663
Returns:
16601664
float: Calmar ratio
@@ -1670,7 +1674,7 @@ def calmar(
16701674
returns = _utils._prepare_returns(returns)
16711675

16721676
# Calculate CAGR and maximum drawdown
1673-
cagr_ratio = cagr(returns, periods=periods)
1677+
cagr_ratio = cagr(returns, compounded=compounded, periods=periods)
16741678
max_dd = max_drawdown(returns)
16751679

16761680
# Return ratio of CAGR to absolute maximum drawdown

0 commit comments

Comments
 (0)