S1-5: Eligibility rules in one place #38

Merged
chris-kreidl merged 3 commits from 10-eligibility-rules into main 2026-11-06 03:55:05 +00:00
chris-kreidl commented 2026-11-06 03:42:52 +00:00 (Migrated from github.com)

🤖 Claude: Closes #10

Fixes #2 (6-month window), #3 (EBIT ≤ 0 ranked), #5 (old prices ranked).

What changed

  • src/eligibility.ts (new) is the one definition. A company is eligible when its latest 10-K was filed within 13 months, EBIT > 0, it has a price from this run (so it has a ticker), market cap ≥ $50M, and its sector is not Financial Services or Utilities. isEligibleForPricing is the same rule without the parts that need a price.
  • enrich-prices.ts prices exactly the companies that pass isEligibleForPricing. Companies with no ticker mapping now have their old price cleared instead of kept (#5).
  • export-ranking.ts filters with isEligible. The filter and the rank columns moved from SQL into TypeScript (same results as SQL RANK()). The earnings-yield SQL is unchanged.
  • analyze.ts uses the shared 13-month freshness check instead of its own 395 days.
  • Commit 77cbcff only formats the three scripts, so the fix commit (71cd460) diffs cleanly.

Acceptance criteria

  • The four rules, each with edge-case tests in test/eligibility.test.ts:
    • filed exactly 13 months ago is fresh, one day earlier is stale
    • EBIT 0, negative or missing is ineligible
    • a market cap of exactly $50M is eligible, $1 less is not
    • Financial Services and Utilities are excluded
    • no price from this run (no ticker or no quote) is ineligible
  • Used by enrichment and ranking. On real data, every eligible company is in the set enrichment prices (0 exceptions).

Real data (Nov 5 data/, run on a copy of company_facts.db)

Before Now
Companies priced by enrichment 228 1,668
Ranked 1,367
Ranked without a price from this run 0
Ranked with EBIT ≤ 0 84 0
Ranked with a stale filing 0 (oldest filing 2025-10-15)
Ranked Financial Services / Utilities 0

Enrichment: 1,577 priced, 86 with no ticker mapping, 5 with no quote.

Definition of Done

  • Acceptance criteria met and demonstrated: see above
  • bun test passes; new logic has tests: 139 pass, 0 fail (19 new)
  • bun check is clean and bun fmt --check passes: no type errors; all changed files formatted
  • Runs end to end on real data: analyze → enrich → export on all 20,547 files, 0 errors

Decided on this PR

  • No price from this run → excluded (commit 2). Requiring a price covers companies with no ticker (86), and also the 5 that have a ticker but got no quote from Yahoo. #5 expects a price from this run for every ranked company. If you'd rather keep those 5, the rule can check for a ticker instead.
  • Unknown sector → still not excluded; #37 should fix most of these.

Found, not fixed (new issue)

  • #37: the ticker mapping picks secondary listings (METAM, GOOGM, MGRB). This gives wrong market caps and no sector, so AMG, an asset manager, ranks #1. It is outside this story's scope, but it affects how trustworthy the M1 ranking is.

🤖 Generated with Claude Code

🤖 **Claude:** Closes #10 Fixes #2 (6-month window), #3 (EBIT ≤ 0 ranked), #5 (old prices ranked). ### What changed - **`src/eligibility.ts`** (new) is the one definition. A company is eligible when its latest 10-K was filed within 13 months, EBIT > 0, it has a price from this run (so it has a ticker), market cap ≥ $50M, and its sector is not Financial Services or Utilities. `isEligibleForPricing` is the same rule without the parts that need a price. - **`enrich-prices.ts`** prices exactly the companies that pass `isEligibleForPricing`. Companies with no ticker mapping now have their old price cleared instead of kept (#5). - **`export-ranking.ts`** filters with `isEligible`. The filter and the rank columns moved from SQL into TypeScript (same results as SQL `RANK()`). The earnings-yield SQL is unchanged. - **`analyze.ts`** uses the shared 13-month freshness check instead of its own 395 days. - Commit `77cbcff` only formats the three scripts, so the fix commit (`71cd460`) diffs cleanly. ### Acceptance criteria - **The four rules**, each with edge-case tests in `test/eligibility.test.ts`: - filed exactly 13 months ago is fresh, one day earlier is stale - EBIT 0, negative or missing is ineligible - a market cap of exactly $50M is eligible, $1 less is not - Financial Services and Utilities are excluded - no price from this run (no ticker or no quote) is ineligible - **Used by enrichment and ranking.** On real data, every eligible company is in the set enrichment prices (0 exceptions). ### Real data (Nov 5 `data/`, run on a copy of `company_facts.db`) | | Before | Now | |---|---|---| | Companies priced by enrichment | 228 | **1,668** | | Ranked | | **1,367** | | Ranked without a price from this run | | **0** | | Ranked with EBIT ≤ 0 | 84 | **0** | | Ranked with a stale filing | | **0** (oldest filing 2025-10-15) | | Ranked Financial Services / Utilities | | **0** | Enrichment: 1,577 priced, 86 with no ticker mapping, 5 with no quote. ### Definition of Done - [x] Acceptance criteria met and demonstrated: see above - [x] `bun test` passes; new logic has tests: 139 pass, 0 fail (19 new) - [x] `bun check` is clean and `bun fmt --check` passes: no type errors; all changed files formatted - [x] Runs end to end on real data: `analyze` → `enrich` → `export` on all 20,547 files, 0 errors ### Decided on this PR - **No price from this run → excluded** (commit 2). Requiring a price covers companies with no ticker (86), and also the 5 that have a ticker but got no quote from Yahoo. #5 expects a price from this run for every ranked company. If you'd rather keep those 5, the rule can check for a ticker instead. - **Unknown sector → still not excluded**; #37 should fix most of these. ### Found, not fixed (new issue) - #37: the ticker mapping picks secondary listings (METAM, GOOGM, MGRB). This gives wrong market caps and no sector, so AMG, an asset manager, ranks #1. It is outside this story's scope, but it affects how trustworthy the M1 ranking is. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
claude[bot] commented 2026-11-06 03:43:41 +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 03:52:41 +00:00 (Migrated from github.com)

If there's no ticker then we can probably exclude them as we can't really act on them anyway.

It sounds like addressing #37 will fix most of these.

> * **Ranked without a live price:** 46 ranked companies have no live price (no ticker mapping or no quote). They are ranked on their SEC public float, as the old export did. [Rows outside the enrich pre-filter keep prices from earlier runs #5](https://github.com/chris-kreidl/screener/issues/5) asks that every ranked company have a price from this run. Should these be excluded? If there's no ticker then we can probably exclude them as we can't really act on them anyway. > * **Unknown sector:** a company Yahoo returns no sector for is not excluded (74 ranked), as before. Most of these come from [Ticker mapping picks a secondary listing (notes, preferreds) instead of the common stock #37](https://github.com/chris-kreidl/screener/issues/37). It sounds like addressing #37 will fix most of these.
chris-kreidl commented 2026-11-06 03:54:00 +00:00 (Migrated from github.com)

🤖 Claude: Done in the latest commit. Companies with no price from this run are now ineligible. That covers no ticker (86) and also the 5 that have a ticker but got no quote from Yahoo, since #5 expects a price from this run for every ranked company. If you'd rather keep those 5, the rule can check for a ticker instead.

Real data: ranked goes from 1,413 to 1,367, and none are left without a price. Sector rule unchanged; #37 is the fix there. Tests: 139 pass; bun check and bun fmt --check clean. PR description updated.

🤖 **Claude:** Done in the latest commit. Companies with no price from this run are now ineligible. That covers no ticker (86) and also the 5 that have a ticker but got no quote from Yahoo, since #5 expects a price from this run for every ranked company. If you'd rather keep those 5, the rule can check for a ticker instead. Real data: ranked goes from 1,413 to **1,367**, and none are left without a price. Sector rule unchanged; #37 is the fix there. Tests: 139 pass; `bun check` and `bun fmt --check` clean. PR description updated.
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!38
No description provided.