{
  "key": "f-cash-order",
  "approach": "Blind uncovered-collateral shadow-price overlay, composing exactly one _N instance. N source was fetched mechanically from the assigned artifact, hash-verified, renamed and executed without inspection. N receives actual StepState every step. The overlay adds no independent orders, so no own_orders hiding is needed. Fair value is a public competitor-quote midpoint plus an EWMA (alpha .25) of midpoint changes, clipped to [.005,.995]; one-sided quotes use a half-spread offset. For each order, estimated conditional-on-fill edge times quantity is divided by reserved cash; covered asks have zero cash cost and are not eviction candidates. Binding is explicitly a proxy: after N actions, residual cash cannot fund a second copy of at least one cash-backed non-probe proposal (quantity >=1), or an action is actually unaffordable. On a bind, cancel the lowest-ratio surviving old order if a new proposal has a strictly higher ratio. Use its released collateral to enlarge the best N proposal by at most its original quantity. Simulate collateral allocation and accept only affordable changes. Later unaffordable N proposals evict inferior survivors then clip to affordable size. Exact collateral coverage is reconstructed from prior actions and observed fills; a reconciliation mismatch suppresses swaps. All thresholds and estimates are fixed across spreads. The spread set alone is chosen from tuning; other spreads return N actions untouched.",
  "tried": {
    "simulator_commit": "b244530ee2a6247b5f930830eeca9dd950da0e7e",
    "incumbent_url": "https://api.imd.fun/artifacts/db22aff7167a4798251ed3d20432509f30e511e4958799aba5b17b41bb39b4b6",
    "incumbent_code_sha256": "bf0d179f3e47d28819f6fa7e0d25548c2ced43374c216d36460b00a26a26ffae",
    "incumbent_seed_310000_edge": 17.1160017503,
    "incumbent_seed_check_matches": true,
    "protocol": "Default ChallengeConfig and ParameterVariance; 2000 steps; serial, one OS process; no sandbox or workers. Tuning only 310000..310199; holdout only 410000..410499, once per strategy per seed. No 900000..903999 seeds run. No other strategy, leaderboard or earlier network result inspected.",
    "binding_definition": "binds counts steps when N residual collateral cannot fund another same-sized cash-backed proposal of quantity >=1, or N actions are unaffordable; it is a budget-binding proxy, not a count of rejected simulator actions. swaps counts regular evictions, repairs counts cash-fit repair steps. Cash below $10 is separately reported for the initial N-only tuning probe.",
    "n_probe_free_cash_under_10": {
      "1": {
        "steps": 94000,
        "under_10": 268,
        "fraction": 0.002851063829787234
      },
      "2": {
        "steps": 114000,
        "under_10": 68,
        "fraction": 0.0005964912280701755
      },
      "3": {
        "steps": 106000,
        "under_10": 365,
        "fraction": 0.003443396226415094
      },
      "4": {
        "steps": 86000,
        "under_10": 198,
        "fraction": 0.002302325581395349
      }
    },
    "variants": [
      {
        "name": "v1",
        "code_sha256": "a016de54b1c9dab8dc5d0a25f73ba1b2be7d246711c0ec4cd7db14c846239227",
        "spreads": [
          1,
          2,
          3,
          4
        ],
        "tuning": {
          "n": 200,
          "complete": false,
          "mean_diff": null,
          "se": null
        },
        "failures": [
          {
            "seed": 310047,
            "incumbent_error": null,
            "overlay_error": "orderbook_pm_challenge.market.OrderBookError: Insufficient free cash for order collateral"
          },
          {
            "seed": 310065,
            "incumbent_error": null,
            "overlay_error": "orderbook_pm_challenge.market.OrderBookError: Insufficient free cash for order collateral"
          },
          {
            "seed": 310094,
            "incumbent_error": null,
            "overlay_error": "orderbook_pm_challenge.market.OrderBookError: Insufficient free cash for order collateral"
          }
        ],
        "decision": "Rejected: three collateral failures after a prior swap changed N future proposals. Also corrected quantization to match the simulator."
      },
      {
        "name": "v2",
        "spreads_tested": [
          1,
          2,
          3,
          4
        ],
        "tuning_all_spreads": {
          "n": 200,
          "incumbent_mean": 85.16265316504199,
          "mean_diff": 0.5243297098154993,
          "se": 0.4360128638343701,
          "sum_d": 104.86594196309986,
          "sum_d2": 7621.251582595191,
          "retail_diff": 0.5604771423805,
          "arb_diff": -0.03614743255800001
        },
        "by_spread": {
          "1": {
            "n": 47,
            "incumbent_mean": 30.59600304578298,
            "mean_diff": 1.6338796225510641,
            "se": 1.6925779078360146,
            "sum_d": 76.79234225990001,
            "sum_d2": 6319.210227178813,
            "retail_diff": 1.8450821994531914,
            "arb_diff": -0.21120257688723415
          },
          "2": {
            "n": 57,
            "incumbent_mean": 81.35713208259824,
            "mean_diff": -0.31114294550701665,
            "se": 0.2884659049418314,
            "sum_d": -17.73514789389995,
            "sum_d2": 271.13271613271036,
            "retail_diff": -0.26161788182631635,
            "arb_diff": -0.049525063680701815
          },
          "3": {
            "n": 53,
            "incumbent_mean": 115.06691980369057,
            "mean_diff": 0.4473500714773566,
            "se": 0.4473500714773566,
            "sum_d": 23.7095537882999,
            "sum_d2": 562.1429408402861,
            "retail_diff": 0.4996018860830182,
            "arb_diff": -0.05225181459433957
          },
          "4": {
            "n": 43,
            "incumbent_mean": 112.9910514314628,
            "mean_diff": 0.5139347397395325,
            "se": 0.503260771040441,
            "sum_d": 22.099193808799896,
            "sum_d2": 468.7656984433829,
            "retail_diff": 0.32116010240697823,
            "arb_diff": 0.1927746373348838
          }
        },
        "failures": [],
        "decision": "Cash-fit repair added. Selected exactly the spreads with strictly positive paired tuning mean, then froze before holdout. Selected-spread tuning is computed by substituting N outcomes for excluded independent spread runs; no additional strategy variant was tried."
      }
    ],
    "tuning_diagnostics_by_spread": {
      "1": {
        "runs": 47,
        "runs_binding": 12,
        "runs_swapping": 9,
        "steps": 94000,
        "binds": 1192,
        "swaps": 242,
        "ledger_misses": 0,
        "released": 7206.682,
        "extra_quantity": 209933.12,
        "repairs": 15,
        "bind_fraction": 0.012680851063829787
      },
      "2": {
        "runs": 57,
        "runs_binding": 6,
        "runs_swapping": 2,
        "steps": 114000,
        "binds": 405,
        "swaps": 157,
        "ledger_misses": 0,
        "released": 3594.761499999999,
        "extra_quantity": 359476.15,
        "repairs": 0,
        "bind_fraction": 0.0035526315789473684
      },
      "3": {
        "runs": 53,
        "runs_binding": 9,
        "runs_swapping": 3,
        "steps": 106000,
        "binds": 118,
        "swaps": 55,
        "ledger_misses": 0,
        "released": 1020.9346000000002,
        "extra_quantity": 83973.46,
        "repairs": 0,
        "bind_fraction": 0.0011132075471698114
      },
      "4": {
        "runs": 43,
        "runs_binding": 2,
        "runs_swapping": 2,
        "steps": 86000,
        "binds": 464,
        "swaps": 140,
        "ledger_misses": 0,
        "released": 1363.2943,
        "extra_quantity": 125245.80000000008,
        "repairs": 0,
        "bind_fraction": 0.005395348837209302
      }
    },
    "holdout_diagnostics_by_spread": {
      "1": {
        "runs": 115,
        "runs_binding": 33,
        "runs_swapping": 25,
        "steps": 230000,
        "binds": 3432,
        "swaps": 577,
        "ledger_misses": 0,
        "released": 17592.491,
        "extra_quantity": 628869.7,
        "repairs": 56,
        "bind_fraction": 0.014921739130434783
      },
      "2": {
        "runs": 116,
        "runs_binding": 22,
        "runs_swapping": 0,
        "steps": 232000,
        "binds": 1551,
        "swaps": 0,
        "ledger_misses": 0,
        "released": 0.0,
        "extra_quantity": 0.0,
        "repairs": 0,
        "bind_fraction": 0.006685344827586207
      },
      "3": {
        "runs": 138,
        "runs_binding": 17,
        "runs_swapping": 11,
        "steps": 276000,
        "binds": 1330,
        "swaps": 330,
        "ledger_misses": 0,
        "released": 7507.4843999999985,
        "extra_quantity": 715435.7499999999,
        "repairs": 0,
        "bind_fraction": 0.004818840579710145
      },
      "4": {
        "runs": 131,
        "runs_binding": 9,
        "runs_swapping": 6,
        "steps": 262000,
        "binds": 659,
        "swaps": 264,
        "ledger_misses": 0,
        "released": 3484.7252999999987,
        "extra_quantity": 248223.78999999995,
        "repairs": 0,
        "bind_fraction": 0.002515267175572519
      }
    },
    "holdout_failures": [],
    "equality_checks": {
      "off_seed_first": 310000,
      "off_seed_last": 310009,
      "off_n": 10,
      "off_full_states_actions_and_results_equal": true,
      "assembled_seeds": [
        310032,
        310033,
        310047,
        310065,
        310094
      ],
      "assembled_n": 5,
      "assembled_full_states_actions_and_results_equal": true
    },
    "synthetic_checks": [
      "Cash-binding bid swap evicts inferior old bid and doubles better proposal using released cash.",
      "Covered ask eviction releases only actual uncovered collateral.",
      "Unaffordable proposal is clipped to a valid positive quantity.",
      "Nonbinding action list remains identical.",
      "Anonymous order quantization matches simulator on floating-point boundary."
    ],
    "scoreboard": {
      "current_best_code_sha256": "bf0d179f3e47d28819f6fa7e0d25548c2ced43374c216d36460b00a26a26ffae",
      "candidate_overlay_code_sha256": "429bc9c5278d27ebeda31aa430d96cc1f6f63bf44710efe5cf8f5086dfdf3547",
      "selected_spread_tuning": {
        "n": 200,
        "incumbent_mean": 85.16265316504199,
        "mean_diff": 0.613005449284999,
        "se": 0.4275371719797223,
        "sum_d": 122.6010898569998,
        "sum_d2": 7350.1188664624815,
        "retail_diff": 0.6350382387010002,
        "arb_diff": -0.022032789408999987
      },
      "holdout": {
        "n": 500,
        "incumbent_mean": 104.4137531881468,
        "mean_diff": 0.23052258987960023,
        "se": 0.3194031685810437,
        "sum_d": 115.26129493980011,
        "sum_d2": 25480.15716507524,
        "retail_diff": 0.27498706822460045,
        "arb_diff": -0.044464478347599916
      },
      "promoted": false
    },
    "seconds_per_simulation_definition": "Holdout wall-clock seconds divided by 1000 simulations (500 N and 500 S1), including local bookkeeping and JSONL writes.",
    "limitations": "Only 200 tuning and 500 holdout seeds. Midpoint is an imperfect fair-value estimate; ratios omit fill probability. Binding uses a same-sized incremental-order proxy because N returns already-sized proposals. Holdout was not used to select spreads or revise code; no finalist evaluation or promotion is claimed."
  },
  "next": "Keep incumbent N. This item alone cannot promote: finalist seeds were reserved and untouched. Consider the frozen candidate only alongside independent measurements; inspect the paired holdout uncertainty and cash-binding concentration before any finalist allocation.",
  "spreads_acted": [
    1,
    3,
    4
  ],
  "off_equals_n": true,
  "code": "from dataclasses import replace as _cash_replace\nimport math as _cash_math\nfrom orderbook_pm_challenge.strategy import BaseStrategy as _CashBase\nfrom orderbook_pm_challenge.types import PlaceOrder as _CashPlace, CancelOrder as _CashCancel, CancelAll as _CashCancelAll, Side as _CashSide\n\nclass Strategy(_CashBase):\n    # Frozen after tuning. No orders are added; only N's proposals are resized.\n    spreads = (1, 3, 4)\n    enabled = True\n    def __init__(self):\n        self.n = _N()\n        self._records = {}\n        self._pending = []\n        self._spread = None\n        self._mid = None\n        self._drift = 0.0\n        self.diagnostics = dict(steps=0, binds=0, swaps=0, ledger_misses=0,\n                                released=0.0, extra_quantity=0.0, repairs=0)\n\n    @staticmethod\n    def _reserve(r):\n        side, tick, qty, covered, step = r\n        return round((tick / 100.0) * qty if side == _CashSide.BUY\n                     else (1.0 - tick / 100.0) * max(0.0, qty - covered), 10)\n\n    def _reconcile(self, state):\n        records = {}\n        pending = list(self._pending)\n        good = True\n        for o in state.own_orders:\n            r = self._records.get(o.order_id)\n            if r is None:\n                candidates = [i for i, p in enumerate(pending)\n                              if p[0] == o.side and p[1] == o.price_ticks\n                              and p[4] == o.submitted_step\n                              and p[2] + 1e-8 >= o.remaining_quantity]\n                if candidates:\n                    r = pending.pop(candidates[0])\n                else:\n                    good = False\n                    r = (o.side, o.price_ticks, o.remaining_quantity, 0.0, o.submitted_step)\n            filled = max(0.0, r[2] - o.remaining_quantity)\n            covered = round(max(0.0, r[3] - filled), 10)\n            records[o.order_id] = (o.side, o.price_ticks, o.remaining_quantity,\n                                   min(covered, o.remaining_quantity), o.submitted_step)\n        if abs(sum(self._reserve(r) for r in records.values()) - state.reserved_cash) > 1e-6:\n            good = False\n        return records, good\n\n    def _simulate(self, state, records, actions):\n        book = dict(records)\n        pending = []\n        legal = True\n        for i, a in enumerate(actions):\n            if isinstance(a, _CashCancelAll):\n                book.clear()\n            elif isinstance(a, _CashCancel):\n                if a.order_id not in book:\n                    legal = False\n                book.pop(a.order_id, None)\n            elif isinstance(a, _CashPlace):\n                q = round(_cash_math.floor((float(a.quantity) + 1e-9) / 0.01) * 0.01, 10)\n                avail = round(max(0.0, state.yes_inventory - round(sum(r[3] for r in book.values()), 10)), 10)\n                cover = min(q, avail) if a.side == _CashSide.SELL else 0.0\n                r = (a.side, a.price_ticks, q, cover, state.step)\n                key = a.client_order_id if a.client_order_id is not None else ('new', i)\n                if key in book or q <= 0:\n                    legal = False\n                book[key] = r\n                if sum(self._reserve(v) for v in book.values()) > state.cash + 1e-9:\n                    legal = False\n        known = {k: r for k, r in book.items() if isinstance(k, str)}\n        pending = [r for k, r in book.items() if not isinstance(k, str)]\n        free = state.cash - sum(self._reserve(r) for r in book.values())\n        return known, pending, free, legal, book\n\n    def on_step(self, state):\n        # N owns every submitted order; the overlay creates no additional orders.\n        actions = list(self.n.on_step(state))\n        d = self.diagnostics\n        d['steps'] += 1\n        bid, ask = state.competitor_best_bid_ticks, state.competitor_best_ask_ticks\n        if self._spread is None:\n            self._spread = max(1, ((ask if ask is not None else 100) -\n                                   (bid if bid is not None else 0) + 1) // 2)\n        if bid is not None and ask is not None:\n            mid = (bid + ask) / 200.0\n        elif bid is not None:\n            mid = min(.995, (bid + self._spread / 2.0) / 100.0)\n        elif ask is not None:\n            mid = max(.005, (ask - self._spread / 2.0) / 100.0)\n        else:\n            mid = self._mid if self._mid is not None else .5\n        if self._mid is not None:\n            self._drift = .75 * self._drift + .25 * (mid - self._mid)\n        self._mid = mid\n        fair = max(.005, min(.995, mid + self._drift))\n        records, good = self._reconcile(state)\n        known, pending, free, legal, final = self._simulate(state, records, actions)\n        if not good:\n            d['ledger_misses'] += 1\n        # Binding means that the residual cash cannot fund a second copy of\n        # at least one cash-backed non-probe proposal. This catches N's own\n        # pre-emptive clipping; an actually unaffordable action would fail.\n        proposals = []\n        for i, a in enumerate(actions):\n            if not isinstance(a, _CashPlace) or a.quantity < 1.0:\n                continue\n            key = a.client_order_id if a.client_order_id is not None else ('new', i)\n            if key not in final:\n                continue\n            r = final[key]\n            cost = self._reserve(r)\n            if cost <= 1e-8:\n                continue\n            edge = (fair - a.price_ticks / 100.0) if a.side == _CashSide.BUY else (a.price_ticks / 100.0 - fair)\n            proposals.append((edge * r[2] / cost, i, a, cost))\n        binding = (not legal) or any(free + 1e-8 < p[3] for p in proposals)\n        if binding:\n            d['binds'] += 1\n        if good and legal and binding and self.enabled and self._spread in self.spreads:\n            # Only a surviving pre-existing order may be evicted. N's explicit\n            # cancels and all other original proposals retain their ordering.\n            survivors = []\n            for oid, r in records.items():\n                if oid not in final or self._reserve(r) <= 1e-8:\n                    continue\n                edge = fair - r[1] / 100.0 if r[0] == _CashSide.BUY else r[1] / 100.0 - fair\n                survivors.append((edge * r[2] / self._reserve(r), oid, r))\n            if survivors and proposals:\n                worst, oid, old = min(survivors, key=lambda x: (x[0], x[1]))\n                best, index, a, cost = max(proposals, key=lambda x: (x[0], -x[1]))\n                if best > worst + 1e-8 and free + 1e-8 < cost:\n                    released = self._reserve(old)\n                    unit = a.price_ticks / 100.0 if a.side == _CashSide.BUY else 1.0 - a.price_ticks / 100.0\n                    extra = _cash_math.floor((min(float(a.quantity), released / unit) + 1e-12) / .01) * .01\n                    if extra >= .01:\n                        changed = list(actions)\n                        changed[index] = _cash_replace(a, quantity=round(a.quantity + extra, 10))\n                        changed.insert(index, _CashCancel(oid))\n                        ck, cp, cf, ok, cb = self._simulate(state, records, changed)\n                        if ok:\n                            actions = changed\n                            known, pending = ck, cp\n                            d['swaps'] += 1\n                            d['released'] += released\n                            d['extra_quantity'] += extra\n        if good and not legal and self.enabled and self._spread in self.spreads:\n            actions = self._repair(state, records, actions, fair)\n            known, pending, _, _, _ = self._simulate(state, records, actions)\n            d['repairs'] += 1\n        self._records, self._pending = known, pending\n        return actions\n\n    def _repair(self, state, records, actions, fair):\n        # A previous collateral swap can leave N's next proposal unfunded.\n        # Evict only inferior survivors, then clip to actual affordable size.\n        doomed = {a.order_id for a in actions if isinstance(a, _CashCancel)}\n        if any(isinstance(a, _CashCancelAll) for a in actions):\n            doomed.update(records)\n        out = []\n        def ratio(r):\n            edge = fair - r[1]/100.0 if r[0] == _CashSide.BUY else r[1]/100.0 - fair\n            cost = self._reserve(r)\n            return edge*r[2]/cost if cost > 1e-8 else float('inf')\n        for a in actions:\n            _, _, free, _, book = self._simulate(state, records, out)\n            if isinstance(a, _CashCancel) and a.order_id not in book:\n                continue\n            if isinstance(a, _CashPlace):\n                unit = a.price_ticks/100.0 if a.side == _CashSide.BUY else 1-a.price_ticks/100.0\n                def capacity():\n                    _, _, f, _, b = self._simulate(state, records, out)\n                    cover = round(max(0.0, state.yes_inventory-round(sum(r[3] for r in b.values()),10)),10) if a.side == _CashSide.SELL else 0.0\n                    return max(0.0, cover + max(0.0, f-1e-7)/unit), cover\n                cap, cover = capacity()\n                new = (a.side,a.price_ticks,float(a.quantity),min(a.quantity,cover),state.step)\n                candidates = sorted((ratio(r),oid) for oid,r in book.items()\n                                    if oid in records and oid not in doomed and self._reserve(r)>1e-8)\n                for score, oid in candidates:\n                    if a.quantity <= cap+1e-8 or score >= ratio(new)-1e-8:\n                        break\n                    out.append(_CashCancel(oid))\n                    cap, cover = capacity()\n                if a.quantity > cap:\n                    q = round(_cash_math.floor(cap/.01)*.01,10)\n                    if q < .01:\n                        continue\n                    a = _cash_replace(a,quantity=q)\n            out.append(a)\n        return out\n",
  "code_sha256": "429bc9c5278d27ebeda31aa430d96cc1f6f63bf44710efe5cf8f5086dfdf3547",
  "assembled_sha256": "409a99d41dd272616f19aa5f653e231acd7ad654f6ac7d6956103196a9d7313f",
  "tuning": {
    "n": 200,
    "mean_diff": 0.613005449284999,
    "se": 0.4275371719797223
  },
  "paired": {
    "first_seed": 410000,
    "last_seed": 410499,
    "n": 500,
    "incumbent_mean": 104.4137531881468,
    "mean_diff": 0.23052258987960023,
    "se": 0.3194031685810437,
    "sum_d": 115.26129493980011,
    "sum_d2": 25480.15716507524,
    "retail_diff": 0.27498706822460045,
    "arb_diff": -0.044464478347599916,
    "complete": true,
    "failures": 0
  },
  "by_spread": {
    "1": {
      "runs": 115,
      "incumbent_mean": 28.495154459731307,
      "mean_diff": -0.16040588702608619,
      "se": 0.43279404974813807,
      "sum_d": -18.446677007999913,
      "sum_d2": 2458.602094898985,
      "retail_diff": 0.20556063978695752,
      "arb_diff": -0.3659665268252173
    },
    "2": {
      "runs": 116,
      "incumbent_mean": 97.76626247947758,
      "mean_diff": 0.0,
      "se": 0.0,
      "sum_d": 0.0,
      "sum_d2": 0.0,
      "retail_diff": 0.0,
      "arb_diff": 0.0
    },
    "3": {
      "runs": 138,
      "incumbent_mean": 128.4054514027384,
      "mean_diff": 0.6984688386521741,
      "se": 1.0639979431468838,
      "sum_d": 96.38869973400003,
      "sum_d2": 21470.64872799363,
      "retail_diff": 0.5041680303724642,
      "arb_diff": 0.19430080828115942
    },
    "4": {
      "runs": 131,
      "incumbent_mean": 151.67248160310686,
      "mean_diff": 0.2848799405633587,
      "se": 0.3007404085149028,
      "sum_d": 37.31927221379999,
      "sum_d2": 1550.9063421826272,
      "retail_diff": 0.3380066591251913,
      "arb_diff": -0.05312671856259519
    }
  },
  "seconds_per_simulation": 0.24666032069502397
}
