# Full-history (21-Oct-2024..23-Oct-2026) candidate pool with the same features/outcomes as s9 + random same-minute/same-type benchmark (30 reps). import sys,time; sys.path.insert(0,'/workspace/research/popular-strategies/scripts') src=open('/workspace/research/popular-strategies/scripts/s9_discretion.py').read(); exec(src.split('LOGD=sorted')[0]) X=pd.read_csv(f'{RS}/signals_all.csv',parse_dates=['date']); cand=[] for d in DAYS: for var in ('V1','V2','V3','V4'): cand+=scan_all(d,var) e=nexp(d) for r in X[X.date==d].itertuples(): cand.append(dict(date=d,m=int(r.m),typ='CE' if r.dir>0 else 'PE',dir=int(r.dir),K=float(round(r.entry/50)*50),stop_prem=np.nan,src=r.cand,e=e,spotR=r.R)) C=pd.DataFrame(cand); print('cands',len(C),round(time.time()-t0),flush=True) rows=[]; rng=np.random.default_rng(2134); pool={sp:[d for d in DAYS if split(d)==sp] for sp in ('train','test')}; rr=[] for i,r in enumerate(C.itertuples()): oa=oarr(r.date,r.e,r.typ,r.K) if oa is None or r.m+1>=NM or np.isnan(oa[0,r.m+1]): continue raw=oa[0,r.m+1]; Rp=(raw-r.stop_prem) if r.src.startswith('V') else 0.5*r.spotR z1=run_exit(r.date,oa,r.m,'X_OLD'); z2=run_exit(r.date,oa,r.m,'X_T50',Rp) rows.append(dict(cid=i,date=r.date,m=r.m,typ=r.typ,dir=r.dir,K=r.K,src=r.src,Rp=Rp,xold=z1['pnl'] if z1 else np.nan,xt50=z2['pnl'] if z2 else np.nan,**feats(r.date,r.m,r.dir,r.K,r.e,r.typ))) sp=split(r.date) for k in range(30): d=pool[sp][rng.integers(len(pool[sp]))]; a=S[d]; sc=a[3,r.m] if np.isnan(sc): continue oa2=oarr(d,nexp(d),r.typ,float(round(sc/50)*50)) if oa2 is None: continue y1=run_exit(d,oa2,r.m,'X_OLD'); y2=run_exit(d,oa2,r.m,'X_T50',Rp) if y1 and y2: rr.append((i,k,d,y1['pnl'],y2['pnl'])) pd.DataFrame(rows).to_csv(f'{RS}/disc_fullhist_candidates.csv',index=False) pd.DataFrame(rr,columns=['cid','rep','date','xold','xt50']).to_csv(f'{RS}/disc_fullhist_random.csv',index=False); print('done',len(rows),len(rr),round(time.time()-t0))