Skip to content

get_cot: overlap weeks keep the larger scaled open interest - #122

Merged
mspinola merged 1 commit into
mainfrom
claude/get-cot-overlap-larger-oi
Oct 10, 2026
Merged

mspinola merged 1 commit into
mainfrom
claude/get-cot-overlap-larger-oi

Conversation

@mspinola

Copy link
Copy Markdown
Owner

Summary

  • get_cot overlap weeks (a hist_codes hand-off between listings) now keep the row with the larger scaled Open_Interest_All, not the primary code. Primary wins ties; a frame with no OI column behaves exactly as before.
  • Measured reason: at the 2017 Russell 2000 hand-off from ICE (23977A) back to CME (239742), CME's first four weeks (2017-08-15 to 2017-09-05) reported 13k to 37k contracts against ICE's 545k to 567k. Primary-wins printed that slice as the market, including a +22% commercial net on 2017-08-15 that the 567k pool did not show.
  • Effect on the live store: RTY switches to CME on 2017-09-12 (the week CME's OI reached 810k); LBR stays on the random-length contract through 2023-04-18 instead of switching on 2023-02-21 at 1,029 contracts. Only RTY and LBR carry hist_codes, so no other symbol changes.
  • Docs: CHANGELOG Unreleased / Changed; a paragraph in docs/design/reading-the-store.md beside the existing hand-off discussion.

Test plan

  • New tests/test_cot_stitch.py: predecessor wins when larger, primary wins when larger, tie goes to primary, no-OI fallback, re-labelling, sorted/unique index
  • tests/test_cot.py LBR stitch test rewritten to assert the new rule in both directions
  • Full suite: 229 passed; ruff check src tests scripts clean
  • Verified against ~/code/cotdata_store for RTY (legacy, tff) and LBR (legacy, disagg): no duplicate dates, switch weeks as stated above

Downstream note: COTMETRICS_CACHE entries for RTY or LBR carry the old weeks until rebuilt.

🤖 Generated with Claude Code

Where a hist_codes predecessor and the primary code both report the same
week, keep the row with the larger Open_Interest_All after the predecessor's
scale is applied. Primary still wins ties; a frame with no OI column keeps
the old primary-wins behaviour exactly.

Measured reason: at the 2017 Russell 2000 hand-off from ICE (23977A) back
to CME (239742), CME's first four weeks (2017-08-15 to 2017-09-05) reported
13k to 37k contracts against ICE's 545k to 567k, and primary-wins printed
that slice as the market, including a +22% commercial net on 2017-08-15
that the 567k pool did not show. RTY now switches to CME on 2017-09-12;
LBR stays on the random-length contract until it stops reporting on
2023-04-18 instead of switching on 2023-02-21 at 1,029 contracts.

Only RTY and LBR carry hist_codes, so only those weeks change.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@mspinola
mspinola merged commit 0ae19b6 into main Oct 10, 2026
5 checks passed
@mspinola
mspinola deleted the claude/get-cot-overlap-larger-oi branch October 10, 2026 14:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant