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