Skip to content

Commit 557459b

Browse files
authored
Merge pull request #456 from ranaroussi/fix-issue-455
Add periods parameter to calmar() function (fixes #455)
2 parents 25d9f99 + f907cfb commit 557459b

4 files changed

Lines changed: 11 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
Changelog
22
===========
33

4+
0.0.69
5+
------
6+
7+
- Added `periods` parameter to `calmar()` function to support custom annualization periods (fixes issue #455)
8+
- Updated reports.py to pass periods parameter to Calmar ratio calculation for consistency with other metrics
9+
410
0.0.68
511
------
612

quantstats/reports.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1301,7 +1301,7 @@ def metrics(
13011301
metrics["Volatility (ann.) %"] = ret_vol
13021302

13031303
# Additional risk and return metrics
1304-
metrics["Calmar"] = _stats.calmar(df, prepare_returns=False)
1304+
metrics["Calmar"] = _stats.calmar(df, prepare_returns=False, periods=win_year)
13051305
metrics["Skew"] = _stats.skew(df, prepare_returns=False)
13061306
metrics["Kurtosis"] = _stats.kurtosis(df, prepare_returns=False)
13071307

quantstats/stats.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1492,7 +1492,7 @@ def kurtosis(returns, prepare_returns=True):
14921492
return returns.kurtosis()
14931493

14941494

1495-
def calmar(returns, prepare_returns=True):
1495+
def calmar(returns, prepare_returns=True, periods=252):
14961496
"""
14971497
Calculate the Calmar ratio (CAGR / Maximum Drawdown).
14981498
@@ -1503,6 +1503,7 @@ def calmar(returns, prepare_returns=True):
15031503
Args:
15041504
returns (pd.Series): Return series to analyze
15051505
prepare_returns (bool): Whether to prepare returns first (default: True)
1506+
periods (int): Periods per year for annualization (default: 252)
15061507
15071508
Returns:
15081509
float: Calmar ratio
@@ -1518,7 +1519,7 @@ def calmar(returns, prepare_returns=True):
15181519
returns = _utils._prepare_returns(returns)
15191520

15201521
# Calculate CAGR and maximum drawdown
1521-
cagr_ratio = cagr(returns)
1522+
cagr_ratio = cagr(returns, periods=periods)
15221523
max_dd = max_drawdown(returns)
15231524

15241525
# Return ratio of CAGR to absolute maximum drawdown

quantstats/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
version = "0.0.68"
1+
version = "0.0.69"

0 commit comments

Comments
 (0)