{"key":"f-side-exposure-cap","mech":"side_exposure_cap","approach":"Overlay _N on spreads 1–4. Project current resting orders through N’s cancel and placement actions, keep bids highest-price first and asks lowest-price first, then cancel the worst-price tail until resting notional fits c times cash or c times YES inventory valued at its $1 face amount. Omit over-cap new orders and cancel over-cap resting orders. Freeze c=1.0.","tried":[{"c":0.25,"mean_diff":-6.488097216610999,"se":1.4697056330969818},{"c":0.5,"mean_diff":-4.4925524078355,"se":1.133119141923397},{"c":1.0,"mean_diff":-3.2413478142904997,"se":0.6998665218119869}],"next":"Do not promote: the frozen setting’s holdout paired difference is negative. Try a mechanism that improves retail edge without increasing arbitrage exposure.","spreads_acted":[1,2,3,4],"off_equals_n":{"switched_off":true,"seeds":[310000,310001,310002,310003,310004,310005,310006,310007,310008,310009],"steps_per_seed":2000,"callbacks_checked":20000,"mismatches":0,"actions_identical_per_step":true,"same_seed_results_equal":true},"code":"from orderbook_pm_challenge import BaseStrategy, CancelAll, CancelOrder, PlaceOrder, Side\n\nclass Strategy(_N):\n    CAP = 1.0\n    FORCE_OFF = False\n    OFF_MISMATCHES = 0\n    SPREAD_COUNTS = {1: 0, 2: 0, 3: 0, 4: 0}\n\n    def on_step(self, state):\n        original = list(super().on_step(state))\n        spread = getattr(self, \"s\", None)\n        active = not self.FORCE_OFF and spread in (1, 2, 3, 4)\n        if self.FORCE_OFF:\n            # Off-path equality is checked at every callback.\n            return original\n        if not active:\n            return original\n        type(self).SPREAD_COUNTS[spread] += 1\n        open_orders = {o.order_id: [o.side, o.price_ticks, o.remaining_quantity, True, None] for o in state.own_orders}\n        normalized = []\n        for index, action in enumerate(original):\n            if isinstance(action, CancelAll):\n                open_orders.clear()\n                normalized.append(action)\n            elif isinstance(action, CancelOrder):\n                open_orders.pop(action.order_id, None)\n                normalized.append(action)\n            elif isinstance(action, PlaceOrder):\n                key = action.client_order_id or (\"__new__\", index)\n                open_orders[key] = [action.side, action.price_ticks, float(action.quantity), False, index]\n                normalized.append(action)\n            else:\n                normalized.append(action)\n        limits = {\n            Side.BUY: max(0.0, float(state.cash)) * self.CAP,\n            Side.SELL: max(0.0, float(state.yes_inventory)) * self.CAP,\n        }\n        keep = set()\n        for side in (Side.BUY, Side.SELL):\n            rows = [(key, row) for key, row in open_orders.items() if row[0] == side]\n            rows.sort(key=lambda pair: (pair[1][1] if side == Side.SELL else -pair[1][1], pair[1][4] if pair[1][4] is not None else -1))\n            total = sum((row[1] / 100.0) * row[2] for _, row in rows)\n            while rows and total > limits[side] + 1e-9:\n                _, removed = rows.pop()\n                total -= (removed[1] / 100.0) * removed[2]\n            keep.update(key for key, _ in rows)\n        out = []\n        for action in normalized:\n            if isinstance(action, PlaceOrder):\n                key = action.client_order_id or next((k for k, row in open_orders.items() if row[4] == normalized.index(action)), None)\n                # Resolve duplicate-equal actions by original position below instead.\n                out.append(action)\n            else:\n                out.append(action)\n        # Rebuild action stream by identity/index so only retained new orders are submitted.\n        out = []\n        for index, action in enumerate(original):\n            if isinstance(action, PlaceOrder):\n                key = action.client_order_id or (\"__new__\", index)\n                if key in keep:\n                    out.append(action)\n            else:\n                out.append(action)\n        for key, row in open_orders.items():\n            if row[3] and key not in keep:\n                out.append(CancelOrder(key))\n        return out\n","code_sha256":"63a225267fe38bf106a17eeef6221c8aa4887a264be5cec32a5631331c326d4a","assembled_sha256":"f8b84f0c94467a6a959490278f2054193546abb62afbd7964872cbe2f1c3de82","tuning":{"seeds":[320000,320001,320002,320003,320004,320005,320006,320007,320008,320009,320010,320011,320012,320013,320014,320015,320016,320017,320018,320019,320020,320021,320022,320023,320024,320025,320026,320027,320028,320029,320030,320031,320032,320033,320034,320035,320036,320037,320038,320039,320040,320041,320042,320043,320044,320045,320046,320047,320048,320049,320050,320051,320052,320053,320054,320055,320056,320057,320058,320059,320060,320061,320062,320063,320064,320065,320066,320067,320068,320069,320070,320071,320072,320073,320074,320075,320076,320077,320078,320079,320080,320081,320082,320083,320084,320085,320086,320087,320088,320089,320090,320091,320092,320093,320094,320095,320096,320097,320098,320099,320100,320101,320102,320103,320104,320105,320106,320107,320108,320109,320110,320111,320112,320113,320114,320115,320116,320117,320118,320119,320120,320121,320122,320123,320124,320125,320126,320127,320128,320129,320130,320131,320132,320133,320134,320135,320136,320137,320138,320139,320140,320141,320142,320143,320144,320145,320146,320147,320148,320149,320150,320151,320152,320153,320154,320155,320156,320157,320158,320159,320160,320161,320162,320163,320164,320165,320166,320167,320168,320169,320170,320171,320172,320173,320174,320175,320176,320177,320178,320179,320180,320181,320182,320183,320184,320185,320186,320187,320188,320189,320190,320191,320192,320193,320194,320195,320196,320197,320198,320199],"selected":1.0,"variants":[{"c":0.25,"n":200,"sum_d":-1297.6194433222,"sum_d2":94388.46008712768,"mean_diff":-6.488097216610999,"se":1.4697056330969818,"incumbent_mean":98.47071831456549,"candidate_mean":91.9826210979545,"retail_diff":-3.9653240952884987,"arb_diff":-2.5227731213180005},{"c":0.5,"n":200,"sum_d":-898.5104815671001,"sum_d2":55138.17322119971,"mean_diff":-4.4925524078355,"se":1.133119141923397,"incumbent_mean":98.47071831456549,"candidate_mean":93.97816590673,"retail_diff":-2.401201422062001,"arb_diff":-2.0913509857825},{"c":1.0,"n":200,"sum_d":-648.2695628580999,"sum_d2":21595.830435098855,"mean_diff":-3.2413478142904997,"se":0.6998665218119869,"incumbent_mean":98.47071831456549,"candidate_mean":95.229370500275,"retail_diff":-1.7223085177434996,"arb_diff":-1.5190392965465}]},"paired":{"seeds":[430000,430001,430002,430003,430004,430005,430006,430007,430008,430009,430010,430011,430012,430013,430014,430015,430016,430017,430018,430019,430020,430021,430022,430023,430024,430025,430026,430027,430028,430029,430030,430031,430032,430033,430034,430035,430036,430037,430038,430039,430040,430041,430042,430043,430044,430045,430046,430047,430048,430049,430050,430051,430052,430053,430054,430055,430056,430057,430058,430059,430060,430061,430062,430063,430064,430065,430066,430067,430068,430069,430070,430071,430072,430073,430074,430075,430076,430077,430078,430079,430080,430081,430082,430083,430084,430085,430086,430087,430088,430089,430090,430091,430092,430093,430094,430095,430096,430097,430098,430099,430100,430101,430102,430103,430104,430105,430106,430107,430108,430109,430110,430111,430112,430113,430114,430115,430116,430117,430118,430119,430120,430121,430122,430123,430124,430125,430126,430127,430128,430129,430130,430131,430132,430133,430134,430135,430136,430137,430138,430139,430140,430141,430142,430143,430144,430145,430146,430147,430148,430149,430150,430151,430152,430153,430154,430155,430156,430157,430158,430159,430160,430161,430162,430163,430164,430165,430166,430167,430168,430169,430170,430171,430172,430173,430174,430175,430176,430177,430178,430179,430180,430181,430182,430183,430184,430185,430186,430187,430188,430189,430190,430191,430192,430193,430194,430195,430196,430197,430198,430199,430200,430201,430202,430203,430204,430205,430206,430207,430208,430209,430210,430211,430212,430213,430214,430215,430216,430217,430218,430219,430220,430221,430222,430223,430224,430225,430226,430227,430228,430229,430230,430231,430232,430233,430234,430235,430236,430237,430238,430239,430240,430241,430242,430243,430244,430245,430246,430247,430248,430249,430250,430251,430252,430253,430254,430255,430256,430257,430258,430259,430260,430261,430262,430263,430264,430265,430266,430267,430268,430269,430270,430271,430272,430273,430274,430275,430276,430277,430278,430279,430280,430281,430282,430283,430284,430285,430286,430287,430288,430289,430290,430291,430292,430293,430294,430295,430296,430297,430298,430299,430300,430301,430302,430303,430304,430305,430306,430307,430308,430309,430310,430311,430312,430313,430314,430315,430316,430317,430318,430319,430320,430321,430322,430323,430324,430325,430326,430327,430328,430329,430330,430331,430332,430333,430334,430335,430336,430337,430338,430339,430340,430341,430342,430343,430344,430345,430346,430347,430348,430349,430350,430351,430352,430353,430354,430355,430356,430357,430358,430359,430360,430361,430362,430363,430364,430365,430366,430367,430368,430369,430370,430371,430372,430373,430374,430375,430376,430377,430378,430379,430380,430381,430382,430383,430384,430385,430386,430387,430388,430389,430390,430391,430392,430393,430394,430395,430396,430397,430398,430399,430400,430401,430402,430403,430404,430405,430406,430407,430408,430409,430410,430411,430412,430413,430414,430415,430416,430417,430418,430419,430420,430421,430422,430423,430424,430425,430426,430427,430428,430429,430430,430431,430432,430433,430434,430435,430436,430437,430438,430439,430440,430441,430442,430443,430444,430445,430446,430447,430448,430449,430450,430451,430452,430453,430454,430455,430456,430457,430458,430459,430460,430461,430462,430463,430464,430465,430466,430467,430468,430469,430470,430471,430472,430473,430474,430475,430476,430477,430478,430479,430480,430481,430482,430483,430484,430485,430486,430487,430488,430489,430490,430491,430492,430493,430494,430495,430496,430497,430498,430499],"n":500,"complete":true,"missing_seeds":[],"overall":{"n":500,"sum_d":-1434.8512748492,"sum_d2":92031.46257932982,"mean_diff":-2.8697025496984003,"se":0.5935993474055619,"incumbent_mean":95.54201511346659,"candidate_mean":92.6723125637682,"retail_diff":-1.1563645718817994,"arb_diff":-1.7133379778262001},"by_spread":{"1":{"n":131,"sum_d":17.614346107000085,"sum_d2":3273.78812726435,"mean_diff":0.13446065730534415,"se":0.43828923883947873,"incumbent_mean":38.277936657049615,"candidate_mean":38.41239731435496,"retail_diff":0.7519456354312977,"arb_diff":-0.61748497809313},"2":{"n":120,"sum_d":-82.49264183420004,"sum_d2":298.2089302197371,"mean_diff":-0.687438681951667,"se":0.13004532102872923,"incumbent_mean":77.8558643979175,"candidate_mean":77.16842571596584,"retail_diff":-0.8200141788008335,"arb_diff":0.13257549686666667},"3":{"n":133,"sum_d":-261.6347801684,"sum_d2":9520.837381036516,"mean_diff":-1.9671787982586468,"se":0.7162372799765412,"incumbent_mean":146.55140363646615,"candidate_mean":144.58422483820752,"retail_diff":-3.122311421345112,"arb_diff":1.155132623093233},"4":{"n":116,"sum_d":-1108.3381989536,"sum_d2":78938.62814080922,"mean_diff":-9.554639646151726,"se":2.263537585744859,"incumbent_mean":120.02204692465259,"candidate_mean":110.46740727850086,"retail_diff":-1.4053279628224127,"arb_diff":-8.149311683433622}}},"failures":[],"check_values":{"310000":17.1160017503,"310001":20.0171113118,"310002":2.3903113616,"310003":241.4847522404},"python_version":"3.12.3","seconds_per_simulation":0.9740325317382813}
