diff --git a/SPRINT_BOARD.md b/SPRINT_BOARD.md index 64c1708..5ef8124 100644 --- a/SPRINT_BOARD.md +++ b/SPRINT_BOARD.md @@ -76,6 +76,9 @@ **[GAP-051] `MicroUpgradeThreshold` advisory re-fires every restart** | Stage 1 | ✅ IMPLEMENTED — deploy skipped by operator - `_microUpgradeSuggested` resets to `false` in `State.SetDefaults`, which runs on every strategy enable — an account already above `MicroUpgradeThreshold` gets `TIER_UPGRADE_SUGGESTED` re-logged every restart, not once per lifetime. Advisory-only (`Print`/`FileLog`), never touches order flow, sizing, or risk. - Prompt: `TASK_GAP051_MICRO_UPGRADE_PERSISTENCE_PROMPT.md`. Implemented Option A: once-per-account-lifetime advisory persistence in a dedicated `micro_upgrade_suggested_.json` file under the configured/default log directory. Missing/corrupt files safely fall back to allowing the reminder and logging a warning; `Account == null`/non-realtime paths perform no file I/O. Verification: focused tests 5/5, `verify-build.bat` 550/550, Core Release no-build 461/461. Deployment skipped per operator instruction. +**[GAP-052] Two hardcoded tick-value tables have already drifted out of sync** | Stage 1 | ✅ IMPLEMENTED — deploy skipped by operator +- `BasicRiskManager.GetTickValue` (6 symbols) and `BasicPositionSizer.GetTickValue` (8 symbols) disagreed: `BasicPositionSizer` supported `6E`/`6A`, while `BasicRiskManager` fell through to its `default: 12.50`. For `6A`, the real tick value is `$10.00`, creating a latent 25% risk-calculation error if traded. NQ/MNQ were unaffected and remain unchanged. +- Prompt: `TASK_GAP052_TICK_VALUE_CONSOLIDATION_PROMPT.md`. Implemented Option A: shared platform-neutral `InstrumentTickValueTable` containing the union of existing symbols (`ES`, `MES`, `NQ`, `MNQ`, `CL`, `GC`, `6E`, `6A`). Basic and Advanced risk/sizing helpers now delegate to the shared table, and `6A` risk validation uses `$10.00` instead of falling through to `$12.50`. Verification: focused tests 26/26, `verify-build.bat` 552/552, Core Release no-build 463/463. Deployment skipped per operator instruction. ### Also raised by the review, not yet prompted GAP-051 (`MicroUpgradeThreshold` fires every session) · GAP-052 (two hardcoded tick-value tables) · GAP-053 (`executive_summary.md` and `roadmap.md` Sprint 3 list present ~12 completed tasks as open) · diff --git a/TASK_GAP052_TICK_VALUE_CONSOLIDATION_PROMPT.md b/TASK_GAP052_TICK_VALUE_CONSOLIDATION_PROMPT.md new file mode 100644 index 0000000..63e2e97 --- /dev/null +++ b/TASK_GAP052_TICK_VALUE_CONSOLIDATION_PROMPT.md @@ -0,0 +1,114 @@ +# TASK: GAP-052 — Two hardcoded tick-value tables have already drifted out of sync +# Staged: 2026-08-18 (v7.0 review, "raised, not yet prompted"), evidenced 2026-08-23/24 +# Sprint: Stage 1 — real latent defect for 6E/6A, zero risk for currently-traded NQ/MNQ +# Owner: Kilocode +# ───────────────────────────────────────────────────────────────── + +## THE DEFECT + +Two independent, unsynchronized `private static double GetTickValue(string symbol)` +methods exist: + + BasicRiskManager.cs ~178-191: ES, MES, NQ, MNQ, CL, GC (6 symbols) → default 12.50 + BasicPositionSizer.cs ~155-170: ES, MES, NQ, MNQ, CL, GC, 6E, 6A (8 symbols) → default 12.50 + +This is not just a duplication risk flagged by the original review — **the +two tables have already drifted out of sync.** `BasicPositionSizer` lists +`6E` ($12.50/tick) and `6A` ($10.00/tick); `BasicRiskManager` does not list +either and falls through to `default: return 12.50`. + +For `6E`, the default happens to match (12.50), so no live bug there today. +For **`6A`, it does not**: `BasicPositionSizer` would size a 6A position +using the correct $10.00/tick, while `BasicRiskManager.ValidateOrder()` / +`CalculateTradeRisk()` would validate that same position's risk using +$12.50/tick instead — a 25% risk-calculation error, silently, if this +symbol is ever traded. `MaxTradeRisk` enforcement on 6A would currently be +wrong. + +GAP-045/046 (this session) already confirmed `MNQ` is correctly present and +matching ($0.50) in both tables — this finding is about the tables' +remaining divergence, not about MNQ, and is not something GAP-045/046 was +scoped to catch (it only checked the specific symbol that task cared about). + +## WHY IT MATTERS NOW + +Not urgent for the currently-traded NQ (matches in both tables). But it's a +live, confirmed correctness defect the moment any strategy instance trades +6E or 6A, and the fact that these two tables have ALREADY diverged once +(silently, with nobody noticing until this review) is itself evidence this +pattern will keep drifting unless consolidated. + +## READ-FIRST + +1. Read both `GetTickValue` methods in full, side by side. +2. Check whether `NinjaTrader.Instrument.MasterInstrument.TickSize`/ + `PointValue` is already used elsewhere in this codebase as a live, + correct tick-value source (yes — `NT8StrategyBase.ValidateStartupRiskConfiguration`, + added this session for GAP-045/046, already falls back to + `Instrument.MasterInstrument` when populated). Consider whether that's + available to `BasicRiskManager`/`BasicPositionSizer` too, or whether + those classes are intentionally platform-neutral (`NT8.Core`, no + NinjaTrader assembly reference) and therefore CANNOT reach + `Instrument.MasterInstrument` directly — confirm which before assuming + either approach is trivial. + +## THE CHANGE + +Consolidate to a single source of truth. Two reasonable shapes — pick one +and justify the choice in your writeback, don't silently default to +whichever is easiest: + +**Option A — shared static table.** A single `TickValueTable` (or similar) +in `NT8.Core`, containing the union of both existing tables (add the +missing `6E`/`6A` entries), with both `BasicRiskManager.GetTickValue` and +`BasicPositionSizer.GetTickValue` calling into it. Smallest diff, keeps the +existing "hardcoded Phase 0 table, configurable later" architecture intact. + +**Option B — resolve from `Instrument.MasterInstrument`** where available, +falling back to the hardcoded table only when the adapter can't supply it +(mirroring the pattern GAP-045/046 already established). Larger change, +removes the duplication-drift risk permanently rather than fixing today's +instance of it — but only pursue this if `NT8.Core`'s platform-neutrality +constraint doesn't block it; if it does, Option A is correct and Option B +should be logged as a future architectural note instead. + +Either way: **add the missing `6E`/`6A` entries so `BasicRiskManager` +matches `BasicPositionSizer` exactly**, regardless of which structural +option you choose — that part is not optional. + +## DO NOT + +- Do not change `MaxTradeRisk`/`MaxStopTicks`/any other risk parameter for + NQ or MNQ as part of this — those are unaffected (both tables already + agree on those two). +- Do not change sizing or risk-validation logic itself, only the tick-value + lookup both already call into. +- Do not add new tradeable-symbol support beyond making the two tables + consistent (i.e. don't go add e.g. RTY or YM unless they were already in + one of the two tables). + +## TESTS (required) + +1. A test asserting `BasicRiskManager.GetTickValue` (or its consolidated + replacement) and `BasicPositionSizer.GetTickValue` (or its consolidated + replacement) return identical values for every symbol either currently + lists — this is the regression test that would have caught today's + 6E/6A divergence and must catch any future one. +2. A test confirming `6A` now resolves to `$10.00` (not the old `$12.50` + default) from whichever code path `BasicRiskManager`'s risk calculation + actually uses. + +## VALIDATION (operator) + +None required — NQ/MNQ (the only currently-traded symbols) are unaffected +by this change; this closes a latent defect for symbols not currently in +use. + +## GOVERNANCE + +Track as [GAP-052] in SPRINT_BOARD.md. Update `docs/00-governance/decisions.md` +DEC-20260823-07 status to `implemented` with an implementation note stating +which option (A or B) was chosen and why, and confirming the platform- +neutrality question from READ-FIRST. +Reference: this task, DEC-20260823-07, GAP-045/GAP-046 (`d652e29`) for the +MNQ tick-value confirmation this finding builds on. diff --git a/docs/00-governance/decisions.md b/docs/00-governance/decisions.md index 63c8c39..a73a8c6 100644 --- a/docs/00-governance/decisions.md +++ b/docs/00-governance/decisions.md @@ -24,6 +24,15 @@ Use this file to record durable project decisions that affect implementation pat - **Related Files:** `src/NT8.Adapters/Strategies/NT8StrategyBase.cs` (`MaybeWriteRejectSummarySnapshot`/`LogRejectRateLimited`/`ResetRejectTracking`/`WriteSessionHeader` ~1444-1517), `src/NT8.Strategies/Examples/SimpleORBStrategy.cs` (`OnBar` ~355-432, `RecordSignalRejection` ~1015-1026), `session_20260823_230519.log` - **Implementation Note (2026-08-25):** GAP-060 implemented as logging/observability only. `NT8StrategyBase.MaybeWriteRejectSummarySnapshot()` no longer has a blanket midnight-to-10:00 AM suppression gate; suppression now delegates to an ORB-window-aware helper and `SimpleORBNT8` overrides that helper so the suppressed window is today's configured 09:30 + `OpeningRangeMinutes`. The once-after-ORB snapshot flag now resets per `barTime.Date`, allowing a new post-ORB summary every day in a continuous multi-day session. `OnBarUpdate()` now calls `MaybeWriteRejectSummarySnapshot(Time[0])` on the live bar heartbeat after the first realtime-bar guard, so 15-minute summary cadence can flush from regular processed bars and is not solely dependent on a newly logged reject. Existing `_rejectDetailsLogged` one-detail-line-per-reason rate limiting, reject reason strings, `REJECT:`/`REJECT SUMMARY:` formats, order flow, sizing, risk, and real trade decisions were unchanged. Open question resolved as possibility **(a)**: the missing `OrbRangeNotEstablished` visibility was adapter summary reporting, not a second SimpleORB rejection defect. A focused `SimpleORBStrategy.OnBar()` test proves the no-breakout RTH path records `OrbRangeNotEstablished` both while the ORB is building and after ORB close when no breakout confirms. Verification: focused GAP-060 tests passed 8/8; `verify-build.bat` passed with 543/543 tests (454 Core, 79 Integration, 10 Performance); `dotnet test tests\NT8.Core.Tests\NT8.Core.Tests.csproj --configuration Release --no-build --verbosity minimal` passed 454/454. - **Action Required:** Deployment remains pending. `deployment\deploy-to-nt8.bat` was attempted on 2026-08-25 but failed because NinjaTrader.exe PID 18800 locked `NT8.Core.dll`; operator instructed Kilocode to commit without deploy. After NinjaTrader is closed, rerun deployment, start NT8, manually compile NinjaScript, and in the next SIM session spanning a full trading day confirm `REJECT SUMMARY` appears throughout RTH at a reasonable cadence. +### DEC-20260823-07 +- **ID:** DEC-20260823-07 +- **Date:** 2026-08-23/24 +- **Status:** implemented +- **Context:** GAP-052 was flagged by the original v7.0 review as "two hardcoded tick-value tables" without further detail. Confirmed duplicated `GetTickValue(string symbol)` helpers in Basic risk/sizing and additional Advanced risk/sizing helpers. The concrete defect was `6A`: `BasicPositionSizer` used `$10.00` while `BasicRiskManager` fell through to `$12.50`, producing a 25% risk-calculation mismatch if 6A were traded. NQ/MNQ were already consistent and remain unchanged. +- **Decision:** Implement Option A — a shared static table — because `BasicRiskManager`, `BasicPositionSizer`, `AdvancedRiskManager`, and `AdvancedPositionSizer` live in platform-neutral `NT8.Core` and cannot directly depend on NinjaTrader `Instrument.MasterInstrument` APIs without changing project layering. Option B remains a possible future adapter-supplied enhancement, not part of this platform-neutral fix. +- **Implementation Note (2026-08-25):** Added `NT8.Core.Common.InstrumentTickValueTable` with the union of existing supported symbols (`ES`, `MES`, `NQ`, `MNQ`, `CL`, `GC`, `6E`, `6A`) and updated all four risk/sizing helpers to delegate to it. This fixes the concrete `6A` defect (`$10.00` instead of the old BasicRiskManager `$12.50` default) and removes the duplicated hardcoded tables from those helpers. Verification: focused `BasicRiskManagerTests` passed 26/26; `verify-build.bat` passed with 552/552 tests (463 Core, 79 Integration, 10 Performance); `dotnet test tests\NT8.Core.Tests\NT8.Core.Tests.csproj --configuration Release --no-build --verbosity minimal` passed 463/463. +- **Related Files:** `src/NT8.Core/Common/InstrumentTickValueTable.cs`, `src/NT8.Core/Risk/BasicRiskManager.cs`, `src/NT8.Core/Sizing/BasicPositionSizer.cs`, `src/NT8.Core/Risk/AdvancedRiskManager.cs`, `src/NT8.Core/Sizing/AdvancedPositionSizer.cs`, `tests/NT8.Core.Tests/Risk/BasicRiskManagerTests.cs`, `TASK_GAP052_TICK_VALUE_CONSOLIDATION_PROMPT.md` +- **Action Required:** Deployment intentionally skipped per operator instruction. No operator validation required for currently traded NQ/MNQ; both remain unchanged at `$5.00`/`$0.50`. ### DEC-20260823-06 - **ID:** DEC-20260823-06 - **Date:** 2026-08-23/24 diff --git a/src/NT8.Core/Common/InstrumentTickValueTable.cs b/src/NT8.Core/Common/InstrumentTickValueTable.cs new file mode 100644 index 0000000..f934079 --- /dev/null +++ b/src/NT8.Core/Common/InstrumentTickValueTable.cs @@ -0,0 +1,47 @@ +using System; +using System.Collections.Generic; + +namespace NT8.Core.Common +{ + /// + /// Shared Phase 0 tick-value lookup for platform-neutral risk and sizing components. + /// + public static class InstrumentTickValueTable + { + /// + /// Returns the currency value of one tick for the supplied symbol. + /// + public static double GetTickValue(string symbol) + { + switch (symbol) + { + case "ES": return 12.50; + case "MES": return 1.25; + case "NQ": return 5.00; + case "MNQ": return 0.50; + case "CL": return 10.00; + case "GC": return 10.00; + case "6E": return 12.50; + case "6A": return 10.00; + default: return 12.50; + } + } + + /// + /// Gets supported symbols with their tick values. + /// + public static Dictionary GetSupportedSymbols() + { + var symbols = new Dictionary(); + symbols.Add("ES", 12.50); + symbols.Add("MES", 1.25); + symbols.Add("NQ", 5.00); + symbols.Add("MNQ", 0.50); + symbols.Add("CL", 10.00); + symbols.Add("GC", 10.00); + symbols.Add("6E", 12.50); + symbols.Add("6A", 10.00); + return symbols; + } + } +} diff --git a/src/NT8.Core/Risk/AdvancedRiskManager.cs b/src/NT8.Core/Risk/AdvancedRiskManager.cs index 89431b5..1569959 100644 --- a/src/NT8.Core/Risk/AdvancedRiskManager.cs +++ b/src/NT8.Core/Risk/AdvancedRiskManager.cs @@ -1,3 +1,4 @@ +using NT8.Core.Common; using NT8.Core.Common.Models; using NT8.Core.Logging; using System; @@ -539,17 +540,7 @@ namespace NT8.Core.Risk /// private static double GetTickValue(string symbol) { - // Static tick values - will be enhanced with dynamic lookup in future phases - switch (symbol) - { - case "ES": return 12.50; - case "MES": return 1.25; - case "NQ": return 5.00; - case "MNQ": return 0.50; - case "CL": return 10.00; - case "GC": return 10.00; - default: return 12.50; // Default to ES - } + return InstrumentTickValueTable.GetTickValue(symbol); } /// @@ -931,4 +922,4 @@ namespace NT8.Core.Risk } } } -} \ No newline at end of file +} diff --git a/src/NT8.Core/Risk/BasicRiskManager.cs b/src/NT8.Core/Risk/BasicRiskManager.cs index d863fa8..422c95f 100644 --- a/src/NT8.Core/Risk/BasicRiskManager.cs +++ b/src/NT8.Core/Risk/BasicRiskManager.cs @@ -1,3 +1,4 @@ +using NT8.Core.Common; using NT8.Core.Common.Models; using NT8.Core.Logging; using System; @@ -177,17 +178,7 @@ namespace NT8.Core.Risk private static double GetTickValue(string symbol) { - // Static tick values for Phase 0 - will be configurable in Phase 1 - switch (symbol) - { - case "ES": return 12.50; - case "MES": return 1.25; - case "NQ": return 5.00; - case "MNQ": return 0.50; - case "CL": return 10.00; - case "GC": return 10.00; - default: return 12.50; // Default to ES - } + return InstrumentTickValueTable.GetTickValue(symbol); } /// @@ -195,14 +186,7 @@ namespace NT8.Core.Risk /// public static Dictionary GetSupportedSymbols() { - var symbols = new Dictionary(); - symbols.Add("ES", 12.50); - symbols.Add("MES", 1.25); - symbols.Add("NQ", 5.00); - symbols.Add("MNQ", 0.50); - symbols.Add("CL", 10.00); - symbols.Add("GC", 10.00); - return symbols; + return InstrumentTickValueTable.GetSupportedSymbols(); } private int GetOpenPositionCount() diff --git a/src/NT8.Core/Sizing/AdvancedPositionSizer.cs b/src/NT8.Core/Sizing/AdvancedPositionSizer.cs index 48a422d..3dbed94 100644 --- a/src/NT8.Core/Sizing/AdvancedPositionSizer.cs +++ b/src/NT8.Core/Sizing/AdvancedPositionSizer.cs @@ -1,3 +1,4 @@ +using NT8.Core.Common; using NT8.Core.Common.Models; using NT8.Core.Intelligence; using NT8.Core.Logging; @@ -506,19 +507,7 @@ namespace NT8.Core.Sizing private static double GetTickValue(string symbol) { - // Static tick values for Phase 0 - will be configurable in Phase 1 - switch (symbol) - { - case "ES": return 12.50; // E-mini S&P 500 - case "MES": return 1.25; // Micro E-mini S&P 500 - case "NQ": return 5.00; // E-mini NASDAQ-100 - case "MNQ": return 0.50; // Micro E-mini NASDAQ-100 - case "CL": return 10.00; // Crude Oil - case "GC": return 10.00; // Gold - case "6E": return 12.50; // Euro FX - case "6A": return 10.00; // Australian Dollar - default: return 12.50; // Default to ES value - } + return InstrumentTickValueTable.GetTickValue(symbol); } public SizingMetadata GetMetadata() diff --git a/src/NT8.Core/Sizing/BasicPositionSizer.cs b/src/NT8.Core/Sizing/BasicPositionSizer.cs index bf6c4be..4393fb2 100644 --- a/src/NT8.Core/Sizing/BasicPositionSizer.cs +++ b/src/NT8.Core/Sizing/BasicPositionSizer.cs @@ -1,3 +1,4 @@ +using NT8.Core.Common; using NT8.Core.Common.Models; using NT8.Core.Logging; using System; @@ -154,19 +155,7 @@ namespace NT8.Core.Sizing private static double GetTickValue(string symbol) { - // Static tick values for Phase 0 - will be configurable in Phase 1 - switch (symbol) - { - case "ES": return 12.50; // E-mini S&P 500 - case "MES": return 1.25; // Micro E-mini S&P 500 - case "NQ": return 5.00; // E-mini NASDAQ-100 - case "MNQ": return 0.50; // Micro E-mini NASDAQ-100 - case "CL": return 10.00; // Crude Oil - case "GC": return 10.00; // Gold - case "6E": return 12.50; // Euro FX - case "6A": return 10.00; // Australian Dollar - default: return 12.50; // Default to ES value - } + return InstrumentTickValueTable.GetTickValue(symbol); } public SizingMetadata GetMetadata() @@ -230,17 +219,7 @@ namespace NT8.Core.Sizing /// public static Dictionary GetSupportedSymbols() { - var symbols = new Dictionary(); - symbols.Add("ES", 12.50); - symbols.Add("MES", 1.25); - symbols.Add("NQ", 5.00); - symbols.Add("MNQ", 0.50); - symbols.Add("CL", 10.00); - symbols.Add("GC", 10.00); - symbols.Add("6E", 12.50); - symbols.Add("6A", 10.00); - - return symbols; + return InstrumentTickValueTable.GetSupportedSymbols(); } } -} \ No newline at end of file +} diff --git a/tests/NT8.Core.Tests/Risk/BasicRiskManagerTests.cs b/tests/NT8.Core.Tests/Risk/BasicRiskManagerTests.cs index f7a3dba..1edbfb1 100644 --- a/tests/NT8.Core.Tests/Risk/BasicRiskManagerTests.cs +++ b/tests/NT8.Core.Tests/Risk/BasicRiskManagerTests.cs @@ -1,4 +1,5 @@ using NT8.Core.Risk; +using NT8.Core.Common; using NT8.Core.Common.Models; using NT8.Core.Logging; using NT8.Core.Sizing; @@ -376,6 +377,40 @@ namespace NT8.Core.Tests.Risk Assert.AreEqual(0.50, sizingSymbols["MNQ"]); } + [TestMethod] + public void GetSupportedSymbols_RiskAndSizingUseSharedUnionTickValueTable() + { + Dictionary sharedSymbols = InstrumentTickValueTable.GetSupportedSymbols(); + Dictionary riskSymbols = BasicRiskManager.GetSupportedSymbols(); + Dictionary sizingSymbols = BasicPositionSizer.GetSupportedSymbols(); + + Assert.AreEqual(sharedSymbols.Count, riskSymbols.Count); + Assert.AreEqual(sharedSymbols.Count, sizingSymbols.Count); + + foreach (KeyValuePair symbol in sharedSymbols) + { + Assert.IsTrue(riskSymbols.ContainsKey(symbol.Key), symbol.Key); + Assert.IsTrue(sizingSymbols.ContainsKey(symbol.Key), symbol.Key); + Assert.AreEqual(symbol.Value, riskSymbols[symbol.Key], 0.000001, symbol.Key); + Assert.AreEqual(symbol.Value, sizingSymbols[symbol.Key], 0.000001, symbol.Key); + } + } + + [TestMethod] + public void ValidateOrder_SixAustralianDollar_UsesTenDollarTickValue() + { + var intent = TestDataBuilder.CreateValidIntent(symbol: "6A", stopTicks: 10); + var context = TestDataBuilder.CreateTestContext(symbol: "6A"); + var config = new RiskConfig(1000.0, 100.0, 5, true); + + RiskDecision decision = _riskManager.ValidateOrder(intent, context, config, 1); + + Assert.IsTrue(decision.Allow, decision.RejectReason); + Assert.IsTrue(decision.RiskMetrics.ContainsKey("trade_risk")); + Assert.AreEqual(100.0, (double)decision.RiskMetrics["trade_risk"], 0.000001); + Assert.AreEqual(10.00, InstrumentTickValueTable.GetTickValue("6A"), 0.000001); + } + [TestMethod] public void GetRiskStatus_ReturnsConfiguredDailyLossLimit() {