{
 "key": "f-end-flatten",
 "mech": "f-end-flatten",
 "approach": "Overlay on N: when steps_remaining <= E, with net = yes - no inventory, drop N's PlaceOrders on the side that would grow |net| (BUY if net>0, SELL if net<0) and cancel resting orders on that side that N leaves live; flat book (|net|<=1e-9) left unchanged. Acts on all spreads 1-4. E tuned over 10/25/50 on 320000..320199; every E lost, E10 least, frozen. Holdout 430000..430499: -0.160 (se 0.065), from lost retail edge (-0.204) barely offset by arb (+0.043). Edge is scored at fill time against the true probability, so end-of-run inventory carries no penalty to remove.",
 "tried": [
  "E=10: tuning mean_diff -0.281 se 0.181",
  "E=25: tuning -0.415 se 0.232",
  "E=50: tuning -1.020 se 0.307",
  "frozen E=10 holdout: -0.160 se 0.065"
 ],
 "next": "Drop end-flatten: the score is per-fill edge against the true probability and terminal inventory is not penalised, so cutting quotes near the end only gives up retail edge. Spend inventory effort on arb-loss (adverse-selection) control during the run instead.",
 "spreads_acted": [
  1,
  2,
  3,
  4
 ],
 "off_equals_n": {
  "ok": true,
  "seeds": "310000..310009",
  "steps_compared": 20000,
  "how": "END_E=0; repr of the action list returned each step compared with N's, identical on all 2000 steps of each of the 10 seeds"
 },
 "code": "# Overlay f-end-flatten: in the last E steps, cancel every order on the side\n# that would increase |net inventory| (net = yes - no). Flat book: unchanged.\nfrom orderbook_pm_challenge.types import CancelAll, CancelOrder, PlaceOrder, Side\n\nEND_E = 10\nACT_SPREADS = (1, 2, 3, 4)\nFLAT_EPS = 1e-9\n\n\nclass Strategy(_N):\n    def on_step(self, state):\n        acts = list(super().on_step(state))\n        E = END_E\n        if E <= 0 or state.steps_remaining > E:\n            return acts\n        if getattr(self, \"s\", None) not in ACT_SPREADS:\n            return acts\n        net = state.yes_inventory - state.no_inventory\n        if net > FLAT_EPS:\n            bad = Side.BUY\n        elif net < -FLAT_EPS:\n            bad = Side.SELL\n        else:\n            return acts\n        live = {o.order_id: o.side for o in state.own_orders}\n        out = []\n        for a in acts:\n            if isinstance(a, CancelAll):\n                live.clear()\n                out.append(a)\n            elif isinstance(a, CancelOrder):\n                live.pop(a.order_id, None)\n                out.append(a)\n            elif isinstance(a, PlaceOrder):\n                if a.side == bad:\n                    continue\n                if a.client_order_id is not None:\n                    live[a.client_order_id] = a.side\n                out.append(a)\n            else:\n                out.append(a)\n        for oid, side in live.items():\n            if side == bad:\n                out.append(CancelOrder(oid))\n        return out\n",
 "code_sha256": "69be55c4b7e1f403bea3b449bf80b14126b26b0a4a3253ebd58c6af1cc377e19",
 "assembled_sha256": "592f5596f3fef8426992798d2effe6619e46099ab27898d2a052d6dd20f8283e",
 "n_sha256": "bf0d179f3e47d28819f6fa7e0d25548c2ced43374c216d36460b00a26a26ffae",
 "tuning": {
  "seeds": "320000..320199",
  "selected": "E10",
  "variants": [
   {
    "name": "E10",
    "END_E": 10,
    "overall": {
     "n": 200,
     "sum_d": -56.164641,
     "sum_d2": 1325.830204,
     "mean_diff": -0.280823,
     "se": 0.181428,
     "incumbent_mean": 98.470718,
     "candidate_mean": 98.189895,
     "retail_diff": -0.365388,
     "arb_diff": 0.084565
    },
    "by_spread_mean_diff": {
     "1": 0.059488,
     "2": -0.334278,
     "3": -0.146779,
     "4": -0.68038
    }
   },
   {
    "name": "E25",
    "END_E": 25,
    "overall": {
     "n": 200,
     "sum_d": -83.077377,
     "sum_d2": 2183.470659,
     "mean_diff": -0.415387,
     "se": 0.232366,
     "incumbent_mean": 98.470718,
     "candidate_mean": 98.055331,
     "retail_diff": -0.579772,
     "arb_diff": 0.164385
    },
    "by_spread_mean_diff": {
     "1": -0.110069,
     "2": -0.457743,
     "3": -0.22927,
     "4": -0.840035
    }
   },
   {
    "name": "E50",
    "END_E": 50,
    "overall": {
     "n": 200,
     "sum_d": -204.002863,
     "sum_d2": 3971.351382,
     "mean_diff": -1.020014,
     "se": 0.307497,
     "incumbent_mean": 98.470718,
     "candidate_mean": 97.450704,
     "retail_diff": -1.015082,
     "arb_diff": -0.004932
    },
    "by_spread_mean_diff": {
     "1": -0.691844,
     "2": -1.17087,
     "3": -0.36755,
     "4": -1.792783
    }
   }
  ]
 },
 "paired": {
  "seeds": "430000..430499",
  "candidate": "E10",
  "n": 500,
  "complete": true,
  "missing_seeds": [],
  "overall": {
   "n": 500,
   "sum_d": -80.153196,
   "sum_d2": 1059.910923,
   "mean_diff": -0.160306,
   "se": 0.064781,
   "incumbent_mean": 95.542015,
   "candidate_mean": 95.381709,
   "retail_diff": -0.203748,
   "arb_diff": 0.043442
  },
  "by_spread": {
   "1": {
    "n": 131,
    "sum_d": -4.901703,
    "sum_d2": 25.271429,
    "mean_diff": -0.037418,
    "se": 0.038382,
    "incumbent_mean": 38.277937,
    "candidate_mean": 38.240519,
    "retail_diff": -0.047083,
    "arb_diff": 0.009666
   },
   "2": {
    "n": 120,
    "sum_d": -19.497041,
    "sum_d2": 90.398684,
    "mean_diff": -0.162475,
    "se": 0.078158,
    "incumbent_mean": 77.855864,
    "candidate_mean": 77.693389,
    "retail_diff": -0.183633,
    "arb_diff": 0.021157
   },
   "3": {
    "n": 133,
    "sum_d": -33.596193,
    "sum_d2": 600.508338,
    "mean_diff": -0.252603,
    "se": 0.183635,
    "incumbent_mean": 146.551404,
    "candidate_mean": 146.298801,
    "retail_diff": -0.340015,
    "arb_diff": 0.087412
   },
   "4": {
    "n": 116,
    "sum_d": -22.15826,
    "sum_d2": 343.732472,
    "mean_diff": -0.191019,
    "se": 0.15953,
    "incumbent_mean": 120.022047,
    "candidate_mean": 119.831027,
    "retail_diff": -0.245243,
    "arb_diff": 0.054224
   }
  }
 },
 "failures": 0,
 "check_values": {
  "310000": 17.116002,
  "310001": 20.017111,
  "310002": 2.390311,
  "310003": 241.484752
 },
 "check_expected": {
  "310000": 17.116002,
  "310001": 20.017111,
  "310002": 2.390311,
  "310003": 241.484752
 },
 "python_version": "3.12.3",
 "seconds_per_simulation": 0.576,
 "notes": "Simulator at commit b244530 unmodified, SimulationEngine called directly, serial in each process (no --workers, no --sandbox); tuning and holdout seed ranges split over 4-8 separate OS processes, so seconds_per_simulation includes CPU contention (about 0.55 s when run alone). Each (seed, strategy) ran exactly once: a run cut off by a tool timeout was resumed by skipping pairs already written. by_spread uses config.competitor.spread_ticks. This is a screen, not a promotion."
}