"""WETH pond v13: survival curve, exit grid (time / target-or-time), entry delays, walk forward, pull timing (timer vs pump). $20, pulled = 0, GMGN 1% each side, pool fee 0.01%, gas $0.03 a side, liquidity from the pool's own swaps, sell fills 3 s after trigger.""" import sqlite3, glob, os, collections, numpy as np, json exec(open("/opt/fw2/wret2.py").read().split("R = collections.defaultdict(list)")[0]) C = [] for fn in sorted(glob.glob("/opt/hist/rh/2026-*.db")): d = os.path.basename(fn)[:10] if not ("2026-09-20" <= d <= "2026-10-05"): continue db = sqlite3.connect("file:%s?mode=ro" % fn, uri=True) for pid, pool, c0, c1 in db.execute("SELECT rowid, pool, c0, c1 FROM pools WHERE fee=100 AND spacing=1"): if pool.lower() not in pools: continue weth0 = c0.lower() == WETH S = db.execute("SELECT block, a0, a1, sqrtp FROM swaps WHERE pid=? ORDER BY block, li", (pid,)).fetchall() if len(S) < 3: continue b = np.array([s[0] for s in S]); xs = np.array([float(int(s[3])) for s in S]) / 2 ** 96 wamt = np.array([float(int(s[1] if weth0 else s[2])) for s in S]) val = (1 / xs ** 2) if weth0 else xs ** 2 C.append(dict(d=d, b=b, xs=xs, wamt=wamt, weth0=weth0, val=val, pb=pull_b(pool))) print("coins", len(C), flush=True) # (1) survival curve from first trade for t in (30, 60, 120, 300, 600, 900, 1800, 3600): print("pulled by %5d s after first trade: %.0f%%" % (t, 100 * np.mean([c["pb"] is not None and c["pb"] <= c["b"][0] + t / SPB for c in C]))) B = lambda s: s / SPB def trade(c, ent, tmax, tgt=None): b, xs, val = c["b"], c["xs"], c["val"]; pb = c["pb"] if c["pb"] is not None else 10 ** 12 e = b[0] + B(ent); ef = e + B(2) if pb <= e: return None i = int(np.searchsorted(b, ef, "right")) - 1 if i < 1: return None Lq = localL(xs, c["wamt"], c["weth0"], i) if not Lq: return None tok = buy(Lq, xs[i], SIZE / ETHUSD, c["weth0"]); v0 = val[i] tsell = e + B(tmax * 60) if tgt: hit = np.nonzero((b > b[i]) & (b <= tsell) & (val >= tgt * v0))[0] if len(hit): tsell = b[hit[0]] sb = tsell + B(3) if pb <= sb: return -1.0 - 0.03 / SIZE k = int(np.searchsorted(b, sb, "right")) - 1 out = sell(localL(xs, c["wamt"], c["weth0"], k) or Lq, xs[k], tok, c["weth0"]) * ETHUSD return (out - 0.03) / (SIZE + 0.03) - 1 TR = lambda d: d <= "2026-09-27" res = {} for ent in (4, 8, 15): for tmax in (1, 2, 3, 5, 10, 15): for tgt in (None, 2, 3): r = [(c["d"], trade(c, ent, tmax, tgt)) for c in C] r = [(d, x) for d, x in r if x is not None] tr = [x for d, x in r if TR(d)]; te = [x for d, x in r if not TR(d)] byd = collections.defaultdict(list) for d, x in r: byd[d].append(x) res[(ent, tmax, tgt)] = (np.mean(tr), np.mean(te), len(tr), len(te), sum(np.mean(v) > 0 for v in byd.values()), len(byd), np.median([x for d, x in r])) print("entry s | sell by min | target | train 20-27 Sep | test 28 Sep-5 Oct | days up | median") for k, v in sorted(res.items(), key=lambda kv: -kv[1][0]): print(k[0], k[1], k[2], "%+.0f%% (n%d)" % (100 * v[0], v[2]), "%+.0f%% (n%d)" % (100 * v[1], v[3]), "%d/%d" % (v[4], v[5]), "%+.0f%%" % (100 * v[6])) best = max(res, key=lambda k: res[k][0]); print("WALK FORWARD: picked on train", best, "-> test %+.0f%%" % (100 * res[best][1])) # (4) pull timing: age histogram and pump before pull ages = np.array([(c["pb"] - c["b"][0]) * SPB for c in C if c["pb"] is not None]) print("pull age q10/25/50/75/90 s:", np.round(np.quantile(ages, [.1, .25, .5, .75, .9]), 0).tolist()) h, edges = np.histogram(ages[ages < 1800], bins=np.arange(0, 1830, 30)) print("pull age 30 s bins (0-30 min):", h.tolist()) near_high = []; mult = [] for c in C: if c["pb"] is None: continue j = int(np.searchsorted(c["b"], c["pb"], "left")) - 1 if j < 1: continue hi = c["val"][:j + 1].max(); near_high.append(c["val"][j] >= 0.8 * hi); mult.append(c["val"][j] / c["val"][0]) print("price just before pull within 20%% of the coin's high so far: %.0f%%" % (100 * np.mean(near_high)), "| multiple vs first trade at pull q25/50/75:", np.round(np.quantile(mult, [.25, .5, .75]), 2).tolist())