Stale XBRL tags: take every metric from the latest 10-K (#1) #41

Merged
chris-kreidl merged 1 commit from 1-stale-xbrl-tags into main 2026-11-06 04:18:10 +00:00
chris-kreidl commented 2026-11-06 04:12:23 +00:00 (Migrated from github.com)

🤖 Claude: Closes #1

analyze.ts picked, for each metric, the first XBRL tag with any 10-K value, however old. The fix (latest fiscal-year extraction) already existed in src/extract.ts from #8, but the legacy script didn't use it. It now does:

  • src/analyze.ts (analyzeCompany): new. Builds one company_analysis row from extractFiscalYearFacts + computeMetrics. analyze.ts keeps only the file loop and the DB upsert, and the old extraction code (~250 lines) is deleted.
  • src/extract.ts: also reads the 10-K's filing date, stockholders' equity (at the fiscal year-end), and the cover-page shares outstanding and public float. The cover-page values are matched by the 10-K's accession number, because they're dated at the cover or the prior Q2, not the fiscal year-end. A missing value is null. The old script fell back to other share tags and older filings.
  • src/metrics.ts: exposes cashAndInvestments, so the row's cash is what EV subtracts.

Column meanings that changed (they now follow the Greenblatt definitions from #9): cash = cash + short-term investments, totalDebt includes finance leases, netWorkingCapital is floored at 0, netFixedAssets includes finance-lease ROU assets. ROTC and EY are null when tangible capital or EV is ≤ 0. The SQL EY recalculation in export-ranking.ts (ebit / (mcap + totalDebt − cash)) still matches computeMetrics.

Definition of Done

  • Acceptance criteria met and demonstrated. The issue's table, from a real-data run of analyze.ts:

    Company Before After
    HRB EBIT $763M (FY2014) $934.5M (FY2026)
    MU debt 2012 value $5,179M (FY2026, incl. finance leases)
    DRI ROTC 228% 31.4%
    CPB debt $3.2B $7,137M

    Every row field now comes from the one fiscal year that extractFiscalYearFacts selects, so no input can be older than the latest 10-K.

  • bun test passes; new logic has tests: 151 pass, 0 fail. New tests are test/analyze.test.ts (the four cases above plus row semantics) and the cover-page/equity tests in test/extract.test.ts.

  • bun check is clean (17 files) and bun fmt --check passes on the changed files.

  • Runs end to end on real data (partly). analyze.ts → export-ranking.ts ran on a copy of the local DB with all 20,547 SEC files: 5,457 fresh companies, 0 errors, 1,449 ranked. enrich-prices.ts was not re-run (about an hour at 1 request/s), so prices are from the earlier run. On that same DB, main also ranks about 1,420, so the jump from the 288 in the Nov 5 CSV isn't from this change. It comes from the earlier eligibility rework, which stopped excluding companies that should have been ranked; the DB hasn't been repriced since. A full bun run pipeline is still needed.

Not in scope, seen while verifying: near-zero tangible capital still gives extreme ROTC (ATRA 49,126%). That's #34, handled by #36's bounds.

🤖 Generated with Claude Code

🤖 **Claude:** Closes #1 `analyze.ts` picked, for each metric, the first XBRL tag with *any* 10-K value, however old. The fix (latest fiscal-year extraction) already existed in `src/extract.ts` from #8, but the legacy script didn't use it. It now does: - **`src/analyze.ts`** (`analyzeCompany`): new. Builds one `company_analysis` row from `extractFiscalYearFacts` + `computeMetrics`. `analyze.ts` keeps only the file loop and the DB upsert, and the old extraction code (~250 lines) is deleted. - **`src/extract.ts`**: also reads the 10-K's filing date, stockholders' equity (at the fiscal year-end), and the cover-page shares outstanding and public float. The cover-page values are matched by the 10-K's accession number, because they're dated at the cover or the prior Q2, not the fiscal year-end. A missing value is null. The old script fell back to other share tags and older filings. - **`src/metrics.ts`**: exposes `cashAndInvestments`, so the row's `cash` is what EV subtracts. **Column meanings that changed** (they now follow the Greenblatt definitions from #9): `cash` = cash + short-term investments, `totalDebt` includes finance leases, `netWorkingCapital` is floored at 0, `netFixedAssets` includes finance-lease ROU assets. ROTC and EY are null when tangible capital or EV is ≤ 0. The SQL EY recalculation in `export-ranking.ts` (`ebit / (mcap + totalDebt − cash)`) still matches `computeMetrics`. ### Definition of Done - [x] Acceptance criteria met and demonstrated. The issue's table, from a real-data run of `analyze.ts`: | Company | Before | After | |---|---|---| | HRB EBIT | $763M (FY2014) | $934.5M (FY2026) | | MU debt | 2012 value | $5,179M (FY2026, incl. finance leases) | | DRI ROTC | 228% | 31.4% | | CPB debt | $3.2B | $7,137M | Every row field now comes from the one fiscal year that `extractFiscalYearFacts` selects, so no input can be older than the latest 10-K. - [x] `bun test` passes; new logic has tests: 151 pass, 0 fail. New tests are `test/analyze.test.ts` (the four cases above plus row semantics) and the cover-page/equity tests in `test/extract.test.ts`. - [x] `bun check` is clean (17 files) and `bun fmt --check` passes on the changed files. - [ ] Runs end to end on real data (partly). `analyze.ts` → `export-ranking.ts` ran on a copy of the local DB with all 20,547 SEC files: 5,457 fresh companies, 0 errors, 1,449 ranked. **`enrich-prices.ts` was not re-run** (about an hour at 1 request/s), so prices are from the earlier run. On that same DB, `main` also ranks about 1,420, so the jump from the 288 in the Nov 5 CSV isn't from this change. It comes from the earlier eligibility rework, which stopped excluding companies that should have been ranked; the DB hasn't been repriced since. A full `bun run pipeline` is still needed. **Not in scope, seen while verifying:** near-zero tangible capital still gives extreme ROTC (ATRA 49,126%). That's #34, handled by #36's bounds. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
claude[bot] commented 2026-11-06 04:13:19 +00:00 (Migrated from github.com)

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

## Code review No issues found. Checked for bugs and CLAUDE.md compliance.
chris-kreidl commented 2026-11-06 04:17:59 +00:00 (Migrated from github.com)

in the interest of keeping things moving, i'm not going to run the full pipeline. a subset of the full data was used successfully, i believe it's unlikely we'll run into any issues once the full dataset is in play.

in the interest of keeping things moving, i'm not going to run the full pipeline. a subset of the full data was used successfully, i believe it's unlikely we'll run into any issues once the full dataset is in play.
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
ckreidl/screener!41
No description provided.