ZipLime's picture
Align the card with the published build
e05e594 verified
|
Raw History Blame Contribute Delete
10.7 kB
# How this dataset is built
Every step is in [`recipe/`](recipe/), published at the same revision as the
data. This document records what the steps do, which judgements were made, and
what went wrong on the way.
## The idea
Sector classification is a licensed product. GICS belongs to MSCI and S&P Dow
Jones Indices, ICB to FTSE Russell, and neither can be redistributed — so a
free dataset that wants to say what business a company is in has to build the
answer from something else.
The something else exists and is public domain: the SEC assigns a Standard
Industrial Classification code to every filer, prints it in the header of
every filing, and publishes the list of the 444 codes it uses. What it does
not provide is a rollup worth using. The SIC divisions put pharmaceuticals,
semiconductors, oil refining and breweries in one bucket called Manufacturing
that covers a third of the listed universe.
So this dataset is two things: the SEC's codes collected with their dates, and
a rollup from those codes to sectors, written here and licensed Apache-2.0.
The first is evidence; the second is an opinion, stated as code in
[`recipe/taxonomy.py`](recipe/taxonomy.py) so it can be argued with.
## Why it is not GICS
It would be easy to write eleven sectors with GICS's names and let readers
assume compatibility. That would be wrong twice: legally, because the GICS
structure is a licensed product, and factually, because a SIC-derived sector
disagrees with GICS on real companies.
The disagreements are not marginal. Alphabet and Meta are Communication
Services in GICS; here they are Technology, because EDGAR files them under
7370 alongside systems integrators and nothing in a filing separates an
advertising platform from a consultancy. Managed care is Health Care in both,
but by different routes. Most of all, GICS has no bucket for a blank cheque
company, and this taxonomy gives it a sector of its own because 2 181 filers
have been one.
Fama and French's industry definitions were considered and left out. They are
the standard free taxonomy in academic finance and they would have been a
natural fit — but the files carry a bare copyright notice with no licence
grant, and the portfolios built from them derive from CRSP. Shipping a
redistributable dataset meant not shipping them. Anyone who wants them can
apply them to the `sic` column in a line of code; this dataset simply does not
carry the table.
## Three sources and almost no source of its own
Like the security master, this is mostly glue.
**The history** comes from `company-fundamentals`, a sibling dataset, whose
`filings` table carries the SIC printed in the header of every XBRL filing
since 2009 — 437 619 dated statements over 16 928 filers. This is the only
free source of SIC *history*. EDGAR's own record of a filer states today's
code and carries no past, so a dataset built on it alone would say Lucid was
a car maker in 2020, when it was an empty shell called Churchill Capital IV.
Measured on the corpus, **2 320 filers have been reclassified at least once**:
13.7% of the 16 928 with a filing history, which is the only population where
a change could be seen at all. That is the number that decides whether the
dated columns are worth their weight.
**The gap** is the 5 774 filers that have had a ticker and never filed XBRL:
delisted before 2009, funds, foreign issuers on paper. They are covered from
EDGAR's submissions archive, and what it gives is explicitly undated — the SEC
states what it has the filer under now, not when that was assigned. Those rows
carry `is_dated = false` and `date_basis = "undated"`, and the `by_ticker`
table stretches the code over the ticker's life rather than pretending to a
date it does not have.
Leaving them out was the alternative, and it would have made the universe out
of survivors. That is the bias the rest of this family exists to avoid.
**The reference** is the SEC's SIC code list — scraped, because it is a web
page and nothing else; there is no CSV, no JSON and no bulk file — and the
Census Bureau's 1987 SIC to 1997 NAICS concordance, which doubles as the
source for the 1987 hierarchy's own titles.
## What a SIC code is, and what EDGAR's codes are
These are two different things, and conflating them loses two fifths of the
list.
The 1987 SIC has 1 005 four-digit industries in 83 major groups. EDGAR assigns
444 codes, and only 284 of them are 1987 industries. The other 160 are a major
group or an industry group padded with zeros — `2000` for the whole of food,
`3570` for computer and office equipment — used when the SEC did not care to
be more precise.
Checked against all 1 005 of them: **no real 1987 code ends in a zero**. So the
padding is unambiguous and `sic_level` reads it off. Joining EDGAR's codes to
the NAICS crosswalk as if they were 1987 industries would have silently
dropped 39% of them; instead a roll-up is expanded to every industry beneath
it before the crosswalk is consulted.
Twelve EDGAR codes are inventions with no 1987 counterpart at all: asset
backed securities, blank cheques, finance lessors, American Depositary
Receipts, foreign governments, non-operating establishments and six others.
Three of them sit arithmetically in major group 88, which is Private
Households — so `division_of` returns nothing for them rather than calling a
depositary receipt a household service.
## The NAICS bridge is weak, and says so
Measured over this corpus: 32.7% of EDGAR's codes resolve to exactly one 1997
NAICS industry, 71.8% to exactly one NAICS sector, and fourteen codes resolve
to nothing. The rest are one-to-many, because 1997 split a 1987 industry in two.
So `naics_1997` is filled only where the answer is unique, `naics_sector` only
where the sector is unique, and `naics_candidates` says how many there were.
Picking one by a tie-break would read as fact and be a coin toss. The full
crosswalk ships as `naics_map` so anyone who wants to pick differently can.
## Spans are runs, not groups
A filer's codes are collapsed into runs of consecutive filings that said the
same thing — not grouped by (filer, code). A company that was a blank cheque,
became a car maker and was reclassified back has three spans, and a groupby
would flatten it to two and lose the order the SEC saw it in.
`valid_to` is the last filing that stated the code, not the day before the
next one. Nobody publishes the day a classification changed, and a filing gap
is a filing gap.
## `by_ticker`, and the two ways it can be wrong
This is the table most people will use: a symbol, a window, a sector. It is
the overlap of a ticker span from the security master and a SIC span from
here, both over the same filer.
Two decisions:
* **Every ticker gets a row**, including the ones with no code at all, marked
`unknown` and unclassified. A symbol missing from the table and a symbol the
SEC never classified look identical to a consumer, and only one of them is a
bug.
* **`is_current` marks exactly one row per live ticker** — the filer's symbol
now, under the newest code it has been seen under. The first version marked
the ticker span current, which brought a reclassified company back under
both its old sector and its new one, and `filter(is_current)` returned two
contradictory rows for the same symbol.
## Verification
[`quality.py`](recipe/quality.py) gates publication. Two checks earn their
place, and both are about the shape of the answer rather than its plumbing:
* **How much of the live universe is unclassified.** The SEC adds codes —
asset-backed securities and crypto assets both arrived after the 1987 manual
— and nothing else would notice that a new one fell into the catch-all.
* **How much of it sits in the largest sector.** The whole reason this exists
is that the SIC divisions are unusable, Manufacturing alone being a third of
the universe. A regression that collapsed the taxonomy back towards its
input would show up here and nowhere else. Measured largest sector is Health
Care at 16.4%; the ceiling is 30%.
The taxonomy is code, so it is tested like code: every rule has to name an
industry that exists, every industry a sector that exists, every four-digit
code has to land somewhere, and no narrow rule may sit after the range that
contains it — which would make it dead.
## What went wrong
**The per-filer crawl.** The first implementation asked
`data.sec.gov/submissions/CIK*.json` once per filer, at six requests a second,
well under SEC's published limit of ten. It ran at **a fifth of a request per
second**: SEC answers a few hundred and then throttles, and the client spends
its life in backoff. Eight hours for six thousand small files, and the process
burned eight seconds of CPU doing it.
SEC publishes a bulk archive of the same directory for exactly this reason. It
is 1.5 GB and one request, and it arrives in four minutes. The lesson is not
about rate limits — the rate was within the published limit — but that a
service offering a bulk file would rather you took it.
**The coverage metric that could not fail.** The first version measured ticker
coverage over the rows in `by_ticker`, which only contained tickers that had
resolved. It read 100% while a fifth of the universe was missing from the
table entirely. Making every ticker present, classified or not, turned the
metric into one that can go down.
## Schedule
A Hugging Face Job runs [`jobs/run.py`](jobs/run.py) weekly on Monday at 09:40
UTC: restore, lint, test, rebuild, verify, publish. Two hours after
`company-fundamentals` (07:10) and `security-master` (07:40), both of which it
reads — running before them would publish a classification a week behind its
own sources. Weekly rather than daily because a company's assigned code moves
on the scale of years.
## What is not done
* **No GICS, ICB or Fama-French.** Covered above. The `sic` column is there so
anyone with a licence can bring their own.
* **No sub-industry below the ~90 industries here.** SIC does not support it:
two fifths of EDGAR's codes are already roll-ups, so a finer taxonomy would
be inventing precision the input does not carry.
* **No revenue-based classification.** The right way to classify a
conglomerate is by segment revenue, which `company-fundamentals` publishes
as dimensional facts. Nothing here reads them yet.
* **No history before 2009 for anything but the ticker window.** XBRL headers
begin in 2009 Q2. A company's code in 1998 is in the SGML header of its
filings, four million of them, and that is a separate dataset's worth of
work.
* **No foreign classification.** The universe is SEC filers.