Skip to content

fix(sec): 13F-HR parser — guard zero total_value, preserve XML entities - #7620

Open
RadioOrc wants to merge 1 commit into
OpenBB-finance:developfrom
RadioOrc:fix/13f-parser-empty-filing-and-entities
Open

fix(sec): 13F-HR parser — guard zero total_value, preserve XML entities#7620
RadioOrc wants to merge 1 commit into
OpenBB-finance:developfrom
RadioOrc:fix/13f-parser-empty-filing-and-entities

Conversation

@RadioOrc

Copy link
Copy Markdown

fix(sec): 13F-HR parser — guard zero total_value, preserve XML entities

Why

Two independent bugs in openbb_sec/utils/parse_13f.py, both verified against live EDGAR filings (details + repro in the two linked issues):

  1. Empty filings crash. Managers with no reportable holdings file a single placeholder row (value=0). total_value is then 0, weight = 0/0 = NaN, .replace({nan: None}) turns it into None, and the required weight: float field fails validation — the whole fetch raises ValidationError. Repro: CIK 1562087 (Thiel Macro), any quarter since 2025-Q4.

  2. & silently dropped from names. The parser soups the entire SGML-wrapped Complete Submission TXT, which is not well-formed XML; lxml recover mode drops character entities, so S&P500 EQL WGT becomes SP500 EQL WGT with no error. Every filer holding S&P ETFs is affected every quarter. Repro: CIK 1536411 (Duquesne), 2026-03-31.

What

  • parse_13f_hr: extract the embedded well-formed <XML> blocks (form header + information table), strip their <?xml?> declarations and reassemble under a synthetic root before parsing — strict XML path, entities preserved. Bare-XML inputs pass through unchanged.
  • parse_13f_hr: guard the weight division — weight = ... if total_value else 0.0.

No public API change; SecForm13FHRData model untouched.

Testing

Against live EDGAR (openbb-sec 1.6.6 == 1.6.7 == main for the affected lines):

  • Empty filing (CIK 1562087, 2026-03-31 and 2025-12-31): no longer raises; returns placeholder row with weight=0.0.
  • Normal filing (CIK 1536411, 2026-03-31, 70 positions): all & preserved (S&P500 EQL WGT, Ishares S&P Gsci Commodity-, State Str Spdr S&P 500 Etf T), sum(weight) == 1.0 exactly, values/shares byte-identical to a direct parse of the standalone information-table XML.
  • Cross-checked 14 filings across 7 institutions (incl. options positions with putCall, and a $1000s-convention filer) — field-level identical to an independent parser fed the standalone XML.

Fixes #7618 and #7619.

@CLAassistant

CLAassistant commented Jul 31, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@RadioOrc

Copy link
Copy Markdown
Author

recheck

@RadioOrc
RadioOrc force-pushed the fix/13f-parser-empty-filing-and-entities branch from 08aafc2 to c410120 Compare July 31, 2026 10:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SEC 13F-HR: empty filings (zero holdings) crash with ValidationError on weight

2 participants