abyXsmart commited on
Commit
2cefbbe
·
verified ·
1 Parent(s): d866ac6

v8 Step 4+5: plain-words verdict dictionary; dataset generation stamp + generation-aware calibration (?all=1)

Browse files
Files changed (2) hide show
  1. Log.md +20 -0
  2. app.py +38 -15
Log.md CHANGED
@@ -2747,3 +2747,23 @@ only; grep-prove + delete _select_verdict; behind SMART_STAGE5_ENABLED; run S5-*
2747
  in-profit run beyond zone. ALL PASS. Full suite SR-1..4 + S4-* + S5-* all green.
2748
  NEXT: Step 4 — §6 plain-words verdict dictionary swap (Stage-4 final phrases + _PHASE_LABELS +
2749
  market.js any hardcoded strings), then Step 5 dataset versioning + generation-aware calibration.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2747
  in-profit run beyond zone. ALL PASS. Full suite SR-1..4 + S4-* + S5-* all green.
2748
  NEXT: Step 4 — §6 plain-words verdict dictionary swap (Stage-4 final phrases + _PHASE_LABELS +
2749
  market.js any hardcoded strings), then Step 5 dataset versioning + generation-aware calibration.
2750
+
2751
+ ## SESSION 24 — STEP 4 + STEP 5 DONE
2752
+ STEP 4 (§6 verdict dictionary): Stage-4 verdicts swapped to plain Title-Case spec phrases:
2753
+ A->"Strong Setup — Taking The Trade"(strong); B->"Good Setup — Taking The Trade"(good);
2754
+ forming/streak/ws8->"Setup Building — Waiting For Confirmation"(good); weak/dead->"Weak Setup
2755
+ — Standing Aside"(warn); btc->"Blocked — Bitcoin Pushing Against Us"(bad). Stage-5 verdicts
2756
+ already matched §6 from Step 3. Confirmed market.js + trades.html render verdicts DYNAMICALLY
2757
+ (esc(g_verdict)/bi.verdict) — no hardcoded strings to change. _PHASE_LABELS already jargon-free.
2758
+ STEP 5 (§7.1/7.2 dataset versioning + generation-aware calibration):
2759
+ - Entry snapshot (STAGE3_ACTIVE active dict) now stamps engine_version, filter_generation,
2760
+ grade_at_entry(=latched v8 grade). Carried onto BOTH closed rows (close_stage4_trade +
2761
+ manual_close_trade) with active-or-fallback. JSON data catch-all = no DB schema change.
2762
+ - _calibration_report(only_generation=True default): filters rows to filter_generation==
2763
+ FILTER_GENERATION so dead-gen data can't poison stats (RX.1); grade bucket now reads
2764
+ grade_at_entry first; returns generation label. /api/calibration?all=1 -> include all gens.
2765
+ - TESTS /data/workspace/tests/calib_tests.py: FILTER_GENERATION==Smart-v8; default=current gen
2766
+ only (2 of 3 rows); ?all=3 rows; Grade-A bucket sourced from grade_at_entry. ALL PASS.
2767
+ Full suite SR/S4/S5/calib all green. py_compile OK.
2768
+ NEXT: Step 6 — settings_schema.json "Smart Engine (v8)" section (§8.1 new keys) + mark legacy
2769
+ keys (§8.3); round-trip test. Then Step 7 Telegram, Step 8 explainer, then §19-24.
app.py CHANGED
@@ -1209,6 +1209,12 @@ def record_stage4_open(st: SetupState):
1209
  "conviction_grade": st.conviction_grade,
1210
  "confluence_members": list(st.confluence_members or []),
1211
  "confluence_count": st.confluence_count,
 
 
 
 
 
 
1212
  "reason": "Stage4 verified entry after Stage3 FVG interaction and confirmation candle",
1213
  }
1214
  STAGE3_ACTIVE[st.symbol] = active
@@ -1374,6 +1380,10 @@ def close_stage4_trade(symbol: str, st: SetupState, bars: List[Candle], prev_set
1374
  "conviction_grade": active.get("conviction_grade") or getattr(st, "conviction_grade", ""),
1375
  "confluence_members": active.get("confluence_members") or list(getattr(st, "confluence_members", []) or []),
1376
  "confluence_count": active.get("confluence_count", getattr(st, "confluence_count", 0)),
 
 
 
 
1377
  }
1378
  # v7.5 WS-8.6: arm a per-symbol cooldown after a stop so a failing structure is not
1379
  # immediately re-entered (no-op unless symbol_cooldown_enabled).
@@ -1453,6 +1463,10 @@ def manual_close_trade(symbol: str, reason: str = "") -> Dict:
1453
  "conviction_grade": active.get("conviction_grade") or st.conviction_grade,
1454
  "confluence_members": active.get("confluence_members") or list(st.confluence_members or []),
1455
  "confluence_count": active.get("confluence_count", st.confluence_count),
 
 
 
 
1456
  }
1457
  try:
1458
  snap_name = _trade_snapshot_name(symbol, row["opened_ts"])
@@ -1632,9 +1646,14 @@ def _set_symbol_cooldown(symbol: str) -> None:
1632
  SYMBOL_COOLDOWN[symbol] = int(time.time()) + int(mins) * 60
1633
 
1634
 
1635
- def _calibration_report() -> Dict:
1636
- """8.2: per-feature hit-rate + avg net R across persisted trades, once enough exist."""
 
 
 
1637
  rows = db_query_trades(0)
 
 
1638
  feats: Dict[str, Dict] = {}
1639
 
1640
  def _bucket(key: str, net: float):
@@ -1654,7 +1673,7 @@ def _calibration_report() -> Dict:
1654
  em = r.get("entry_model_label") or r.get("entry_model")
1655
  if em:
1656
  _bucket("Model · " + str(em), net)
1657
- g = r.get("conviction_grade")
1658
  if g:
1659
  _bucket("Grade " + str(g), net)
1660
  for m in (r.get("confluence_members") or []):
@@ -1669,7 +1688,9 @@ def _calibration_report() -> Dict:
1669
  out.sort(key=lambda x: (-x["trades"], -x["avg_net_r"]))
1670
  min_n = CFG.get("calibration_min_trades", 10)
1671
  return {"ready": n_total >= min_n, "total_trades": n_total,
1672
- "min_trades": min_n, "features": out}
 
 
1673
 
1674
 
1675
  EVENTS: Deque[Dict] = deque(maxlen=320)
@@ -4362,20 +4383,21 @@ async def evaluate_pre_entry_conviction(session: aiohttp.ClientSession, st: "Set
4362
  passed = False
4363
 
4364
  # Plain-words verdict (Title Case). Final §6 dictionary swap lands in build step 4.
 
4365
  if hard_block:
4366
- verdict, vclass = "Blocked — BTC Against Us", "warn"
4367
  elif dead:
4368
- verdict, vclass = "Skip — Market Dead Here", "reject"
4369
  elif passed and grade == "A":
4370
- verdict, vclass = "Strong Setup — Entering Now", "strong"
4371
  elif passed:
4372
- verdict, vclass = "Good Setup — Entering Now", "strong"
4373
  elif ws8_reason:
4374
- verdict, vclass = "Holding Back — " + ws8_reason, "warn"
4375
  elif grade == "B":
4376
- verdict, vclass = "Thesis Forming — Watching The Zone", "good"
4377
  else:
4378
- verdict, vclass = "Studying The Zone", "good"
4379
 
4380
  st.conviction = conv
4381
  st.conviction_raw = int(raw)
@@ -6603,10 +6625,11 @@ async def api_trades(since: int = Query(0, description="unix seconds; only trade
6603
 
6604
 
6605
  @app.get("/api/calibration")
6606
- async def api_calibration():
6607
- """v7.5 WS-8.2: per-feature hit-rate + average NET R across persisted trades, so the
6608
- confluence members and entry-model grades become evidence instead of guesses."""
6609
- return _calibration_report()
 
6610
 
6611
 
6612
  @app.get("/market.js")
 
1209
  "conviction_grade": st.conviction_grade,
1210
  "confluence_members": list(st.confluence_members or []),
1211
  "confluence_count": st.confluence_count,
1212
+ # v8 §7.1: stamp the decision generation so the calibration loop only ever learns
1213
+ # from a SINGLE filter generation (mixed-generation data was the RX.1 root cause).
1214
+ # grade_at_entry is the LATCHED leading-fact grade — a TRUE pre-move label.
1215
+ "engine_version": ENGINE_VERSION,
1216
+ "filter_generation": FILTER_GENERATION,
1217
+ "grade_at_entry": st.conviction_grade,
1218
  "reason": "Stage4 verified entry after Stage3 FVG interaction and confirmation candle",
1219
  }
1220
  STAGE3_ACTIVE[st.symbol] = active
 
1380
  "conviction_grade": active.get("conviction_grade") or getattr(st, "conviction_grade", ""),
1381
  "confluence_members": active.get("confluence_members") or list(getattr(st, "confluence_members", []) or []),
1382
  "confluence_count": active.get("confluence_count", getattr(st, "confluence_count", 0)),
1383
+ # v8 §7.1: generation stamp + true pre-move grade carried onto the closed row.
1384
+ "engine_version": active.get("engine_version") or ENGINE_VERSION,
1385
+ "filter_generation": active.get("filter_generation") or FILTER_GENERATION,
1386
+ "grade_at_entry": active.get("grade_at_entry") or active.get("conviction_grade") or getattr(st, "conviction_grade", ""),
1387
  }
1388
  # v7.5 WS-8.6: arm a per-symbol cooldown after a stop so a failing structure is not
1389
  # immediately re-entered (no-op unless symbol_cooldown_enabled).
 
1463
  "conviction_grade": active.get("conviction_grade") or st.conviction_grade,
1464
  "confluence_members": active.get("confluence_members") or list(st.confluence_members or []),
1465
  "confluence_count": active.get("confluence_count", st.confluence_count),
1466
+ # v8 §7.1: generation stamp + true pre-move grade carried onto the manual-close row.
1467
+ "engine_version": active.get("engine_version") or ENGINE_VERSION,
1468
+ "filter_generation": active.get("filter_generation") or FILTER_GENERATION,
1469
+ "grade_at_entry": active.get("grade_at_entry") or active.get("conviction_grade") or st.conviction_grade,
1470
  }
1471
  try:
1472
  snap_name = _trade_snapshot_name(symbol, row["opened_ts"])
 
1646
  SYMBOL_COOLDOWN[symbol] = int(time.time()) + int(mins) * 60
1647
 
1648
 
1649
+ def _calibration_report(only_generation: bool = True) -> Dict:
1650
+ """8.2 + v8 §7.2: per-feature hit-rate + avg net R across persisted trades, once enough
1651
+ exist. By default reports ONLY rows whose filter_generation matches the CURRENT
1652
+ FILTER_GENERATION so dead-generation trades can never poison the stats (RX.1). Pass
1653
+ only_generation=False (?all=1) to include every historical row regardless of generation."""
1654
  rows = db_query_trades(0)
1655
+ if only_generation:
1656
+ rows = [r for r in rows if (r.get("filter_generation") == FILTER_GENERATION)]
1657
  feats: Dict[str, Dict] = {}
1658
 
1659
  def _bucket(key: str, net: float):
 
1673
  em = r.get("entry_model_label") or r.get("entry_model")
1674
  if em:
1675
  _bucket("Model · " + str(em), net)
1676
+ g = r.get("grade_at_entry") or r.get("conviction_grade")
1677
  if g:
1678
  _bucket("Grade " + str(g), net)
1679
  for m in (r.get("confluence_members") or []):
 
1688
  out.sort(key=lambda x: (-x["trades"], -x["avg_net_r"]))
1689
  min_n = CFG.get("calibration_min_trades", 10)
1690
  return {"ready": n_total >= min_n, "total_trades": n_total,
1691
+ "min_trades": min_n, "features": out,
1692
+ "generation": FILTER_GENERATION if only_generation else "all",
1693
+ "filter_generation": FILTER_GENERATION}
1694
 
1695
 
1696
  EVENTS: Deque[Dict] = deque(maxlen=320)
 
4383
  passed = False
4384
 
4385
  # Plain-words verdict (Title Case). Final §6 dictionary swap lands in build step 4.
4386
+ # §6 verdict dictionary (plain words, Title Case).
4387
  if hard_block:
4388
+ verdict, vclass = "Blocked — Bitcoin Pushing Against Us", "bad"
4389
  elif dead:
4390
+ verdict, vclass = "Weak Setup — Standing Aside", "warn"
4391
  elif passed and grade == "A":
4392
+ verdict, vclass = "Strong Setup — Taking The Trade", "strong"
4393
  elif passed:
4394
+ verdict, vclass = "Good Setup — Taking The Trade", "good"
4395
  elif ws8_reason:
4396
+ verdict, vclass = "Setup Building — Waiting For Confirmation", "good"
4397
  elif grade == "B":
4398
+ verdict, vclass = "Setup Building — Waiting For Confirmation", "good"
4399
  else:
4400
+ verdict, vclass = "Weak Setup — Standing Aside", "warn"
4401
 
4402
  st.conviction = conv
4403
  st.conviction_raw = int(raw)
 
6625
 
6626
 
6627
  @app.get("/api/calibration")
6628
+ async def api_calibration(all: int = Query(0, description="1 = include all generations")):
6629
+ """v7.5 WS-8.2 + v8 §7.2: per-feature hit-rate + average NET R across persisted trades, so
6630
+ the confluence members and entry-model grades become evidence instead of guesses. Defaults
6631
+ to the CURRENT filter generation only; pass ?all=1 to include every historical row."""
6632
+ return _calibration_report(only_generation=(int(all) == 0))
6633
 
6634
 
6635
  @app.get("/market.js")