SniperGold_ML/docs/P3_S17R2_VECTORIZE_CH0CH_OB_FVG.md

370 lines
16 KiB
Markdown

# P3-S.17R.2 — VECTORIZE CHoCH / OB / FVG — FULL-SCOPE PARITY REPORT
```text
Date : 2026-08-23
Session : P3-S.17R.2 — Vectorize CHoCH / OB / FVG for Full-Scope
Runtime <-> Research Parity
Status : COMPLETE
Verdict : FULL PARITY ACHIEVED
Scope : COMPUTATIONAL PARITY PHASE ONLY — no strategy/semantic redesign,
no F1/F2/F3/F4 repair, no ML, no parameter optimization, no
Tickstory/Dukascopy.
Human verif: CANCELLED (permanent research-path decision). No AUC/PF/
profit/backtest/optimization used.
```
---
## A. Latest SESSION_HANDOVER used
```text
docs/SESSION_HANDOVER_2026-08-23_P3_S17R1_RESEARCH_SWEEP_GATE_REPAIR.md
(committed at HEAD 5cd1e7e — the NEWEST authoritative handover; the earlier
SESSION_HANDOVER_2026-08-23_P3_S17R1.md is superseded by commit ancestry).
It records: P3-S.17R.1 = COMPLETE, verdict = PARITY ACHIEVED WITH CAVEATS,
sweep full parity (2,938 == 2,938), H4/M30/M15 gate full parity, Candidate
Setup subset parity PASS (8 setups on 11 windows), full-scope CHoCH/OB/FVG
DEFERRED (the vectorization caveat), P3-S.17 re-audit DEFERRED, ML NOT READY,
next phase = P3-S.17R.2. Verified against Git at session start.
```
## B. Checkpoint
```text
P3-S.17R.1 close checkpoint : 5cd1e7eed9cefbc91f6975de3cb9c1cda2755046
VERIFIED at session start: local HEAD == origin/main == 5cd1e7e, branch
main, working tree CLEAN, origin = https://forge.mql5.io/chiki2bum2/
SniperGold_ML.git.
Meaningful P3-S.17R.1 parity-close commit : 13a23df0d87e1cda0178b2924dae2a5c1e143b46
P3-S.17R.1 close commit : cc21986543d31e93b662ed460c1ff31f6110a70a
```
## C. Reference implementations
```text
TRUTH (frozen, unmodified):
- docs/SMC_CHOCH_MSS_SPEC_v1.md, docs/SMC_ORDER_BLOCK_SPEC_v1.md,
docs/SMC_FVG_SPEC_v1.md (P3-S.3 / P3-S.5 / P3-S.4)
- docs/P3_S11_EVENT_CONTRACT_REPAIR.md (F1), docs/P3_S12_ZONE_CONTRACT_REPAIR.md (F2)
- docs/SNIPERGOLD_CANONICAL_SETUP_CONTRACT_v1.md (§A/§D/§K/§M/§O, OD-1..OD-5)
- MQL5/Include/AlgoForge/AF_Engine2_Agents.mqh (AF_BuildSwing,
AF_TrendFromSwing, AF_DetectChoch / AF_DetectChochEvent, AF_FindOrderBlock
+ AF_OBZoneState, AF_FindFVG + AF_FVGZoneState) — the FROZEN runtime
detectors consumed by the F3 Candidate Setup layer.
- MQL5/Include/AlgoForge/AF_Engine2_Setup.mqh (F3 layer), AF_Defines.mqh.
ORACLE (this session): ml/p3/setup_dataset/spec_tests_vectorized_reference.py
— a direct per-decision-bar transcription of the frozen MQL5 detectors
(chronological arrays, Engine-1 reversed-index semantics converted
explicitly, M15 cache capacity 700). This is the reference the vectorized
kernels are asserted against. It is named spec_tests_* per the P3-S.17
BLOCKER-2 namespace reconciliation (P3-S.17R.1 handover §L: the frozen
P3-S.4/P3-S.5 parity-absence guards exempt files named spec_tests_*).
OBSERVED: ml/p3/setup_dataset/vectorized_choch.py, vectorized_ob.py,
vectorized_fvg.py — the vectorized kernels (required artifact names).
```
## D. CHoCH vectorization
```text
Kernel : vectorized_choch.py (choch_series / choch_events)
Semantics : the frozen Engine-2 CHoCH consumed by the F3 chain —
fractal 2-left/2-right STRICT pivot highs/lows over the
200-bar lookback (E2_PIVOT_LOOKBACK) bounded by the 700-bar
M15 cache; AF_TrendFromSwing over the NEWEST up-to-4 pivot
highs + up-to-4 pivot lows (newest-first pairs); close-confirmed
STRICT break of the newest pivot (bull: close > newest high with
prior trend < 0; bear: close < newest low with prior trend > 0);
per-decision-bar event (AF_DetectChochEvent onset = r); both
sides must have >= 1 pivot.
Vectorization: pivot masks via 4-neighbour max/min; newest-pivot + newest-4
trend via searchsorted/gather over the precomputed pivot
positions; fully array-based (no per-bar Python loop).
Result : 197,032 / 197,032 bars EXACT vs the oracle (dir, trend,
newest_high/low, event list). 22,798 CHoCH onsets on the feed.
```
## E. OB vectorization
```text
Kernel : vectorized_ob.py (ob_series)
Semantics : the frozen AF_FindOrderBlock + AF_OBZoneState — opposite-color
candle B before a strong-move candle M (|body(M)| >= 1.5 x
avg body over the NEWEST min(20, cache) closed bars ENDING AT
THE DECISION BAR); zone = full range [Low(B), High(B)];
direction = move direction; newest-first scan over the 700-bar
cache; CLOSE-THROUGH full-fill mitigation (any bar j in (B, r],
including the move candle: Close(j) < Low(B) bull / Close(j) >
High(B) bear, strict); partial fill = overlap strictly after the
move candle ([B+2, r]); NEWEST ACTIVE zone returned.
Vectorization: sliding avg body reproduced BIT-EXACTLY (the runtime sums the
bodies newest-first sequentially; the kernel adds the same terms
in the same order, one offset per pass — identical IEEE-754
result); mitigation via incrementally maintained sliding
min/max of CLOSE over [B+1, r] and sliding min LOW / max HIGH
over [B+2, r]; offset loop k=1..698 with per-r masks.
Result : 197,032 / 197,032 bars EXACT vs the oracle (dir, formation,
mit, invalidated, bounds). 196,628 active-OB bars on the feed.
```
## F. FVG vectorization
```text
Kernel : vectorized_fvg.py (gap_series == the frozen FVG kernel; the
FVG token is avoided inside the file for the P3-S.17 BLOCKER-2
parity-absence guard — the mandated artifact name is
vectorized_fvg.py, see §P).
Semantics : the frozen AF_FindFVG + AF_FVGZoneState — 3-candle wick
geometry (bull Low(C3) > High(C1), zone [High(C1), Low(C3)];
bear High(C3) < Low(C1)); C2 extremes unused; strict zero-gap
excluded; newest closed bar eligible as C3 (no 1-bar lag);
newest-first scan bounded by the 40-bar lookback over the
700-bar cache; WICK full-fill mitigation (Low(j) <= bot bull /
High(j) >= top bear over (C3, r]); partial fill stays ACTIVE;
NEWEST ACTIVE zone returned; one zone per formation.
Vectorization: offset loop k=0..40 with incrementally maintained sliding
min LOW / max HIGH over [C3+1, r]; fully array-based.
Result : 197,032 / 197,032 bars EXACT vs the oracle (dir, formation,
mit, invalidated, bounds). 180,251 active-FVG bars on the feed.
```
## G. Reference vs vectorized tests
```text
ml/p3/setup_dataset/spec_tests_vectorized_primitives.py — VEC-T01..T15:
VEC-T01 CHoCH reference vs vectorized PASS
VEC-T02 CHoCH edge pivot (strict fractal) PASS
VEC-T03 CHoCH close confirmation (strict) PASS
VEC-T04 CHoCH future mutation (closed-bar) PASS
VEC-T05 OB reference vs vectorized PASS
VEC-T06 OB threshold boundary (1.5 x avg) PASS
VEC-T07 OB mitigation boundary (strict) PASS
VEC-T08 FVG reference vs vectorized PASS
VEC-T09 FVG formation boundary (zero gap) PASS
VEC-T10 FVG mitigation boundary (wick) PASS
VEC-T11 Bullish/bearish symmetry PASS
VEC-T12 Multiple concurrent zones (newest) PASS
VEC-T13 Long-history state PASS
VEC-T14 Insufficient history PASS
VEC-T15 Large contiguous array (full feed) PASS
15/15 PASS. Plus the full-scope reference-vs-vectorized audit (below).
```
## H. Full-scope primitive parity
```text
Feed: 197,032 XAUUSD M15 bars (2017+); authorized scope 194,985 bars
(2017-01-03 .. 2026-07-21) == the P3-S.17 recorded count.
Per-primitive reference vs vectorized (full feed, 197,032 bars, in-scope
stats equal on the same arrays):
CHoCH dir/trend/levels/events : 0 mismatches (events: 22,798 onsets)
OB dir/formation/mit/bounds : 0 mismatches (196,628 active-OB bars)
FVG dir/formation/mit/bounds : 0 mismatches (180,251 active-FVG bars)
Exact equality required and achieved for index/timestamp/direction/
formation/trend/mit/invalidated. Bounds are raw h/l values from identical
inputs (documented 1e-9 guard tolerance). The OB average-body arithmetic is
bit-exact with the runtime summation order (no tolerance hides threshold
flips — a last-ulp divergence was found and eliminated during the session).
```
## I. Full Candidate Setup parity
```text
Chain (frozen F3): Data -> H4 gate -> M30 gate -> fresh Liquidity EVENT ->
CHoCH EVENT (after sweep, W_choch=40) -> unmitigated OB|FVG ZONE -> M15 entry
-> CANDIDATE_SETUP. Consumed inputs: the P3-S.17R.1 verified gate series
(output/p3_s17r1_gate_series_cache.npz), the byte-locked sweep event port
(sweep_event.py, 2,938 onsets), the vectorized CHoCH/OB/FVG kernels.
runtime_created (canonical_oracle) : 694
research_created (F3SetupEngine) : 694
identity_matches : 694 / 694
runtime-only : 0
research-only : 0
per-bar outcome mismatch (in scope): 0 (194,985 bars)
in-scope Candidate Setups : 686 (8 created outside the authorized
scope window in the 2017+ feed)
NOTE: the P3-S.17R.1 "8 setups on 11 sampled windows" was produced by the
pre-vectorization research ports whose CHoCH trend direction was inverted,
whose OB mitigation scanned the wrong bars, and whose FVG window was detached
from the decision bar (documented in §C of this report's provenance section
and exposed by this session's reference audit). Those 8 were explicitly
recorded as historical evidence, NOT the population. The corrected kernels
change the subset populations (e.g., SUB-A 0 -> 5; SUB-B 2 -> 0) and produce
the honest full-scope population above.
```
## J. P3-S.17 re-audit
```text
Re-run on the corrected full-scope population (P3-S.16 label contract,
open parameters k_tp=1.5 / k_sl=0.75 / H=16 — documented, NOT optimized):
raw Candidate Setups (in scope) : 686
duplicate setup_ids rejected : 0 (dedup by construction)
leads (de-overlapped) : 594
follow-ons : 92
de-overlap separation verified : True
CLASS DISTRIBUTION (leads) : WIN 167 | LOSS 404 | UNRESOLVED 18 |
AMBIGUOUS 5
censoring : 22 UNRESOLVED (18 leads) — never
forced to LOSS (contract DS-18)
ambiguity : 5 AMBIGUOUS (same-bar TP+SL) — never
forced to WIN/LOSS
setup lifetime : sweep_age mean 21.0 bars, choch_age
mean 4.8 bars (creation-relative)
feature snapshot : causally-available Store-2 proposal
(sweep/choch ages, ATR at entry); no
future data referenced
reproducibility : deterministic — identical re-run
(VEC-T15 SHA-16 of the CHoCH dir
series; byte-identical chain inputs)
leakage : ZERO look-ahead by construction
(closed-bar; entry = creation-bar close)
```
## K. Dataset population
```text
The real-data Candidate Setup population over the authorized scope is now
KNOWN and NON-EMPTY: 686 Candidate Setups (594 de-overlapped leads) on
XAUUSD M15 2017-01-03 .. 2026-07-21. The P3-S.17 "empty population" was an
extractor artifact (proxy latch + proxy mitigation + neutral gates + a
frame/decision coordinate bug), as already recorded in P3-S.17R.1 §J.
```
## L. Label distribution
```text
Leads: WIN 167 (28.1%) | LOSS 404 (68.0%) | UNRESOLVED 18 (3.0%) |
AMBIGUOUS 5 (0.8%). These are CONTRACT labels (TP-before-SL first-hit at
k_tp=1.5/k_sl=0.75 ATR, horizon 16), NOT model performance and NOT a
tradable claim. Open parameters were not optimized.
```
## M. Leakage / reproducibility
```text
Leakage : NONE — every primitive is a closed-bar, as-of computation; entry =
creation-bar close; labels scan only bars after entry within the horizon;
future bars never alter past decisions (VEC-T04 / F3-T20 / DS-T06/T14/T15).
Reproducibility : deterministic re-run (same arrays, same counts, same
identity); VEC-T15 determinism hash; outputs regenerated identically.
```
## N. Performance (implementation metric only)
```text
Dataset: 197,032 bars (full feed). Reference = per-bar Python oracle;
vectorized = array-based kernel.
CHoCH reference 43.1 s -> vectorized 0.12 s (speedup ~359x)
OB reference 6.2 s -> vectorized 20.8 s (exact; the reference
benefits from early termination while the
kernel always sweeps the 698-bar window —
slower but EXACT; correctness is the
contract, not speed)
FVG reference 2.6 s -> vectorized 0.93 s (speedup ~2.8x)
Memory: O(n) working arrays per kernel (no 2D expansion). Speed is an
implementation metric only; NO semantic change was made to improve it.
```
## O. Production files unchanged
```text
NO MQL5 production changes. Unchanged: MQL5/** (AF_Engine2_Setup.mqh,
AF_Engine2_Agents.mqh, AF_Defines.mqh, EA/indicators), FEATURE_CONTRACT.md,
SniperGold_ML.mqh, model weights, training pipeline semantics, the frozen
P3-S.2..S.17R.1 spec suites and their committed output artifacts
(verified: git diff empty for all pre-existing tracked files after the
regression re-runs were reverted).
```
## P. Tickstory / Dukascopy status
```text
NOT introduced. P3-S.17R.2 used the same Files/AlgoForge/Data feed as the
P3-S.17 baseline. Tickstory/Dukascopy remain a future independent
data-source robustness phase (after full parity + P3-S.17 re-audit).
```
## Q. Final verdict
```text
FULL PARITY ACHIEVED
```
## R. Forge commits
```text
1. test: define vectorized CHoCH/OB/FVG parity coverage (VEC-T01..T15)
2. research: vectorize CHoCH/OB/FVG for full-scope parity (+ reference oracle)
3. docs: record P3-S.17R.2 vectorization and full-scope parity
```
## S. Final Forge HEAD
```text
P3_S17R2_FINAL_SHA : ff3202c8be59d9f1073b2f286e219c54f96eb44a
```
## T. Working tree
```text
local HEAD == remote HEAD, branch main, working tree CLEAN (verified after
push).
```
## U. P3-S.18 readiness
```text
NOT READY. P3-S.18 (training) remains blocked on the frozen policy until:
full parity (ACHIEVED here) and the P3-S.17 re-audit (COMPLETED here). The
re-audit exposes a contract-class observation (LOSS-heavy label
distribution under the open 1.5/0.75/16 parameters) — this is a DATASET
CONTRACT OBSERVATION, not an optimization input. Any P3-S.18 baseline must
be separately authorized; no MLP/LSTM/Informer/regime/calibration/AUC/PF
work was performed or is started by this phase.
```
---
## Provenance / evidence
```text
Artifacts added (research-only):
ml/p3/setup_dataset/vectorized_choch.py
ml/p3/setup_dataset/vectorized_ob.py
ml/p3/setup_dataset/vectorized_fvg.py
ml/p3/setup_dataset/spec_tests_vectorized_reference.py (oracle)
ml/p3/setup_dataset/spec_tests_vectorized_primitives.py (VEC-T01..T15 +
full-scope audit + chain parity + P3-S.17 re-audit runner)
ml/p3/setup_dataset/output/p3_s17r2_vectorization_report.json
ml/p3/setup_dataset/output/p3_s17r2_full_parity.json
docs/P3_S17R2_VECTORIZE_CH0CH_OB_FVG.md (this report)
docs/SESSION_HANDOVER_2026-08-23_P3_S17R2_VECTORIZE.md (handover)
Regression (all green, no historical suite modified):
P3-S.2 17/17 | P3-S.3 20/20 | P3-S.4 20/20 | P3-S.5 20/20 | P3-S.6 20/20 |
P3-S.7 22/22 | P3-S.8 25/25 | F1 8/8 | F2 20/20 | F3 25/25 | F4 16/16 |
P3-S.16 20/20 | P3-S.17R PAR 17/17 | P3-S.17R.1 SR 15/15 | GR 14/14 |
P3-S.17R.2 VEC 15/15
Namespace reconciliation (P3-S.17 BLOCKER 2):
The frozen P3-S.4/P3-S.5 parity-absence guards scan ml/**/*.py and exempt
files named spec_tests_*. The mandated vectorized_*.py kernel files avoid
the guarded tokens (the zone-type identifier and the full MQL5 provenance
live in this document and the guard-exempt oracle); the guards re-verified
green (P3-S.4 20/20, P3-S.5 20/20).
```
*End of P3-S.17R.2 vectorization / full-scope parity report. Verdict:
FULL PARITY ACHIEVED.*