From 4ac39abf057e1600264bd0cbeb6834a983da7fe7 Mon Sep 17 00:00:00 2001 From: Newman Gao Date: Wed, 23 Sep 2026 14:57:52 +0800 Subject: [PATCH] fix(sec): handle zero-value 13F holdings --- .../sec/openbb_sec/utils/parse_13f.py | 4 ++- .../providers/sec/tests/test_parse_13f.py | 33 +++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 openbb_platform/providers/sec/tests/test_parse_13f.py diff --git a/openbb_platform/providers/sec/openbb_sec/utils/parse_13f.py b/openbb_platform/providers/sec/openbb_sec/utils/parse_13f.py index 22ffab90ca59..a562bec1069d 100644 --- a/openbb_platform/providers/sec/openbb_sec/utils/parse_13f.py +++ b/openbb_platform/providers/sec/openbb_sec/utils/parse_13f.py @@ -221,7 +221,9 @@ async def parse_13f_hr(filing: str): df.drop(columns=col, inplace=True) total_value = df.value.sum() - df["weight"] = round(df.value.astype(float) / total_value, 6) + df["weight"] = ( + round(df.value.astype(float) / total_value, 6) if total_value else 0.0 + ) return ( df.reset_index() diff --git a/openbb_platform/providers/sec/tests/test_parse_13f.py b/openbb_platform/providers/sec/tests/test_parse_13f.py new file mode 100644 index 000000000000..a262aa177c52 --- /dev/null +++ b/openbb_platform/providers/sec/tests/test_parse_13f.py @@ -0,0 +1,33 @@ +"""Tests for SEC Form 13F-HR parsing.""" + +import asyncio + +from openbb_sec.utils.parse_13f import parse_13f_hr + +EMPTY_13F_FILING = """ + + + 2025-12-31 + + + + NA + NA + 000000000 + 0 + 0SH + SOLE + 000 + + +""" + + +def test_parse_13f_hr_uses_zero_weight_for_empty_filings(): + """Placeholder rows in zero-holding filings must remain model-valid.""" + result = asyncio.run(parse_13f_hr(EMPTY_13F_FILING)) + + assert len(result) == 1 + assert result[0]["nameOfIssuer"] == "NA" + assert result[0]["value"] == 0 + assert result[0]["weight"] == 0.0