Skip to content

fix(verify): drop unmatched still-open TV rows from coverage denominator#69

Merged
luisleo526 merged 1 commit into
mainfrom
fix/coverage-denom-open-exclusion
Jul 6, 2026
Merged

fix(verify): drop unmatched still-open TV rows from coverage denominator#69
luisleo526 merged 1 commit into
mainfrom
fix/coverage-denom-open-exclusion

Conversation

@luisleo526

Copy link
Copy Markdown
Collaborator

Problem

TV 'List of Trades' exports emit a mark-to-market row (exit Signal=='Open') for any position still open at the backtest-window end. verify_corpus.py counted these in the coverage denominator, but the engine reports only closed trades — so a position it also holds open at end has no closed row to match, and coverage was penalised for a non-divergence. The sibling harness verify-engine-local.py (tv_still_open) and countAbsDelta already exclude these; this aligns the canonical coverage gate with them.

Fix (matched-aware, coverage-denominator only)

A still-open TV row is dropped from the coverage denominator only when it is unmatched. A matched open row (engine opened AND closed the position for real past the window — align_by_time pairs on entry) stays counted. Touches only the coverage denominator — not parse_trades, the entry-time matcher, tv_cmp, or the count/entry/exit/pnl gates — so it is structurally monotonic (can only raise coverage) and cannot paper over closed-trade divergences.

Validation (fresh-context R7)

  • Corpus gate HELD: 0 tier drops across 251 validation dirs (115 of which carry a still-open row — the path is exercised yet moves nothing).
  • Count gate reads abs=0 identically before/after on every affected strategy.
  • Rejected the blanket form (drop from the matcher too): it regressed 12 excellent→strong — kept out.
  • Masking audit: every upward flip is a genuine both-holding position (engine end-of-run unrealized PnL non-zero); no missed-entry masked.

🤖 Generated with Claude Code

TV 'List of Trades' exports emit a mark-to-market row (exit Signal=='Open') for
any position still open at the backtest-window end. verify_corpus counted these
in the coverage denominator (tv_cov_denom = tv), but the engine reports only
CLOSED trades, so a position it also holds open at end has no closed row to
match -> coverage was penalised for a non-divergence. verify-engine-local's
compare() (tv_still_open) and countAbsDelta already exclude these; this aligns
the canonical coverage gate with them.

MATCHED-AWARE (not blanket): a still-open TV row is dropped from the coverage
denominator ONLY when it is UNMATCHED. A matched open row (engine opened AND
closed the position for real past the window -> align_by_time pairs it on entry)
stays counted. Touches ONLY the coverage denominator -- not parse_trades, the
entry-time matcher, tv_cmp, or the count/entry/exit/pnl gates -- so it cannot
paper over closed-trade divergences (the count gate still bites: e.g. grid bots
with real post-window count deltas stay strong, not excellent).

Adjudicated by a fresh-context design review: corpus-clean (0 tier drops across
251 corpus strategies, 115 of which carry open rows) vs the rejected blanket
form (12 excellent->strong regressions). Regrades ~17 scraper grid/DCA bots
moderate/strong->excellent whose only gap was unreproduced OPEN grid levels.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@luisleo526 luisleo526 merged commit b835ae9 into main Jul 6, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant