Cache sector and industry #14

Closed
opened 2026-11-06 01:19:21 +00:00 by chris-kreidl · 3 comments
chris-kreidl commented 2026-11-06 01:19:21 +00:00 (Migrated from github.com)

Look up profile data only for companies we have not seen before.

Acceptance criteria

  • A sector_cache table, keyed by CIK, stores the ticker the lookup used, sector, industry, source (yahoo or sic), and the date fetched.
  • Enrich looks up a profile only for CIKs not in the cache, or cached more than 90 days ago. Everyone else's sector and industry come from the cache.
  • The #45 fallback still applies: no Yahoo sector → SIC code. The source is recorded.
  • A lookup that finds no sector from either source is not cached, so it's retried on the next run.
  • Moved from #13: sector and industry are fetched only when missing.
  • Demonstrated on real data:
    • the first run fills the cache with the same sectors as today's company_analysis;
    • a second run makes profile lookups only for new CIKs (count shown in the enrich summary);
    • the ranked CSV is unchanged between the two runs, apart from price movement.

Notes

  • Keyed by CIK, not ticker: SEC never changes or reuses a CIK, while tickers change (FB → META) and get reused by unrelated companies, which could attach the wrong sector. The rest of the pipeline is already keyed by CIK.
  • Until #13 batches prices, enrich still makes one quoteSummary call per company for the price, so this story alone doesn't make enrich much faster.

Dependencies

None. #13 depends on this one.

Definition of Done

  • Acceptance criteria met and demonstrated
  • bun test passes; new logic has tests
  • bun check is clean and bun fmt --check passes
  • Runs end to end on real data (not just fixtures)
  • Committed with Closes #<this issue>
Look up profile data only for companies we have not seen before. ### Acceptance criteria - [ ] A `sector_cache` table, keyed by **CIK**, stores the ticker the lookup used, sector, industry, source (`yahoo` or `sic`), and the date fetched. - [ ] Enrich looks up a profile only for CIKs not in the cache, or cached more than **90 days** ago. Everyone else's sector and industry come from the cache. - [ ] The #45 fallback still applies: no Yahoo sector → SIC code. The source is recorded. - [ ] A lookup that finds no sector from either source is **not** cached, so it's retried on the next run. - [ ] Moved from #13: sector and industry are fetched only when missing. - [ ] Demonstrated on real data: - the first run fills the cache with the same sectors as today's `company_analysis`; - a second run makes profile lookups only for new CIKs (count shown in the enrich summary); - the ranked CSV is unchanged between the two runs, apart from price movement. ### Notes - Keyed by CIK, not ticker: SEC never changes or reuses a CIK, while tickers change (FB → META) and get reused by unrelated companies, which could attach the wrong sector. The rest of the pipeline is already keyed by CIK. - Until #13 batches prices, enrich still makes one `quoteSummary` call per company for the price, so this story alone doesn't make enrich much faster. ### Dependencies None. #13 depends on this one. ### Definition of Done - [ ] Acceptance criteria met and demonstrated - [ ] `bun test` passes; new logic has tests - [ ] `bun check` is clean and `bun fmt --check` passes - [ ] Runs end to end on real data (not just fixtures) - [ ] Committed with `Closes #<this issue>`
chris-kreidl commented 2026-11-11 20:24:49 +00:00 (Migrated from github.com)

🤖 Claude: Proposed acceptance criteria (backlog refinement)

Today: sector and industry come from quoteSummary (one request per company, about 1 per second), with SEC's SIC code as the fallback when Yahoo has none (#45). Eligibility needs a sector: an unknown one excludes the company.

Acceptance criteria

  • A sector_cache table, keyed by ticker, stores sector, industry, source (yahoo or sic), and the date fetched.
  • Enrich looks up a profile only for tickers not in the cache, or cached more than 90 days ago. Everyone else's sector and industry come from the cache.
  • The #45 fallback still applies: no Yahoo sector → SIC code. The source is recorded.
  • A lookup that finds no sector from either source is not cached, so it's retried on the next run (only a handful of companies).
  • Moved from #13: sector and industry are fetched only when missing.
  • Demonstrated on real data:
    • the first run fills the cache with the same sectors as today's company_analysis;
    • a second run makes profile lookups only for new tickers (count shown in the enrich summary);
    • the ranked CSV is unchanged between the two runs, apart from price movement.

Questions

  1. Keyed by ticker (as the issue says) or by CIK? Ticker means a company whose ticker changes is looked up again, which is a sensible point to recheck. CIK survives ticker changes. I'd go with ticker.
  2. Is 90 days right for refreshing a cached sector? Sectors rarely change, but a stale SIC fallback, e.g. for a new IPO that Yahoo later profiles, only heals when the entry is refreshed.

Dependencies

None. #13 depends on this one.

🤖 **Claude:** **Proposed acceptance criteria** (backlog refinement) **Today:** sector and industry come from `quoteSummary` (one request per company, about 1 per second), with SEC's SIC code as the fallback when Yahoo has none (#45). Eligibility needs a sector: an unknown one excludes the company. ### Acceptance criteria - [ ] A `sector_cache` table, keyed by ticker, stores sector, industry, source (`yahoo` or `sic`), and the date fetched. - [ ] Enrich looks up a profile only for tickers not in the cache, or cached more than **90 days** ago. Everyone else's sector and industry come from the cache. - [ ] The #45 fallback still applies: no Yahoo sector → SIC code. The source is recorded. - [ ] A lookup that finds no sector from either source is **not** cached, so it's retried on the next run (only a handful of companies). - [ ] Moved from #13: sector and industry are fetched only when missing. - [ ] Demonstrated on real data: - the first run fills the cache with the same sectors as today's `company_analysis`; - a second run makes profile lookups only for new tickers (count shown in the enrich summary); - the ranked CSV is unchanged between the two runs, apart from price movement. ### Questions 1. Keyed by **ticker** (as the issue says) or by **CIK**? Ticker means a company whose ticker changes is looked up again, which is a sensible point to recheck. CIK survives ticker changes. I'd go with ticker. 2. Is **90 days** right for refreshing a cached sector? Sectors rarely change, but a stale SIC fallback, e.g. for a new IPO that Yahoo later profiles, only heals when the entry is refreshed. ### Dependencies None. #13 depends on this one.
chris-kreidl commented 2026-11-12 01:06:30 +00:00 (Migrated from github.com)

It seems to me that if CIK is more constant we'd want to key by CIK rather than ticker. But I'm not very well versed in this area. I know I've seen tickers change. I don't know that CIKs change.

90 days is fine.

It seems to me that if CIK is more constant we'd want to key by CIK rather than ticker. But I'm not very well versed in this area. I know I've seen tickers change. I don't know that CIKs change. 90 days is fine.
chris-kreidl commented 2026-11-12 01:14:06 +00:00 (Migrated from github.com)

🤖 Claude: Final acceptance criteria are in the issue body. One change from the proposal: the cache is keyed by CIK, not ticker. SEC never changes or reuses a CIK, but tickers change (FB → META) and get reused by unrelated companies after a delisting, so a ticker-keyed cache could give a new company the old one's sector. The ticker used for the lookup is stored alongside for traceability. Refresh age stays at 90 days.

🤖 **Claude:** Final acceptance criteria are in the issue body. One change from the proposal: the cache is keyed by **CIK**, not ticker. SEC never changes or reuses a CIK, but tickers change (FB → META) and get reused by unrelated companies after a delisting, so a ticker-keyed cache could give a new company the old one's sector. The ticker used for the lookup is stored alongside for traceability. Refresh age stays at 90 days.
Sign in to join this conversation.
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#14
No description provided.