DEV Community

Mukul Dutt
Mukul Dutt

Posted on

How to parse 13F filings without double-counting every position

Berkshire Hathaway's latest 13F lists 89 rows. Berkshire holds 29 positions.

If you built a 13F filing parser that reads the SEC information table and treats each row as one holding, your portfolio is wrong by a factor of three, and nothing in the filing tells you. To parse 13F filings correctly you group rows by CUSIP and put/call flag, not by row and not by issuer name. Berkshire's 89 rows collapse to 29 real positions, a 3.1x over-count, because each sub-manager files its own line for the same security.

Why does one holding show up as twelve rows?
A 13F-HR reports every US equity position an institutional manager holds, and large filers split investment discretion across sub-managers. Each sub-manager files a separate line for the same security. In Berkshire's filing for the period ending 2026-06-30, Apple occupies 12 rows, Coca-Cola 10, and Bank of America 8. The otherManager field is the only hint, and it points into a separate table.

Nothing in a row says "this is a fragment." There's no flag, no parent ID, no count. You get twelve Apple rows that each look like a complete position.

Here's what those rows actually look like once you pull the XML:

issuer cusip shares value otherManager
APPLE INC 037833100 ... ... 4,11
APPLE INC 037833100 ... ... 2,4,11
APPLE INC 037833100 ... ... 4,5
... nine more
The SEC's own Form 13F FAQ covers the filing obligations in detail but says nothing about how consumers should reassemble the table. That part is left to you.

This is not an obscure edge case. The EdgarTools documentation tells its own users to work with holdings aggregated by CUSIP and to touch the raw infotable only when they specifically need per-manager detail. Every serious 13F pipeline solves this. Most quick scripts don't.

How do you check whether your parser is double-counting?
Run your parser against Berkshire Hathaway, CIK 1067983, accession 0001193125-26-352200, and print the number of positions. If it prints 89 you're counting fragments. If it prints 29 you're aggregating correctly. Berkshire is a useful test case because the over-count is large enough to be obvious and the filing is public, so anyone can reproduce the number.

Here's a standalone check. No dependencies beyond the standard library:

import json, urllib.request, collections
import xml.etree.ElementTree as ET

UA = {"User-Agent": "your-app/1.0 (you@example.com)"} # SEC requires a real contact

def get(url):
return urllib.request.urlopen(urllib.request.Request(url, headers=UA), timeout=60).read()

def infotable(cik, accession):
acc = accession.replace("-", "")
idx = json.loads(get(f"https://www.sec.gov/Archives/edgar/data/{cik}/{acc}/index.json"))
names = [i["name"] for i in idx["directory"]["item"]]
xml_name = [n for n in names if n.endswith(".xml") and "primary_doc" not in n][0]
root = ET.fromstring(get(f"https://www.sec.gov/Archives/edgar/data/{cik}/{acc}/{xml_name}"))
ns = {"n": root.tag.split("}")[0].strip("{")} if "}" in root.tag else {}
q = lambda e, t: e.find(f"n:{t}", ns) if ns else e.find(t)
rows = []
for it in (root.findall("n:infoTable", ns) if ns else root.findall("infoTable")):
pc = q(it, "putCall")
rows.append({
"issuer": q(it, "nameOfIssuer").text.strip(),
"cusip": q(it, "cusip").text.strip().upper(),
"value": float(q(it, "value").text),
"shares": float(q(q(it, "shrsOrPrnAmt"), "sshPrnamt").text),
"put_call": pc.text.strip() if pc is not None and pc.text else None,
})
return rows

rows = infotable("1067983", "0001193125-26-352200")

The whole fix: group by (CUSIP, putCall). Not by row. Not by issuer name.

agg = collections.defaultdict(lambda: {"shares": 0.0, "value": 0.0, "rows": 0})
for r in rows:
k = (r["cusip"], r["put_call"] or "")
a = agg[k]
a["shares"] += r["shares"]; a["value"] += r["value"]; a["rows"] += 1
a["issuer"] = r["issuer"]

print(f"raw rows: {len(rows)} -> positions: {len(agg)}")
for k, a in sorted(agg.items(), key=lambda kv: -kv[1]["value"])[:5]:
print(f" {a['issuer']:<22} ${a['value']/1e9:>7.2f}B across {a['rows']:>2} raw rows")
Output, which you can reproduce right now:

raw rows: 89 -> positions: 29
APPLE INC $ 65.95B across 12 raw rows
AMERICAN EXPRESS CO $ 51.28B across 3 raw rows
COCA COLA CO $ 32.51B across 10 raw rows
ALPHABET INC $ 28.16B across 4 raw rows
BANK OF AMER CORP $ 27.54B across 8 raw rows
I verified the aggregate two ways. My raw XML parse and a completely separate production pipeline both return 227,917,808 Apple shares worth $65,950,296,923, and both count 29 positions. Two independent implementations agreeing to the share is decent evidence the grouping is right.

Why group by CUSIP instead of issuer name?
Because one issuer can legitimately hold several CUSIPs, and merging them destroys real information. Alphabet appears twice in Berkshire's filing under 02079K305 (Class A) and 02079K107 (Class C). Those are different securities with different voting rights and different prices. Collapsing them because the issuer string matches is exactly as wrong as splitting Apple across its 12 sub-manager rows, just in the opposite direction.

Issuer names are also unreliable as keys. The same company appears as "ALPHABET INC" in one filing and with trailing punctuation, casing differences, or a truncated name in another.

CUSIP is the identifier the SEC actually requires in the information table. Use it.

The scale of the share-class problem is easy to underestimate. The SEC's own company_tickers.json contains 10,391 ticker rows mapping to only 8,001 distinct CIKs. About 23% of the tickers in that file are additional share classes of a company already listed.

What else silently corrupts 13F data?
Three things, and each one produces plausible-looking numbers rather than an error. A putCall row is a bet against the stock, not a holding. Filings before 2023 report value in thousands while newer ones report whole dollars. And amended filings restate positions, so pulling the wrong accession gives you superseded data. None of these throw. All of them change your answer.

Put and call rows. Options positions sit in the same information table with a putCall value of Put or Call. Sum a Put row into the long book and you'll report a fund as holding a stock it is actually short. This is why the grouping key above is (cusip, put_call) rather than cusip alone. Keep them in separate buckets, and label them when you display them.

The 2023 units change. Value was reported in thousands before the SEC's amendments took effect, and in whole dollars afterward. Diff a position across that boundary without normalising and it appears to have grown by a factor of 1,000. If your date range straddles it, scale the older side before comparing.

Amendments. A 13F-HR/A restates part or all of a prior filing. If you index by period rather than by accession, a later amendment can silently overwrite or duplicate positions depending on how you upsert.

Trap What it looks like Fix
Sub-manager rows 89 rows, 29 real positions Group by CUSIP
Issuer-name grouping Alphabet A and C merged into one Key on CUSIP, never the name
putCall rows Fund reported long a name it is short Include put/call in the grouping key
Pre-2023 units Position appears to grow 1000x Scale thousands to dollars before diffing
Amendments Positions overwritten or duplicated Index by accession, not period
How do you diff one quarter against the last?
Once positions are aggregated, a quarter-over-quarter diff is a dictionary comparison on the same key. Pull the prior filing, aggregate it identically, then classify each position as new, added, reduced, held or exited. The classification is what makes the data useful, because "Berkshire owns Apple" is not news and "Berkshire added Alphabet and exited Constellation Brands" is.

def classify(cur, prev):
out = {}
for k, a in cur.items():
p = prev.get(k)
if not p: out[k] = "NEW"
elif a["shares"] > p["shares"]: out[k] = "ADDED"
elif a["shares"] < p["shares"]: out[k] = "REDUCED"
else: out[k] = "HELD"
for k in prev.keys() - cur.keys(): out[k] = "EXITED"
return out
Running that for Berkshire's Q2 2026 filing against Q1 gives 1 new position, 7 added, 6 reduced, 15 unchanged and 1 exited, across a $299.25 billion portfolio.

Five of those 29 numbers are worth a headline. The other 24 are noise you now know to ignore.

What about the 45-day lag?
A 13F is due within 45 days of quarter end, so the data describes what a fund owned up to 45 days before you read it, not what it holds today. Berkshire's Q2 2026 filing covers the period ending 2026-06-30 and was filed 2026-08-14. Treat 13F data as a record of past positioning. It is not a live portfolio feed and it is not a trading signal on its own.

The lag also means a fund can build and exit a position entirely inside one quarter and you will never see it.

Two more blind spots worth knowing. 13F covers US-listed equities and some options, so short positions, cash, bonds, and foreign-listed holdings are invisible. And funds can request confidential treatment to delay disclosing a position, which means the table you're reading may be deliberately incomplete.

Should you build this or use an API?
Build it if you track a handful of funds and enjoy owning the edge cases. The snippet above is 20 lines and works. Use an API if you need many funds, historical diffs, or you'd rather not maintain the units logic and the amendment handling yourself.

I run one, so treat this as the biased paragraph it is: Edgrapi returns positions already aggregated by CUSIP, put/call flagged and diffed against the prior quarter.

pip install edgrapi
from edgrapi import Client

r = Client("edgr_...").holdings("berkshire")
r["positions_count"] # 29
r["changes"] # {'new': 1, 'added': 7, 'reduced': 6, 'unchanged': 15, 'exited': 1}
Zero dependencies, free tier is 100 credits a month with no card. The parsing rules in this article are the same either way, and the 20-line version is genuinely fine for a small watchlist.

Frequently asked questions
Why does my 13F parser show more positions than the fund actually holds?
Because each sub-manager files a separate row for the same security and nothing marks those rows as fragments. Berkshire's latest filing has 89 rows and 29 positions, a 3.1x over-count. Group rows by CUSIP and put/call flag, summing shares and value, and the count resolves to the real number of positions.

Should I group 13F holdings by CUSIP or by issuer name?
By CUSIP. One issuer can hold several CUSIPs for different share classes, and merging them loses real distinctions. Alphabet appears under 02079K305 for Class A and 02079K107 for Class C in the same filing. Issuer name strings also vary between filings in casing, punctuation and truncation, which makes them unreliable as keys.

What does putCall mean in a 13F information table?
It marks the row as an options position rather than a share holding. A row with putCall set to Put is a bet against the stock, so summing it into the long book reports a fund as holding a name it is actually short. Include the put/call value in your grouping key and display options positions separately.

Why do older 13F filings show values 1,000 times smaller?
Value was reported in thousands before the SEC's 2023 amendments and in whole dollars afterward. A position compared across that boundary appears to grow by a factor of 1,000. If your query range straddles the change, normalise the older filings to whole dollars before running any diff or growth calculation.

How current is 13F data?
It lags by up to 45 days. Managers must file within 45 days of quarter end, so Berkshire's period ending 2026-06-30 was filed 2026-08-14. The filing describes past positioning, not current holdings, and a fund can open and close a position inside a single quarter without it ever appearing.

Do 13F filings show short positions?
No. 13F covers US-listed equities and certain options only. Short positions, cash, bonds, commodities and foreign-listed holdings are all invisible. A fund can also request confidential treatment to delay disclosing a specific position, so the table may be incomplete by design rather than by error.

Test your parser against Berkshire before you trust it
Point your parser at CIK 1067983, accession 0001193125-26-352200, and check that it returns 29 positions rather than 89 rows. If it returns 89, add the CUSIP grouping from this article. If it returns 29 but merges Alphabet's two share classes, switch your key from issuer name to CUSIP. Both bugs produce numbers that look reasonable, which is exactly why they survive in production.

Data in this article comes from public-domain SEC EDGAR filings and was verified on 5 September 2026. None of it is investment advice.

{
"@context": "https://schema.org",
"@graph": [
{
"@type": "Article",
"headline": "How to parse 13F filings without double-counting every position",
"description": "Berkshire's latest 13F has 89 rows and 29 positions. Why naive 13F parsers triple-count, and the Python that fixes it.",
"datePublished": "2026-09-05",
"dateModified": "2026-09-05",
"author": { "@id": "https://edgrapi.com/#author" },
"publisher": { "@id": "https://edgrapi.com/#org" }
},
{
"@type": "Person",
"@id": "https://edgrapi.com/#author",
"name": "Mukul Dutt",
"jobTitle": "Founder, Edgrapi",
"sameAs": ["{{AUTHOR_LINKEDIN_URL}}", "https://edgrapi.com"]
},
{
"@type": "Organization",
"@id": "https://edgrapi.com/#org",
"name": "Edgrapi",
"url": "https://edgrapi.com"
},
{
"@type": "FAQPage",
"mainEntity": [
{ "@type": "Question", "name": "Why does my 13F parser show more positions than the fund actually holds?",
"acceptedAnswer": { "@type": "Answer", "text": "Each sub-manager files a separate row for the same security and nothing marks those rows as fragments. Berkshire's latest filing has 89 rows and 29 positions, a 3.1x over-count. Group rows by CUSIP and put/call flag, summing shares and value." } },
{ "@type": "Question", "name": "Should I group 13F holdings by CUSIP or by issuer name?",
"acceptedAnswer": { "@type": "Answer", "text": "By CUSIP. One issuer can hold several CUSIPs for different share classes. Alphabet appears under 02079K305 for Class A and 02079K107 for Class C in the same filing. Issuer name strings also vary between filings." } },
{ "@type": "Question", "name": "What does putCall mean in a 13F information table?",
"acceptedAnswer": { "@type": "Answer", "text": "It marks the row as an options position rather than a share holding. A row with putCall set to Put is a bet against the stock, so summing it into the long book reports a fund as holding a name it is actually short." } },
{ "@type": "Question", "name": "Why do older 13F filings show values 1,000 times smaller?",
"acceptedAnswer": { "@type": "Answer", "text": "Value was reported in thousands before the SEC's 2023 amendments and in whole dollars afterward. Normalise older filings to whole dollars before running any diff or growth calculation." } },
{ "@type": "Question", "name": "How current is 13F data?",
"acceptedAnswer": { "@type": "Answer", "text": "It lags by up to 45 days. Managers must file within 45 days of quarter end. The filing describes past positioning, not current holdings." } },
{ "@type": "Question", "name": "Do 13F filings show short positions?",
"acceptedAnswer": { "@type": "Answer", "text": "No. 13F covers US-listed equities and certain options only. Short positions, cash, bonds and foreign-listed holdings are invisible, and funds can request confidential treatment to delay disclosure." } }
]
}
]
}

Top comments (0)