"""Reproduce decision.json (scenario costs, assessment pass, funded line search + pick, cash/fee) from the exact chains only."""
import json, time
from pa_imp import *
D=json.load(open('/root/Projects/trading-framework/src/notebooks/reports/topics/prime_academy/paper/decision.json'))
SPLIT=0.7
T3=PA.Tier(3000,38,51)
stop=D['stop']; coin=D['side_share']['coin']
G={"commission only":PA.cost_share(stop,s=0.0),"commission and spread":PA.cost_share(stop),
   "random side, swap charged":PA.cost_share(stop)+coin,"random side, with the asides":PA.cost_share(stop)*2.33+coin}
wt=D['wait']
t0=time.time()
for name,g in G.items():
    e=PA.eval_chain(0.03,g*0.03,rr=1.0,clip_up=True,clip_dn=True)
    rows=PA.funded_line_search(g,lo=0.006,hi=0.020,step=0.00025,wait=wt)
    plat=PA.plateau(rows)
    pick=min(plat,key=lambda r:(r['med_first_pay'],-r['e_W']))
    f=PA.funded_chain(pick['risk'],g*pick['risk'],PA.payout_threshold(pick['risk'],1.0,3000,SPLIT),rr=1.0,clip_dn=True,wait=wt)
    cash=SPLIT*3000*e['p_pass']*f['e_W']
    ref=D['scenarios'][name]
    print(f"{name:30s} cost {g:.5f} (json {ref['cost']:.5f}) pass3 {e['p_pass']:.5f} (json {ref['assess']['pass_3']:.5f}) pick {pick['risk']:.5f} (json {ref['pick']['risk']:.5f}) p_any {f['p_any']:.5f} (json {ref['gate']['p_any']:.5f}) cash/fee {cash/38:.4f} (json {ref['gate']['cash_fee']:.4f}) plateau {plat[0]['risk']:.5f}-{plat[-1]['risk']:.5f} best p_any {max(r['p_any'] for r in rows):.4f}")
print('seconds',time.time()-t0)
