import pandas as pd,numpy as np,matplotlib; matplotlib.use('Agg'); import matplotlib.pyplot as plt,json O='charts/'; F=pd.read_csv('results/flaw_cost_exit_pooled.csv') fig,ax=plt.subplots(figsize=(8,4)); p=F.pivot(index='ex',columns='scen',values='pnl')[['OLD','STRESS','REAL']] p.plot.bar(ax=ax,color=['#c0392b','#e67e22','#2e86c1']); ax.axhline(0,color='k',lw=.8); ax.set_ylabel('net pts / trade'); ax.set_title('All 6 candidates pooled (804 trades, Oct-2024..Oct-2026): cost assumption vs exit'); ax.set_xlabel('exit'); plt.xticks(rotation=0); plt.tight_layout(); plt.savefig(O+'cost_vs_exit.png',dpi=110); plt.close() P=pd.read_csv('results/primary_results.csv'); fig,ax=plt.subplots(figsize=(8,4)); x=np.arange(6); c=P.cand.unique() tr=P[P.split=='train'].set_index('cand').loc[c]; te=P[P.split=='test'].set_index('cand').loc[c] ax.bar(x-.27,tr['mean'],.27,label='train 2024-25'); ax.bar(x,te['mean'],.27,label='test 2026'); ax.bar(x+.27,te['random_mean'],.27,label='random same-time 2026',color='grey') ax.set_xticks(x); ax.set_xticklabels([f'{k}\n{tr.loc[k,"ex"]}' for k in c]); ax.axhline(0,color='k',lw=.8); ax.set_ylabel('net pts/trade (real costs)'); ax.legend(); ax.set_title('Pre-declared candidates, train-chosen exit'); plt.tight_layout(); plt.savefig(O+'candidates.png',dpi=110); plt.close() T=pd.read_csv('results/random_by_tod.csv'); fig,ax=plt.subplots(figsize=(8,3.6)) for ex,g in T.groupby('ex'): ax.plot(g.hm,g.pnl,marker='o',label=ex) ax.axhline(0,color='k',lw=.8); ax.set_ylabel('net pts/trade'); ax.set_title('Random ATM buys (both directions, R=40) by entry time — real costs'); ax.legend(); plt.tight_layout(); plt.savefig(O+'random_tod.png',dpi=110); plt.close() D=pd.read_csv('results/deep_itm_orb_E1_summary.csv'); D=D[D.scen=='REAL']; fig,ax=plt.subplots(figsize=(8,3.6)) for (cd,sp),g in D.groupby(['cand','split']): ax.plot(g.itm,g.pnl,marker='o',label=f'{cd} {sp} option net'); for (cd,sp),g in D.groupby(['cand','split']): ax.plot(g.itm,g.spot_pts,ls=':',marker='x',label=f'{cd} {sp} spot pts') ax.axhline(0,color='k',lw=.8); ax.set_xlabel('strikes ITM'); ax.set_ylabel('pts/trade'); ax.set_title('ORB with-gap, structural stop to 15:14: spot edge vs what the option buyer keeps'); ax.legend(fontsize=7,ncol=2); plt.tight_layout(); plt.savefig(O+'spot_vs_option.png',dpi=110); plt.close() print('ok')