@@ -387,3 +387,32 @@ def test_drawdown_series_timestamps_match_snapshots(self):
387387
388388 for (_ , ts ), expected_ts in zip (drawdown_series , timestamps ):
389389 self .assertEqual (ts , expected_ts )
390+
391+
392+ class TestMaxDrawdownReturnConvention (unittest .TestCase ):
393+ """Pin the documented return convention of ``get_max_drawdown``.
394+
395+ The docstring's own worked example is the thing that drifted: it promised
396+ ``-12.5`` for a 12.5% drawdown while the function returns ``abs()`` of a
397+ ``(equity - peak) / peak`` fraction. These assertions fail if either the
398+ sign or the scale changes again.
399+ """
400+
401+ def test_returns_a_positive_fraction_not_a_negative_percent (self ):
402+ snapshots = _make_snapshots (
403+ [datetime (2024 , 1 , 1 ), datetime (2024 , 1 , 2 )], [100.0 , 87.5 ]
404+ )
405+ self .assertAlmostEqual (get_max_drawdown (snapshots ), 0.125 )
406+
407+ def test_scale_matches_get_twr_max_drawdown (self ):
408+ # Both are documented as fractions; a 30% decline is 0.3, not 30.0.
409+ snapshots = _make_snapshots (
410+ [datetime (2024 , 1 , 1 ), datetime (2024 , 1 , 2 )], [200.0 , 140.0 ]
411+ )
412+ self .assertAlmostEqual (get_max_drawdown (snapshots ), 0.3 )
413+
414+ def test_no_drawdown_is_zero (self ):
415+ snapshots = _make_snapshots (
416+ [datetime (2024 , 1 , 1 ), datetime (2024 , 1 , 2 )], [100.0 , 110.0 ]
417+ )
418+ self .assertEqual (get_max_drawdown (snapshots ), 0.0 )
0 commit comments