import pandas as pd P='../data/nse' def rd(kind,d): x=pd.read_csv(f'{P}/fao_participant_{kind}_{d}.csv',skiprows=1); x.columns=[c.strip() for c in x.columns]; return x.set_index('Client Type').drop('TOTAL') cols={'Future Index Long':'FutIdx L','Future Index Short':'FutIdx S','Option Index Call Long':'Call L','Option Index Call Short':'Call S','Option Index Put Long':'Put L','Option Index Put Short':'Put S'} out=[] for prev,d in [('12102026','13102026'),('22102026','23102026')]: a,b=rd('oi',prev)[list(cols)],rd('oi',d)[list(cols)]; ch=(b-a).rename(columns=cols) v=rd('vol',d) ch['FutIdx net OI chg']=ch['FutIdx L']-ch['FutIdx S'] ch['FutIdx bought(vol)']=v['Future Index Long']; ch['FutIdx sold(vol)']=v['Future Index Short'] ch['Calls net (L-S) chg']=ch['Call L']-ch['Call S']; ch['Puts net (L-S) chg']=ch['Put L']-ch['Put S'] ch['FutIdx long% (EOD)']=(100*b['Future Index Long']/(b['Future Index Long']+b['Future Index Short'])).round(1) ch.insert(0,'date',f'{d[4:]}-{d[2:4]}-{d[:2]}'); out.append(ch.reset_index()) T=pd.concat(out); T.to_csv('results/participant_changes.csv',index=False) pd.set_option('display.width',250); print(T.to_string(index=False))