{
  "key": "f-exposure-ratchet",
  "mech": "Exposure ratchet: a reported own buy (sell) followed by a visible rival midpoint decline (rise) of >=2 ticks within 3 steps resets a 0.5 size multiplier. Hold 50 steps, then recover linearly over 50 steps. Both sides are scaled; repeat triggers restart the clock.",
  "approach": "Blind subclass overlay; N source was downloaded, hash-checked and assembled by script without viewing it. Anchor fills at the preceding callback midpoint; require both rival quotes. Apply on spreads 1-4. Scale new orders; reduce surviving orders on multiplier drops, never enlarge retained orders during recovery. Preserve N prices and cancellations. Tune 50/100-step hold/recovery plus a 50-step variant with conservative collateral capping after an observed failure; freeze the best failure-free paired mean. Screen only; no promotion.",
  "tried": [
    {
      "name": "h50",
      "hold_steps": 50,
      "linear_recovery_steps": 50
    },
    {
      "name": "h100",
      "hold_steps": 100,
      "linear_recovery_steps": 100
    },
    {
      "name": "h50safe",
      "hold_steps": 50,
      "linear_recovery_steps": 50,
      "collateral_cap": true
    }
  ],
  "next": "Reject this overlay: the frozen screen loses edge and has holdout runtime failures. Keep N; no promotion. Do not tune further on this holdout. Statistics include partial engine edge on failed runs, which are explicitly listed.",
  "spreads_acted": [
    1,
    2,
    3,
    4
  ],
  "off_equals_n": true,
  "code": "from dataclasses import replace as _ratchet_replace\nfrom orderbook_pm_challenge.types import PlaceOrder as _RP, CancelAll as _RCA, CancelOrder as _RC\n\nclass Strategy(_N):\n    ratchet_enabled = True\n    ratchet_hold = 50\n    ratchet_spreads = (1, 2, 3, 4)\n\n    def on_step(self, state):\n        actions = super().on_step(state)\n        if not self.ratchet_enabled or self.s not in self.ratchet_spreads:\n            return actions\n        t = state.step\n        if t == 0:\n            self._er_pending = []\n            self._er_mid = None\n            self._er_last_trigger = None\n            self._er_scales = {}\n        bid = state.competitor_best_bid_ticks\n        ask = state.competitor_best_ask_ticks\n        mid = (bid + ask) / 2.0 if bid is not None and ask is not None else None\n        # Fills reported at t happened at t-1; use its pre-fill midpoint.\n        if self._er_mid is not None and t > 0:\n            if state.buy_filled_quantity > 0:\n                self._er_pending.append((t-1, self._er_mid, 1))\n            if state.sell_filled_quantity > 0:\n                self._er_pending.append((t-1, self._er_mid, -1))\n        pending = []\n        hit = False\n        for filled_at, ref, direction in self._er_pending:\n            if t - filled_at <= 3:\n                if mid is not None and direction * (mid - ref) <= -2.0:\n                    hit = True\n                else:\n                    pending.append((filled_at, ref, direction))\n        self._er_pending = pending\n        self._er_mid = mid\n        if hit:\n            self._er_last_trigger = t\n        scale = 1.0\n        if self._er_last_trigger is not None:\n            age = t - self._er_last_trigger\n            hold = self.ratchet_hold\n            if age < hold:\n                scale = 0.5\n            elif age < 2 * hold:\n                scale = 0.5 + 0.5 * (age - hold) / hold\n        self._er_scales[t] = scale\n        # N's cancellations remain authoritative. Reduce retained orders only\n        # when the multiplier falls; recovery applies to newly placed orders.\n        actions = list(actions)\n        all_cancelled = any(isinstance(a, _RCA) for a in actions)\n        cancelled = {a.order_id for a in actions if isinstance(a, _RC)}\n        retained = []\n        extra_cancels = []\n        if not all_cancelled:\n            for o in state.own_orders:\n                old = self._er_scales.get(o.submitted_step, 1.0)\n                if o.order_id not in cancelled and scale < old - 1e-12:\n                    extra_cancels.append(_RC(o.order_id))\n                    q = int((o.remaining_quantity * scale / old + 1e-9) * 100) / 100\n                    if q >= 0.01:\n                        retained.append(_RP(o.side, o.price_ticks, q, o.order_id))\n        out = list(extra_cancels)\n        for a in actions:\n            if isinstance(a, _RP) and scale < 1.0:\n                q = int((a.quantity * scale + 1e-9) * 100) / 100\n                if q >= 0.01:\n                    out.append(_ratchet_replace(a, quantity=q))\n            else:\n                out.append(a)\n        out.extend(retained)\n        return self._er_cap(state, out) if scale < 1.0 else out\n\n    def _er_cap(self, state, actions):\n        # Lower bound on free collateral; no private simulator state is used.\n        from orderbook_pm_challenge.types import Side as _RS\n        cash = max(0.0, state.free_cash)\n        yes = max(0.0, state.yes_inventory)\n        live = {o.order_id: (o.side, o.price_ticks, o.remaining_quantity)\n                for o in state.own_orders}\n        out = []\n        for i, a in enumerate(actions):\n            if isinstance(a, _RCA):\n                live.clear()\n                cash = max(0.0, state.cash)\n                out.append(a)\n            elif isinstance(a, _RC):\n                o = live.pop(a.order_id, None)\n                if o is not None:\n                    side, tick, qty = o\n                    cash += qty * tick / 100 if side == _RS.BUY else max(0.0, qty - yes) * (1 - tick / 100)\n                out.append(a)\n            elif isinstance(a, _RP):\n                price = a.price_ticks / 100\n                free_yes = max(0.0, yes - sum(q for side, tick, q in live.values() if side == _RS.SELL))\n                limit = cash / price if a.side == _RS.BUY else free_yes + cash / (1 - price)\n                qty = int((min(a.quantity, max(0.0, limit)) + 1e-10) * 100) / 100\n                if qty < 0.01:\n                    continue\n                cost = qty * price if a.side == _RS.BUY else max(0.0, qty - free_yes) * (1 - price)\n                cash = max(0.0, cash - cost)\n                live[a.client_order_id if a.client_order_id else ('new', i)] = (a.side, a.price_ticks, qty)\n                out.append(_ratchet_replace(a, quantity=qty))\n            else:\n                out.append(a)\n        return out\n",
  "code_sha256": "4cc20e7b283dd38b42589255fdc0a04877b2588568d66146e6964167be8af1da",
  "assembled_sha256": "4e51e7fe7f19e8334bcece9f5e250d8781aedf9fadd6ee54a2435651d4fe8798",
  "tuning": {
    "seeds": {
      "start": 320000,
      "end_inclusive": 320199
    },
    "selected": "h50safe",
    "variants": [
      {
        "name": "h50",
        "failed_seeds": [
          320151
        ],
        "partial_edges_included_for_failed_runs": true,
        "collateral_cap": false,
        "hold_steps": 50,
        "linear_recovery_steps": 50,
        "spreads_acted": [
          1,
          2,
          3,
          4
        ],
        "code_sha256": "afb8e6e4ca62e2c14e7c4e52d0ea33cdb5b1dc2951ac38b1e97e0e26cbfe502c",
        "assembled_sha256": "98d376d9d085b7b0fe3ecbabfb6c29249d4f33a873f06dc5df705e6e7f4f3a85",
        "overall": {
          "n": 200,
          "sum_d": -6562.7751194511,
          "sum_d2": 612001.2257423342,
          "mean_diff": -32.8138755972555,
          "se": 3.1569144793846244,
          "incumbent_mean": 98.47071831456549,
          "candidate_mean": 65.65684271731,
          "retail_diff": -14.3049098142845,
          "arb_diff": -18.5089657829865
        },
        "by_spread": {
          "1": {
            "n": 50,
            "sum_d": -282.8099905367,
            "sum_d2": 9882.367530470585,
            "mean_diff": -5.656199810734,
            "se": 1.8386705174234261,
            "incumbent_mean": 25.711261479664,
            "candidate_mean": 20.05506166893,
            "retail_diff": -4.287810675136001,
            "arb_diff": -1.368389135634
          },
          "2": {
            "n": 50,
            "sum_d": -956.2372542968,
            "sum_d2": 33572.43074258464,
            "mean_diff": -19.124745085936,
            "se": 2.4977244347673486,
            "incumbent_mean": 61.219908510538,
            "candidate_mean": 42.095163424602,
            "retail_diff": -13.875054605644,
            "arb_diff": -5.249690480283999
          },
          "3": {
            "n": 48,
            "sum_d": -2201.5129310697,
            "sum_d2": 167613.8884037241,
            "mean_diff": -45.86485273061874,
            "se": 5.435054252914001,
            "incumbent_mean": 130.8342429047854,
            "candidate_mean": 84.96939017416666,
            "retail_diff": -21.183445139122917,
            "arb_diff": -24.68140759157917
          },
          "4": {
            "n": 52,
            "sum_d": -3122.2149435479,
            "sum_d2": 400932.5390655548,
            "mean_diff": -60.04259506822885,
            "se": 8.97177263328206,
            "incumbent_mean": 174.37579815333268,
            "candidate_mean": 114.33320308510385,
            "retail_diff": -18.00064100269231,
            "arb_diff": -42.041954065492305
          }
        }
      },
      {
        "name": "h100",
        "failed_seeds": [
          320109,
          320151,
          320154
        ],
        "partial_edges_included_for_failed_runs": true,
        "collateral_cap": false,
        "hold_steps": 100,
        "linear_recovery_steps": 100,
        "spreads_acted": [
          1,
          2,
          3,
          4
        ],
        "code_sha256": "c78cbe292f307ca5429b10d567cf7e18e8ccb92996a46aeedc47b6b69d261ea0",
        "assembled_sha256": "f9dbe4ac8f3a0a25e4b2037dd46d5b305a320244532092169ca22b89d329979c",
        "overall": {
          "n": 200,
          "sum_d": -8381.6510248307,
          "sum_d2": 1037304.8642880145,
          "mean_diff": -41.9082551241535,
          "se": 4.1517826127777315,
          "incumbent_mean": 98.47071831456549,
          "candidate_mean": 56.562463190412,
          "retail_diff": -17.088103982312,
          "arb_diff": -24.8201511418775
        },
        "by_spread": {
          "1": {
            "n": 50,
            "sum_d": -382.17369180290007,
            "sum_d2": 20038.351294346478,
            "mean_diff": -7.643473836058002,
            "se": 2.643221340174061,
            "incumbent_mean": 25.711261479664,
            "candidate_mean": 18.067787643606,
            "retail_diff": -5.4335362531980005,
            "arb_diff": -2.2099375828680006
          },
          "2": {
            "n": 50,
            "sum_d": -1321.6472198009,
            "sum_d2": 77600.43487869423,
            "mean_diff": -26.432944396018,
            "se": 4.173062664599171,
            "incumbent_mean": 61.219908510538,
            "candidate_mean": 34.78696411452,
            "retail_diff": -17.370972357935997,
            "arb_diff": -9.06197203808
          },
          "3": {
            "n": 48,
            "sum_d": -2593.6856555130003,
            "sum_d2": 226245.2131146214,
            "mean_diff": -54.035117823187505,
            "se": 6.177598482854461,
            "incumbent_mean": 130.8342429047854,
            "candidate_mean": 76.79912508159792,
            "retail_diff": -24.3362038190625,
            "arb_diff": -29.698914004316666
          },
          "4": {
            "n": 52,
            "sum_d": -4084.1444577139,
            "sum_d2": 713420.8650003524,
            "mean_diff": -78.54123957142116,
            "se": 12.167866477898423,
            "incumbent_mean": 174.37579815333268,
            "candidate_mean": 95.83455858191154,
            "retail_diff": -21.33187658828269,
            "arb_diff": -57.20936298309424
          }
        }
      },
      {
        "name": "h50safe",
        "failed_seeds": [],
        "partial_edges_included_for_failed_runs": true,
        "collateral_cap": true,
        "hold_steps": 50,
        "linear_recovery_steps": 50,
        "spreads_acted": [
          1,
          2,
          3,
          4
        ],
        "code_sha256": "4cc20e7b283dd38b42589255fdc0a04877b2588568d66146e6964167be8af1da",
        "assembled_sha256": "4e51e7fe7f19e8334bcece9f5e250d8781aedf9fadd6ee54a2435651d4fe8798",
        "overall": {
          "n": 200,
          "sum_d": -6557.5581757957,
          "sum_d2": 611928.0832141116,
          "mean_diff": -32.7877908789785,
          "se": 3.1579851611629355,
          "incumbent_mean": 98.47071831456549,
          "candidate_mean": 65.682927435587,
          "retail_diff": -14.2788250960075,
          "arb_diff": -18.5089657829865
        },
        "by_spread": {
          "1": {
            "n": 50,
            "sum_d": -277.5930468813,
            "sum_d2": 9809.225002248071,
            "mean_diff": -5.5518609376259995,
            "se": 1.8370414334046437,
            "incumbent_mean": 25.711261479664,
            "candidate_mean": 20.159400542038,
            "retail_diff": -4.183471802028,
            "arb_diff": -1.368389135634
          },
          "2": {
            "n": 50,
            "sum_d": -956.2372542968,
            "sum_d2": 33572.43074258464,
            "mean_diff": -19.124745085936,
            "se": 2.4977244347673486,
            "incumbent_mean": 61.219908510538,
            "candidate_mean": 42.095163424602,
            "retail_diff": -13.875054605644,
            "arb_diff": -5.249690480283999
          },
          "3": {
            "n": 48,
            "sum_d": -2201.5129310697,
            "sum_d2": 167613.8884037241,
            "mean_diff": -45.86485273061874,
            "se": 5.435054252914001,
            "incumbent_mean": 130.8342429047854,
            "candidate_mean": 84.96939017416666,
            "retail_diff": -21.183445139122917,
            "arb_diff": -24.68140759157917
          },
          "4": {
            "n": 52,
            "sum_d": -3122.2149435479,
            "sum_d2": 400932.5390655548,
            "mean_diff": -60.04259506822885,
            "se": 8.97177263328206,
            "incumbent_mean": 174.37579815333268,
            "candidate_mean": 114.33320308510385,
            "retail_diff": -18.00064100269231,
            "arb_diff": -42.041954065492305
          }
        }
      }
    ],
    "scoreboard": {
      "current_best_code_sha256": "bf0d179f3e47d28819f6fa7e0d25548c2ced43374c216d36460b00a26a26ffae",
      "candidate_paired_differences": {
        "h50": {
          "mean_diff": -32.8138755972555,
          "se": 3.1569144793846244
        },
        "h100": {
          "mean_diff": -41.9082551241535,
          "se": 4.1517826127777315
        },
        "h50safe": {
          "mean_diff": -32.7877908789785,
          "se": 3.1579851611629355
        }
      }
    },
    "selection_rule": "Largest overall paired mean difference among variants with no failures on all 200 tuning seeds; no per-spread tuning."
  },
  "paired": {
    "seeds": {
      "start": 430000,
      "end_inclusive": 430499
    },
    "n": 500,
    "complete": true,
    "missing_seeds": [],
    "failed_seeds": [
      430009,
      430108,
      430216
    ],
    "statistics_include_partial_edges_on_failed_runs": true,
    "complete_means": "All 500 requested seed pairs attempted once; failures are not successful 2000-step runs",
    "overall": {
      "n": 500,
      "sum_d": -17318.8369245721,
      "sum_d2": 1689723.700242409,
      "mean_diff": -34.6376738491442,
      "se": 2.089998586073646,
      "incumbent_mean": 95.54201511346659,
      "candidate_mean": 60.9043412643224,
      "retail_diff": -14.0172621364234,
      "arb_diff": -20.6204117127372
    },
    "by_spread": {
      "1": {
        "n": 131,
        "sum_d": -573.5923277093,
        "sum_d2": 85042.83198770859,
        "mean_diff": -4.378567387093893,
        "se": 2.2014157528683014,
        "incumbent_mean": 38.277936657049615,
        "candidate_mean": 33.89936926995573,
        "retail_diff": 0.2571812686832072,
        "arb_diff": -4.635748655753435
      },
      "2": {
        "n": 120,
        "sum_d": -3034.5576480661,
        "sum_d2": 151609.70196744482,
        "mean_diff": -25.287980400550833,
        "se": 2.2897877600142116,
        "incumbent_mean": 77.8558643979175,
        "candidate_mean": 52.56788399736667,
        "retail_diff": -16.186723266488332,
        "arb_diff": -9.101257134088334
      },
      "3": {
        "n": 133,
        "sum_d": -6339.9282644568,
        "sum_d2": 615043.7548515502,
        "mean_diff": -47.668633567344365,
        "se": 4.2212400411709705,
        "incumbent_mean": 146.55140363646615,
        "candidate_mean": 98.8827700691218,
        "retail_diff": -23.567060090997746,
        "arb_diff": -24.101573476406767
      },
      "4": {
        "n": 116,
        "sum_d": -7370.7586843399,
        "sum_d2": 838027.4114357055,
        "mean_diff": -63.54102314086121,
        "se": 5.264245777537733,
        "incumbent_mean": 120.02204692465259,
        "candidate_mean": 56.48102378379138,
        "retail_diff": -16.94393129593017,
        "arb_diff": -46.59709184493276
      }
    },
    "successful_pairs_only": {
      "overall": {
        "n": 497,
        "sum_d": -17187.3936096338,
        "sum_d2": 1679389.141725968,
        "mean_diff": -34.58228090469578,
        "se": 2.0979629359920127,
        "incumbent_mean": 95.78644213205513,
        "candidate_mean": 61.20416122735936,
        "retail_diff": -13.911739800740644,
        "arb_diff": -20.670541103968812
      },
      "by_spread": {
        "1": {
          "n": 130,
          "sum_d": -573.4095022814,
          "sum_d2": 85042.7985625715,
          "mean_diff": -4.410842325241538,
          "se": 2.218176923658692,
          "incumbent_mean": 38.538409508369234,
          "candidate_mean": 34.127567183127695,
          "retail_diff": 0.2643593750607703,
          "arb_diff": -4.675201700281539
        },
        "2": {
          "n": 120,
          "sum_d": -3034.5576480661,
          "sum_d2": 151609.70196744482,
          "mean_diff": -25.287980400550833,
          "se": 2.2897877600142116,
          "incumbent_mean": 77.8558643979175,
          "candidate_mean": 52.56788399736667,
          "retail_diff": -16.186723266488332,
          "arb_diff": -9.101257134088334
        },
        "3": {
          "n": 132,
          "sum_d": -6303.6226427857,
          "sum_d2": 613725.6566866252,
          "mean_diff": -47.75471699080076,
          "se": 4.252456674980703,
          "incumbent_mean": 147.39383805961742,
          "candidate_mean": 99.63912106881666,
          "retail_diff": -23.50028391310379,
          "arb_diff": -24.254433077749997
        },
        "4": {
          "n": 115,
          "sum_d": -7275.8038165006,
          "sum_d2": 829010.9845093265,
          "mean_diff": -63.26785927391826,
          "se": 5.3030685858101965,
          "incumbent_mean": 119.97546219064174,
          "candidate_mean": 56.70760291672348,
          "retail_diff": -16.557018532327824,
          "arb_diff": -46.710840741585216
        }
      }
    }
  },
  "failures": [
    {
      "phase": "tuning",
      "seed": 320109,
      "strategy": "h100",
      "error": "orderbook_pm_challenge.market.OrderBookError: Insufficient free cash for order collateral"
    },
    {
      "phase": "tuning",
      "seed": 320151,
      "strategy": "h50",
      "error": "orderbook_pm_challenge.market.OrderBookError: Insufficient free cash for order collateral"
    },
    {
      "phase": "tuning",
      "seed": 320151,
      "strategy": "h100",
      "error": "orderbook_pm_challenge.market.OrderBookError: Insufficient free cash for order collateral"
    },
    {
      "phase": "tuning",
      "seed": 320154,
      "strategy": "h100",
      "error": "orderbook_pm_challenge.market.OrderBookError: Insufficient free cash for order collateral"
    },
    {
      "phase": "holdout",
      "seed": 430009,
      "strategy": "h50safe",
      "error": "orderbook_pm_challenge.market.OrderBookError: Insufficient free cash for order collateral"
    },
    {
      "phase": "holdout",
      "seed": 430108,
      "strategy": "h50safe",
      "error": "orderbook_pm_challenge.market.OrderBookError: Insufficient free cash for order collateral"
    },
    {
      "phase": "holdout",
      "seed": 430216,
      "strategy": "h50safe",
      "error": "orderbook_pm_challenge.market.OrderBookError: Insufficient free cash for order collateral"
    }
  ],
  "check_values": [
    17.1160017503,
    20.0171113118,
    2.3903113616,
    241.4847522404
  ],
  "python_version": "3.12.3",
  "seconds_per_simulation": 0.3109347607898219,
  "validation": {
    "simulator_commit": "b244530ee2a6247b5f930830eeca9dd950da0e7e",
    "default_config": true,
    "default_parameter_variance": true,
    "configured_steps_per_simulation": 2000,
    "serial": true,
    "sandbox": false,
    "off_equality": {
      "seeds": {
        "start": 310000,
        "end_inclusive": 310009
      },
      "steps_each": 2000,
      "comparison": "Two independent instances see the same StepState; N actions drive the unmodified engine. Off overlay actions equal N at every callback."
    },
    "synthetic_checks": [
      "buy and sell trigger",
      "three-step window boundary and expiry",
      "hold and linear recovery",
      "retained order shrink",
      "retrigger reset",
      "conservative collateral cap: 38 synthetic market states"
    ],
    "holdout_selected_before_running": true,
    "tuning_observations": 800,
    "holdout_observations": 1000,
    "holdout_successful_runs": 997,
    "no_duplicate_seed_strategy_pairs_tuning_and_holdout": true,
    "equality_check_simulations": 20,
    "equality_check_details": "Original and collateral-capped overlays each checked switched off on the ten specified check seeds, with N as an independent action comparator.",
    "no_finalist_seeds_used": true,
    "timing_includes": "Engine.run wall time, including 20 reference/equality runs; excludes downloading and assembly."
  }
}
