Skip to content

/categories: the Flow view, price, weekly cohort flow and positioning index on one axis - #140

Closed
mspinola wants to merge 2 commits into
mainfrom
claude/cot-flows-heatmap-panel
Closed

mspinola wants to merge 2 commits into
mainfrom
claude/cot-flows-heatmap-panel

Conversation

@mspinola

@mspinola mspinola commented Sep 26, 2026 •

Copy link
Copy Markdown
Owner

PR 2 of cotmetrics docs/design/cot-flows.md, as scoped by the "Scope, restated" block of docs/handoffs/2026-09-26-cot-flow-states-cross-universe.md: the three-panel view in docs/analysis/2026-09-26-cot-view-proposed-gold.png, ported to /categories, and nothing else. Draft until mspinola/cotmetrics#52 (0.15.0) merges, because it reads columns that release adds; the floor moves to 0.15.0 here.

What it adds. A third Layout choice on /categories, Flow view, beside Overlay and Small multiples (components/flow_traces.py). Three full-width panels on one time axis:

  1. price, with open interest dotted on a second axis;
  2. the weekly flow heatmap: one row per cohort, one column per report week, each cell that cohort's net change over its own 52-week standard deviation of weekly changes (the app's diverging pair, clipped at 3 for display). Rows come from cotmetrics per market: Producer/Merchant and Swap Dealers are one Commercials row on GC, SI, PL, PA (its weekly change equals Legacy Commercial's exactly), every category is its own row elsewhere. A triangle marks a cell where that row's positioning index is in its top or bottom decile that week, the mockup's rule. The hover gives the week, net change with both legs, the z, the index when marked, and the state name with "a vocabulary label, not a signal";
  3. the same rows' positioning index at the page's tuned per-symbol lookback, shaded at the decile cutoffs.

Opens on 104 weeks (52 on a phone), dates under the bottom panel; the plot selector and Cols grey out while it is chosen. The page computes nothing: flows, z, indexes and markers are cotmetrics'.

Not in this PR (out of scope per the block): the state strip, the week-in-words caption, flow rows in small multiples, a stack panel in the plot selector, the cross-asset board, and a Legacy back-fill of history before 2006 (irrelevant to a 104-week window). The earlier commit on this branch added a Weekly Flow panel to the plot selector; the second commit takes it back out, so category_traces.py is main's again. #141 is closed as superseded.

Verification. Suite 912 passed (897 on main), 15 new store-free tests in tests/test_flow_traces.py whose frames go through cotmetrics' own build_category_frame and build_flow_frame; ruff clean. Looked at in the running app on Gold (four rows, matching the mockup) and Corn (five rows, no merge). check_dep_floors stays red until #52 merges.

Differences from the mockup: colours are the app's validated diverging pair rather than red/blue; no colorbar (the title states the scale); the level is the tuned lookback (26 weeks on Gold) rather than 3 years, so the index panel is busier and about a third of Gold's weeks sit in a decile.

🤖 Generated with Claude Code

…with the counterparty row

The Disaggregated and TFF page drew levels only: net, percent of OI, the
range index, a level z-score, momentum, legs, spreading and trader counts.
The gold flow-state study and its 42-market replication (cotmetrics
docs/design/cot-flows.md) showed that the picture a single week's bar chart
cannot give is the cohort-by-week heatmap of each cohort's weekly change
scaled by its own trailing 52-week standard deviation, and cotmetrics
0.15.0 (#52 there) now computes that family inside get_category_data.
This draws it, and computes nothing.

One new id in CATEGORY_SPECS, appended last so the persisted selector order
is unchanged, DEFAULT_PLOTS untouched. The overlay builder draws ONE
go.Heatmap: rows are the selected cohorts in report order plus the
counterparty composite row always, whatever the checklist says, because the
newsletter failure the study came from was a chart that named only one side
of each transfer. The composite's tick label is the bare word
"Counterparty" and its members are named in the hover, since plotly's
automargin sized every panel in the stack to the long label. z is clipped
for display at three sigma; the colour scale runs from the validated
diverging pair through a grey midpoint composited from DIM_TEXT over the
background (a dead band under one sigma erased the multi-week runs the
panel exists to show; polarity never borrows an identity palette slot).
The hover is pre-rendered per cell (the heatmap's own z format printed a
raw float under unified hover in plotly 6.9): cohort, "positions as of
<weekday> <date>" read from the index rather than a hard-coded Tuesday,
the net change in contracts with both legs, and the z against the cohort's
own 52-week sd; thin cohorts say to read the count. No colorbar (the
stack's right margin clips one; the panel label states the scale), no
price overlay, no secondary axis. The facet builder draws a one-row
heatmap per category cell with the tick labels off (the row is already
named by the axis title) and no gap between cells (a facet column is a
fraction of the figure width). The gap is also off on phones.

The window is fixed at 52 weeks inside cotmetrics and rides in the column
name, so the page's Lookback control does not move it; the panel label
says so. Nothing here attaches a forward return, the words mover, biggest
move and unusual are held out by a test (the Home board's movers rank
index-point changes of the Legacy Commercial leg, a different quantity),
and the state vocabulary stays out of this panel; that is the strip and
caption of the next PR.

Verified in the running app against the cotmetrics 0.15.0 tree: overlay
and facet layouts on Gold, the unified hover box in the stack, and the
375 px phone width. 19 new tests, all store-free; the analyzer suite is
916 passed. The cotmetrics floor moves to 0.15.0 (category_traces imports
cotmetrics.flows, which does not exist at 0.14.x, and use_pages imports
every page at boot), so CI stays red on check_dep_floors until #52 merges
in cotmetrics and the editable install is refreshed.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Scoped by the "Scope, restated" block of cotmetrics
docs/handoffs/2026-09-26-cot-flow-states-cross-universe.md: PR 2 is the
three-panel view in docs/analysis/2026-09-26-cot-view-proposed-gold.png and
nothing else. The Weekly Flow panel in the plot selector (previous commit) is
taken back out; category_traces.py and its tests are main's again.

components/flow_traces.py, drawn when Layout is "Flow view":
- price with open interest dotted on a second axis;
- a heatmap with cotmetrics' rows for the market (attrs["flow_rows"]): one
  Commercials row for Producer/Merchant plus Swap Dealers on GC, SI, PL, PA,
  every category its own row elsewhere; each cell the net change over the
  cohort's own 52-week sd, the app's diverging pair, clipped at 3; a triangle
  where that row's index is in its top or bottom decile that week
  (flows.level_marks); the state name only in the cell hover, with "a
  vocabulary label, not a signal";
- the same rows' positioning index at the tuned lookback, shaded at the
  decile cutoffs;
- one time axis, opening on 104 weeks (52 on a phone), dates under the bottom
  panel; the plot selector and Cols grey out.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mspinola mspinola changed the title Add the Weekly Flow z panel to /categories: a cohort-by-week heatmap with the counterparty row /categories: the Flow view, price, weekly cohort flow and positioning index on one axis Sep 26, 2026
@mspinola

Copy link
Copy Markdown
Owner Author

Stopped: "Scope, restated v2" (cotmetrics handoff, 2026-09-26 evening) withdraws the multi-row heatmap and the Flow view. What replaces it is a Speculator series and one flow-z strip on the existing Positioning Index panel of /analysis, in a new PR from main.

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