Drawdown-resilience screen: who was positive when equities crashed

fundlab/drawdown.py detects the severe equity drawdown scenarios from
the index (IVV) rather than hard-coding them: one worst peak->trough
per calendar year since 2022, min depth 8% (a 10% floor would silently
drop the 2023 rate shock at -9.9% and the 2024 Aug-5 dip at -8.4%).
Detected: 2022 bear mkt (-24.5%), 2023 rate shock (-9.9%), 2024 vol
spike (-8.4%), 2025 tariff crash (-18.8%), 2026 Q1 drawdown (-8.9%).

For each of the 2,384 screened funds it computes that fund's own-NAV
return over each peak->trough window (first print after the peak to
the last print on/before the trough) and ranks the 250 CANDIDATEs by
# scenarios positive.

Key finding: positive in all 5 scenarios = only 7 funds, all
ultra-short/cash (BILS, QCMMRX, PULS, FHCOX, FHMIX, SAFEX, COIAX).
Drawdown resilience at the top tier is a duration property, not alpha.
The interesting tier is 4/5 WITH real 5y alpha: HMEZX merger arb
(+1.5% 2022, +3.1% 2023, t5 +7.1), MERVX, CBHCX market-neutral, SCFZX
securitized credit (t5 +8.4), ENIAX (t5 +10.1), WMNUX (t5 +6.9), RCTIX.

App: Fund Lab "Drawdown resilience" expander (scenario table +
candidate table). Output: fundlab/drawdown_results.json.
Tests: test_drawdown() added (4 checks). 88/32 suites green.
This commit is contained in:
gmp
2026-08-27 13:29:01 -04:00
parent a09861f39f
commit d0ae2ec348
5 changed files with 42957 additions and 1 deletions
+35
View File
@@ -452,6 +452,40 @@ def test_xcheck() -> None:
and s.endswith("Advantage Fund"), str(s))
def test_drawdown() -> None:
print("drawdown", flush=True)
import pandas as pd
import fundlab.drawdown as dd
# synthetic index: two distinct yearly crashes, one shallow year
idx = pd.date_range("2022-01-03", periods=756, freq="B")
px = [100.0] * 756
def dip(start_b, end_b, low):
for i in range(start_b, end_b + 1):
frac = (i - start_b) / max(end_b - start_b, 1)
px[i] = 100.0 * (1 - low * (4 * frac * (1 - frac)))
dip(10, 160, 0.24) # 2022: deep bear
dip(380, 430, 0.09) # 2023: shallow-ish shock
dip(640, 690, 0.18) # 2024: tariff-style crash
p = pd.Series(px, index=idx)
eps = dd.detect_episodes(p, min_dd=0.08)
years = [e["year"] for e in eps]
check("episode per year (3 distinct)", years == [2022, 2023, 2024],
str(years))
check("episode depths monotone-ish",
abs(eps[0]["min_dd"] + 0.24) < 0.02 and len(eps) == 3,
str([e["min_dd"] for e in eps]))
check("0.20 threshold keeps only the deepest year (2022)",
[e["year"] for e in dd.detect_episodes(p, min_dd=0.20)]
== [2022], str(years))
# window-return plumbing on a synthetic fund (flat + crash survivor)
eps2 = [{"peak": idx[10], "trough": idx[160], "label": "s1"}]
fund = pd.Series([100.0] * 756, index=idx)
w = dd.fund_windows # takes (sym, eps) reading from disk - skip live
check("fund_windows callable", callable(w), "")
def main() -> int:
test_pool()
test_text_and_objective()
@@ -464,6 +498,7 @@ def main() -> int:
test_overnight()
test_curated()
test_xcheck()
test_drawdown()
test_edgar_live()
print(f"\n{PASS} passed, {FAIL} failed")
return 1 if FAIL else 0