Upload data_collection_readme.md with huggingface_hub
Browse files- data_collection_readme.md +261 -3
data_collection_readme.md
CHANGED
|
@@ -51,7 +51,7 @@ The output of Phase 1 is **Milestone M1**: *"Clean corpus, temporal split indice
|
|
| 51 |
|
| 52 |
---
|
| 53 |
|
| 54 |
-
###
|
| 55 |
|
| 56 |
**What it is:** Non-derivative insider transactions (open-market stock buys/sells by directors, officers, and >10% shareholders) for all 656 S&P 500 CIKs, covering 2006 Q1 – 2026 Q1.
|
| 57 |
|
|
@@ -80,6 +80,8 @@ The output of Phase 1 is **Milestone M1**: *"Clean corpus, temporal split indice
|
|
| 80 |
*Why SEC flat files?* The SEC publishes pre-parsed quarterly ZIP archives of all Form 3/4/5 XML submissions as flat TSV files at:
|
| 81 |
`https://www.sec.gov/files/structureddata/data/insider-transactions-data-sets/{year}q{n}_form345.zip`
|
| 82 |
|
|
|
|
|
|
|
| 83 |
The alternative — scraping 357,000+ individual Form 4 XML files via the EDGAR submissions API — was first attempted but abandoned for three reasons: (1) runtime of ~11 hours at EDGAR's 10 req/sec rate limit; (2) `primaryDocument` in the submissions API pointed to XSL-rendered HTML files (path prefix `xslF345X05/`) rather than raw XML, requiring expensive directory-listing fallbacks per filing; (3) the SEC flat files contain the same data, already parsed, with no rate-limit concerns. The flat-file approach completed in ~11 minutes.
|
| 84 |
|
| 85 |
*What the script does:*
|
|
@@ -118,7 +120,9 @@ Output: final `form4_transactions.csv` (1,670,042 rows, 24 columns, with `is_off
|
|
| 118 |
|
| 119 |
---
|
| 120 |
|
| 121 |
-
|
|
|
|
|
|
|
| 122 |
|
| 123 |
| Metric | Value |
|
| 124 |
|--------|-------|
|
|
@@ -126,7 +130,7 @@ Output: final `form4_transactions.csv` (1,670,042 rows, 24 columns, with `is_off
|
|
| 126 |
| Source | WRDS CRSP Annual Update → Legacy Data - Stock / Events → Names (query ID 11340756) |
|
| 127 |
| File size | ~290 KB |
|
| 128 |
|
| 129 |
-
**What it is:** One row per name period per PERMNO — the full history of each
|
| 130 |
|
| 131 |
**Why `namedt`/`nameendt`?** These date-bound name periods are what distinguish `crsp_dsenames` from the header-level `crsp_2025_daily.csv`. A given PERMNO (e.g., 10145) may have been "Allied Chemical Corp" in 1970, "Allied Signal Inc" in 1985, and "Honeywell International Inc" in 2000. Any downstream process that matches by company name (e.g., GDELT news matching) must use the name that was active at the time of the relevant event — `namedt`/`nameendt` provide that temporal boundary.
|
| 132 |
|
|
@@ -181,6 +185,255 @@ The split boundary is applied via `filing_date` (not `report_date`) per §3.1.1:
|
|
| 181 |
|
| 182 |
---
|
| 183 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 184 |
## Scripts Reference
|
| 185 |
|
| 186 |
| Script | Input(s) | Output | Purpose |
|
|
@@ -196,6 +449,11 @@ The split boundary is applied via `filing_date` (not `report_date`) per §3.1.1:
|
|
| 196 |
| `scripts/postprocess_form4.py` | `form4_transactions.csv` (raw) | `form4_transactions.csv` (clean, 20 cols) | Drops 12 `_fn` footnote columns; converts dates from DD-MON-YYYY to YYYY-MM-DD |
|
| 197 |
| `scripts/form4_add_roles.py` | `form4_transactions.csv` (clean), SEC EDGAR quarterly ZIPs | `form4_transactions.csv` (final, 24 cols) | Re-fetches REPORTINGOWNER from all 81 quarters; parses `rptowner_relationship` to derive `is_officer`, `is_director`, `is_ten_pct_owner`, `officer_title` |
|
| 198 |
| `scripts/test_form4_pipeline.py` | SEC EDGAR API | *(console)* | Smoke-test: validates metadata fetch + XML parse + column structure for 5 companies before full run |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 199 |
|
| 200 |
---
|
| 201 |
|
|
|
|
| 51 |
|
| 52 |
---
|
| 53 |
|
| 54 |
+
### 👤 `form4_transactions.csv` — SEC Form 4 Insider Trading
|
| 55 |
|
| 56 |
**What it is:** Non-derivative insider transactions (open-market stock buys/sells by directors, officers, and >10% shareholders) for all 656 S&P 500 CIKs, covering 2006 Q1 – 2026 Q1.
|
| 57 |
|
|
|
|
| 80 |
*Why SEC flat files?* The SEC publishes pre-parsed quarterly ZIP archives of all Form 3/4/5 XML submissions as flat TSV files at:
|
| 81 |
`https://www.sec.gov/files/structureddata/data/insider-transactions-data-sets/{year}q{n}_form345.zip`
|
| 82 |
|
| 83 |
+
Browse all available quarters and download manually: https://www.sec.gov/data-research/sec-markets-data/insider-transactions-data-sets
|
| 84 |
+
|
| 85 |
The alternative — scraping 357,000+ individual Form 4 XML files via the EDGAR submissions API — was first attempted but abandoned for three reasons: (1) runtime of ~11 hours at EDGAR's 10 req/sec rate limit; (2) `primaryDocument` in the submissions API pointed to XSL-rendered HTML files (path prefix `xslF345X05/`) rather than raw XML, requiring expensive directory-listing fallbacks per filing; (3) the SEC flat files contain the same data, already parsed, with no rate-limit concerns. The flat-file approach completed in ~11 minutes.
|
| 86 |
|
| 87 |
*What the script does:*
|
|
|
|
| 120 |
|
| 121 |
---
|
| 122 |
|
| 123 |
+
---
|
| 124 |
+
|
| 125 |
+
### 🏷️ `crsp_dsenames.csv` — CRSP Security Names History
|
| 126 |
|
| 127 |
| Metric | Value |
|
| 128 |
|--------|-------|
|
|
|
|
| 130 |
| Source | WRDS CRSP Annual Update → Legacy Data - Stock / Events → Names (query ID 11340756) |
|
| 131 |
| File size | ~290 KB |
|
| 132 |
|
| 133 |
+
**What it is:** One row per name period per PERMNO — the full history of each firm's trading name, ticker, and exchange listing. Columns: `namedt, comnam, ticker, permno, nameendt, shrcd, exchcd, siccd, permco`.
|
| 134 |
|
| 135 |
**Why `namedt`/`nameendt`?** These date-bound name periods are what distinguish `crsp_dsenames` from the header-level `crsp_2025_daily.csv`. A given PERMNO (e.g., 10145) may have been "Allied Chemical Corp" in 1970, "Allied Signal Inc" in 1985, and "Honeywell International Inc" in 2000. Any downstream process that matches by company name (e.g., GDELT news matching) must use the name that was active at the time of the relevant event — `namedt`/`nameendt` provide that temporal boundary.
|
| 136 |
|
|
|
|
| 185 |
|
| 186 |
---
|
| 187 |
|
| 188 |
+
---
|
| 189 |
+
|
| 190 |
+
---
|
| 191 |
+
|
| 192 |
+
### 📄 `sec/` — Full 10-K and 10-Q SEC Filings
|
| 193 |
+
|
| 194 |
+
**What it is:** Complete SEC 10-K (annual) and 10-Q (quarterly) filings in plain text for 634 S&P 500 companies, downloaded from the Finstream lab server (`labvm`). Each filing is the full document — all sections including Item 1 Business, Item 1A Risk Factors, Item 7 MD&A, financials, and exhibits.
|
| 195 |
+
|
| 196 |
+
| Metric | Value |
|
| 197 |
+
|--------|-------|
|
| 198 |
+
| CIK folders | 634 |
|
| 199 |
+
| Total filing files | 2,285 (classified) + 45 UNCERTAIN (exhibits, safely ignored) |
|
| 200 |
+
| 10-K filings | 817 |
|
| 201 |
+
| 10-Q filings | 1,468 |
|
| 202 |
+
| Total size | ~9 GB |
|
| 203 |
+
| Date range | 2025–2026 (latest filings) |
|
| 204 |
+
|
| 205 |
+
**Local directory structure (`datasets/sec/`):**
|
| 206 |
+
```
|
| 207 |
+
datasets/
|
| 208 |
+
└── sec/
|
| 209 |
+
├── sec_filings_index.csv ← master index (paths relative to datasets/)
|
| 210 |
+
├── sec_filings_UNCERTAIN.csv ← 45 exhibit/non-filing files flagged for review
|
| 211 |
+
└── firm/
|
| 212 |
+
├── txt/<CIK>/<YYYY-MM-DD>.txt ← plain text (primary)
|
| 213 |
+
├── html/<CIK>/<YYYY-MM-DD>.html ← HTML version
|
| 214 |
+
└── pdf/<CIK>/<YYYY-MM-DD>.pdf ← PDF version
|
| 215 |
+
```
|
| 216 |
+
|
| 217 |
+
**Server path:** `/data/finstream/airflow/data/SP500/sec/` on `labvm`
|
| 218 |
+
|
| 219 |
+
**Why this complements `sp500_1A/`:** The existing `sp500_1A/` corpus contains only the extracted Item 1A Risk Factors section from 10-Ks (2006–2025). This dataset provides the full filing text for all sections, and includes 10-Q quarterly reports which are absent from `sp500_1A/`.
|
| 220 |
+
|
| 221 |
+
---
|
| 222 |
+
|
| 223 |
+
##### Step-by-Step: Collection and Sorting
|
| 224 |
+
|
| 225 |
+
**Step 1 — Download from Finstream server**
|
| 226 |
+
*(SSH to `labvm`, rsync to local — no script required)*
|
| 227 |
+
|
| 228 |
+
Files are stored on the University of Edinburgh Finstream lab server at `/data/finstream/airflow/data/SP500/sec/`. Downloaded into `datasets/sec/` via:
|
| 229 |
+
```bash
|
| 230 |
+
rsync -avz --progress labvm:/data/finstream/airflow/data/SP500/sec/ \
|
| 231 |
+
"D:/UoE AI/Dissertation/IPP Draft/datasets/sec/"
|
| 232 |
+
```
|
| 233 |
+
Files are named by date only (`YYYY-MM-DD.txt`) with no form-type label in the filename.
|
| 234 |
+
|
| 235 |
+
**Step 2 — Sort into 10-K vs 10-Q**
|
| 236 |
+
*(run `scripts/sort_sec_filings.py` → generates `datasets/sec_filings_index.csv` + `datasets/sec_filings_UNCERTAIN.csv`, ~6 sec)*
|
| 237 |
+
|
| 238 |
+
*Why not use filename or file size?* Filenames contain only the filing date. File size correlates loosely with form type but is unreliable — 10-Q files range from 80 KB to 900 KB depending on company complexity, overlapping with 10-K sizes entirely.
|
| 239 |
+
|
| 240 |
+
*How classification works (sure-shot method):* Every SEC XBRL txt file embeds the fiscal period token in its first line of metadata:
|
| 241 |
+
```
|
| 242 |
+
abt-20241231 0000001800 2024 FY false ...
|
| 243 |
+
```
|
| 244 |
+
The token `FY` → 10-K (annual); `Q1`/`Q2`/`Q3`/`Q4` → 10-Q (quarterly). The script scans all whitespace-separated tokens in the first line (position-independent, since the token appears at different offsets across XBRL format variants). Only 1 line per file is read — the full 9 GB is never loaded.
|
| 245 |
+
|
| 246 |
+
*Why `sec_filings_UNCERTAIN.csv` is safe to ignore:* Of 45 unclassified files, 43 are exhibit documents (insider trading policies, RSU agreements, consent letters, XBRL viewer fragments) that are not 10-K or 10-Q filings. The remaining 2 (CIK `0001881551`) are genuine 10-Ks in a non-XBRL plain text format — manually patched into the index via `scripts/patch_sec_index.py`.
|
| 247 |
+
|
| 248 |
+
**Step 3 — Patch 2 manually identified 10-Ks**
|
| 249 |
+
*(run `scripts/patch_sec_index.py` → overwrites `datasets/sec_filings_index.csv`, adds 2 rows)*
|
| 250 |
+
|
| 251 |
+
Appends the 2 plain-text 10-K filings from CIK `0001881551` (Apr 2025 and Apr 2026) that the XBRL parser could not classify, marked with `confidence = MANUAL`.
|
| 252 |
+
|
| 253 |
+
**Output:** `sec/sec_filings_index.csv` — master reference for all 2,285 filings (2,283 HIGH confidence + 2 MANUAL).
|
| 254 |
+
|
| 255 |
+
---
|
| 256 |
+
|
| 257 |
+
---
|
| 258 |
+
|
| 259 |
+
### 🗂️ `sec/sec_filings_index.csv` — SEC Filings Master Index
|
| 260 |
+
|
| 261 |
+
| Metric | Value |
|
| 262 |
+
|--------|-------|
|
| 263 |
+
| Rows | 2,285 |
|
| 264 |
+
| 10-K | 817 |
|
| 265 |
+
| 10-Q | 1,468 |
|
| 266 |
+
| Confidence HIGH | 2,283 |
|
| 267 |
+
| Confidence MANUAL | 2 (CIK 0001881551) |
|
| 268 |
+
|
| 269 |
+
**Columns:** `cik, filing_date, form_type, fiscal_period, size_kb, confidence, txt_path, html_path, pdf_path`
|
| 270 |
+
|
| 271 |
+
**Purpose:** Lookup table mapping every filing file to its form type and paths. Any downstream script reads this CSV rather than scanning the 9 GB directory. `confidence` is `HIGH` for XBRL-classified files and `MANUAL` for the 2 hand-labelled entries.
|
| 272 |
+
|
| 273 |
+
**Path convention:** All paths (`txt_path`, `html_path`, `pdf_path`) are **relative to the `datasets/` directory** (one level above `sec/`). This makes the index portable across machines (local Windows, GPU cluster, HuggingFace download). To resolve a path in Python:
|
| 274 |
+
```python
|
| 275 |
+
from pathlib import Path
|
| 276 |
+
import pandas as pd
|
| 277 |
+
|
| 278 |
+
# Note: index lives inside datasets/sec/ but paths are relative to datasets/
|
| 279 |
+
datasets_dir = Path("datasets")
|
| 280 |
+
df = pd.read_csv(datasets_dir / "sec" / "sec_filings_index.csv")
|
| 281 |
+
full_path = datasets_dir / df.iloc[0]['txt_path']
|
| 282 |
+
# → datasets/sec/firm/txt/0000001800/2025-02-21.txt
|
| 283 |
+
```
|
| 284 |
+
|
| 285 |
+
---
|
| 286 |
+
|
| 287 |
+
---
|
| 288 |
+
|
| 289 |
+
### 🎙️ `calls/` — S&P 500 Earnings Call Transcripts
|
| 290 |
+
|
| 291 |
+
**What it is:** Quarterly earnings call transcripts for S&P 500 firms. Two separate datasets exist — one on the Finstream server (historic, not yet downloaded) and one downloaded locally (recent, 2025–2026).
|
| 292 |
+
|
| 293 |
+
---
|
| 294 |
+
|
| 295 |
+
#### Local dataset — `datasets/calls/` (already on disk)
|
| 296 |
+
|
| 297 |
+
| Metric | Value |
|
| 298 |
+
|--------|-------|
|
| 299 |
+
| Total transcripts | 299 |
|
| 300 |
+
| Total tickers | 172 |
|
| 301 |
+
| Date range | 2025–2026 |
|
| 302 |
+
| Format | JSON, one file per ticker/year/quarter |
|
| 303 |
+
|
| 304 |
+
**Directory structure:**
|
| 305 |
+
```
|
| 306 |
+
datasets/calls/firm/json/<ticker>/<year>/calls_<TICKER>_<YEAR>_<Q>.json
|
| 307 |
+
```
|
| 308 |
+
|
| 309 |
+
**JSON structure (example — AAPL Q1 2025):**
|
| 310 |
+
```json
|
| 311 |
+
{
|
| 312 |
+
"date": "2025-01-30",
|
| 313 |
+
"transcript": "Suhasini Chandramouli: Good afternoon...",
|
| 314 |
+
"transcript_split": "split transcript is available for premium subscribers only."
|
| 315 |
+
}
|
| 316 |
+
```
|
| 317 |
+
|
| 318 |
+
**Note on `transcript_split`:** Full Q&A/executive section breakdown requires a premium API Ninjas subscription. Only the combined `transcript` field is available — this is sufficient for DAPT corpus expansion and sentiment scoring.
|
| 319 |
+
|
| 320 |
+
**Source:** API Ninjas (`https://api-ninjas.com/`). No redistribution restrictions.
|
| 321 |
+
|
| 322 |
+
---
|
| 323 |
+
|
| 324 |
+
#### Finstream server dataset — **NOT YET DOWNLOADED** (pending)
|
| 325 |
+
|
| 326 |
+
The Finstream lab server holds a much larger historic corpus:
|
| 327 |
+
|
| 328 |
+
| Metric | Value |
|
| 329 |
+
|--------|-------|
|
| 330 |
+
| Total transcripts | 37,962 |
|
| 331 |
+
| Total firms | 653 |
|
| 332 |
+
| Coverage (recall) | 96.25% |
|
| 333 |
+
| Date range | Jan 2008 – Dec 2024 |
|
| 334 |
+
| Missing | 6,373 transcripts (concentrated in 2008–2012 and Q1 filings) |
|
| 335 |
+
|
| 336 |
+
**Server path:** `/data/finstream/airflow/data/SP500/calls/firm/<ticker>/<year>/`
|
| 337 |
+
|
| 338 |
+
**Download command (when ready):**
|
| 339 |
+
```bash
|
| 340 |
+
rsync -avz --progress labvm:/data/finstream/airflow/data/SP500/calls/ \
|
| 341 |
+
"D:/UoE AI/Dissertation/IPP Draft/datasets/calls_historic/"
|
| 342 |
+
```
|
| 343 |
+
|
| 344 |
+
This dataset would provide the historical coverage (2008–2024) needed if earnings calls are to be included in the DAPT corpus (see `Literature (new)/Literature (new).md` Section 5 for the scientific rationale). For 2025–2026 pipeline work, the local 299-file dataset is sufficient.
|
| 345 |
+
|
| 346 |
+
**Why two datasets:** The local 299-file dataset covers the 2025–2026 test/val period used in the SEC filings pipeline. The Finstream corpus covers the 2008–2024 training period. If both are downloaded and merged, they provide full temporal coverage aligned to the `feature_table.parquet` training split.
|
| 347 |
+
|
| 348 |
+
**Purpose:** Per literature survey (`Literature (new).md`, Section 5): earnings calls are the only new dataset with a scientific case for NLP training integration (DAPT corpus expansion + 4th contrastive view). Stage 5 use: call tone features (net_optimism, Q&A tone) as scalar predictors alongside embeddings.
|
| 349 |
+
|
| 350 |
+
---
|
| 351 |
+
|
| 352 |
+
---
|
| 353 |
+
|
| 354 |
+
---
|
| 355 |
+
|
| 356 |
+
### 📰 `gdelt/` — GDELT Global Knowledge Graph News Sentiment
|
| 357 |
+
|
| 358 |
+
**What it is:** Daily news sentiment signals for S&P 500 companies, extracted from the GDELT 1.0 Global Knowledge Graph (GKG). GDELT monitors 215 languages of global news media and scores each article for tone (positive/negative sentiment), organisations mentioned, and economic/financial themes. Used as a company-specific news sentiment feature alongside SEC filings and earnings calls.
|
| 359 |
+
|
| 360 |
+
**Why GDELT and not RavenPack:** RavenPack is the standard financial-research news sentiment dataset available via WRDS, but the University of Edinburgh's WRDS subscription does not include it. GDELT is the closest freely available alternative and is used extensively in financial research.
|
| 361 |
+
|
| 362 |
+
| Metric | Value |
|
| 363 |
+
|--------|-------|
|
| 364 |
+
| Daily rows (final output) | 170,153 |
|
| 365 |
+
| Unique PERMNOs covered | 543 / 646 (84%) |
|
| 366 |
+
| Date range | 2025-01-01 → 2026-06-10 |
|
| 367 |
+
| Raw daily parquet files | 508 |
|
| 368 |
+
| Source | `http://data.gdeltproject.org/gkg/YYYYMMDD.gkg.csv.zip` |
|
| 369 |
+
| Cost | Free — no account required |
|
| 370 |
+
|
| 371 |
+
**PERMNO coverage note:** 543 of 646 PERMNOs (84%) are matched. The 103 unmatched PERMNOs are companies with short, ambiguous, or rarely news-mentioned names that do not reliably appear in GDELT's `ORGANIZATIONS` field. Coverage is sufficient for pilot analysis; the supervisor will decide whether to pursue BigQuery (GDELT 2.0 GKG) for richer coverage and historical extension to 2006–2024.
|
| 372 |
+
|
| 373 |
+
**Key output columns:**
|
| 374 |
+
|
| 375 |
+
`gdelt_gkg_daily.parquet` — richest output, one row per (PERMNO, date):
|
| 376 |
+
|
| 377 |
+
| Column | Meaning |
|
| 378 |
+
|--------|---------|
|
| 379 |
+
| `permno` | CRSP PERMNO — links to volatility labels and prices |
|
| 380 |
+
| `article_date` | Date of news article (YYYY-MM-DD) |
|
| 381 |
+
| `n_articles` | Articles mentioning this company that day |
|
| 382 |
+
| `n_sources` | Distinct news outlets |
|
| 383 |
+
| `avg_tone` | Mean overall tone (negative = bad news, positive = good news) |
|
| 384 |
+
| `avg_tone_pos` | Mean positive sentiment density |
|
| 385 |
+
| `avg_tone_neg` | Mean negative sentiment density |
|
| 386 |
+
| `avg_polarity` | Mean polarity score |
|
| 387 |
+
| `n_econ_themes` | Articles with at least one `ECON_` theme code |
|
| 388 |
+
| `n_fin_themes` | Articles with finance-specific themes |
|
| 389 |
+
|
| 390 |
+
`gdelt_daily.parquet` — combined output (future use, currently ignorable):
|
| 391 |
+
|
| 392 |
+
| Column | Meaning |
|
| 393 |
+
|--------|---------|
|
| 394 |
+
| `permno` | CRSP PERMNO |
|
| 395 |
+
| `date` | Date (YYYY-MM-DD) |
|
| 396 |
+
| `n_records` | Articles mentioning this company that day |
|
| 397 |
+
| `n_sources` | Distinct news outlets |
|
| 398 |
+
| `avg_tone` | Mean overall tone |
|
| 399 |
+
| `avg_tone_pos` | Mean positive sentiment score |
|
| 400 |
+
| `avg_tone_neg` | Mean negative sentiment score |
|
| 401 |
+
| `source` | Data source (`GKG` or `EVENTS`) |
|
| 402 |
+
|
| 403 |
+
> **Which file to use:** Use `gdelt_gkg_daily.parquet` for all pipeline work — it has more columns and no information has been dropped. `gdelt_daily.parquet` strips out `avg_polarity`, `n_econ_themes`, and `n_fin_themes` to prepare a common schema for a future merge with GDELT 1.0 Events data (2006–2014). Until that historical data is collected, `gdelt_daily.parquet` is a strict subset of `gdelt_gkg_daily.parquet` and can be ignored.
|
| 404 |
+
|
| 405 |
+
**How company matching works:** `crsp_dsenames.csv` provides the bridge between CRSP PERMNOs and GDELT organisation names. Each CRSP company name (`comnam`) is cleaned to GDELT-style — suffixes stripped (`INC`, `CORP`, `&`) and 30+ manual overrides applied (e.g. `AMAZON COM INC` → `AMAZON`, `JOHNSON & JOHNSON` → `JOHNSON JOHNSON`). Matching uses temporal bounds (`namedt`/`nameendt`) so a 2025 article mentioning `ORACLE` is only assigned to PERMNO 10104 if that name was active on the article date. This produces 800 unique patterns across 646 PERMNOs stored in `datasets/gdelt/company_names.csv`.
|
| 406 |
+
|
| 407 |
+
**Why GDELT 1.0 GKG for direct download:** GDELT 1.0 GKG publishes one file per day (527 files for 2025–2026). GDELT 2.0 GKG publishes one file every 15 minutes (~50,592 files for the same period) — impractical to direct-download. GDELT 2.0 GKG is accessible via Google BigQuery (pending supervisor decision on historical extension). See `datasets/gdelt_readme.md` for full detail on both approaches.
|
| 408 |
+
|
| 409 |
+
---
|
| 410 |
+
|
| 411 |
+
##### Step-by-Step: Collection
|
| 412 |
+
|
| 413 |
+
**Step 1 — Prepare company name patterns**
|
| 414 |
+
*(run `scripts/gdelt/step1_prepare_names.py` → generates `datasets/gdelt/company_names.csv`)*
|
| 415 |
+
|
| 416 |
+
Reads `crsp_dsenames.csv`, strips legal suffixes from each `comnam`, applies manual overrides for edge cases, and outputs 800 GDELT-style search patterns with PERMNO and temporal bounds (`namedt`/`nameendt`).
|
| 417 |
+
|
| 418 |
+
**Step 2 — Download and filter daily GKG files**
|
| 419 |
+
*(run `scripts/gdelt/step2_download_gkg.py` → generates `datasets/gdelt/raw/gkg_YYYYMMDD.parquet`, one per day)*
|
| 420 |
+
|
| 421 |
+
Downloads each daily ZIP into RAM (never written to disk as a temp file), extracts the CSV, filters rows where the `ORGANIZATIONS` column contains any S&P 500 pattern via regex match, saves only the filtered rows as a parquet file, then discards the ZIP. Peak disk usage: ~500 MB total for all 508 filtered parquets. Resume-safe — already-downloaded dates are skipped on re-run.
|
| 422 |
+
|
| 423 |
+
```powershell
|
| 424 |
+
python scripts/gdelt/step2_download_gkg.py --year 2025
|
| 425 |
+
python scripts/gdelt/step2_download_gkg.py --year 2026
|
| 426 |
+
```
|
| 427 |
+
|
| 428 |
+
**Step 3 — PERMNO matching and daily aggregation**
|
| 429 |
+
*(run `scripts/gdelt/step3_aggregate_daily.py` → generates `datasets/gdelt/gdelt_daily.parquet`)*
|
| 430 |
+
|
| 431 |
+
Reads all 508 daily parquets, matches organisation names to PERMNOs using temporal bounds from `company_names.csv`, and aggregates to one row per (PERMNO, date) with tone averages, article counts, source counts, and theme flags.
|
| 432 |
+
|
| 433 |
+
**Output:** `datasets/gdelt/gdelt_daily.parquet` — 170,153 rows, 543 PERMNOs, 2025-01-01 → 2026-06-10.
|
| 434 |
+
|
| 435 |
+
---
|
| 436 |
+
|
| 437 |
## Scripts Reference
|
| 438 |
|
| 439 |
| Script | Input(s) | Output | Purpose |
|
|
|
|
| 449 |
| `scripts/postprocess_form4.py` | `form4_transactions.csv` (raw) | `form4_transactions.csv` (clean, 20 cols) | Drops 12 `_fn` footnote columns; converts dates from DD-MON-YYYY to YYYY-MM-DD |
|
| 450 |
| `scripts/form4_add_roles.py` | `form4_transactions.csv` (clean), SEC EDGAR quarterly ZIPs | `form4_transactions.csv` (final, 24 cols) | Re-fetches REPORTINGOWNER from all 81 quarters; parses `rptowner_relationship` to derive `is_officer`, `is_director`, `is_ten_pct_owner`, `officer_title` |
|
| 451 |
| `scripts/test_form4_pipeline.py` | SEC EDGAR API | *(console)* | Smoke-test: validates metadata fetch + XML parse + column structure for 5 companies before full run |
|
| 452 |
+
| `scripts/sort_sec_filings.py` | `sec/firm/txt/<CIK>/*.txt` | `sec/sec_filings_index.csv`, `sec/sec_filings_UNCERTAIN.csv` | Classifies each filing as 10-K or 10-Q by reading XBRL period token from first line only; flags non-filing exhibit documents as UNCERTAIN |
|
| 453 |
+
| `scripts/patch_sec_index.py` | `sec/sec_filings_index.csv` | `sec/sec_filings_index.csv` (updated) | Manually appends 2 plain-text 10-K filings (CIK 0001881551) that XBRL parser could not classify; already applied — do not re-run |
|
| 454 |
+
| `scripts/gdelt/step1_prepare_names.py` | `crsp_dsenames.csv` | `gdelt/company_names.csv` | Cleans CRSP company names to GDELT-style patterns; 30+ manual overrides; outputs 800 patterns with PERMNO + temporal bounds |
|
| 455 |
+
| `scripts/gdelt/step2_download_gkg.py` | `gdelt/company_names.csv`, GDELT website | `gdelt/raw/gkg_YYYYMMDD.parquet` | Downloads daily GKG ZIPs into RAM, filters for S&P 500 companies, saves filtered rows. Resume-safe. |
|
| 456 |
+
| `scripts/gdelt/step3_aggregate_daily.py` | `gdelt/raw/*.parquet`, `gdelt/company_names.csv` | `gdelt/gdelt_gkg_daily.parquet` (primary), `gdelt/gdelt_daily.parquet` (slim secondary) | Matches organisation names to PERMNOs via temporal bounds; aggregates to daily per-PERMNO tone/count features. Use `gdelt_gkg_daily.parquet` for all pipeline work. |
|
| 457 |
|
| 458 |
---
|
| 459 |
|