# builds section_whoflow.html (section 9) from whoflow/results CSVs import pandas as pd P=pd.read_csv('results/participant_changes.csv') def tbl(df): return df.to_html(index=False,border=0,float_format=lambda x:f'{x:,.0f}') p=P[['date','Client Type','FutIdx bought(vol)','FutIdx sold(vol)','FutIdx L','FutIdx S','FutIdx net OI chg','Call L','Call S','Put L','Put S','Calls net (L-S) chg','Puts net (L-S) chg']].copy() p.columns=['date','who','idx fut bought','idx fut sold','fut long OI chg','fut short OI chg','net fut chg','call long chg','call short chg','put long chg','put short chg','net calls','net puts'] F=pd.read_csv('results/fut_phases_2026-10-23.csv'); O=pd.read_csv('results/options_bands_2026-10-23.csv') f=F[['phase','nifty_spot','NIfut_pts','NI_vol_ctr','NI_dOI_ctr_allexp','NI_dOI_ctr_oct','bn_spot','BA_vol_ctr','BA_dOI_ctr_allexp']].copy() f.columns=['phase (IST)','Nifty spot pts','Nifty Oct fut pts','Nifty fut vol (ctr, all exp)','Nifty fut OI chg (all exp)','Nifty fut OI chg (Oct)','BN spot pts','BN fut vol','BN fut OI chg'] o=O.pivot_table(index='phase',columns='type',values=['dOI_all','vol_all']).round(0); o.columns=[f'{t} {"OI chg" if a=="dOI_all" else "volume"} (contracts)' for a,t in o.columns]; o=o.reset_index().rename(columns={'phase':'phase (IST)'}) F13=pd.read_csv('results/fut_phases_2026-10-13.csv')[['phase','nifty_spot','NIfut_pts','NI_vol_ctr','NI_dOI_ctr_allexp','bn_spot','BA_dOI_ctr_allexp']] F13.columns=['phase (IST)','Nifty spot pts','Nifty Oct fut pts','Nifty fut vol (ctr)','Nifty fut OI chg (all exp)','BN spot pts','BN fut OI chg'] C=pd.read_csv('results/components_2026-10-23_1336.csv').head(10)[['sym','pts_contrib','pct','vol_x20d','first_up015']] C.columns=['stock','Nifty pts 13:36→13:47','% move','cash vol vs 20d','first +0.15% minute'] h=f"""
Source: NSE fao_participant_oi / fao_participant_vol archives. 'bought/sold' = that day's long/short-side volume. Index futures and options cover all indices (Nifty, Bank Nifty, etc.). 13-Oct was a weekly Nifty expiry, so its option OI changes are mostly expiry settlement.
All 50 stocks together: +136.8 pts. Banks (HDFCB, ICICI, Axis, Kotak, SBI) +36.7, Reliance +13.2, IT +11.8. Bank Nifty and Nifty turned in the same minute (BN spot +0.19%, Nifty +0.20% at 13:38), so there was no Bank Nifty lead this time. Bulk deals 23-Oct: no Nifty-50 stock appears. Block deals 23-Oct: none.
Caveats. (1) Who traded in a given minute is not published; the per-minute identities above are inferred from end-of-day category positions plus OI, premium and options patterns. (2) On 23-Oct (rollover week) Upstox 1m Nifty Oct-futures OI ended at 13.39M against NSE's official 11.32M. Calendar-spread trades are missing from the 1m feed (1m volume = 72% of the day's total), and one bar (13:57) shows a −2,939-contract OI jump on 185 contracts of volume, which is impossible. So the 23-Oct futures 'fresh longs' reading is low confidence. Option 1m OI matched NSE end-of-day within 1–2%. 13-Oct futures 1m volume matched NSE exactly. (3) Spot 15:15–15:29 is not used. (4) 13-Oct bulk/block deals: not available free (NSE historical API returned 503; the archive keeps only the latest day). Data: whoflow/results/, scripts: whoflow/scripts/.
""" open('../whoflow/section_whoflow.html','w').write(h); print(len(h))