{
  "key": "f-cp-filter",
  "approach": "Blind drop/cancel overlay owning one incumbent N instance. A 641-bin latent-score posterior on [-8,8] at spacing 0.025 is propagated with bin-integrated Gaussian diffusion plus the full compound-Poisson Gaussian jump mixture (Poisson tail tolerance 1e-12). Quote bid/ask bounds truncate the posterior, with fractional boundary-bin likelihoods. The posterior mean uses the documented compound-Poisson terminal-probability formula. Hidden per-run jump intensity, jump sigma and jump mean are assumed to be ParameterVariance midpoints (0.0019, 0.4, 0); this is exact mixture evaluation under an assumed model, not an exact posterior for the unknown sampled parameters. The initial score prior is uniform on [-0.75,0.75]; zero-mass observations reset to uniform allowed cells. Finite grid, uniform within-bin likelihoods and retail-driven quote replenishment are additional approximations. New N orders on the wrong side of the posterior mean by the tuned margin are dropped; uncanceled resting N orders on that side are canceled. No orders are added, so N sees all its own orders without any state masking. N.on_step is called on every step. Outside the frozen spread set its actions are returned untouched.",
  "tried": {
    "incumbent_sha256": "bf0d179f3e47d28819f6fa7e0d25548c2ced43374c216d36460b00a26a26ffae",
    "seed_310000_incumbent_edge": 17.1160017503,
    "seed_check_matches_17_116002": true,
    "tuning_seeds": "310000..310199; both variants on every seed; no other tuning seeds",
    "variants": [
      {
        "variant": 0,
        "margin": 0.0,
        "spreads": [
          1
        ],
        "by_spread": {
          "1": {
            "n": 47,
            "mean_diff": -23.872230850776596,
            "se": 9.707269098987677,
            "sum_d": -1121.9948499865,
            "sum_d2": 230512.1006769283
          },
          "2": {
            "n": 57,
            "mean_diff": -93.40330463402807,
            "se": 12.172535672982328,
            "sum_d": -5323.9883641396,
            "sum_d2": 970238.741118159
          },
          "3": {
            "n": 53,
            "mean_diff": -134.57970128133962,
            "se": 12.843676172133128,
            "sum_d": -7132.724167911,
            "sum_d2": 1414549.6963855475
          },
          "4": {
            "n": 43,
            "mean_diff": -119.32035086930232,
            "se": 12.574005732514344,
            "sum_d": -5130.77508738,
            "sum_d2": 897744.633668971
          }
        },
        "all_spreads": {
          "n": 200,
          "mean_diff": -93.5474123470855,
          "se": 6.655223324544393,
          "sum_d": -18709.4824694171,
          "sum_d2": 3513045.1718496056
        },
        "selected": {
          "n": 200,
          "mean_diff": -5.6099742499325,
          "se": 2.3735230184462397,
          "sum_d": -1121.9948499865,
          "sum_d2": 230512.1006769283
        }
      },
      {
        "variant": 1,
        "margin": 0.5,
        "spreads": [
          1
        ],
        "by_spread": {
          "1": {
            "n": 47,
            "mean_diff": -7.0056725256638295,
            "se": 4.185494931681364,
            "sum_d": -329.2666087062,
            "sum_d2": 40181.44526783943
          },
          "2": {
            "n": 57,
            "mean_diff": -59.73595746572456,
            "se": 11.238489893716515,
            "sum_d": -3404.9495755463,
            "sum_d2": 606559.1900687796
          },
          "3": {
            "n": 53,
            "mean_diff": -102.41347562266792,
            "se": 11.710127777206866,
            "sum_d": -5427.9142080014,
            "sum_d2": 933813.8265143428
          },
          "4": {
            "n": 43,
            "mean_diff": -107.45577874012326,
            "se": 8.976167388649468,
            "sum_d": -4620.5984858253005,
            "sum_d2": 642022.283806024
          }
        },
        "all_spreads": {
          "n": 200,
          "mean_diff": -68.913644390396,
          "se": 5.654985502258038,
          "sum_d": -13782.7288780792,
          "sum_d2": 2222576.745656986
        },
        "selected": {
          "n": 200,
          "mean_diff": -1.646333043531,
          "se": 0.9979799039501333,
          "sum_d": -329.2666087062,
          "sum_d2": 40181.44526783943
        }
      }
    ],
    "tuning_incumbent_mean": 85.162653165042,
    "selected_tuning_mean": 83.516320121511,
    "selection": "For each margin, use all positive-mean spread groups; if none are positive, use its single least-negative spread group. Choose the resulting variant with the larger paired tuning mean. Require a nonempty set to measure the proposed mechanism even if tuning rejects it.",
    "selected_margin_ticks": 0.5,
    "off_check": "All SimulationResult fields equal N on seeds 310000..310009 with SPREADS=(). The off path directly returns N actions.",
    "assembly_check": "N text renamed using the required single class-line replacement, followed by newline and overlay. Assembled and S1 actions equal at every callback on five active-spread tuning seeds; complete simulation results also match the recorded tuning outcomes.",
    "assembly_seeds": [
      310002,
      310005,
      310011,
      310012,
      310020
    ],
    "math_check": "Mixture map agrees with simulator true_probability within 1e-14 at 7 grid points for each horizon 1,10,500,2000 using the assumed parameters. Symmetric transition kernel mass is 0.9999999999999999.",
    "timing_definition": "seconds_per_simulation is combined measured N and S1 holdout runtime divided by 1000 complete individual simulations, including cold filter-map initialization.",
    "execution": "Unmodified simulator at b244530ee2a6247b5f930830eeca9dd950da0e7e, default ChallengeConfig and ParameterVariance, 2000 steps, serial in-process SimulationEngine; no workers or sandbox. No finalist seeds used."
  },
  "next": "Do not promote: this holdout does not show a paired gain greater than twice its standard error. A follow-up mechanism should estimate or marginalize the hidden jump parameters and model quote replenishment from retail rather than treating all current quotes as hard arbitrage bounds. Do not retune using these holdout seeds.",
  "spreads_acted": [
    1
  ],
  "off_equals_n": true,
  "code": "import math as _cp_math\nimport bisect as _cp_bisect\nfrom orderbook_pm_challenge.types import PlaceOrder as _CPPlace, CancelOrder as _CPCancel, CancelAll as _CPAll, Side as _CPSide\n\n# Fixed latent grid, with exact Poisson-Gaussian mixture probabilities at\n# bin boundaries. Unknown jump parameters use ParameterVariance midpoints.\n_CP_DX = 0.025\n_CP_ZERO = 320\n_CP_SIZE = 641\n_CP_MAP = {}\n_CP_KERNEL = None\n\ndef _cp_weights(lam):\n    w = _cp_math.exp(-lam)\n    out = [w]\n    total = w\n    n = 0\n    while 1.0 - total > 1e-12:\n        n += 1\n        w *= lam / n\n        out.append(w)\n        total += w\n    return [v / total for v in out]\n\ndef _cp_cdf(x):\n    return 0.5 * (1.0 + _cp_math.erf(x / _cp_math.sqrt(2.0)))\n\ndef _cp_mapping(h):\n    if h not in _CP_MAP:\n        weights = _cp_weights(0.0019 * h)\n        scales = [1.0 / _cp_math.sqrt(h * 0.0004 + n * 0.16) for n in range(len(weights))]\n        values = []\n        for i in range(_CP_SIZE):\n            z = (i - _CP_ZERO) * _CP_DX\n            values.append(sum(w * _cp_cdf(z * a) for w, a in zip(weights, scales)))\n        _CP_MAP[h] = values\n    return _CP_MAP[h]\n\ndef _cp_kernel():\n    global _CP_KERNEL\n    if _CP_KERNEL is None:\n        weights = _cp_weights(0.0019)\n        scales = [1.0 / _cp_math.sqrt(0.0004 + n * 0.16) for n in range(len(weights))]\n        _CP_KERNEL = [sum(w * (_cp_cdf((d + 0.5) * _CP_DX * a) - _cp_cdf((d - 0.5) * _CP_DX * a)) for w, a in zip(weights, scales)) for d in range(_CP_SIZE)]\n    return _CP_KERNEL\n\nclass Strategy(_N):\n    # Set selected using tuning seeds only. Empty tuple disables the overlay.\n    SPREADS = (1,)\n    MARGIN_TICKS = 0.5\n\n    def __init__(self):\n        self._n = _N()\n        self._spread = None\n        self._post = None\n        self._lo = 0\n\n    def _estimate(self, state):\n        pmap = _cp_mapping(state.steps_remaining)\n        bid = state.competitor_best_bid_ticks\n        ask = state.competitor_best_ask_ticks\n        lower = 0.0 if bid is None else bid / 100.0\n        upper = 1.0 if ask is None else ask / 100.0\n        # Include grid cells intersecting the quote interval, to avoid\n        # empty support when the latent interval is narrower than a bin.\n        lo = max(0, _cp_bisect.bisect_left(pmap, lower) - 1)\n        hi = min(_CP_SIZE - 1, _cp_bisect.bisect_right(pmap, upper))\n        if hi < lo:\n            lo, hi = hi, lo\n        kernel = _cp_kernel()\n        if self._post is None:\n            prior = [1.0 if abs((j - _CP_ZERO) * _CP_DX) <= 0.75 else 0.0 for j in range(lo, hi + 1)]\n        else:\n            old = self._post\n            oldlo = self._lo\n            prior = [sum(v * kernel[abs(j - oldlo - k)] for k, v in enumerate(old)) for j in range(lo, hi + 1)]\n        # Uniform within-bin observation likelihood, with fractional cells.\n        for k, j in enumerate(range(lo, hi + 1)):\n            left = 0.0 if j == 0 else (pmap[j - 1] + pmap[j]) * 0.5\n            right = 1.0 if j == _CP_SIZE - 1 else (pmap[j] + pmap[j + 1]) * 0.5\n            prior[k] *= max(0.0, min(upper, right) - max(lower, left)) / max(1e-15, right - left)\n        total = sum(prior)\n        if total <= 1e-200:\n            prior = [1.0] * (hi - lo + 1)\n            total = len(prior)\n        self._post = [v / total for v in prior]\n        self._lo = lo\n        return 100.0 * sum(v * pmap[lo + k] for k, v in enumerate(self._post))\n\n    def on_step(self, state):\n        actions = self._n.on_step(state)\n        if self._spread is None:\n            bid = state.competitor_best_bid_ticks\n            ask = state.competitor_best_ask_ticks\n            self._spread = max(1, (ask - bid + 1) // 2) if bid is not None and ask is not None else 0\n        if self._spread not in self.SPREADS:\n            return actions\n        mean = self._estimate(state)\n        margin = self.MARGIN_TICKS\n        def wrong(side, price):\n            return price > mean + margin if side == _CPSide.BUY else price < mean - margin\n        kept = [a for a in actions if not isinstance(a, _CPPlace) or not wrong(a.side, a.price_ticks)]\n        if not any(isinstance(a, _CPAll) for a in kept):\n            canceled = {a.order_id for a in kept if isinstance(a, _CPCancel)}\n            extra = [_CPCancel(o.order_id) for o in state.own_orders if o.order_id not in canceled and wrong(o.side, o.price_ticks)]\n            kept = extra + kept\n        return kept\n",
  "code_sha256": "0d8b3bfc15f4ebb6d87b6f0319fa0b5d7d8656faf01b39822de07a18ae40e73b",
  "assembled_sha256": "cfb2b64ae8853f5ce7fdb1e0735c7e3c62d38bdbc70de23140aefb5e96276053",
  "tuning": {
    "n": 200,
    "mean_diff": -1.646333043531,
    "se": 0.9979799039501333
  },
  "paired": {
    "first_seed": 410000,
    "last_seed": 410499,
    "n": 500,
    "complete": true,
    "incumbent_mean": 104.4137531881468,
    "mean_diff": -1.1100869039471999,
    "se": 0.5379546442126854,
    "sum_d": -555.0434519736,
    "sum_d2": 72820.24867504176,
    "retail_diff": -0.28749331825019975,
    "arb_diff": -0.8225935857025999,
    "failures": []
  },
  "by_spread": {
    "1": {
      "runs": 115,
      "incumbent_mean": 28.495154459731303,
      "mean_diff": -4.826464799770434,
      "se": 2.3130537103475493,
      "sum_d": -555.0434519736,
      "sum_d2": 72820.24867504176,
      "retail_diff": -1.249970948913912,
      "arb_diff": -3.576493850880869
    },
    "2": {
      "runs": 116,
      "incumbent_mean": 97.76626247947759,
      "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.0,
      "se": 0.0,
      "sum_d": 0.0,
      "sum_d2": 0.0,
      "retail_diff": 0.0,
      "arb_diff": 0.0
    },
    "4": {
      "runs": 131,
      "incumbent_mean": 151.67248160310686,
      "mean_diff": 0.0,
      "se": 0.0,
      "sum_d": 0.0,
      "sum_d2": 0.0,
      "retail_diff": 0.0,
      "arb_diff": 0.0
    }
  },
  "seconds_per_simulation": 1.1527774860858917
}
