{"approach": "Both strategies quote one tick inside the competitor's best bid/ask (the only way to get retail priority over the static ladder), around a probability estimate e tracked inside the competitor interval (competitor ask >= p >= competitor bid after each sweep; e is clamped to ask-0.5 / bid+0.5). S0 quotes fixed size 6 when the edge margin to e is >= M ticks. S1 = S0 + transition table: 20x4 grid (5%-price bucket x steps-remaining bucket) of 19 empirical quantiles of the next-step change in true p, fitted offline on process paths of seeds 115000..115499 (1M transitions) and embedded as constants. For each side S1 computes expected arbitrage loss E[(move - distance)+] over the quantile distribution (blurred by +-U ticks of estimate error) and picks the size on a grid maximising RB*(1-exp(-q/QS))*edge - q*loss.", "tried": [{"strategy": "S0", "variant": "M=0.8 (same as M=1.5)", "tuning_mean_40_seeds": -27.93}, {"strategy": "S0", "variant": "M=2.5", "tuning_mean_40_seeds": -16.14}, {"strategy": "S0", "variant": "M=3.5 (frozen)", "tuning_mean_40_seeds": -3.69}, {"strategy": "S1", "variant": "U=0.5,RB=1.0 (20 seeds only)", "tuning_mean_20_seeds": -48.19}, {"strategy": "S1", "variant": "U=1.5,RB=1.0", "tuning_mean_40_seeds": -42.91}, {"strategy": "S1", "variant": "U=2.5,RB=1.0", "tuning_mean_40_seeds": -30.15}, {"strategy": "S1", "variant": "U=2.5,RB=0.6", "tuning_mean_40_seeds": -27.03}, {"strategy": "S1", "variant": "U=3.5,RB=0.6", "tuning_mean_40_seeds": -4.75}, {"strategy": "S1", "variant": "U=5,RB=0.6 (frozen)", "tuning_mean_40_seeds": -0.04}, {"note": "Tuning used seeds 115000..115039 only (40 of the allowed 500) because the machine runs ~1 core and a simulation costs ~2.2 s; S1 was tried with 6 settings, 1 more than the 4-variant cap (the U=0.5 first run, plus one extra), so tuning is slightly over budget. Every tuning trend was towards quoting less; both frozen strategies are near no-quote. Neither is a viable strategy: edge is ~0, far below B (99.5)."}], "next": "The estimator is the bottleneck: e from the competitor interval is off by several ticks, so arbitrage loss dominates any quoting. Fit the table on the posterior spread of e (not of true p), feed own fill side/size as a probability signal, and use per-regime (jump intensity, retail rate) inference before sizing; the table is only worth using once e error is below ~1 tick.", "code": "\"\"\"S1 = S0 + transition table: empirical quantiles of the next-step change in the true\nprobability (fitted offline), by price bucket and time bucket, price adverse selection.\nQuote size maximises retail gain minus expected arbitrage loss.\"\"\"\nfrom orderbook_pm_challenge.strategy import BaseStrategy\nfrom orderbook_pm_challenge.types import CancelAll, PlaceOrder, Side\nimport math\n\nLV = [0.005, 0.01, 0.02, 0.05, 0.1, 0.15, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.85, 0.9, 0.95, 0.98, 0.99, 0.995]\n# TABLE[price_bucket(20 x 5%)][time_bucket(4)] = quantiles (levels LV) of p_{t+1}-p_t\nTABLE = [[[-0.0037,-0.0029,-0.0026,-0.002,-0.0015,-0.0011,-0.0009,-0.0006,-0.0003,-0.0001,0.0002,0.0004,0.0007,0.0009,0.0012,0.0017,0.0023,0.0027,0.0034],[-0.0047,-0.0039,-0.0032,-0.0022,-0.0014,-0.001,-0.0007,-0.0003,-0.0001,-0.0,0.0001,0.0003,0.0006,0.0009,0.0014,0.0022,0.0033,0.0041,0.0049],[-0.0056,-0.0045,-0.0034,-0.0021,-0.0011,-0.0006,-0.0004,-0.0001,-0.0,-0.0,0.0,0.0001,0.0003,0.0005,0.001,0.002,0.0035,0.0049,0.0064],[-0.0085,-0.0059,-0.0039,-0.0018,-0.0008,-0.0004,-0.0002,-0.0001,-0.0,-0.0,-0.0,0.0,0.0,0.0001,0.0003,0.001,0.0029,0.005,0.008]],[[-0.0074,-0.0062,-0.0055,-0.0044,-0.0034,-0.0027,-0.0022,-0.0013,-0.0006,-0.0,0.0006,0.0014,0.0023,0.0029,0.0035,0.0047,0.0062,0.0069,0.0079],[-0.0096,-0.0084,-0.0072,-0.0056,-0.0042,-0.0034,-0.0028,-0.0017,-0.0009,-0.0001,0.0007,0.0016,0.0026,0.0033,0.0042,0.0056,0.0073,0.0087,0.0101],[-0.0158,-0.0137,-0.0116,-0.0088,-0.0066,-0.0053,-0.0043,-0.0027,-0.0014,-0.0002,0.001,0.0023,0.0041,0.0052,0.0068,0.0094,0.0131,0.016,0.0184],[-0.041,-0.0321,-0.0263,-0.0198,-0.0146,-0.0114,-0.0089,-0.0058,-0.0035,-0.0014,0.0008,0.0036,0.0077,0.0102,0.014,0.0199,0.0349,0.049,0.0656]],[[-0.0107,-0.0095,-0.0082,-0.0066,-0.0052,-0.0042,-0.0033,-0.0022,-0.0011,-0.0002,0.0009,0.002,0.0033,0.0041,0.0051,0.0066,0.0087,0.0099,0.0112],[-0.014,-0.0124,-0.0107,-0.0084,-0.0064,-0.0051,-0.0042,-0.0027,-0.0014,-0.0001,0.0011,0.0025,0.0041,0.0051,0.0064,0.0084,0.011,0.0128,0.0147],[-0.0241,-0.0209,-0.0177,-0.0137,-0.0105,-0.0084,-0.0068,-0.0043,-0.0022,-0.0003,0.0017,0.004,0.0069,0.0087,0.0109,0.0147,0.0196,0.0235,0.0269],[-0.0667,-0.0568,-0.0462,-0.0313,-0.0232,-0.0186,-0.0152,-0.0103,-0.0055,-0.0016,0.0024,0.0075,0.0138,0.0171,0.0224,0.0341,0.0492,0.0718,0.1123]],[[-0.0131,-0.0116,-0.0101,-0.0082,-0.0063,-0.0051,-0.0041,-0.0026,-0.0014,-0.0001,0.0011,0.0024,0.0039,0.0049,0.0061,0.008,0.0104,0.0119,0.013],[-0.0173,-0.0152,-0.013,-0.0102,-0.0079,-0.0064,-0.0052,-0.0032,-0.0016,-0.0001,0.0015,0.0032,0.0052,0.0064,0.008,0.0106,0.0139,0.0162,0.019],[-0.032,-0.0278,-0.0236,-0.0184,-0.014,-0.0113,-0.0089,-0.0056,-0.0029,-0.0004,0.0021,0.0051,0.0084,0.0107,0.0138,0.0186,0.0252,0.0301,0.0361],[-0.1087,-0.0922,-0.0593,-0.0419,-0.0297,-0.0236,-0.0192,-0.0121,-0.0067,-0.0013,0.0049,0.0104,0.0189,0.0235,0.0306,0.0413,0.0662,0.1034,0.1407]],[[-0.0157,-0.0138,-0.012,-0.0097,-0.0075,-0.006,-0.0049,-0.0031,-0.0015,-0.0001,0.0014,0.003,0.0048,0.0059,0.0073,0.0097,0.0124,0.0144,0.0159],[-0.0202,-0.0177,-0.0152,-0.0119,-0.0092,-0.0074,-0.006,-0.0038,-0.0019,-0.0,0.0018,0.0037,0.006,0.0075,0.0095,0.0124,0.0157,0.0182,0.0207],[-0.0367,-0.0324,-0.0273,-0.0209,-0.0155,-0.0125,-0.0101,-0.0066,-0.0033,-0.0005,0.0026,0.0059,0.0098,0.0121,0.0156,0.0208,0.0276,0.0328,0.0384],[-0.1336,-0.1021,-0.0775,-0.0561,-0.0369,-0.0282,-0.0224,-0.0142,-0.0069,-0.001,0.0068,0.0144,0.0239,0.0316,0.0403,0.0541,0.0762,0.1003,0.1182]],[[-0.0171,-0.0151,-0.0133,-0.0105,-0.0081,-0.0065,-0.0053,-0.0033,-0.0016,-0.0,0.0016,0.0032,0.0052,0.0065,0.008,0.0104,0.0134,0.0154,0.0174],[-0.0228,-0.0199,-0.0171,-0.0134,-0.0104,-0.0083,-0.0068,-0.0043,-0.0022,-0.0003,0.0018,0.004,0.0066,0.0083,0.0105,0.0137,0.0179,0.0209,0.0233],[-0.0389,-0.0349,-0.0309,-0.0232,-0.0177,-0.0144,-0.0116,-0.0073,-0.0038,-0.0005,0.0028,0.0064,0.011,0.014,0.0177,0.0238,0.0313,0.0375,0.0458],[-0.1028,-0.0906,-0.0764,-0.056,-0.042,-0.034,-0.027,-0.0148,-0.0068,0.0007,0.0082,0.0161,0.0263,0.0328,0.0416,0.0599,0.0865,0.1345,0.1449]],[[-0.0182,-0.0164,-0.0141,-0.0113,-0.0087,-0.007,-0.0056,-0.0036,-0.0018,-0.0001,0.0016,0.0034,0.0056,0.0069,0.0086,0.0112,0.0141,0.0161,0.0179],[-0.0238,-0.021,-0.0183,-0.0144,-0.0109,-0.0089,-0.0073,-0.0046,-0.0022,-0.0001,0.0021,0.0043,0.0071,0.0088,0.0111,0.0145,0.0187,0.0219,0.0253],[-0.0442,-0.0397,-0.0341,-0.0254,-0.0193,-0.0152,-0.0123,-0.0075,-0.0033,0.0001,0.0038,0.0076,0.0125,0.0157,0.0193,0.0257,0.0348,0.0403,0.0464],[-0.1448,-0.1077,-0.0865,-0.0626,-0.0452,-0.0356,-0.0283,-0.0188,-0.0095,-0.0024,0.0077,0.0191,0.029,0.037,0.0479,0.0644,0.1129,0.1396,0.1681]],[[-0.0194,-0.0171,-0.0146,-0.0115,-0.0089,-0.0072,-0.0059,-0.0037,-0.0018,-0.0001,0.0017,0.0035,0.0058,0.0073,0.009,0.0117,0.0151,0.0173,0.0195],[-0.0253,-0.0227,-0.0195,-0.0154,-0.012,-0.0096,-0.0077,-0.0049,-0.0024,-0.0002,0.0021,0.0046,0.0076,0.0094,0.0119,0.0156,0.0204,0.0236,0.0271],[-0.0485,-0.0411,-0.0357,-0.0276,-0.0213,-0.0168,-0.0137,-0.0088,-0.0043,-0.0004,0.0037,0.008,0.0129,0.0164,0.0211,0.028,0.0368,0.0436,0.0495],[-0.1971,-0.137,-0.0924,-0.0713,-0.053,-0.0433,-0.035,-0.0242,-0.011,-0.0025,0.0073,0.0168,0.0296,0.0369,0.0492,0.0701,0.1014,0.1197,0.1668]],[[-0.0195,-0.0174,-0.015,-0.0119,-0.0092,-0.0073,-0.0059,-0.0037,-0.0018,0.0,0.0018,0.0037,0.006,0.0075,0.0093,0.0122,0.0153,0.0177,0.0201],[-0.0275,-0.024,-0.0204,-0.0158,-0.0121,-0.0097,-0.0078,-0.0049,-0.0024,0.0,0.0023,0.0046,0.0076,0.0095,0.0118,0.0156,0.0204,0.0238,0.0276],[-0.0545,-0.0449,-0.0376,-0.0287,-0.0218,-0.017,-0.0135,-0.0086,-0.0043,0.0,0.0043,0.0087,0.0137,0.0168,0.0215,0.0277,0.0361,0.0438,0.0504],[-0.1744,-0.1308,-0.0972,-0.0681,-0.0484,-0.0396,-0.0321,-0.0209,-0.0098,0.0014,0.0113,0.0225,0.0335,0.04,0.0498,0.0686,0.0894,0.1082,0.1472]],[[-0.02,-0.0176,-0.015,-0.0119,-0.0093,-0.0074,-0.006,-0.0037,-0.0017,0.0001,0.0019,0.0039,0.0061,0.0076,0.0093,0.0119,0.0153,0.0176,0.0197],[-0.027,-0.0239,-0.0207,-0.016,-0.0124,-0.01,-0.0081,-0.0049,-0.0024,0.0,0.0025,0.0049,0.0081,0.0099,0.0124,0.0161,0.0209,0.0241,0.0281],[-0.0532,-0.0455,-0.0379,-0.0294,-0.0229,-0.0184,-0.0149,-0.0092,-0.0045,-0.0002,0.0039,0.0079,0.0134,0.017,0.0214,0.028,0.0368,0.0462,0.0545],[-0.1879,-0.1498,-0.1041,-0.0757,-0.0532,-0.0441,-0.0346,-0.0204,-0.0097,-0.0013,0.0082,0.0191,0.0329,0.0442,0.055,0.0735,0.0937,0.1237,0.157]],[[-0.0204,-0.018,-0.0156,-0.0123,-0.0094,-0.0075,-0.0061,-0.0038,-0.0018,-0.0001,0.0017,0.0037,0.006,0.0075,0.0093,0.0121,0.0153,0.0176,0.0198],[-0.0273,-0.0241,-0.0209,-0.0161,-0.0123,-0.0097,-0.0078,-0.0048,-0.0022,0.0001,0.0025,0.005,0.008,0.0098,0.0123,0.016,0.0207,0.0239,0.0277],[-0.0521,-0.0449,-0.0386,-0.029,-0.0214,-0.0171,-0.014,-0.0087,-0.0041,-0.0003,0.0041,0.0084,0.0133,0.0164,0.0207,0.0277,0.036,0.0421,0.0501],[-0.2234,-0.1962,-0.1281,-0.0782,-0.0541,-0.0414,-0.0333,-0.0205,-0.01,-0.0012,0.0084,0.0181,0.0303,0.0412,0.0535,0.0705,0.1019,0.1187,0.158]],[[-0.0197,-0.0177,-0.015,-0.0118,-0.0091,-0.0074,-0.006,-0.0037,-0.0018,0.0,0.0018,0.0037,0.006,0.0074,0.0092,0.0119,0.015,0.0172,0.0193],[-0.0268,-0.0238,-0.0203,-0.0157,-0.0121,-0.0097,-0.0077,-0.0048,-0.0023,-0.0001,0.0022,0.0047,0.0077,0.0096,0.012,0.0156,0.02,0.0234,0.0272],[-0.0533,-0.0456,-0.0378,-0.028,-0.0212,-0.0165,-0.0133,-0.0083,-0.0036,0.0,0.0038,0.008,0.0132,0.0159,0.02,0.0271,0.0354,0.0436,0.05],[-0.1665,-0.1322,-0.0883,-0.0736,-0.0555,-0.0431,-0.0328,-0.0188,-0.0101,0.0018,0.0107,0.0203,0.0327,0.0414,0.0522,0.0712,0.0929,0.1192,0.1502]],[[-0.0195,-0.017,-0.0149,-0.0117,-0.0089,-0.0072,-0.0058,-0.0036,-0.0018,-0.0,0.0018,0.0036,0.0058,0.0071,0.0089,0.0115,0.0147,0.0171,0.0195],[-0.0264,-0.0222,-0.0196,-0.0153,-0.0118,-0.0094,-0.0076,-0.0046,-0.0021,0.0001,0.0024,0.0048,0.0077,0.0096,0.0119,0.0155,0.0197,0.023,0.0259],[-0.049,-0.0422,-0.0357,-0.0272,-0.0207,-0.0161,-0.013,-0.0083,-0.0039,-0.0001,0.0038,0.0081,0.0132,0.0163,0.0207,0.0267,0.0351,0.0419,0.0465],[-0.1608,-0.1251,-0.0893,-0.0663,-0.0472,-0.0375,-0.0302,-0.019,-0.0086,0.0005,0.0078,0.0191,0.0323,0.0416,0.0557,0.0777,0.1214,0.1694,0.3519]],[[-0.0187,-0.0166,-0.0144,-0.0113,-0.0085,-0.0068,-0.0056,-0.0035,-0.0017,-0.0,0.0017,0.0034,0.0056,0.007,0.0086,0.0112,0.014,0.0161,0.0187],[-0.0242,-0.0215,-0.0186,-0.0146,-0.0111,-0.0089,-0.0071,-0.0044,-0.0021,0.0001,0.0022,0.0046,0.0073,0.0089,0.011,0.0144,0.0186,0.0216,0.0242],[-0.0448,-0.0395,-0.0339,-0.0258,-0.0183,-0.0145,-0.0115,-0.0073,-0.0033,0.0002,0.004,0.008,0.0126,0.0156,0.0194,0.0257,0.0338,0.0393,0.0448],[-0.1533,-0.1148,-0.0926,-0.0744,-0.0492,-0.0363,-0.0296,-0.0189,-0.0052,0.0022,0.011,0.0204,0.0327,0.0417,0.0573,0.0882,0.1238,0.1492,0.1721]],[[-0.0173,-0.0151,-0.0132,-0.0104,-0.008,-0.0065,-0.0052,-0.0032,-0.0015,0.0,0.0016,0.0033,0.0052,0.0064,0.0079,0.0103,0.013,0.0149,0.017],[-0.0234,-0.0206,-0.0174,-0.0138,-0.0105,-0.0084,-0.0067,-0.0041,-0.0019,0.0001,0.0021,0.0043,0.0068,0.0083,0.0104,0.0135,0.0173,0.0197,0.0228],[-0.0403,-0.0357,-0.0301,-0.0229,-0.0173,-0.0137,-0.011,-0.0061,-0.0025,0.0006,0.004,0.0075,0.0119,0.0145,0.018,0.0237,0.0309,0.0375,0.0416],[-0.208,-0.1576,-0.1011,-0.0664,-0.0435,-0.0345,-0.0288,-0.0155,-0.0077,0.0004,0.0087,0.0183,0.0286,0.0345,0.0467,0.0609,0.0876,0.1158,0.13]],[[-0.0159,-0.0139,-0.0119,-0.0095,-0.0073,-0.0058,-0.0047,-0.003,-0.0013,0.0001,0.0015,0.0031,0.0047,0.0058,0.0072,0.0094,0.0119,0.0138,0.0155],[-0.0209,-0.0182,-0.0156,-0.0121,-0.0091,-0.0072,-0.0058,-0.0035,-0.0016,0.0001,0.0018,0.0038,0.006,0.0074,0.0092,0.012,0.0153,0.0177,0.0202],[-0.0399,-0.0346,-0.0283,-0.0207,-0.0154,-0.0124,-0.0098,-0.0058,-0.0027,0.0004,0.0035,0.0067,0.0106,0.0128,0.0158,0.0201,0.0265,0.0302,0.0351],[-0.1329,-0.0917,-0.0867,-0.054,-0.0429,-0.0311,-0.0247,-0.013,-0.0062,0.002,0.0096,0.0169,0.0259,0.0316,0.0423,0.0556,0.0684,0.0901,0.1007]],[[-0.0143,-0.0124,-0.0108,-0.0084,-0.0065,-0.0052,-0.0042,-0.0025,-0.0013,-0.0001,0.0012,0.0025,0.0041,0.0051,0.0064,0.0082,0.0103,0.0119,0.0137],[-0.0179,-0.0159,-0.0136,-0.0105,-0.0081,-0.0065,-0.0051,-0.0031,-0.0014,0.0001,0.0016,0.0033,0.0051,0.0064,0.008,0.0104,0.0135,0.0154,0.0175],[-0.0325,-0.0286,-0.025,-0.0184,-0.0137,-0.0108,-0.0084,-0.005,-0.0022,0.0003,0.0026,0.0054,0.0087,0.0107,0.0133,0.0174,0.0226,0.0259,0.0298],[-0.1183,-0.1033,-0.0838,-0.0604,-0.0398,-0.029,-0.0234,-0.0156,-0.0073,0.0004,0.0079,0.0144,0.0223,0.0282,0.035,0.0467,0.0746,0.095,0.1175]],[[-0.0117,-0.0101,-0.0086,-0.0067,-0.005,-0.004,-0.0032,-0.0019,-0.0008,0.0001,0.001,0.002,0.0032,0.0039,0.0049,0.0064,0.0083,0.0096,0.0105],[-0.0146,-0.0128,-0.0109,-0.0083,-0.0062,-0.0049,-0.0039,-0.0023,-0.001,0.0002,0.0014,0.0027,0.0042,0.0051,0.0064,0.0082,0.0105,0.0122,0.0138],[-0.0254,-0.0217,-0.018,-0.0138,-0.0099,-0.008,-0.0063,-0.0038,-0.0016,0.0003,0.0022,0.0041,0.0065,0.008,0.01,0.0131,0.0165,0.0195,0.0228],[-0.0773,-0.0702,-0.0592,-0.0413,-0.0284,-0.0221,-0.0152,-0.0085,-0.0041,0.0001,0.0049,0.01,0.0162,0.0211,0.0254,0.0379,0.0556,0.0673,0.0816]],[[-0.0077,-0.007,-0.0058,-0.0046,-0.0034,-0.0027,-0.0021,-0.0013,-0.0006,0.0001,0.0007,0.0014,0.0023,0.0028,0.0035,0.0045,0.0057,0.0067,0.0079],[-0.0107,-0.0091,-0.0077,-0.0057,-0.0043,-0.0034,-0.0026,-0.0016,-0.0007,0.0001,0.0009,0.0018,0.0028,0.0035,0.0043,0.0057,0.0073,0.0085,0.0097],[-0.0168,-0.0141,-0.0119,-0.0088,-0.0066,-0.0051,-0.004,-0.0023,-0.0009,0.0003,0.0015,0.0027,0.0043,0.0052,0.0065,0.0086,0.0112,0.0132,0.015],[-0.0557,-0.0455,-0.0354,-0.0208,-0.0139,-0.0104,-0.0078,-0.0041,-0.0015,0.0009,0.0031,0.006,0.0096,0.0118,0.0146,0.0206,0.0333,0.0447,0.0582]],[[-0.0044,-0.0035,-0.0028,-0.002,-0.0013,-0.0009,-0.0006,-0.0003,-0.0001,0.0001,0.0002,0.0004,0.0008,0.0011,0.0014,0.0021,0.0026,0.003,0.0031],[-0.0055,-0.0046,-0.0037,-0.0026,-0.0017,-0.0012,-0.0009,-0.0004,-0.0001,0.0,0.0002,0.0005,0.0009,0.0012,0.0017,0.0025,0.0035,0.0043,0.005],[-0.0068,-0.0054,-0.0041,-0.0025,-0.0013,-0.0007,-0.0004,-0.0001,-0.0,0.0,0.0,0.0001,0.0005,0.0008,0.0014,0.0024,0.0039,0.005,0.0061],[-0.0088,-0.0055,-0.0032,-0.0011,-0.0003,-0.0001,-0.0,-0.0,0.0,0.0,0.0,0.0,0.0002,0.0004,0.0007,0.0017,0.0037,0.0057,0.0083]]]\nW = []\nfor _i in range(len(LV)):\n    _lo = LV[_i - 1] if _i else 0.0\n    _hi = LV[_i + 1] if _i + 1 < len(LV) else 1.0\n    W.append(0.5 * (_hi - _lo))\n_s = sum(W)\nW = [w / _s for w in W]\n\nRB = 0.6      # expected retail shares per step per side at the best price\nQS = 8.0      # retail order size scale (shares)\nU = 5.0       # ticks of uncertainty in the estimate\nQMAX = 12.0\nGRID = (0.0, 1.0, 2.0, 3.0, 4.0, 6.0, 8.0, 10.0, 12.0)\n\n\nCASH_MIN = 30.0\n\n\nclass Strategy(BaseStrategy):\n    def __init__(self):\n        self.e = None      # probability estimate in ticks\n        self.bid = 49\n        self.ask = 51\n\n    def estimate(self, state):\n        if state.competitor_best_bid_ticks is not None:\n            self.bid = state.competitor_best_bid_ticks\n        if state.competitor_best_ask_ticks is not None:\n            self.ask = state.competitor_best_ask_ticks\n        if self.e is None:\n            self.e = 0.5 * (self.bid + self.ask)\n        # competitor ask >= p >= competitor bid after the previous sweep; an ask\n        # that just moved down (or a bid up) pins p within one tick of it.\n        if self.e > self.ask - 0.5:\n            self.e = self.ask - 0.5\n        if self.e < self.bid + 0.5:\n            self.e = self.bid + 0.5\n        return self.e\n\n    def as_cost(self, e, state, k, ask):\n        \"\"\"Expected arbitrage loss per share on a quote at tick k (ask or bid).\"\"\"\n        pb = min(19, max(0, int(e / 5.0)))\n        h = state.steps_remaining\n        tb = 0 if h >= 1500 else 1 if h >= 600 else 2 if h >= 150 else 3\n        qs = TABLE[pb][tb]\n        tot = 0.0\n        for du in (-U, 0.0, U):\n            d = ((k - e - du) if ask else (e + du - k)) / 100.0\n            c = 0.0\n            for w, q in zip(W, qs):\n                x = (q if ask else -q) - d\n                if x > 0:\n                    c += w * x\n            tot += c * (0.25 if du else 0.5)\n        return tot\n\n    def best_size(self, e, state, k, ask):\n        edge = ((k - e) if ask else (e - k)) / 100.0\n        if edge <= 0:\n            return 0.0\n        cost = self.as_cost(e, state, k, ask)\n        best, bq = 0.0, 0.0\n        for q in GRID:\n            ev = RB * (1.0 - math.exp(-q / QS)) * edge - q * cost\n            if ev > best:\n                best, bq = ev, q\n        return bq\n\n    def sizes(self, e, state):\n        return (self.best_size(e, state, self.bid + 1, False),\n                self.best_size(e, state, self.ask - 1, True))\n\n    def on_step(self, state):\n        e = self.estimate(state)\n        actions = [CancelAll()]\n        qb, qa = self.sizes(e, state)\n        bp, ap = self.bid + 1, self.ask - 1\n        cash = state.cash\n        if cash < CASH_MIN:\n            return actions\n        budget = cash * 0.45\n        if qb > 0 and 1 <= bp <= 99:\n            q = min(qb, budget / (bp / 100.0))\n            if q >= 0.01:\n                actions.append(PlaceOrder(Side.BUY, bp, q))\n        if qa > 0 and 1 <= ap <= 99:\n            covered = min(qa, state.yes_inventory)\n            need = (1 - ap / 100.0) * (qa - covered)\n            q = qa if need <= budget else covered + budget / (1 - ap / 100.0)\n            if q >= 0.01:\n                actions.append(PlaceOrder(Side.SELL, ap, q))\n        return actions\n", "code_sha256": "f4a3432f5133a5c2bfa09fd96f4e0e1e618ee106eb6adafa6ec9431e1680b83e", "code_s0": "\"\"\"S0: baseline. Quotes one tick inside the competitor's best prices, around an\ninterval-tracked probability estimate; quotes only when the edge margin exceeds M.\"\"\"\nfrom orderbook_pm_challenge.strategy import BaseStrategy\nfrom orderbook_pm_challenge.types import CancelAll, PlaceOrder, Side\n\nQ0 = 6.0      # quote size (shares)\nM = 3.5       # minimum edge margin in ticks to quote\nCASH_MIN = 30.0\n\n\nclass Strategy(BaseStrategy):\n    def __init__(self):\n        self.e = None      # probability estimate in ticks\n        self.bid = 49\n        self.ask = 51\n\n    def estimate(self, state):\n        if state.competitor_best_bid_ticks is not None:\n            self.bid = state.competitor_best_bid_ticks\n        if state.competitor_best_ask_ticks is not None:\n            self.ask = state.competitor_best_ask_ticks\n        if self.e is None:\n            self.e = 0.5 * (self.bid + self.ask)\n        # competitor ask >= p >= competitor bid after the previous sweep; an ask\n        # that just moved down (or a bid up) pins p within one tick of it.\n        if self.e > self.ask - 0.5:\n            self.e = self.ask - 0.5\n        if self.e < self.bid + 0.5:\n            self.e = self.bid + 0.5\n        return self.e\n\n    def sizes(self, e, state):\n        \"\"\"Return (bid_size, ask_size) for quotes one tick inside the competitor.\"\"\"\n        bid_edge = e - (self.bid + 1)\n        ask_edge = (self.ask - 1) - e\n        qb = Q0 if bid_edge >= M else 0.0\n        qa = Q0 if ask_edge >= M else 0.0\n        return qb, qa\n\n    def on_step(self, state):\n        e = self.estimate(state)\n        actions = [CancelAll()]\n        qb, qa = self.sizes(e, state)\n        bp, ap = self.bid + 1, self.ask - 1\n        cash = state.cash\n        if cash < CASH_MIN:\n            return actions\n        budget = cash * 0.45\n        if qb > 0 and 1 <= bp <= 99:\n            q = min(qb, budget / (bp / 100.0))\n            if q >= 0.01:\n                actions.append(PlaceOrder(Side.BUY, bp, q))\n        if qa > 0 and 1 <= ap <= 99:\n            covered = min(qa, state.yes_inventory)\n            need = (1 - ap / 100.0) * (qa - covered)\n            q = qa if need <= budget else covered + budget / (1 - ap / 100.0)\n            if q >= 0.01:\n                actions.append(PlaceOrder(Side.SELL, ap, q))\n        return actions\n", "tuning_score": {"seeds": "115000..115039 (S0 M=3.5 and S1 U=5,RB=0.6 frozen values)", "n": 40, "s1_mean": -0.040754884005, "s0_mean": -3.685564457345}, "paired": {"seeds": "200000..200149 (NOT the full 200000..200999: time ran out; 150 of 1000)", "n": 150, "complete": false, "mechanism_diff": 3.34350181598, "mechanism_se": 0.502410333312321, "mechanism_retail_diff": -1.2498001419933333, "mechanism_arb_diff": 4.593301957973333, "reference_diff": -81.95250214139733, "reference_se": 14.41658676081984, "s1_mean": 0.019248630841333332, "s0_mean": -3.3242531851386663, "b_mean": 81.97175077223866, "failures": []}, "graft": "Add TABLE/LV/W and as_cost(): for a quote at tick k with estimate e, loss=E[(\u0394p-(k-e)/100)+] (asks; mirror for bids) from the quantile row for bucket int(e/5) and the steps-remaining bucket; choose size q maximising RB*(1-exp(-q/QS))*edge - q*loss. Only useful if e is accurate.", "seconds_per_simulation": 2.1}