Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion openbb_platform/providers/sec/openbb_sec/utils/parse_13f.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
33 changes: 33 additions & 0 deletions openbb_platform/providers/sec/tests/test_parse_13f.py
Original file line number Diff line number Diff line change
@@ -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 = """<?xml version="1.0" encoding="UTF-8"?>
<edgarSubmission>
<headerData>
<filerInfo><periodOfReport>2025-12-31</periodOfReport></filerInfo>
</headerData>
<informationTable>
<infoTable>
<nameOfIssuer>NA</nameOfIssuer>
<titleOfClass>NA</titleOfClass>
<cusip>000000000</cusip>
<value>0</value>
<shrsOrPrnAmt><sshPrnamt>0</sshPrnamt><sshPrnamtType>SH</sshPrnamtType></shrsOrPrnAmt>
<investmentDiscretion>SOLE</investmentDiscretion>
<votingAuthority><Sole>0</Sole><Shared>0</Shared><None>0</None></votingAuthority>
</infoTable>
</informationTable>
</edgarSubmission>"""


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