"""Pass-rate effect of the strict daily-loss reading: each stop-out kills the account with probability q (measured in e08), chain otherwise as eval_chain."""
from pa_imp import *
g=PA.cost_share(34.791728647093755)+0.004783927673690548
def dp(risk,c,q,T=0.09,D=0.09):
    U=40/c; iC=40; iR=round(risk*U); iD=round(D*U); iT=round(T*U)
    v={0:1.0}; pp=0; n=0; et=0
    while v and n<5000:
        n+=1; nv={}
        for s,p in v.items():
            a=min(iR,max(1,iT-s+iC)); b=min(iR,max(1,s+iD-iC)); pw=b/(a+b)
            t=s+a-iC
            if t>=iT: pp+=p*pw
            else: nv[t]=nv.get(t,0)+p*pw
            t=s-b-iC
            if t>-iD: nv[t]=nv.get(t,0)+p*(1-pw)*(1-q)
        v={k:x for k,x in nv.items() if x>1e-16}
    return pp
for r,q in ((0.03,0.0),(0.03,0.0150),(0.029,0.0056),(0.0315,0.0249)):
    print(f"risk {r:.4f}: q={q:.4f}  P(pass) = {dp(r,g*r,q):.4f}")
