Skip to content

Fetch the futures-and-options combined basis of Legacy, Disaggregated and TFF - #131

Merged
mspinola merged 2 commits into
mainfrom
claude/cot-combined-basis
Nov 1, 2026
Merged

mspinola merged 2 commits into
mainfrom
claude/cot-combined-basis

Conversation

@mspinola

@mspinola mspinola commented Oct 31, 2026 •

Copy link
Copy Markdown
Owner

Why

cotdata fetched one basis per CFTC report: futures-only for Legacy, Disaggregated and TFF, and combined for the Supplemental, which the CFTC publishes on no other basis. The CFTC publishes the first three on both bases. This closes that gap on the pattern ADR-0002 set for the fourth report: the boundary is "CFTC positioning", not the inventory we happened to have. Decision recorded in docs/adr/ADR-0003-combined-basis-is-in-scope.md.

What

  • Three new store domains cot_legacy_combined/, cot_disagg_combined/, cot_tff_combined/, all on the cot half of the manifest seam. A directory per basis, never a column: the futures-only directories are byte-for-byte what they were, and no reader can return both bases in one frame.
  • Producers take combined=True, which selects zip name, cache directory and store writer together. Legacy combined runs from 1995 (deacom_xls_ before 2004, dea_com_xls_ after). Disaggregated and TFF use the com_* annual zips and their own 2006-2016 bundles, and _assert_basis refuses a file whose own FutOnly_or_Combined disagrees with the basis asked for. The Legacy files carry no such column (checked on the 2026 and 2003 files: 126 columns, same names as futures-only), so there the URL is the only evidence and the two bases are separated by construction.
  • CLI: --cot-legacy-combined, --cot-disagg-combined, --cot-tff-combined; --cot-all now runs all seven. Every deployed launcher calls --cot-all, so the new domains appear on the next scheduled run after the producer pulls this. The first such run downloads the Legacy combined history and the two bundles once.
  • Reader: get_cot(name, report, combined=None). None is each report's natural basis, so every existing call returns what it did. combined=False on supplemental raises.
  • Vintage: annual_sources emits both bases of every annual zip (seven per year from 2010); Source and every snapshot record carry combined; the fetch default captures all seven current-week statics (deafut, deacom, f_disagg, c_disagg, FinFutWk, FinComWk, deacit), each holding its report date in the field vintage_schedule already reads. Ingest passes the snapshot basis to the Legacy canonicaliser and cross-checks the file's flag for Disaggregated and TFF. derive_coverage, write_coverage, read_coverage and asof take combined; the natural-basis coverage artifact keeps its filename, {report}_combined.parquet holds the other. cotdata-vintage coverage --combined.
  • --check widens the domain column to fit the new names.
  • Docs: README, CHANGELOG, ADR-0003, amendments to docs/design/cot_vintage.md §3c and docs/design/cross-report-comparability.md §4/§5.

Measured

Open interest on 2026-10-27, all three producers run on both bases for 2026 into a scratch store, read back through get_cot:

Market Report Futures-only Combined
ES Legacy / TFF 1,955,711 2,843,639
GC Legacy / Disagg 396,810 518,784
CL Disagg 1,886,280 2,606,478

The combined Disaggregated/TFF files read FutOnly_or_Combined == "Combined" on every row and have the same 190 / 86 columns as the futures-only files.

Tests

  • cotdata: 259 passed, ruff check src tests scripts clean. New tests/test_cot_combined_basis.py pins the URL tables and the 2004 rename on both bases, domain isolation, reader dispatch per basis, the CLI flags and --cot-all meaning seven, the both-bases vintage source set and start years, the seven statics, basis on snapshot and failure records, canonicaliser dispatch and mismatch refusal, and per-basis coverage.
  • One existing assertion updated (test_capture_includes_supplemental_from_2006): 2005 now has two Legacy sources, one per basis.
  • Downstream, via the editable installs: cotmetrics 513 passed, cot-analyzer 1134 passed. Neither consumes the combined series yet; the point is that neither noticed.

Not in this PR

  • The workspace CLAUDE.md line about cotdata is updated in crucible-stack/docs/workspace-CLAUDE.md as a separate PR.
  • The CIT provider comment says there is no 2006-2016 Supplemental bundle; dea_cit_txt_2006_2016.zip does exist today (no _hist). Left alone, the code works either way.

Type of change

  • New feature (non-breaking change which adds functionality)
  • This change requires a documentation update (done in this PR)

Checklist:

  • My code follows the style guidelines of this project (ruff check src tests scripts clean)
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have run tests (pytest, 259 passed) and they pass locally
  • Any dependent changes have been merged and published in downstream modules (none depend on this)

Second commit: cotdata.cit, the Supplemental joined to Legacy combined

With the combined basis in the store, the Supplemental (whose _NoCIT buckets are Legacy combined's buckets minus the index traders) joins Legacy week by week. cit.decompose(name) splits each Legacy bucket into its ex-index part and the index position carved from it; cit.check(name) counts how the join holds. It never reads futures-only Legacy and refuses a market where open interest or non-reportable disagree (a basis, stitching or vintage error on this basis). Measured over the full history (scripts/cit_legacy_decomposition.py, docs/analysis/2026-10-31-cit-legacy-combined-decomposition.md): exact on 13,753 of 13,753 shared market-weeks; 187 carve-outs at -1 from rounding, none below; a fifth to two thirds of Legacy "commercial" longs in these 13 markets is index money. Corrects Soybean Meal's first Supplemental report to 2013-04-02. 10 new tests (269 total), ruff clean on src tests scripts.

🤖 Generated with Claude Code

… and TFF

cotdata fetched one basis per report: futures-only for Legacy, Disaggregated
and TFF, combined for the Supplemental (which has no other). The CFTC publishes
the first three on both bases, so the combined files now land in three new
store domains, cot_legacy_combined/, cot_disagg_combined/ and
cot_tff_combined/, on the cot half of the manifest seam (ADR-0003).

- Producers take combined=True, which selects zip name, cache directory and
  store writer together. Legacy combined runs from 1995 (deacom_xls_ before
  2004, dea_com_xls_ after); Disaggregated and TFF use the com_* zips and their
  own 2006-2016 bundles, and refuse a file whose FutOnly_or_Combined column
  disagrees with the basis asked for.
- cotdata-update gains --cot-legacy-combined, --cot-disagg-combined and
  --cot-tff-combined; --cot-all now runs all seven domains.
- get_cot(name, report, combined=None): None is each report's natural basis,
  so every existing call is unchanged; combined=False on supplemental raises.
- Vintage: annual_sources emits both bases of every zip, Source and every
  snapshot record carry a combined flag, the fetch default captures all seven
  current-week statics, ingest passes the basis to the Legacy canonicaliser and
  cross-checks the file flag for Disaggregated and TFF, and coverage/asof take
  a basis with the natural-basis artifact keeping its name.
- --check widens the domain column to fit the new names.

Measured 2026-10-27, combined against futures-only open interest: ES 2,843,639
vs 1,955,711, GC 518,784 vs 396,810, CL 2,606,478 vs 1,886,280. All three
producers smoke-tested on both bases for 2026 against a scratch store.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
The Supplemental's _NoCIT buckets are Legacy combined's buckets with the
index traders removed, so with the combined basis in the store the two
reports join week by week into a partition neither publishes alone.
cit.decompose(name) makes the join for one of the 13 markets and splits
each Legacy bucket into its ex-index part and the index position carved
from it (spreading as the residual: the store keeps no Legacy spread
column); cit.check(name) counts how it holds. It never reads futures-only
Legacy and refuses a market where open interest or non-reportable
disagree, which on the combined basis is a basis, stitching or vintage
error.

Measured over the whole history from the store (scripts/
cit_legacy_decomposition.py, docs/analysis/2026-10-31-cit-legacy-
combined-decomposition.md): the exact identities hold on 13,753 of
13,753 shared market-weeks; 187 carve-outs sit at -1 from rounding and
none below; between a fifth and two thirds of Legacy's commercial longs
in these markets is index money, and the Legacy commercial net is
positive on average in ZW and GF only because of it. Corrects Soybean
Meal's first Supplemental report to 2013-04-02 (the 2026-08-03 doc gave
the 2013 file's first date).

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@mspinola
mspinola merged commit 82917cf into main Nov 1, 2026
5 checks passed
@mspinola
mspinola deleted the claude/cot-combined-basis branch November 1, 2026 20:15
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