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.
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.
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.
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.