Files
momentum-system/strategy/evaluation/runner_quality.py
T
momentum devandClaude Opus 4.8 ee6991d05a Runner track: match wgcbvb3ce grade signature + attach grade-stratified conversion
Fidelity pass against the leading-gainer-runner workflow (wgcbvb3ce) synthesis:

- runner_quality.py: reorder calculate_runner_quality signature to the spec's
  (gap_pct, vol_burst, velocity, above_vwap, ...) — behavior identical (all callers
  use keywords), now matches the documented signature so a positional caller reading
  the spec is correct.

- labeler.py: close build_plan step (3) "attach the runner grade". The grade is a pure
  function of components already persisted on each fire (gap/velocity/burst/vwap), so
  it is recomputed exactly at report/validate time (catalyst-OFF) — no 34-min rebuild.
  report-runner now stratifies forward +1R and median 60m upside BY GRADE; validate-runner
  adds the A/B-subset test (does concentrating on top grades salvage the locked bar?).

FINDING (385 fires, 25 session-days): the detector still FAILS all 5 pre-registered
bars (the workflow predicted this — SVRE/JEM put 100% of the move pre-market, RTH fires
confirm at/after the top). BUT the grade is MONOTONE with forward outcome:
  grade A: +1R 45%, median max-upside 60m 17.7%   (n=73)
  grade B: +1R 41%, median 9.2%                    (n=186)
  grade C: +1R 35%, median 7.8%                    (n=106)
  grade F: +1R 30%, median 3.5%                    (n=20)
Grade A ALONE clears the +15% upside bar (17.7%) but not +1R>50% (45%): A-runners have
real continuation, the naive last-close entry still whipsaws. Confirms the grade earns
its keep as a RANKER/sizer (concentrate on A) while the bottleneck stays ENTRY-conversion.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-01 00:58:46 -04:00

76 lines
3.5 KiB
Python

"""Runner-aware setup grade — score a VERTICAL leading-gainer sensibly.
The default calculate_setup_quality (quality.py) pins catalyst RUNNERS at F/C because
two of its components structurally break on a vertical spike:
- STRUCTURE (30% weight): classify_setup returns NONE on a vertical impulse (no clean
pullback), so the biggest component reads 0.
- adv-RVOL (25%): rolling_avg_volume_20d is NULL for fresh reverse-split runners, so
relative_volume reads 1.0x -> ~0.2. (This is the exact SVRE "grades F at 0.35" bug.)
On the 2026-06-30 tape the source trader's winners (SVRE +247%, JEM +348%, CELZ +472%)
all graded C 0.565 while the bot's F-grade chop scored the same range — the grade could
not tell a runner from noise.
This is a PARALLEL scorer (quality.py is untouched, its ORB grading/tests unchanged). It
DROPS the two broken components and grades on the traits that actually separate runners
from chop on real bars: session gap, price VELOCITY (the "running up" acceleration),
a RELATIVE volume burst (vs the name's OWN recent bars, never adv-RVOL or raw cum-volume
— which is anti-signal: the liquid chop dwarfs the thin runners), above-VWAP, and the
catalyst tag. Weights are COARSE and seeded from one day's clean in-sample split (n=9
runners vs 5 chop) — a starting point to CALIBRATE on shadow data, not a fitted model.
It RANKS runners; it does not authorize entry (a runner that then loses VWAP grades F,
but a well-graded bar can still bleed — see the runner detector's shadow-only discipline).
"""
from __future__ import annotations
from strategy.evaluation.quality import QualityScore, QualityThresholds
def calculate_runner_quality(
gap_pct: float,
vol_burst: float,
velocity: float,
above_vwap: bool,
catalyst_score: float = 0.0,
data_quality: float = 1.0,
thresholds: QualityThresholds | None = None,
) -> QualityScore:
"""Blend runner traits into one 0..1 grade. Pure. Inputs:
gap_pct — session_high/prev_close - 1 (saturates at +100%, NOT +10%, so a
+472% runner doesn't read the same as +11%).
velocity — the "running up" signal: max recent N-bar return (saturates at +20%).
vol_burst — recent-vol / prior-vol on the name's OWN bars (relative, saturates 3x).
above_vwap — price at/above the session-cumulative VWAP (the safety: a name that
loses VWAP drops this to 0 and the grade falls).
catalyst_score — 0..1 LLM catalyst read; degrades to 0 gracefully (Ollama gated OFF).
"""
thresholds = thresholds or QualityThresholds()
def _clip(x: float) -> float:
return min(1.0, max(0.0, x))
gap_c = _clip(gap_pct / 1.0) # saturate at +100%
vel_c = _clip(velocity / 0.20) # saturate at +20% over the velocity window
avol_c = _clip(vol_burst / 3.0) # saturate at a 3x burst
vwap_c = 1.0 if above_vwap else 0.0
cat_c = _clip(catalyst_score)
components = {
"gap": gap_c, "velocity": vel_c, "volume_burst": avol_c,
"vwap": vwap_c, "catalyst": cat_c,
}
score = (0.30 * gap_c + 0.25 * vel_c + 0.15 * avol_c
+ 0.15 * vwap_c + 0.15 * cat_c) * _clip(data_quality)
if score >= thresholds.a_grade:
grade = "A"
elif score >= thresholds.b_grade:
grade = "B"
elif score >= thresholds.c_grade:
grade = "C"
else:
grade = "F"
return QualityScore(score=round(score, 4), grade=grade, components=components,
tradeable=score >= thresholds.min_tradeable)