"""Inputs from real EURUSD hourly bars with my own light walker (walker.py), no broker: mean stop, Jensen gap on the cost share,
swap nights, hold, pace (calendar days per trade), for the deployed stop rule and the two 40-pip rules of paper Section 'front'."""
import numpy as np, pandas as pd, time
from walker import trades
rules={"deployed max(0.75 sigma,30)":(0.75,30.0),"40-pip by beta: max(0.924 sigma,30)":(0.9244754690483855,30.0),"40-pip by floor: max(0.75 sigma,38.34)":(0.75,38.34362482448531),
       "45-pip by beta: max(1.056 sigma,30)":(1.055825385910252,30.0)}
t0=time.time()
for name,(b,f) in rules.items():
    out=[]
    for seed in range(1,6):
        df=trades(beta=b,floor=f,seed=seed); out.append(df)
    df=pd.concat(out)
    n=len(df)
    # pace: mean calendar days between consecutive exits within each seed run
    paces=[]
    for d in out:
        paces.append(np.diff(d.t_out.to_numpy()).mean()/86400)
    mean_stop=df.stop.mean(); jens=(1.0/df.stop).mean()*mean_stop   # E[1/stop]*E[stop]
    cs_mean=(0.5+0.5)/mean_stop; cs_true=((0.5+0.5)/df.stop).mean()
    sw=(0.224*df.nights/df.stop).mean()    # per-trade swap share (random side: mean of -6.24 and +1.76 per lot per night = -2.24 USD => 0.224 pip/night)
    sw_ratio=0.224*df.nights.mean()/mean_stop
    print(f"{name:42s} trades {n} mean stop {mean_stop:.2f}  hold {df.hold.mean():.3f} d  pace {np.mean(paces):.3f} d/trade  nights {df.nights.mean():.3f} (none {np.mean(df.nights==0):.1%})  "
          f"cost share at mean stop {cs_mean:.4%} vs mean of per-trade shares {cs_true:.4%} (Jensen {cs_true/cs_mean-1:+.1%})  swap share ratio-of-means {sw_ratio:.4%} per-trade mean {sw:.4%}")
print(time.time()-t0)
