"""Where the arithmetic cash rate G of section 26 (the formulation's own gate, G > 0 at 80% honoured)
turns negative at the deployed 34.8-pip cell, on the exact chains, funded risk re-picked at each cost.
G > 0 is h x cash/fee > 1, so the honour threshold is 1 / (cash/fee) and needs no search."""
from common import G_COIN, G_SPREAD, STOP0, cell

lo, hi = G_COIN, G_COIN + 0.05
rows = []
for _ in range(12):
    mid = 0.5 * (lo + hi)
    c = cell(mid, 7)
    rows.append((mid, c["rf"], c["cash_fee"], c["G"]))
    print(f"cost {mid:.3%}: pick {c['rf']:.3%} cash/fee {c['cash_fee']:.3f} G ${c['G']:+.1f}", flush=True)
    if c["G"] > 0:
        lo = mid
    else:
        hi = mid
gstar = 0.5 * (lo + hi)
d = gstar - G_COIN
print(f"G = 0 at cost share {gstar:.3%} (+{d:.3%}): spread {0.5 + d * STOP0:.2f} pips, step-asides {d / G_SPREAD:.2f} a trade, "
      f"extra {d * STOP0:.2f} pips a trade; honour threshold at the deployed cost {1 / cell(G_COIN, 7)['cash_fee']:.1%}")
