S1-4: Greenblatt metrics #35

Merged
chris-kreidl merged 1 commit from 9-greenblatt-metrics into main 2026-11-06 03:08:56 +00:00
chris-kreidl commented 2026-11-06 02:56:33 +00:00 (Migrated from github.com)

🤖 Claude: Closes #9

Fixes #4 (ROTC definition). Also removes the sign flip in #3 (negative EBIT now gives negative ROTC); excluding EBIT ≤ 0 stays with S1-5 (#10).

What changed

  • src/metrics.ts (new): computeMetrics(facts, marketCap)
    • ROTC = EBIT ÷ (max(0, NWC) + net PP&E), NWC = (current assets − cash − short-term investments) − (current liabilities − short-term debt)
    • EY = EBIT ÷ (market cap + total debt − cash − short-term investments)
    • Tangible capital 0 → ROTC null; EV ≤ 0 → EY null (your decisions, recorded on #9)
    • Missing cash, investments, debt or leases count as 0; missing EBIT, current assets/liabilities or PP&E → null
  • src/extract.ts: new fields shortTermInvestments, financeLeaseCurrent / financeLeaseNoncurrent (only when reported outside the debt lines), financeLeaseRightOfUseAsset (only when PP&E is the plain PropertyPlantAndEquipmentNet). Debt lines count as including leases when tagged *CapitalLeaseObligations* or DebtCurrent (the taxonomy defines it to include them; MU's $491M is all finance leases).
  • Short-term debt in NWC includes current finance leases, so DRI is treated like MU (whose current leases sit inside DebtCurrent). This follows from the apples-to-apples decision; say if you want it otherwise.

Acceptance criteria (hand-computed, in test/metrics.test.ts)

Before (old DB) Now
DRI ROTC 228% 1,582.8 ÷ 5,048.6 = 31.4% (NWC −1,569.7 → 0)
DRI total debt 2,331.3 + 1,740.4 = $4,071.7M
MU total debt $5,179M (leases not counted twice)
MU ROTC 108% 99,340 ÷ 83,955 = 118%
OTEX ROTC 6,465% 207%
Tangible capital 0 ROTC null (test)

Definition of Done

  • Acceptance criteria met and demonstrated: table above, 20 new tests
  • bun test passes; new logic has tests: 120 pass, 0 fail
  • bun check is clean and bun fmt --check passes: no type errors; all files formatted
  • Runs end to end on real data: extract + metrics over all 20,547 files in the Nov 5 data/, 0 errors, market caps from company_facts.db. 5,170 filers with a fiscal year in the last 13 months: 3,173 get ROTC (25 have capital 0 → null), 3,025 get EY (243 have EV ≤ 0 → null). Leases added off the debt lines for 1,101; right-of-use assets added to PP&E for 656.

Risks / follow-ups

  • Double counting: a filer that tags LongTermDebt or PropertyPlantAndEquipmentNet but actually includes leases in it would have them counted twice. No fixture does this, but it isn't detectable from tags alone across the 1,101 / 656 companies above.
  • Missing debt still counts as 0. Telling debt-free companies from unrecognized debt is #32.
  • Near-zero capital still gives extreme ROTC (RIGL 418,220%); handled by user-set bounds with re-ranking in #36.
  • Not wired into the legacy scripts yet; that's S1-6 (#11).

🤖 Generated with Claude Code

🤖 **Claude:** Closes #9 Fixes #4 (ROTC definition). Also removes the sign flip in #3 (negative EBIT now gives negative ROTC); excluding EBIT ≤ 0 stays with S1-5 (#10). ### What changed - **`src/metrics.ts`** (new): `computeMetrics(facts, marketCap)` - ROTC = EBIT ÷ (max(0, NWC) + net PP&E), NWC = (current assets − cash − short-term investments) − (current liabilities − short-term debt) - EY = EBIT ÷ (market cap + total debt − cash − short-term investments) - Tangible capital 0 → ROTC null; EV ≤ 0 → EY null (your decisions, recorded on #9) - Missing cash, investments, debt or leases count as 0; missing EBIT, current assets/liabilities or PP&E → null - **`src/extract.ts`**: new fields `shortTermInvestments`, `financeLeaseCurrent` / `financeLeaseNoncurrent` (only when reported *outside* the debt lines), `financeLeaseRightOfUseAsset` (only when PP&E is the plain `PropertyPlantAndEquipmentNet`). Debt lines count as including leases when tagged `*CapitalLeaseObligations*` or `DebtCurrent` (the taxonomy defines it to include them; MU's $491M is all finance leases). - **Short-term debt in NWC includes current finance leases**, so DRI is treated like MU (whose current leases sit inside `DebtCurrent`). This follows from the apples-to-apples decision; say if you want it otherwise. ### Acceptance criteria (hand-computed, in `test/metrics.test.ts`) | | Before (old DB) | Now | |---|---|---| | DRI ROTC | 228% | 1,582.8 ÷ 5,048.6 = **31.4%** (NWC −1,569.7 → 0) | | DRI total debt | | 2,331.3 + 1,740.4 = **$4,071.7M** | | MU total debt | | **$5,179M** (leases not counted twice) | | MU ROTC | 108% | 99,340 ÷ 83,955 = **118%** | | OTEX ROTC | 6,465% | **207%** | | Tangible capital 0 | | ROTC **null** (test) | ### Definition of Done - [x] Acceptance criteria met and demonstrated: table above, 20 new tests - [x] `bun test` passes; new logic has tests: 120 pass, 0 fail - [x] `bun check` is clean and `bun fmt --check` passes: no type errors; all files formatted - [x] Runs end to end on real data: extract + metrics over all 20,547 files in the Nov 5 `data/`, 0 errors, market caps from `company_facts.db`. 5,170 filers with a fiscal year in the last 13 months: 3,173 get ROTC (25 have capital 0 → null), 3,025 get EY (243 have EV ≤ 0 → null). Leases added off the debt lines for 1,101; right-of-use assets added to PP&E for 656. ### Risks / follow-ups - **Double counting:** a filer that tags `LongTermDebt` or `PropertyPlantAndEquipmentNet` but actually includes leases in it would have them counted twice. No fixture does this, but it isn't detectable from tags alone across the 1,101 / 656 companies above. - Missing debt still counts as 0. Telling debt-free companies from unrecognized debt is #32. - Near-zero capital still gives extreme ROTC (RIGL 418,220%); handled by user-set bounds with re-ranking in #36. - Not wired into the legacy scripts yet; that's S1-6 (#11). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
claude[bot] commented 2026-11-06 02:57:26 +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!35
No description provided.