"""mc5v15.py (FW Analyst 2, sup v15): mc5 size curve with the 4 h time stop (A1.18), main model (own buy kept in pool) and lower bound (own buy ignored at exit), plus the 2 h line for reference. Same 201 trades, same tick walker as mc5size.py.""" exec(open("/opt/fw2/mc5size.py").read().split("SIZES = ")[0]) def trade2(P, V, tstop, own=True, te=300): t = P.t; eu = t["eu"]; gas = 0.05 / eu; x = V / eu i = P.at(te) if i < 0: return None xin = max(0.0, (x * 0.99 - gas) * (1 - P.pf)) * 1e18 q = swap(P.S[i], xin, not P.is0, 0.0) pull = P.pull def net(k): g = gross_back(P, k, xin, q) if own else swap(P.S[k], q, P.is0, 0.0) return max(0.0, g / 1e18 * (1 - P.pf) * 0.99 - gas) / x peak = 0.0 for k in range(i + 1, len(P.S)): sec, kind, sp, L, tk, nt, tks, we = P.S[k] if sec > tstop: break if kind != "s" or we < 0.01 or sec <= te: continue m = net(k); peak = max(peak, m) if m <= 0.5: if pull is not None and pull <= sec + 3: return 0.0, "pull", peak j = max(k, P.at(sec + 3)); return net(j), "stop", peak if pull is not None and pull <= tstop: return 0.0, "pull", peak return net(P.at(tstop)), "time", peak rows = [] for own, lab in ((True, "main"), (False, "lower")): for ts in (7200, 14400): print("== %s model, time stop %d h" % (lab, ts // 3600), flush=True) for V in (100, 500, 1000, 2000, 3000, 5000): R = [(P.t, *trade2(P, V, ts, own)) for P in PS] o = summ(R, V) srt = sorted(((v - 1) * V for t, v, w, pk in R), reverse=True) print("$%5d mean %.2fx (H1 %.2fx H2 %.2fx) /tday $%+.0f (H1 %+.0f H2 %+.0f) worst day %+.0f worst3 %+.0f green %d/%d w/o top3 $%+.0f %s" % ( V, o["all"]["mean"], o["H1"]["mean"], o["H2"]["mean"], o["all"]["perday"], o["H1"]["perday"], o["H2"]["perday"], o["worst_day"], o["worst3"], o["green"], o["days"], sum(srt[3:]), o["why"]), flush=True) for t, v, w, pk in R: rows.append((lab, ts // 3600, V, t["pool"], t["token"], str(day(t["t"])), round(v, 4), w, round(pk, 3))) import csv with open("/opt/fw2/mc5/mc5v15_trades.csv", "w") as f: w = csv.writer(f); w.writerow(["model", "hold_h", "usd", "pool", "token", "day_bkk", "x", "exit", "peak_x"]); w.writerows(rows)