How do I read the SEC’s quarterly bulk tables?

Read a table from the SEC’s quarterly ZIPs, join a Form 4 to its trades and reporting owners, count each reported trade once, and read the dollar value of a 13F holding.

After this lesson, you can count the shares traded in a Form 4 filed by two owners and read the value of each holding in a Form 13F.

How do I read one table from a quarterly ZIP?

read_table(raw, name) opens the ZIP’s bytes in memory with io.BytesIO, opens the member name + ".tsv" and reads it with pd.read_csv(sep="\t"), because the SEC stores each table as a tab-separated file. The insider ZIP’s NONDERIV_TRANS table holds AAA’s two purchases of 100 shares, on lines 101 and 102 of the filing.

The SEC publishes quarterly ZIPs of insider filings on Forms 3, 4 and 5 and of Form 13F holdings on its pages for insider data sets and 13F data sets. Every row carries the filing’s accession number, the identifier of one submission. Here two made-up ZIPs use the SEC’s table and column names. dtype={"DOCUMENT_TYPE": str} keeps the form type "4" as text, and keep_default_na=False with na_values=[""] treats only empty fields as missing, so a ticker spelled NA keeps its letters.

Code: the two made-up ZIPs
import io
from zipfile import ZipFile

import pandas as pd

def zip_of_tables(tables):
    buffer = io.BytesIO()
    with ZipFile(buffer, "w") as archive:
        for name, columns in tables.items():
            archive.writestr(name + ".tsv", pd.DataFrame(columns).to_csv(sep="\t", index=False))
    return buffer.getvalue()

insider_zip = zip_of_tables({
    "SUBMISSION": {"ACCESSION_NUMBER": ["0000000001-23-000001"], "ISSUERTRADINGSYMBOL": ["AAA"], "DOCUMENT_TYPE": ["4"], "FILING_DATE": ["08-FEB-2023"]},
    "REPORTINGOWNER": {"ACCESSION_NUMBER": ["0000000001-23-000001"] * 2, "RPTOWNERNAME": ["Lee", "Rao"]},
    "NONDERIV_TRANS": {"ACCESSION_NUMBER": ["0000000001-23-000001"] * 2, "NONDERIV_TRANS_SK": [101, 102], "TRANS_CODE": ["P", "P"], "TRANS_DATE": ["06-FEB-2023"] * 2, "TRANS_SHARES": [100, 100]},
})
holdings_zip = zip_of_tables({
    "SUBMISSION": {"ACCESSION_NUMBER": ["0000000002-23-000003"], "FILING_DATE": ["14-FEB-2023"], "PERIODOFREPORT": ["31-DEC-2022"]},
    "INFOTABLE": {"ACCESSION_NUMBER": ["0000000002-23-000003"] * 2, "NAMEOFISSUER": ["BBB", "CCC"], "VALUE": [2500, 600]},
})

A live download needs your name and email in the User-Agent header, and the SEC allows at most 10 requests per second, as its access guidance says. The following box, which does not run on this page, downloads the insider ZIP of the first quarter of 2023.

import requests

reply = requests.get("https://www.sec.gov/files/structureddata/data/insider-transactions-data-sets/2023q1_form345.zip", headers={"User-Agent": "Example Research analyst@example.org"}, timeout=30)
reply.raise_for_status()
insider_zip = reply.content

The following box defines read_table and reads the three insider tables.

def read_table(raw, name):
    with ZipFile(io.BytesIO(raw)) as archive, archive.open(name + ".tsv") as file:
        return pd.read_csv(file, sep="\t", dtype={"DOCUMENT_TYPE": str}, na_values=[""], keep_default_na=False)

submissions = read_table(insider_zip, "SUBMISSION")
owners = read_table(insider_zip, "REPORTINGOWNER")
trades = read_table(insider_zip, "NONDERIV_TRANS")
print(trades.to_string())
       ACCESSION_NUMBER  NONDERIV_TRANS_SK TRANS_CODE   TRANS_DATE  TRANS_SHARES
0  0000000001-23-000001                101          P  06-FEB-2023           100
1  0000000001-23-000001                102          P  06-FEB-2023           100

How do I count a trade once when two owners filed?

Joining the owners by accession number pairs each trade with every owner of the filing, so AAA’s two trades and two owners give four rows and 400 shares, and .drop_duplicates(subset=["ACCESSION_NUMBER", "NONDERIV_TRANS_SK"]) keeps one row per trade, 200 shares. Dropping repeats on date and size would also drop line 102, which has the same date and size as line 101.

validate="many_to_one" checks that each trade finds at most one submission, as in the lesson on merge. The mask keeps purchases, P, and sales, S, on original Forms 4. The join cannot tell which owner made a trade. A filing date has no time of day, so a study of what investors knew needs the release time.

The following box joins the tables and counts the rows and shares before and after dropping the repeats.

filings = trades.merge(submissions, on="ACCESSION_NUMBER", how="left", validate="many_to_one")
purchases_and_sales = filings[(filings["DOCUMENT_TYPE"] == "4") & filings["TRANS_CODE"].isin(["P", "S"])]
with_owners = purchases_and_sales.merge(owners, on="ACCESSION_NUMBER", how="left")
once = with_owners.drop_duplicates(subset=["ACCESSION_NUMBER", "NONDERIV_TRANS_SK"])
print(with_owners[["NONDERIV_TRANS_SK", "RPTOWNERNAME", "TRANS_SHARES"]])
print(len(with_owners), with_owners["TRANS_SHARES"].sum(), len(once), once["TRANS_SHARES"].sum())
   NONDERIV_TRANS_SK RPTOWNERNAME  TRANS_SHARES
0                101          Lee           100
1                101          Rao           100
2                102          Lee           100
3                102          Rao           100
4 400 2 200

How do I date and value a 13F holding?

Joining INFOTABLE, one row per holding, to SUBMISSION by accession number gives each holding its report period and filing date. The manager held BBB on 31 December 2022, filed on 14 February 2023, and reported a value of 2,500 dollars, since filings from 3 January 2023 give VALUE in dollars.

Earlier filings report VALUE in thousands of dollars, so the same 2500 would mean 2,500,000 dollars, as the 13F readme explains. The posts on insider trades and 13F holdings apply these steps to a full quarter.

The following box joins the holdings to their filing.

holdings = read_table(holdings_zip, "INFOTABLE").merge(read_table(holdings_zip, "SUBMISSION"), on="ACCESSION_NUMBER", how="left", validate="many_to_one")
print(holdings)
       ACCESSION_NUMBER NAMEOFISSUER  VALUE  FILING_DATE PERIODOFREPORT
0  0000000002-23-000003          BBB   2500  14-FEB-2023    31-DEC-2022
1  0000000002-23-000003          CCC    600  14-FEB-2023    31-DEC-2022

Your turn

Print the owner names of the Form 4 once each. You should see Lee and Rao.

.unique() keeps each value once.

print(with_owners["RPTOWNERNAME"].unique().tolist())
['Lee', 'Rao']