S1-3: Fiscal-year fact extraction #33

Merged
chris-kreidl merged 2 commits from 8-fiscal-year-extraction into main 2026-11-06 02:45:56 +00:00
chris-kreidl commented 2026-11-06 02:38:54 +00:00 (Migrated from github.com)

🤖 Claude: Closes #8

Adds src/extract.ts: extractFiscalYearFacts() reads every metric from a company's latest 10-K fiscal year only, with the source XBRL tag recorded for each value. This is the core fix for #1 (stale tags).

How it was built

  1. claude[bot] on GitHub wrote the extractor and 24 tests against the fixtures (commit 600381a). Run log
  2. Local real-data check across all 20,547 SEC files found a debt bug the fixtures couldn't show, fixed in 8618cf6.

The fix: LongTermDebt is usually the total

The first version treated LongTermDebt as the noncurrent portion, as DRI uses it, and added the current portion on top. I checked filers' debt maturity schedules, whose yearly repayments sum to total principal: in 10 of 12 testable cases LongTermDebt is the total, as the US-GAAP taxonomy defines it. Current debt was double-counted (Exelon +$1.7B; CIM +$1.7B on $3.1B).

Now LongTermDebt is treated as the total unless the maturity schedule matches LongTermDebt + next year's repayments (DRI, Xerox).

  • New DIOD fixture, where LongTermDebt is the total, verified against its filed balance sheet: $1,442K current + $24,224K noncurrent = $25,666K.
  • Maturity-schedule tags added to the fixtures.

Real-data results (5,170 companies with a fiscal year in the last 13 months)

Check Before fix After
Possible double-counts (LongTermDebt + current added) 125 74, of which 60 add ShortTermBorrowings (a separate line, correct)
Total debt > total liabilities (impossible) 18 13
Extraction time, all companies 0.2s
Errors 0

Known gaps (not in this story)

  • #32 (new bug, M1): ~1,050 companies report debt under tags not read yet (notes payable, lines of credit, convertibles), so their total debt is null. Also covers 13 filers where DebtCurrent + total LongTermDebt may double-count.
  • analyze.ts doesn't use the extractor yet. That's wired up in S1-6 (#11).

Decisions raised by claude[bot] (FYI; defaults seem right)

  • EBIT is null, not a guess, when the pretax-plus-interest fallback is missing a piece.
  • A reported zero (e.g. HRB current debt = 0) is kept as 0, not treated as null.

Definition of Done

  • Acceptance criteria met: latest-FY-only extraction; nulls, never older values; tag recorded per value; HRB EBIT $934.5M; DRI noncurrent-only LongTermDebt; CPB $7,137M without double-counted commercial paper; MU/DRI debt match FY26
  • bun test: 100 pass
  • bun check clean; bun fmt --check passes on changed files
  • Runs end to end on real data: all 20,547 files, results above

🤖 Generated with Claude Code

🤖 **Claude:** Closes #8 Adds `src/extract.ts`: `extractFiscalYearFacts()` reads every metric from a company's latest 10-K fiscal year only, with the source XBRL tag recorded for each value. This is the core fix for #1 (stale tags). ### How it was built 1. **`claude[bot]` on GitHub** wrote the extractor and 24 tests against the fixtures (commit `600381a`). [Run log](https://github.com/chris-kreidl/screener/actions/runs/42149536723) 2. **Local real-data check** across all 20,547 SEC files found a debt bug the fixtures couldn't show, fixed in `8618cf6`. ### The fix: `LongTermDebt` is usually the total The first version treated `LongTermDebt` as the noncurrent portion, as DRI uses it, and added the current portion on top. I checked filers' debt maturity schedules, whose yearly repayments sum to total principal: in **10 of 12** testable cases `LongTermDebt` is the **total**, as the US-GAAP taxonomy defines it. Current debt was double-counted (Exelon +$1.7B; CIM +$1.7B on $3.1B). Now `LongTermDebt` is treated as the total unless the maturity schedule matches `LongTermDebt` + next year's repayments (DRI, Xerox). - New **DIOD fixture**, where `LongTermDebt` is the total, verified against its filed balance sheet: $1,442K current + $24,224K noncurrent = $25,666K. - Maturity-schedule tags added to the fixtures. ### Real-data results (5,170 companies with a fiscal year in the last 13 months) | Check | Before fix | After | |---|---|---| | Possible double-counts (`LongTermDebt` + current added) | 125 | 74, of which 60 add `ShortTermBorrowings` (a separate line, correct) | | Total debt > total liabilities (impossible) | 18 | 13 | | Extraction time, all companies | | 0.2s | | Errors | | 0 | ### Known gaps (not in this story) - **#32 (new bug, M1):** ~1,050 companies report debt under tags not read yet (notes payable, lines of credit, convertibles), so their total debt is null. Also covers 13 filers where `DebtCurrent` + total `LongTermDebt` may double-count. - `analyze.ts` doesn't use the extractor yet. That's wired up in S1-6 (#11). ### Decisions raised by `claude[bot]` (FYI; defaults seem right) - EBIT is null, not a guess, when the pretax-plus-interest fallback is missing a piece. - A reported zero (e.g. HRB current debt = 0) is kept as 0, not treated as null. ### Definition of Done - [x] Acceptance criteria met: latest-FY-only extraction; nulls, never older values; tag recorded per value; HRB EBIT $934.5M; DRI noncurrent-only `LongTermDebt`; CPB $7,137M without double-counted commercial paper; MU/DRI debt match FY26 - [x] `bun test`: 100 pass - [x] `bun check` clean; `bun fmt --check` passes on changed files - [x] Runs end to end on real data: all 20,547 files, results above 🤖 Generated with [Claude Code](https://claude.com/claude-code)
claude[bot] commented 2026-11-06 02:39:47 +00:00 (Migrated from github.com)

🤖 Claude: ## Code review

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

🤖 **Claude:** ## Code review No issues found. Checked for bugs and CLAUDE.md compliance.
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!33
No description provided.