Repository navigation
feat(stocks): stocks rotation, a relative rotation graph against IHSG - #127
Merged
Merged
Conversation
analysis::rotation computes a relative rotation graph from daily closes: RS = 100 x close / benchmark close on shared dates, RS-Ratio = 100 + the z-score of RS over a rolling window, RS-Momentum = 100 + the z-score of RS-Ratio's rate of change (sample sd), resampled to each week's last session by default. The JdK formulas are proprietary, so the model carries method.approximation = true and the formula in words. model::rotation holds the JSON contract: Rotation, RotationRow (latest point, change over the tail, the tail), RotationPoint, Quadrant (leading, weakening, lagging, improving; 100 counts as the upper and right side), RotationInterval (1wk | 1d) and RotationMethod. A flat RS (a symbol that moved with its benchmark) or a short history gives no point, never a fill. Tested on synthetic series (warm-up of 2 x window bars, ISO weeks across the new year, a point computed by hand) and on the recorded one-year charts: as of 2026-11-04, BBCA leading, TLKM lagging, GIAA improving, ITMG weakening, matching an independent computation of the same formulas.
idx stocks rotation SYMBOLS [--benchmark ^JKSE] [--interval 1wk|1d] [--window 14] [--tail 10] (alias rrg), and the MCP tool idx_rotation with the same arguments, return idx.rotation.v1: each symbol's RS-Ratio, RS-Momentum, quadrant, change over the tail and the tail itself. service::rotation reads five years of daily candles, the history `stocks returns` reads, so the two share the cache; at most 8 symbols at a time. The benchmark must be readable; a symbol that fails is a warning, one with a short history keeps its row with null values and a warning, and a warning names the symbols whose newest close waits for ^JKSE's bar (it often arrives a session late). The table lists the rows, then the four quadrants laid out as the graph draws them; -o jsonl prints one line per symbol, so `idx stocks quote -` reads them back. The web terminal does not draw a scatter chart yet: idx_rotation is CLI and MCP only there (tools.js, the landing tables, 48 tools), and `stocks rotation`, `rotation` and `rrg` reach its notice (route.js, which gains the MCP-only lookup under stocks). docs/mcp.md, docs/json-output.md and scripts/smoke.sh follow.
README gains a Relative rotation section (what the axes and quadrants mean, the formulas, why it is an approximation of the JdK RRG, defaults, history needed, no sector graph yet, CLI and MCP only) and the command in the tables and lists; the agent guide says to quote it as an approximation; AGENTS.md lists the new modules and subcommand.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #99. Scope and decisions are on the issue.
What it does
idx stocks rotation SYMBOLS(aliasrrg) and the MCP toolidx_rotationplace each ticker on a relative rotation graph against a benchmark, IHSG (^JKSE) by default: RS-Ratio (is it beating the benchmark?), RS-Momentum (is that getting stronger?), the quadrant (leading, weakening, lagging, improving), the change over the tail and the tail itself. New schemaidx.rotation.v1.(the recorded fixtures; live data runs to today)
Method: an open approximation, labelled as one
The JdK formulas are proprietary. On the dates a stock and the benchmark share, resampled to each week's last session by default:
Sample sd, two decimals, 100 counts as the upper and right side.
method.approximation: trueandmethod.formulain the JSON, the table header,--help, the MCP description and the README all say it approximates JdK.Decisions (as recommended on #99)
--window(3 to 100) and--tail(1 to 52) are flags;--interval 1dfor sessions. The current week counts with its latest session.-from stdin). No bundled LQ45 list (it changes twice a year);^JKLQ45and^JKIIwork as symbols or benchmark (5y history checked on Yahoo).stocks returns, so the two share the cache.stocks rotation,rotationandrrgto its notice. Tools go from 47 to 48.IDXFINANCE.JKanswers a 1d/5d snapshot only).A short history (a new listing) or a symbol that moved exactly with the benchmark gives
nullvalues with a warning, never a fill. A warning names symbols whose newest close waits for^JKSE's bar (often a session late).Tests
--interval 1d --window 20 --tail 5in JSONL, a missing symbol as a warning, a missing benchmark (exit 5), bad flags (exit 2),idx schema rotation.idx_rotationfrom the seeded cache, and badintervalandwindowas usage errors; 48 tools.cargo test766 lib, 75 cli, 2 mcp; web 327; npm 6; worker check. Each of the three commits builds and passes on its own.idx stocks rotation BBCA BBRI TLKM GOTO ASIIandidx stocks rrg BBCA ^JKLQ45against Yahoo, as of 2026-11-13.scripts/smoke.shgains the same lines.Docs
README (a Relative rotation section, the commands table, MCP list, schema list,
IDX_EXCHANGE, stdin), docs/json-output.md, docs/mcp.md, docs/agent-guide.md, AGENTS.md.