"""prime_academy_strategy.py:726-733 lands the clipped target and the stop 'net of the round trip' using cost_per_lot, and broker_map.py:63 passes
cost_per_lot = 2 x commission_per_side = $5 (commission only).  The model (prime._legs, cost C) nets commission + spread (+ swap in the swap scenario).
Live there is a spread, and a swap.  Per-trade simulation on the tick lattice (1 tick = 0.1 pip, 348 ticks = the 34.8-pip stop = 3% risk), 5,000 paths:
 A  clip nets the full cost, true cost = full cost (the model)
 B  clip nets commission only, true cost = commission + spread 0.5 pip (no swap)
 C  as B plus the swap's mean debit (random side)
 D  clip nets the full cost but the true spread is 0.1 pip wider than assumed
Pass = equity >= target (1e-9), dead = equity <= -floor.  Trades capped at 400 per account; an account still alive then counts as not passed."""
import numpy as np
risk=0.03; tick=risk/348; T=0.09; D=0.09
comm=0.5/34.8*risk; spr=0.5/34.8*risk; swap=0.004783927673690548*risk
def run(clip_cost,true_cost,n=5000,seed=3,maxt=400):
    rng=np.random.default_rng(seed); eq=np.zeros(n); alive=np.ones(n,bool); passed=np.zeros(n,bool); tr=np.zeros(n)
    for _ in range(maxt):
        a_t=np.minimum(348,np.maximum(1,np.ceil((T-eq+clip_cost)/tick-1e-9)))
        b_t=np.minimum(348,np.maximum(1,np.floor((eq+D-clip_cost)/tick+1e-9)))
        win=rng.random(n)<b_t/(a_t+b_t)
        step=np.where(win,a_t*tick,-b_t*tick)-true_cost
        act=alive&~passed
        eq=np.where(act,eq+step,eq); tr+=act
        passed|=act&(eq>=T-1e-9); alive&=~(act&(eq<=-D+1e-9))
        if not (alive&~passed).any(): break
    return passed.mean(),np.mean(alive&~passed),tr.mean()
for tag,cc,tc in (("A model: clip nets full cost 3.35%/risk, true cost the same",comm+spr+swap,comm+spr+swap),
                  ("B clip nets commission only, true = commission + 0.5 pip spread",comm,comm+spr),
                  ("C clip nets commission only, true = commission + spread + mean swap",comm,comm+spr+swap),
                  ("D clip nets commission+spread+swap, true spread 0.1 pip wider",comm+spr+swap,comm+spr+swap+0.1/34.8*risk),
                  ("E clip nets commission+spread+swap, true spread 0.1 pip narrower",comm+spr+swap,comm+spr+swap-0.1/34.8*risk)):
    p,stuck,tr=run(cc,tc)
    print(f"{tag:75s} pass {p:.4f}  alive-but-stalled after 400 trades {stuck:.4f}  mean trades {tr:.1f}")
