From 107bcc6648ed5f5a3c486bef4c7a2eadb2e603c6 Mon Sep 17 00:00:00 2001 From: jgrusewski Date: Sun, 7 Jun 2026 11:03:41 +0200 Subject: [PATCH] =?UTF-8?q?fix(crypto):=20MANDATORY=20hedgeability=20filte?= =?UTF-8?q?r=20=E2=80=94=20funding=20edge=20was=20partly=20phantom?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Phase-2 setup (orders command) revealed 0/7 qualifying coins were hedgeable: all perp-only (no spot leg = cannot build the delta-neutral hedge). Diagnostic: of 191 liquid crypto-native perps, 135 hedgeable / 56 perp-only. HEDGEABLE median funding -0.12bp/day, 0 of 134 clear 5bp (arbed flat by existing cash-and-carry). PERP-ONLY median +2.59bp/day, all 8 qualifiers live there. The carry survives ONLY where it can't be hedged. crypto_pit backtest never checked hedgeability -> the ~2-3.6 Sharpe was inflated by un-capturable perp-only funding. Fix: universe() now requires a spot market (hedgeable only). Current regime: 0/135 hedgeable qualify -> nothing to harvest (deleverage arbed flat). Real edge = classic basis trade on hedgeable majors: regime-dependent (rich in bull leverage, ~zero now), more competed, lower true Sharpe than backtest. Phase-2 deploy correctly BLOCKED by reality, not process. State reset (prior bookings were on un-hedgeable coins). Co-Authored-By: Claude Opus 4.8 (1M context) --- scripts/surfer/crypto_funding_paper.py | 48 +++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/scripts/surfer/crypto_funding_paper.py b/scripts/surfer/crypto_funding_paper.py index 87412200a..7d3339f5e 100644 --- a/scripts/surfer/crypto_funding_paper.py +++ b/scripts/surfer/crypto_funding_paper.py @@ -10,6 +10,7 @@ Sharpe ~2-3.6); this tool tracks the no-capital forward record. python3 crypto_funding_paper.py run daily step: book funding on prior positions, log, persist python3 crypto_funding_paper.py status current book + cumulative track record python3 crypto_funding_paper.py gate Phase-1 -> Phase-2 assessment vs backtest + python3 crypto_funding_paper.py orders [USD] Phase-2: current book -> exact delta-neutral orders python3 crypto_funding_paper.py log [N] last N run-log lines (default 25) (alias: 'paper' == 'run', for the cron) """ @@ -49,11 +50,22 @@ def crypto_native(): return {s["symbol"] for s in info["symbols"] if s.get("underlyingType") == "COIN"} +def spot_symbols(): + """Symbols with a Binance SPOT market — required to build the delta-neutral hedge. + Perp-only coins can't be cash-and-carry harvested (no spot leg); their high funding survives + PRECISELY because the arb is impossible, so they must be excluded.""" + return {x["symbol"] for x in get("https://api.binance.com/api/v3/ticker/price")} + + def universe(): + """Liquid, crypto-native, HEDGEABLE (spot+perp) USDT perps — the only ones that can be + delta-neutral harvested.""" native = crypto_native() + spot = spot_symbols() t = get(f"{FAPI}/fapi/v1/ticker/24hr") return {x["symbol"]: float(x["quoteVolume"]) for x in t - if x["symbol"].endswith("USDT") and x["symbol"] in native and float(x["quoteVolume"]) > LIQ_USD} + if x["symbol"].endswith("USDT") and x["symbol"] in native and x["symbol"] in spot + and float(x["quoteVolume"]) > LIQ_USD} def funding_hist(sym, limit=90): @@ -169,6 +181,38 @@ def cmd_gate(): print(" tail is the real -100% risk (un-modeled); current qualifiers may be small/niche coins.") +def cmd_orders(capital): + """Phase-2 bridge: turn the current paper book into exact delta-neutral orders for `capital`, + and flag coins that are perp-only (no spot leg = can't hedge cleanly on Binance).""" + st = load_state() + book = st.get("positions", {}) + if not book: + print("no current book — run 'snapshot'/'run' first."); return + try: + spot_px = {x["symbol"]: float(x["price"]) for x in get("https://api.binance.com/api/v3/ticker/price")} + except Exception: + spot_px = {} + perp_px = {x["symbol"]: float(x["price"]) for x in get(f"{FAPI}/fapi/v1/ticker/price")} + LEV = 2.0 # conservative perp leverage (avoid liquidation) + n = len(book) + X = capital / (n * (1 + 1 / LEV)) # notional per leg per coin + print(f"=== Phase-2 delta-neutral orders for ${capital:.0f} across {n} coins (perp {LEV:.0f}x) ===") + print(f" per coin: ~${X:.0f} notional/leg, ~${X/LEV:.0f} perp margin, ~${X*(1+1/LEV):.0f} capital") + print(f"{'coin':>14} {'hedge':>6} {'SPOT buy (units @ px)':>26} {'PERP short (units @ px)':>26}") + ok = 0 + for c in sorted(book): + if c in spot_px and c in perp_px: + print(f"{c:>14} {'YES':>6} {X/spot_px[c]:>14.4f} @ {spot_px[c]:<9.5g} {X/perp_px[c]:>14.4f} @ {perp_px[c]:<9.5g}") + ok += 1 + else: + why = "no-spot" if c not in spot_px else "no-perp" + print(f"{c:>14} {'NO':>6} ({why}) cannot delta-neutral hedge on Binance — skip / alt-venue") + print(f"\n {ok}/{n} coins hedgeable on Binance (spot+perp both exist).") + print(" Place SPOT + PERP legs together to stay delta-neutral. Keep perp leverage low; never let the") + print(" perp leg liquidate while holding spot. API keys: ENV ONLY, never commit. Place manually for") + print(" micro-live to validate fills before any automation. DEPLOY ONLY AFTER the Phase-1 gate passes.") + + def cmd_log(n=25): if not os.path.exists(LOG): print(f"(no log yet at {LOG} — cron writes it nightly; 'run' appends when redirected)"); return @@ -186,6 +230,8 @@ def main(): cmd_status() elif cmd == "gate": cmd_gate() + elif cmd == "orders": + cmd_orders(float(sys.argv[2]) if len(sys.argv) > 2 else 2000.0) elif cmd == "log": cmd_log(int(sys.argv[2]) if len(sys.argv) > 2 else 25) else: