fix: align daily matrix ranking universe

This commit is contained in:
2026-07-17 16:39:43 +02:00
parent 27bc8a6631
commit 9800114fc4
3 changed files with 122 additions and 5 deletions
+8 -3
View File
@@ -1039,11 +1039,16 @@ def _replay_candidates_for_period(
benchmark_closes: dict[date, float] | None,
start_date: date,
cadence: str = DEFAULT_BACKTEST_CADENCE,
include_short_candidates: bool = False,
) -> list[dict]:
"""Slim picklable replay used by local event studies.
Unlike the full report worker it skips factor-series construction and only
evaluates setup dates on or after ``start_date``.
evaluates setup dates on or after ``start_date``. Long-only remains the
compatibility default. Set ``include_short_candidates`` when the caller
needs the production-faithful cross-sectional ranking universe; shorts can
then contribute to percentiles while the portfolio simulator still trades
only qualified longs.
"""
date_ords, opens, highs, lows, closes, volumes = columns
bars = [
@@ -1075,14 +1080,14 @@ def _replay_candidates_for_period(
vol_6m = _realized_vol_6m(window_closes, len(window) - 1)
iso = bars[i].date.isocalendar()
for setup in _window_setups(window, config, activation):
if setup["direction"] != "long":
if not include_short_candidates and setup["direction"] != "long":
continue
candidates.append({
"symbol": symbol,
"date": bars[i].date.isoformat(),
"iso_week": (iso[0], iso[1]),
"ranking_period": _ranking_period(bars[i].date, cadence),
"direction": "long",
"direction": setup["direction"],
"entry": setup["entry"],
"stop": setup["stop"],
"target": setup["target"],