| 201 |
201 |
return empty, 0 |
| 202 |
202 |
names = ["trade_date", "strike", "expiry", "call_put", "last_price", "bid", "ask", "bid_iv", "ask_iv", "open_interest", |
| 203 |
203 |
"volume", "delta", "gamma", "vega", "theta", "rho"] |
| 204 |
|
− ncols = len(lines[0].split(",")) |
|
204 |
+ from collections import Counter |
|
205 |
+ ncols = Counter(len(ln.split(",")) for ln in lines[:500]).most_common(1)[0][0] |
| 205 |
206 |
if ncols != 16: |
| 206 |
207 |
raise ValueError(f"unexpected option-chain column count {ncols} for {underlying}") |
| 207 |
|
− df = pl.read_csv("\n".join(lines).encode(), has_header=False, new_columns=names, infer_schema_length=0) |
|
208 |
+ df = pl.read_csv("\n".join(lines).encode(), has_header=False, new_columns=names, infer_schema_length=0, truncate_ragged_lines=True) |
| 208 |
209 |
num = [c for c in names if c not in ("trade_date", "expiry", "call_put")] |
| 209 |
210 |
df = df.with_columns([pl.col(c).str.strip_chars().cast(pl.Float64, strict=False) for c in num]) |
| 210 |
211 |
df = df.with_columns( |