From 80c5f53bb93d526cb0ae095f11f79823b744c5f9 Mon Sep 17 00:00:00 2001 From: mo Date: Sun, 23 Aug 2026 13:55:57 -0400 Subject: [PATCH] [GAP-047]: runtime confluence weights complete - ConfluenceScorer.cs: apply designed factor baseline weights - ConfluenceScorerTests.cs: cover 5.85 total weight, worked example, and overrides - TASK_GAP047_PART2_WEIGHT_RUNTIME_PROMPT.md: add accepted runtime prompt - docs/00-governance: record DEC implementation and fresh-freeze requirement - SPRINT_BOARD.md: mark GAP-047 Part 2 implemented Build: clean | Tests: 514 passing; Core 425 passing | Deploy: backup 20260823_135331 --- SPRINT_BOARD.md | 7 +- TASK_GAP047_PART2_WEIGHT_RUNTIME_PROMPT.md | 128 ++++++++++++++++++ docs/00-governance/2026-08-19-run-book.md | 10 +- docs/00-governance/active_work.md | 2 +- docs/00-governance/current_status.md | 17 ++- docs/00-governance/decisions.md | 13 +- src/NT8.Core/Intelligence/ConfluenceScorer.cs | 10 +- .../Intelligence/ConfluenceScorerTests.cs | 92 +++++++++++++ 8 files changed, 260 insertions(+), 19 deletions(-) create mode 100644 TASK_GAP047_PART2_WEIGHT_RUNTIME_PROMPT.md diff --git a/SPRINT_BOARD.md b/SPRINT_BOARD.md index ec19247..a8f82ab 100644 --- a/SPRINT_BOARD.md +++ b/SPRINT_BOARD.md @@ -41,12 +41,13 @@ - **Decided 2026-08-19:** collision resolved via MNQ (staged separately, DEC-20260819-01); MaxTradeRisk is per-position (total). Tier 1 check reorders to post-sizing. Implement and validate on NQ first — MNQ cutover is a later, separate step. - Prompt: `TASK_GAP045_GAP046_RISK_GUARDS_PROMPT.md` (Part 3 rewritten 2026-08-19, now fully actionable). -**[GAP-047] Confluence factor weights pre-populated to 1.0 — Part 1, offline re-scoring study** | Stage 1 | ✅ PART 1 COMPLETE — decision proposed 2026-08-23 +**[GAP-047] Confluence factor weights pre-populated to 1.0** | Stage 1 | ✅ PART 2 IMPLEMENTED — fresh freeze required - `ConfluenceScorer.cs` ~108–117 / ~410–419: the calculators' designed weights (0.20/0.15/0.15/0.20/0.15) are unreachable dead code. Every `STATE:` factor reads `x1.00`. - Designed total weight 5.85 vs actual 10.00. Grade A reachable on factors 1–5 alone under the design; close to structurally unreachable under equal weights. - Live example: 0.640 (C) as logged vs 0.727 (B) under designed weights. **Leading hypothesis for GAP-034a and for the low trade rate.** -- Part 1 is analysis only against existing `STATE:` / `SIGNAL_DETAIL:` lines — no runtime change, no risk. -- Prompt: `TASK_GAP047_WEIGHT_RESCORE_PROMPT.md`. Evidence: `tools/rescore/GAP-047_weight_rescore_output.md` / `.json`; proposed decision: DEC-20260823-01. Part 2 (the runtime change) must be staged separately after operator acceptance. +- Part 1 (offline study) complete 2026-08-23: `TASK_GAP047_WEIGHT_RESCORE_PROMPT.md`, evidence `tools/rescore/GAP-047_weight_rescore_output.md`/`.json`, commit `cbf45df`. +- **Part 2 implemented 2026-08-23 (DEC-20260823-01):** replaced the five wrong `1.0` literals with the designed values. Composite normalization already correct (dynamic `weightedScoreSum/totalWeight`) — verified, unchanged. No SIM trade required to validate; fully tested in `NT8.Core`. +- Prompt: `TASK_GAP047_PART2_WEIGHT_RUNTIME_PROMPT.md`. Verification: `verify-build.bat` 514/514, Core Release no-build 425/425, deploy backup `20260823_135331`. Fresh gate config freeze needed before any gate evidence collected after this lands. **[GAP-055] `MaxDailyTrades` does not survive a strategy restart** | Stage 0 | ✅ READY - In-memory counter only (`SimpleORBStrategy.cs` ~39). CME trading date 2026-08-17 took two trades under `MaxDailyTrades=1` across two NT8 sessions; the second session's `DayPnL=$271.96 → $545.44` proves NT8 treated them as one day. diff --git a/TASK_GAP047_PART2_WEIGHT_RUNTIME_PROMPT.md b/TASK_GAP047_PART2_WEIGHT_RUNTIME_PROMPT.md new file mode 100644 index 0000000..ff47e79 --- /dev/null +++ b/TASK_GAP047_PART2_WEIGHT_RUNTIME_PROMPT.md @@ -0,0 +1,128 @@ +# TASK: GAP-047 Part 2 — Apply the designed confluence factor weights +# Staged: 2026-08-23 (v7.0 review, Finding 1 — runtime change) +# APPROVED: 2026-08-23 — see DEC-20260823-01. Implementation approach resolved, +# not an open decision. Depends on GAP-047 Part 1 (`TASK_GAP047_WEIGHT_RESCORE_PROMPT.md`, +# complete, commit cbf45df) for its evidence base. +# Sprint: Stage 1 (P1-A step 2) +# Owner: Kilocode +# ───────────────────────────────────────────────────────────────── + +## THE DEFECT (confirmed by Part 1's study, DEC-20260823-01) + +`ConfluenceScorer`'s constructor (`src/NT8.Core/Intelligence/ConfluenceScorer.cs` ~105-117) +pre-populates `_factorWeights` with `1.0` for ALL TEN `FactorType` values: + + _factorWeights.Add(FactorType.Setup, 1.0); // correct — 1.0 by design + _factorWeights.Add(FactorType.Trend, 1.0); // correct — 1.0 by design + _factorWeights.Add(FactorType.Volatility, 1.0); // correct — 1.0 by design + _factorWeights.Add(FactorType.Timing, 1.0); // correct — 1.0 by design + _factorWeights.Add(FactorType.ExecutionQuality, 1.0); // correct — 1.0 by design + _factorWeights.Add(FactorType.NarrowRange, 1.0); // WRONG — should be 0.20 + _factorWeights.Add(FactorType.OrbRangeVsAtr, 1.0); // WRONG — should be 0.15 + _factorWeights.Add(FactorType.GapDirectionAlignment, 1.0); // WRONG — should be 0.15 + _factorWeights.Add(FactorType.BreakoutVolumeStrength, 1.0); // WRONG — should be 0.20 + _factorWeights.Add(FactorType.PriorDayCloseStrength, 1.0); // WRONG — should be 0.15 + +`ResolveWeight(type, fallbackWeight)` (~410-419) checks `_factorWeights` first and returns +the stored value if present — it always is, so each calculator's own designed weight +(passed as `fallbackWeight` via `factor.Weight`) is unreachable dead code. Confirmed against +`FactorCalculators.cs`: `NarrowRangeFactorCalculator` declares `0.20` (line 569), +`OrbRangeVsAtrFactorCalculator` declares `0.15` (line 670), `GapDirectionAlignmentCalculator` +declares `0.15` (line 797), `BreakoutVolumeStrengthCalculator` declares `0.20` (line 897), +`PriorDayCloseStrengthCalculator` declares `0.15` (line 1021). + +## NORMALIZATION — ALREADY CORRECT, NOTHING TO FIX HERE + +`Score()`'s composite (`ConfluenceScorer.cs` ~144-183) computes: + + weightedScoreSum += (weightedFactor.Score * weightedFactor.Weight); + totalWeight += weightedFactor.Weight; + ... + var weightedScore = totalWeight > 0.0 ? weightedScoreSum / totalWeight : 0.0; + +This already normalizes DYNAMICALLY by whatever weights are actually applied — it is not +hardcoded to divide by 10 or by 5.85. Once the five wrong literals below are corrected, +`totalWeight` will naturally sum to 5.85 and the composite will be correctly scaled with +no further change needed. Confirm this during Read-First; do not re-derive or "fix" the +normalization — it isn't broken. + +## THE CHANGE — approved, not an open decision + +In the `ConfluenceScorer` constructor, change exactly these five literals: + + NarrowRange: 1.0 → 0.20 + OrbRangeVsAtr: 1.0 → 0.15 + GapDirectionAlignment: 1.0 → 0.15 + BreakoutVolumeStrength: 1.0 → 0.20 + PriorDayCloseStrength: 1.0 → 0.15 + +Leave `Setup`, `Trend`, `Volatility`, `Timing`, `ExecutionQuality` at `1.0` — unchanged, +correct by design. + +DO NOT: touch `ResolveWeight()`, `UpdateFactorWeights()`, the `Score()` composite +calculation, any `FactorCalculators.cs` file, `MapScoreToGrade()` or its thresholds, +`MinTradeGrade`, or any NinjaScript/adapter-layer file. This task is scoped entirely to +`src/NT8.Core/Intelligence/ConfluenceScorer.cs` — five numeric literals. + +**Why not remove the pre-population and let `fallbackWeight` flow through instead?** +Considered and rejected — same runtime result, but a larger diff, and it would make the +dictionary conditionally authoritative depending on what each calculator happens to pass, +undermining the `UpdateFactorWeights()` API's own assumption that the dictionary is the +single source of truth. Changing the five literals directly is the smaller, more precise +fix for what is actually a wrong-placeholder-constant bug, not an architecture problem. + +## READ-FIRST + +1. `src/NT8.Core/Intelligence/ConfluenceScorer.cs` — constructor (~105-117), `Score()` + (~144-200), `ResolveWeight()` (~410-419), `UpdateFactorWeights()` (~302-334). +2. `src/NT8.Core/Intelligence/FactorCalculators.cs` — confirm the five weight literals + above still match lines 569/670/797/897/1021 exactly before editing; if any calculator's + weight has drifted since the Part 1 study, use the CURRENT value and flag the drift. +3. Any existing `ConfluenceScorer` unit tests that hardcode an expected composite score or + grade assuming equal 1.0 weights — these encode the bug's behavior, not the design, and + will need updating as part of this task, not left red. + +## TESTS (required) + +1. Unit test(s) asserting `ResolveWeight`/`Score()` now applies the five designed weights + for a synthetic factor set — confirm `totalWeight` sums to 5.85, not 10.0. +2. **Reproduce Part 1's worked example as an automated test.** Using the same factor scores + as the 2026-08-18 10:10:11.833 sample (`Setup=1.00, Trend=0.30, Volatility=0.70, + Timing=1.00, ExecutionQuality=0.80, NarrowRange=0.45, OrbRangeVsAtr=0.50, + GapDirectionAlignment=0.10, BreakoutVolumeStrength=0.85, PriorDayCloseStrength=0.70`), + assert `Score()` now returns `0.727` (not the old `0.640`) and grade `B`. This is the + same cross-check DEC-20260818-18/DEC-20260823-01's evidence chain already relies on — + closing the loop with a real test means this can never silently regress. +3. Fix any existing test broken by the weight change per Read-First item 3 — update the + expected values to the designed-weight result, do not skip or delete the test. +4. Confirm `UpdateFactorWeights()` still overrides correctly on top of the new baseline + (existing behavior, should be unaffected — verify, don't assume). + +## VALIDATION + +Unlike GAP-054, this change is fully contained in the platform-neutral `NT8.Core` layer — +no NinjaScript managed-order call is involved. **No SIM trade is required to validate +correctness**; the automated test in TESTS item 2 is the actual proof. Standard build/test +gate applies: +- `.\verify-build.bat` passes. +- `dotnet test tests\NT8.Core.Tests\NT8.Core.Tests.csproj --configuration Release --no-build --verbosity minimal` passes. +- Deploy per the usual process; a live/SIM session afterward is worth watching to observe + the real trade-frequency and grade-distribution shift in practice, but that's a + nice-to-have observation, not a blocking correctness gate the way GAP-054's SIM trade was. + +## FOLLOW-ON, NOT THIS TASK + +- A fresh Gate 3 configuration freeze/baseline is needed before collecting gate evidence + after this lands — trade-qualification behavior changes. Flag when this task is done; + don't run `preflight.ps1 --freeze` as part of this task itself. +- The workspace currently runs `MinTradeGrade=4` (B) while the Gate 3 plan targets + `MinTradeGrade=A` (5) — now that Grade A is reachable, whether to raise the live + threshold is an operator call, not part of this task. + +## GOVERNANCE + +Track as [GAP-047] Part 2 in SPRINT_BOARD.md. Update DEC-20260823-01 with an +Implementation Note on completion (commit hash, test results) — same pattern as +DEC-20260818-18's GAP-054 implementation note. +Reference: NT8_SDK_Master_Document_v7.0 Finding 1, Sections 4.6, 9.4 (P1-A), 12.2 (O-01). +DEC-20260823-01, `tools/rescore/GAP-047_weight_rescore_output.md`. diff --git a/docs/00-governance/2026-08-19-run-book.md b/docs/00-governance/2026-08-19-run-book.md index 3c60cf2..909a614 100644 --- a/docs/00-governance/2026-08-19-run-book.md +++ b/docs/00-governance/2026-08-19-run-book.md @@ -71,10 +71,12 @@ Both can run at the same time; neither touches runtime behavior. **Play 3 — Review GAP-048 output.** Confirm the four overloaded KillSwitch paths and four overloaded GradeFilter paths now log distinguishable reasons, that existing log-line formats are unchanged (only the reason string), and that the existing test suite still passes. Mark SPRINT_BOARD entry done. -**Play 4 — Review GAP-047 output.** This is a study, not a change — read the re-scoring report (equal-weight vs. designed-weight composite against historical STATE:/SIGNAL_DETAIL: lines). Confirm it reports the pre/post GAP-049 telemetry populations separately, per the task's caveat. Do NOT apply any weight change from this yet; it's an input to a future decision, not an approved fix. +**Play 4 — Review GAP-047 output and apply runtime weights. DONE 2026-08-23.** +Part 1: Kilocode built `tools/rescore/rescore_weights.py`, scanned 182 session logs, reproduced the required worked example exactly (equal=0.640, designed=0.727), and reported the STATE telemetry population (923 samples, direction-degraded per GAP-049) separately from the real signal population (81 samples), per the task's caveat. Independently re-derived the headline numbers from the raw distribution tables in `GAP-047_weight_rescore_output.md` rather than trusting the summary — they check out, including that the signal population's "25 cross into A" figure is a gross count net of a small number of downgrades (consistent with the report's own note that some real signals score worse under designed weights). +Part 2: DEC-20260823-01 was accepted, and `TASK_GAP047_PART2_WEIGHT_RUNTIME_PROMPT.md` applied the five designed baseline weights in `ConfluenceScorer.cs` with no normalization, calculator, threshold, or adapter/NinjaScript changes. Automated proof now covers default total weight 5.85, the worked example at 0.727 / Grade B, and `UpdateFactorWeights()` override behavior. A fresh gate freeze is required before gate evidence after this scoring-policy change. -**Play 5 — Runner trail fix (DEC-18 accepted). DONE 2026-08-21, source-verified.** -Kilocode implemented Option 0: removed the `OnBarUpdate()` `SetStopLoss` call on the runner signal, added no new `SetTrailStop` call, removed the stale `Diag_Breakeven` draw, cited NT8's own API docs on the mutual-exclusivity behavior. Independently re-read the changed code directly (not just the report) — confirmed. Build/tests/deploy all passed, hash matches. Two low-priority follow-ups logged in the process (GAP-056: breakeven params now fully inert, not scaler-scoped as previously assumed; GAP-057: no test seam for NT8 managed-order call assertions) — see `decisions.md` DEC-20260821-01. **Not committed yet** — sits on top of the still-unreconciled DASH-002 diff from Section 0; recommend two separate commits (DASH-002 first, GAP-054 second) when the operator is ready to commit. +**Play 5 — Runner trail fix (DEC-18 accepted). DONE 2026-08-21, source-verified. Committed 2026-08-23 as its own isolated commit (`28c30bc`), exactly as recommended in Section 0.** +Kilocode implemented Option 0: removed the `OnBarUpdate()` `SetStopLoss` call on the runner signal, added no new `SetTrailStop` call, removed the stale `Diag_Breakeven` draw, cited NT8's own API docs on the mutual-exclusivity behavior. Independently re-read the changed code directly (not just the report) — confirmed. Build/tests/deploy all passed, hash matches. Two low-priority follow-ups logged in the process (GAP-056: breakeven params now fully inert, not scaler-scoped as previously assumed; GAP-057: no test seam for NT8 managed-order call assertions) — see `decisions.md` DEC-20260821-01. The DASH-002 reconciliation from Section 0 is also resolved — committed as `d84949c` ahead of the GAP-054 commit, working tree is clean. **Play 6 — Validate GAP-054 before any live exposure. STILL PENDING — this is the next actual step.** NinjaTrader needs to be reopened for a manual NinjaScript compile, then a SIM trade run reaching +25 ticks or more, confirming no `BREAKEVEN runner stop ->` line appears and the runner's exit is materially better than entry + 1 tick (a trail stop in the execution grid, not a fixed stop), and that the scaler leg's target behavior is unchanged. Only after this passes is GAP-054 done and RUNNER-001 unblocked. @@ -110,7 +112,7 @@ This is a separate, later step — not part of today's six tasks. Once GAP-054, - [x] Section 1 decisions recorded — all accepted 2026-08-19 - [ ] GAP-048 taxonomy: implemented, tested, SPRINT_BOARD updated -- [ ] GAP-047 Part 1: study delivered, read, weight-change decision explicitly deferred (not silently applied) +- [x] GAP-047 Part 1/2: study delivered, DEC-20260823-01 accepted, runtime designed weights implemented and tested - [ ] GAP-054 runner trail: implemented, validated on sim/replay before any live gate run - [ ] GAP-055 persistence: implemented, restart/rollover-boundary test passed - [ ] GAP-045/046 all three parts: implemented on NQ, including the post-sizing Tier 1 reorder and the MNQ tick-table check diff --git a/docs/00-governance/active_work.md b/docs/00-governance/active_work.md index a251abd..ca44a29 100644 --- a/docs/00-governance/active_work.md +++ b/docs/00-governance/active_work.md @@ -16,7 +16,7 @@ Full detail: `docs/NT8_SDK_Master_Document_v7.0_Complete.docx`. | 2 | **GAP-045/046 guards** — resolved: MNQ (cutover staged separately) + per-position semantics | `TASK_GAP045_GAP046_RISK_GUARDS_PROMPT.md` (Part 3 now actionable) | Kilocode, on current NQ config | All high-ATR days | | 3 | **GAP-048** — split the reject taxonomy | `TASK_GAP048_REJECT_TAXONOMY_PROMPT.md` | Kilocode | Nothing — diagnostics only, safe now | | 4 | **GAP-055** — persist `MaxDailyTrades` across restarts | `TASK_GAP055_MAXDAILYTRADES_PERSIST_PROMPT.md` | Kilocode | Gate Run #3 sample integrity | -| 5 | **GAP-047 Part 1** — offline factor-weight re-scoring study | `TASK_GAP047_WEIGHT_RESCORE_PROMPT.md` — completed 2026-08-23, evidence in `tools/rescore/`, DEC-20260823-01 proposed | Kilocode | Part 2 blocked on operator weighting decision | +| 5 | **GAP-047** — Part 1 complete (commit `cbf45df`), Part 2 runtime weight fix implemented 2026-08-23 | `TASK_GAP047_PART2_WEIGHT_RUNTIME_PROMPT.md` — verification passed, deploy backup `20260823_135331` | Kilocode | Fresh gate freeze needed before gate evidence | | 6 | **GAP-054** — auto-breakeven destroys the runner trail | `TASK_GAP054_RUNNER_TRAIL_PROMPT.md` — **Option 0 implemented + source-verified 2026-08-21, NOT yet SIM-validated, NOT committed** | Kilocode implemented; operator validates | **RUNNER-001**, still blocked until SIM/replay validation passes | | 7 | **GAP-049** — telemetry `STATE:` score is direction-incorrect | `TASK_GAP049_TELEMETRY_DIRECTION_PROMPT.md` | Kilocode | Dashboard trustworthiness; degrades item 5 | | 8 | **MNQ cutover** — reconfigure instrument, retune risk params for $0.50/tick, fresh Gate 3 freeze | not yet staged as its own TASK file | Operator + Kilocode | Only after items 2, 4, 5, 6 pass validation on NQ | diff --git a/docs/00-governance/current_status.md b/docs/00-governance/current_status.md index a971241..94f9137 100644 --- a/docs/00-governance/current_status.md +++ b/docs/00-governance/current_status.md @@ -1,5 +1,20 @@ # Current Status — NT8 SDK -**Last Updated:** 2026-08-23 (GAP-047 Part 1 offline re-scoring study complete; decision proposed) +**Last Updated:** 2026-08-23 (GAP-047 Part 2 runtime designed weights implemented) + +--- + +## 2026-08-23 — GAP-047 Part 2 IMPLEMENTED, fresh gate freeze required + +Kilocode executed `TASK_GAP047_PART2_WEIGHT_RUNTIME_PROMPT.md`. The runtime scoring fix is intentionally minimal: `ConfluenceScorer` now uses the designed baseline weights for the five non-core factors (`0.20/0.15/0.15/0.20/0.15`) while leaving scoring normalization, overrides, calculators, grade thresholds, and NinjaScript/adapter files unchanged. + +Evidence: +- `src/NT8.Core/Intelligence/ConfluenceScorer.cs` changed only the five approved baseline weight constants. +- `tests/NT8.Core.Tests/Intelligence/ConfluenceScorerTests.cs` now asserts total default weight is 5.85, reproduces the 2026-08-18 worked example at weighted score 0.727 / Grade B, and verifies `UpdateFactorWeights()` still overrides the baseline. +- `verify-build.bat`: passed, 514/514 tests. +- `dotnet test tests\NT8.Core.Tests\NT8.Core.Tests.csproj --configuration Release --no-build --verbosity minimal`: passed, 425/425. +- `deployment\deploy-to-nt8.bat`: completed; backup `deployment\backups\20260823_135331`; `NinjaTrader.Custom.dll` was not present to invalidate. + +Next required action: run the normal manual NT8 compile/deploy hygiene when starting NinjaTrader, then capture a fresh Gate 3 configuration freeze/baseline before collecting any gate evidence because trade-qualification behavior changed. No SIM trade is required to prove correctness for this platform-neutral `NT8.Core` change. --- diff --git a/docs/00-governance/decisions.md b/docs/00-governance/decisions.md index f8878cf..2f5a5fb 100644 --- a/docs/00-governance/decisions.md +++ b/docs/00-governance/decisions.md @@ -16,13 +16,16 @@ Use this file to record durable project decisions that affect implementation pat ### DEC-20260823-01 - **ID:** DEC-20260823-01 - **Date:** 2026-08-23 -- **Status:** proposed +- **Status:** **accepted** (2026-08-23) +- **Operator Decision (2026-08-23):** Approved — proceed with the designed weights. +- **Implementation approach resolved (Claude, 2026-08-23):** Read `ConfluenceScorer.cs` directly rather than assume. Two things confirmed that shape Part 2: (1) `Score()`'s composite (`weightedScoreSum / totalWeight`, ~line 183) already normalizes dynamically by whatever weights are actually applied — it is NOT hardcoded to divide by 10 or 5.85, so there is no separate normalization defect to fix; removing the bug is sufficient on its own. (2) The five wrong weights are hardcoded `1.0` literals in the constructor (`ConfluenceScorer.cs` ~113-117) rather than the calculators' own designed values ever being consulted, even though a `ResolveWeight()`/`UpdateFactorWeights()` mechanism already exists to make the dictionary the authoritative source — this reads as a placeholder value that was never replaced, not an architectural gap. **Resolved fix: change the five literals directly** (`NarrowRange 1.0→0.20`, `OrbRangeVsAtr 1.0→0.15`, `GapDirectionAlignment 1.0→0.15`, `BreakoutVolumeStrength 1.0→0.20`, `PriorDayCloseStrength 1.0→0.15`, verified against `FactorCalculators.cs` lines 569/670/797/897/1021) rather than removing the pre-population and routing through `ResolveWeight`'s fallback path — smaller diff, same result, keeps the dictionary as the single source of truth the API already assumes. The "configuration-driven" alternative floated in the original task is not pursued now — no scenario surfaced that needs it, and it would add parameter surface for no behavioral benefit. Flag if you want it anyway. - **Context:** GAP-047 Part 1 completed the offline equal-weight versus designed-weight re-scoring study against existing NT8 SDK session logs. The study scanned 182 `session_*.log` files under `C:\Users\billy\Documents\NinjaTrader 8\log\nt8-sdk`, including `ARCHIVE`, and reproduced the required worked example from `session_20260818_071117.log` at 10:10:11.833: equal=0.640, designed=0.727. The `STATE:` telemetry population remains direction-degraded by GAP-049 and is reported separately from real signal samples. No runtime trading code was changed. - **Evidence:** `tools/rescore/GAP-047_weight_rescore_output.md` and `.json`. Headline results: `STATE:` telemetry samples=923, designed weights crossed A while equal weights did not in 82 samples and crossed B while equal weights did not in 164 samples. Real signal factor samples=81, designed weights crossed A while equal weights did not in 25 samples. Current logs contained 0 `SIGNAL_DETAIL:` lines; signal scoring used real `SIGNAL` lines followed by their numeric `Factors:` breakdowns. -- **Decision:** Proposed operator decision: proceed to GAP-047 Part 2 planning with an explicit weighting policy decision. The study supports replacing accidental equal 1.00 weights with the designed factor weights or making the weighting model configuration-driven, but the runtime change must be staged separately because it changes scoring behavior and `ConfigHash`. -- **Consequences:** Designed weights would materially increase grade eligibility in the direction-degraded telemetry population and upgrade a meaningful subset of real signal samples to Grade A. Because some real signal samples also downgrade under designed weights, the decision should be treated as a scoring-policy change rather than a pure relaxation. A fresh configuration freeze is required before any gate evidence is collected after implementation. -- **Related Files:** `tools/rescore/rescore_weights.py`, `tools/rescore/GAP-047_weight_rescore_output.md`, `tools/rescore/GAP-047_weight_rescore_output.json`, `TASK_GAP047_WEIGHT_RESCORE_PROMPT.md` -- **Action Required:** Operator to accept/reject the proposed direction, then stage GAP-047 Part 2 as a separate runtime-change prompt. +- **Decision:** Replace the accidental equal 1.00 weights with the designed factor weights, per the resolved implementation approach above. Staged as `TASK_GAP047_PART2_WEIGHT_RUNTIME_PROMPT.md`. +- **Consequences:** Designed weights will materially increase grade eligibility in the direction-degraded telemetry population and upgrade a meaningful subset of real signal samples to Grade A — this is the intended effect, directly targeting the low-trade-frequency problem. Because some real signal samples also downgrade under designed weights, this is a scoring-policy change, not a pure relaxation — expect a shift in which setups qualify, not just how many. Unlike GAP-054, this change is fully testable in the platform-neutral `NT8.Core` layer with ordinary unit tests — no NinjaTrader-specific managed-order call is involved, so no SIM trade is required to prove correctness (see `TASK_GAP047_PART2_WEIGHT_RUNTIME_PROMPT.md` Validation). A fresh gate configuration freeze/baseline is still required before any gate evidence is collected after this lands, since trade-qualification behavior changes. Also worth revisiting once live: the workspace currently runs `MinTradeGrade=4` (B) while the Gate 3 plan targets `MinTradeGrade=A` (5) — now that Grade A is actually reachable, the operator may want to reconsider which threshold to gate on. +- **Related Files:** `tools/rescore/rescore_weights.py`, `tools/rescore/GAP-047_weight_rescore_output.md`, `tools/rescore/GAP-047_weight_rescore_output.json`, `TASK_GAP047_WEIGHT_RESCORE_PROMPT.md`, `TASK_GAP047_PART2_WEIGHT_RUNTIME_PROMPT.md`, `src/NT8.Core/Intelligence/ConfluenceScorer.cs` +- **Implementation Note (2026-08-23):** Implemented in `src/NT8.Core/Intelligence/ConfluenceScorer.cs` by changing only the five approved constructor baseline weights: `NarrowRange=0.20`, `OrbRangeVsAtr=0.15`, `GapDirectionAlignment=0.15`, `BreakoutVolumeStrength=0.20`, and `PriorDayCloseStrength=0.15`. `Score()` normalization, `ResolveWeight()`, `UpdateFactorWeights()`, factor calculators, grade thresholds, and adapter/NinjaScript files were left unchanged. Added `ConfluenceScorerTests` coverage proving the default total weight is 5.85, the 2026-08-18 10:10:11.833 worked example now scores 0.727 / Grade B instead of the old 0.640, and `UpdateFactorWeights()` still overrides the new baseline. Verification: `verify-build.bat` passed with 514/514 tests (425 Core, 79 Integration, 10 Performance); `dotnet test tests\NT8.Core.Tests\NT8.Core.Tests.csproj --configuration Release --no-build --verbosity minimal` passed 425/425; `deployment\deploy-to-nt8.bat` completed with backup `20260823_135331` and noted `NinjaTrader.Custom.dll` was not present to invalidate. +- **Action Required:** Fresh Gate 3 configuration freeze/baseline is required before collecting gate evidence after this scoring-policy change. Manual NT8 compile remains part of normal deploy hygiene, but no SIM trade is required for correctness. ### DEC-20260821-01 - **ID:** DEC-20260821-01 diff --git a/src/NT8.Core/Intelligence/ConfluenceScorer.cs b/src/NT8.Core/Intelligence/ConfluenceScorer.cs index fbb0ed0..25d7a54 100644 --- a/src/NT8.Core/Intelligence/ConfluenceScorer.cs +++ b/src/NT8.Core/Intelligence/ConfluenceScorer.cs @@ -110,11 +110,11 @@ namespace NT8.Core.Intelligence _factorWeights.Add(FactorType.Volatility, 1.0); _factorWeights.Add(FactorType.Timing, 1.0); _factorWeights.Add(FactorType.ExecutionQuality, 1.0); - _factorWeights.Add(FactorType.NarrowRange, 1.0); - _factorWeights.Add(FactorType.OrbRangeVsAtr, 1.0); - _factorWeights.Add(FactorType.GapDirectionAlignment, 1.0); - _factorWeights.Add(FactorType.BreakoutVolumeStrength, 1.0); - _factorWeights.Add(FactorType.PriorDayCloseStrength, 1.0); + _factorWeights.Add(FactorType.NarrowRange, 0.20); + _factorWeights.Add(FactorType.OrbRangeVsAtr, 0.15); + _factorWeights.Add(FactorType.GapDirectionAlignment, 0.15); + _factorWeights.Add(FactorType.BreakoutVolumeStrength, 0.20); + _factorWeights.Add(FactorType.PriorDayCloseStrength, 0.15); } /// diff --git a/tests/NT8.Core.Tests/Intelligence/ConfluenceScorerTests.cs b/tests/NT8.Core.Tests/Intelligence/ConfluenceScorerTests.cs index dae2feb..73f245f 100644 --- a/tests/NT8.Core.Tests/Intelligence/ConfluenceScorerTests.cs +++ b/tests/NT8.Core.Tests/Intelligence/ConfluenceScorerTests.cs @@ -208,6 +208,68 @@ namespace NT8.Core.Tests.Intelligence Assert.AreEqual(0.666666, result.WeightedScore, 0.0005); } + [TestMethod] + public void CalculateScore_DefaultDesignedWeights_TotalWeightIs585() + { + var scorer = CreateScorer(); + var intent = CreateIntent(); + var context = CreateContext(); + var bar = CreateBar(); + var factors = CreateWorkedExampleFactors(); + + var result = scorer.CalculateScore(intent, context, bar, factors); + + Assert.AreEqual(5.85, Convert.ToDouble(result.Metadata["total_weight"]), 0.000001); + AssertFactorWeight(result, FactorType.Setup, 1.0); + AssertFactorWeight(result, FactorType.Trend, 1.0); + AssertFactorWeight(result, FactorType.Volatility, 1.0); + AssertFactorWeight(result, FactorType.Timing, 1.0); + AssertFactorWeight(result, FactorType.ExecutionQuality, 1.0); + AssertFactorWeight(result, FactorType.NarrowRange, 0.20); + AssertFactorWeight(result, FactorType.OrbRangeVsAtr, 0.15); + AssertFactorWeight(result, FactorType.GapDirectionAlignment, 0.15); + AssertFactorWeight(result, FactorType.BreakoutVolumeStrength, 0.20); + AssertFactorWeight(result, FactorType.PriorDayCloseStrength, 0.15); + } + + [TestMethod] + public void CalculateScore_WorkedExample_UsesDesignedWeightsAndReturnsB() + { + var scorer = CreateScorer(); + var intent = CreateIntent(); + var context = CreateContext(); + var bar = CreateBar(); + var factors = CreateWorkedExampleFactors(); + + var result = scorer.CalculateScore(intent, context, bar, factors); + + Assert.AreEqual(0.640, result.RawScore, 0.0005); + Assert.AreEqual(0.727, result.WeightedScore, 0.0005); + Assert.AreEqual(TradeGrade.B, result.Grade); + } + + [TestMethod] + public void UpdateFactorWeights_OverridesDesignedBaselineWeights() + { + var scorer = CreateScorer(); + var intent = CreateIntent(); + var context = CreateContext(); + var bar = CreateBar(); + var updates = new Dictionary(); + updates.Add(FactorType.NarrowRange, 1.0); + scorer.UpdateFactorWeights(updates); + + var factors = new List(); + factors.Add(new FixedFactorCalculator(FactorType.Setup, 1.0, 1.0)); + factors.Add(new FixedFactorCalculator(FactorType.NarrowRange, 0.0, 0.20)); + + var result = scorer.CalculateScore(intent, context, bar, factors); + + Assert.AreEqual(2.0, Convert.ToDouble(result.Metadata["total_weight"]), 0.000001); + Assert.AreEqual(0.5, result.WeightedScore, 0.000001); + AssertFactorWeight(result, FactorType.NarrowRange, 1.0); + } + [TestMethod] public void UpdateFactorWeights_InvalidWeight_ThrowsArgumentException() { @@ -357,6 +419,36 @@ namespace NT8.Core.Tests.Intelligence return factors; } + private static List CreateWorkedExampleFactors() + { + var factors = new List(); + factors.Add(new FixedFactorCalculator(FactorType.Setup, 1.00, 1.0)); + factors.Add(new FixedFactorCalculator(FactorType.Trend, 0.30, 1.0)); + factors.Add(new FixedFactorCalculator(FactorType.Volatility, 0.70, 1.0)); + factors.Add(new FixedFactorCalculator(FactorType.Timing, 1.00, 1.0)); + factors.Add(new FixedFactorCalculator(FactorType.ExecutionQuality, 0.80, 1.0)); + factors.Add(new FixedFactorCalculator(FactorType.NarrowRange, 0.45, 0.20)); + factors.Add(new FixedFactorCalculator(FactorType.OrbRangeVsAtr, 0.50, 0.15)); + factors.Add(new FixedFactorCalculator(FactorType.GapDirectionAlignment, 0.10, 0.15)); + factors.Add(new FixedFactorCalculator(FactorType.BreakoutVolumeStrength, 0.85, 0.20)); + factors.Add(new FixedFactorCalculator(FactorType.PriorDayCloseStrength, 0.70, 0.15)); + return factors; + } + + private static void AssertFactorWeight(ConfluenceScore result, FactorType type, double expectedWeight) + { + for (var i = 0; i < result.Factors.Count; i++) + { + if (result.Factors[i].Type == type) + { + Assert.AreEqual(expectedWeight, result.Factors[i].Weight, 0.000001); + return; + } + } + + Assert.Fail("Missing factor type {0}", type); + } + private class FixedFactorCalculator : IFactorCalculator { private readonly FactorType _type;