[GAP-045/GAP-046]: risk envelope guards complete

- BasicRiskManager.cs: add sized per-position risk validation and startup validator

- NT8StrategyBase.cs: fail fast on incoherent risk config and validate after sizing

- BasicRiskManagerTests.cs: cover assertions, sized risk, property sweep, MNQ tables

- docs/00-governance: record validation evidence and NQ SIM follow-up

Build: clean | Tests: 535 passing; Core 446 passing | Deploy: backup 20260823_144817
This commit is contained in:
2026-08-23 14:50:02 -04:00
parent 6658d2d120
commit d652e29959
8 changed files with 382 additions and 35 deletions

View File

@@ -82,8 +82,8 @@ Kilocode implemented Option 0: removed the `OnBarUpdate()` `SetStopLoss` call on
**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.
**Play 7 — Risk guards, all three parts (DEC-19a/19b accepted).**
Hand `TASK_GAP045_GAP046_RISK_GUARDS_PROMPT.md` to Kilocode in full — Part 3 is now written as directly actionable: implement the Tier 1 check reordering (post-sizing, `Qty`-aware) and confirm MNQ is present and correctly valued in both `GetTickValue` tables (GAP-052) as prep for the later cutover. **Do this on the current NQ configuration — do not switch the traded instrument as part of this task.** That's Play 11.
**Play 7 — Risk guards, all three parts (DEC-19a/19b accepted). IMPLEMENTED 2026-08-23, manual NQ SIM validation pending.**
`TASK_GAP045_GAP046_RISK_GUARDS_PROMPT.md` now fails startup for incoherent risk-envelope pairs, confirms MNQ is already `$0.50` in both hardcoded tick-value tables, and moves the live NT8 per-position `MaxTradeRisk` check to after sizing so `StopTicks * TickValue * Qty <= MaxTradeRisk` is enforced. Build/tests/deploy passed with backup `20260823_144817`. Remaining validation: manual NT8 compile, NQ SIM guard checks, and high-ATR signal behavior. The MNQ cutover is still Play 11 and was not started.
**Play 8 — MaxDailyTrades persistence (DEC-21 accepted). IMPLEMENTED 2026-08-23, manual SIM restart validation pending.**
`TASK_GAP055_MAXDAILYTRADES_PERSIST_PROMPT.md` now persists `{trading_date, daily_trade_count, account, strategy_name, symbol}` to `daily_trade_count_<AccountName>_<StrategyName>.json`, rehydrates same-date count, resets and overwrites on a new trading date, and skips file I/O when `Account == null`. Automated tests cover same-date restore, new-date reset, corrupt file, backtest no-I/O, and the 2026-08-16 19:12 / 2026-08-17 11:04 same-CME-date scenario. Remaining validation: manual NT8 compile plus SIM restart test confirming the next same-day signal rejects with `REJECT: reason=MaxDailyTrades`.
@@ -116,7 +116,7 @@ This is a separate, later step — not part of today's six tasks. Once GAP-054,
- [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
- [x] GAP-055 persistence: implemented and automated restart/rollover-boundary tests passed; manual SIM restart validation pending
- [ ] GAP-045/046 all three parts: implemented on NQ, including the post-sizing Tier 1 reorder and the MNQ tick-table check
- [x] GAP-045/046 all three parts: implemented on NQ, including the post-sizing Tier 1 reorder and the MNQ tick-table check; manual NQ SIM validation pending
- [ ] GAP-049 telemetry: implemented, -523.25 anomaly re-checked and resolved
- [ ] `git status --short` re-checked: confirm exactly the files each TASK prompt's DO list authorized, nothing else
- [ ] SPRINT_BOARD.md, active_work.md, decisions.md all reflect end-of-day state

View File

@@ -13,7 +13,7 @@ Full detail: `docs/NT8_SDK_Master_Document_v7.0_Complete.docx`.
| Order | Item | Prompt | Owner | Blocking |
|---|---|---|---|---|
| 1 | **GAP-046** — set `AccountStartingBalance` or disable `EnableTrailingDrawdown` | operator action, no code | Operator | Every entry, from 14:30 ET daily |
| 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 |
| 2 | **GAP-045/046 guards** — resolved: MNQ (cutover staged separately) + per-position semantics | `TASK_GAP045_GAP046_RISK_GUARDS_PROMPT.md` — implemented/deployed 2026-08-23, backup `20260823_144817` | Kilocode, on current NQ config | Manual NT8 compile and NQ SIM validation |
| 3 | **GAP-048** — split the reject taxonomy | `TASK_GAP048_REJECT_TAXONOMY_PROMPT.md` — implemented/deployed 2026-08-23, backup `20260823_142014` | Kilocode | Manual NT8 compile and dashboard spot-check |
| 4 | **GAP-055** — persist `MaxDailyTrades` across restarts | `TASK_GAP055_MAXDAILYTRADES_PERSIST_PROMPT.md` — implemented/deployed 2026-08-23, backup `20260823_143311` | Kilocode | Manual NT8 compile and SIM restart validation |
| 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 |

View File

@@ -1,5 +1,28 @@
# Current Status — NT8 SDK
**Last Updated:** 2026-08-23 (GAP-055 MaxDailyTrades persistence implemented and deployed)
**Last Updated:** 2026-08-23 (GAP-045/046 risk guards implemented and deployed)
---
## 2026-08-23 — GAP-045/046 IMPLEMENTED, manual NT8/NQ SIM validation pending
Kilocode executed `TASK_GAP045_GAP046_RISK_GUARDS_PROMPT.md` Parts 1-3 on the current NQ configuration. The MNQ instrument cutover was not performed and remains a separate DEC-20260819-01 follow-on.
Implementation notes:
- Added startup risk-envelope assertions via `RiskEnvelopeValidator` and `NT8StrategyBase`.
- `EnableTrailingDrawdown=True` now requires `AccountStartingBalance>0` at startup.
- `MaxStopTicks * TickValue <= MaxTradeRisk`, `MinContracts>=1`, `MinContracts<=MaxContracts`, and `MaxTradeRisk<=DailyLossLimit` are enforced before runtime order flow.
- GAP-048 had already split the misconfigured trailing-drawdown reject reason to `TrailingDrawdownNotConfigured`; no duplicate taxonomy change was needed.
- Confirmed MNQ is present and valued at `$0.50` in both `BasicRiskManager` and `BasicPositionSizer` tick-value tables.
- Added quantity-aware per-position risk enforcement: the NT8 live path now sizes first, then validates `StopTicks * TickValue * Qty <= MaxTradeRisk` against the selected quantity.
- Existing `IRiskManager.ValidateOrder()` compatibility remains for older callers and validates one contract.
Evidence:
- Added tests for all startup assertions, quantity-aware Tier 1 rejection, the old pre-quantity pass / new two-contract reject case, bounded property-style range coverage, and MNQ tick table parity.
- `verify-build.bat`: passed, 535/535 tests.
- `dotnet test tests\NT8.Core.Tests\NT8.Core.Tests.csproj --configuration Release --no-build --verbosity minimal`: passed, 446/446.
- `deployment\deploy-to-nt8.bat`: completed; backup `deployment\backups\20260823_144817`; `NinjaTrader.Custom.dll` was not present to invalidate.
Next required action: manual NinjaScript compile after starting NinjaTrader, then NQ SIM validation of startup guard failures and the quantity-aware per-position `MaxTradeRisk` behavior. Do not validate or execute the MNQ cutover as part of this task.
---

View File

@@ -88,7 +88,9 @@ Use this file to record durable project decisions that affect implementation pat
- **Decision (proposed, two parts):** **Decision 1 — resolve the collision.** Choose one of: (a) `MaxTradeRisk = $250`, making `MaxStopTicks=50` reachable and raising per-contract worst case 25%; (b) `MaxStopTicks = 40`, leaving nothing unreachable but tightening the stop relative to ATR on volatile days and raising stop-out rate; (c) validate on MNQ at $0.50/tick, where 50 ticks = $25 per contract, the collision disappears entirely and sizing becomes granular enough for `MaxContracts` to do real work. **Decision 2 — define the semantics.** State explicitly whether `MaxTradeRisk` is a per-contract stop-distance ceiling (what the code does today) or a per-position risk limit (what the name and the master document imply). If per-position, the Tier 1 check must move to after sizing or take an estimated quantity — a real ordering change that must not be made without this entry being accepted first. Independently of both, add startup assertions in the GAP-003 style for: `EnableTrailingDrawdown ⇒ AccountStartingBalance > 0`; `MaxStopTicks × tickValue ≤ MaxTradeRisk`; `MinContracts ≤ MaxContracts`; and a bound relating `MaxTradeRisk × MaxContracts` to `DailyLossLimit`.
- **Consequences:** Either value change alters `ConfigHash` and requires a fresh freeze capture and a new `DEC-GATE3-CONFIG`. Option (c) is a larger strategic change than a parameter edit and interacts with the roadmap's instrument sequencing; it is also the only option that removes the class of problem rather than an instance of it. Until Decision 2 is answered, the system's true worst-case single-trade loss is undefined in the documentation and under-enforced in the code, which is the largest open drawdown exposure in the project.
- **Related Files:** `src/NT8.Core/Risk/BasicRiskManager.cs`, `src/NT8.Core/Sizing/BasicPositionSizer.cs`, `src/NT8.Adapters/Strategies/NT8StrategyBase.cs`, `TASK_GAP045_GAP046_RISK_GUARDS_PROMPT.md`
- **Action Required:** Both decisions made — see above. Execute `TASK_GAP045_GAP046_RISK_GUARDS_PROMPT.md` in full (Part 3 is now unblocked) on the current NQ configuration. Hold the MNQ instrument cutover itself for DEC-20260819-01's sequencing.
- **Implementation Note (2026-08-23):** Executed `TASK_GAP045_GAP046_RISK_GUARDS_PROMPT.md` Parts 1-3 on the current NQ configuration without changing the traded instrument or retuning NQ values. Added `RiskEnvelopeValidator.ValidateStartupConfiguration()` and wired `NT8StrategyBase` startup to fail fast when: `EnableTrailingDrawdown=True` with `AccountStartingBalance<=0`; `MaxStopTicks * TickValue > MaxTradeRisk`; `MinContracts<1` or `MinContracts>MaxContracts`; or `MaxTradeRisk>DailyLossLimit`. Messages include the symbol and both conflicting values. GAP-048 had already split the nonconfigured trailing-drawdown reject reason to `TrailingDrawdownNotConfigured`, so no duplicate taxonomy change was needed. Confirmed MNQ exists at `$0.50` in both hardcoded tick-value tables; no table patch was needed. Implemented the approved per-position semantics by adding a sized `BasicRiskManager.ValidateOrder(..., candidateContracts)` overload and moving `NT8StrategyBase.ProcessStrategyIntent()` to calculate size before risk validation, then enforce `StopTicks * tickValue * Qty <= MaxTradeRisk` against the selected quantity. Existing `IRiskManager.ValidateOrder()` remains compatible and still validates one contract for older callers.
- **Verification (2026-08-23):** Added tests for each startup assertion's fail/pass behavior, quantity-aware Tier 1 rejection, the old pre-quantity passing case now rejecting at two contracts, a bounded property-style sweep over declared ranges, and MNQ tick-value parity in both risk and sizing tables. `verify-build.bat` passed 535/535 tests (446 Core, 79 Integration, 10 Performance); `dotnet test tests\NT8.Core.Tests\NT8.Core.Tests.csproj --configuration Release --no-build --verbosity minimal` passed 446/446; `deployment\deploy-to-nt8.bat` completed with backup `20260823_144817` and noted `NinjaTrader.Custom.dll` was not present to invalidate.
- **Action Required:** Manually compile in NinjaTrader. Validate on NQ before MNQ cutover: verify the misconfigured trailing-drawdown pair refuses startup, `MaxTradeRisk<=DailyLossLimit` is enforced, and a former 10:10-style high-ATR signal either sizes within `MaxTradeRisk` or rejects from the quantity-aware per-position check. Do not perform the MNQ cutover in this validation step.
### DEC-20260818-18
- **ID:** DEC-20260818-18