Skip to content

J-KAUFMANSTOP-DIST — distance to Kaufman's stop, long (22, mult 2) - #352

Merged
TolgaUyanik merged 2 commits into
devfrom
issue-124-j-kaufmanstop-dist
Nov 20, 2026
Merged

TolgaUyanik merged 2 commits into
devfrom
issue-124-j-kaufmanstop-dist

Conversation

@TolgaUyanik

Copy link
Copy Markdown
Owner

Refs #124

Opened by issue-solver, a headless run; the owner merges. The launcher's code checked the paths, both repos' suites and Gate E. A fresh review gate returned PASS on 9a3ad1b642e3 in round 1 of 3.

Gate (round 1)

I read the acceptance scope, the issue, the diff inputs, the launcher's `tests.md` and the Gate E run folder, then checked the shipped module, the receipt, the ledger row, the test module and the five wiring touch points against those outputs.

What I verified line by line:

- **Math vs source formula.** `rng = hi - lo`; `avg = sma(rng, 22)` (`rolling(22, min_periods=22).mean()`); `stop = lo - 2.0*avg`; `dist = (px - stop)/px`. That is the issue's quote `L - 2*SMA22(H - L)` with its scale-free wrapper `(close - stop)/close`, no lag on `L`, no reinterpretation. `MIN_BARS = PERIOD = 22`, first fire at index 21, which is right for a chain that reads no previous close.
- **Look-ahead.** No forward `shift` anywhere; the only window is a backward `rolling`. Gate B pins it from both sides: 0/36 sweep catches on six frames, six `shift(-1)` mutants read off the shipped source and caught, plus three *lagging* mutants that the sweep is structurally blind to and the oracle rejects. The backward limb is a prefix truncation, 979 bars bit-equal.
- **Gate E numbers against `gatee/`.** Every figure in the receipt's §E1/§E2, the ledger row and the test module reconciles digit for digit with `overlap_max.csv`, `top25.csv`, `perframe.csv`, `degenerate.csv` and `meta.json`: 0.8776182137043913 vs `natr` (`compute_all`), n 396,980, per-frame max median 0.8600682984579084 over 89 frames, 7.865 % ≥ 0.90 (7 of 89), 92.135 % ≥ 0.80 (82 of 89), max 0.9150028247747078, min 0.6844900587878294, 687 comparators = 329 + 358, one degenerate (`squeeze_SQZ_NO`, `constant`) → 686, 398,849 pooled bars, all five stamps and the canary. `DISCLOSE_GAP` is what `r3-perframe-0.90` gives at 0.80 ≤ 0.8776 < 0.90 with no top-5 per-frame median at 0.90, and the waiver column is correctly empty.
- **Gate C's real-data limb.** 396,980 non-NaN and the same 396,980 non-zero of 398,849, straight out of `overlap_max.csv`; the 1,869 blanked = 89 × 21 identity is flagged as a recount, not a per-frame measurement.
- **Gate D.** ×8/×64 bit-identical over 9 frames and over 9 × 3 levels × 2 factors = 54 cells, inexact factors under 1e-9 with NaN masks matched, `0 < fires < n` on all nine, and a +10 shift that moves every fired bar (flat frame pinned as the exception) so the bit-identity is not vacuous.
- **Deliverables and wiring.** Receipt, ledger row, dictionary entry (warm-up 21, `SF`), README 359/367/`trend (65)`, contract 704/341, module, `trend/__init__.py`, `Category["trend"]`, the `df.ta` accessor, tests, review folder, both measure scripts — all present and mutually consistent.

VERDICT: PASS
FINDINGS:
  - severity: MINOR
    location: pandas_ta/trend/j_kaufmanstop_dist.py:285-293 (docstring)
    problem:  The shipped docstring still says "Gate E on the PROTOTYPE was DISCLOSE_GAP … It is PENDING: the launcher runs it after this session", which is now false — the run happened and is recorded. The prototype figures quoted there (0.8776, 0.8601, 396,980) are correct as the screen's, so no number is wrong; only the status is stale. Not editing the file is the right call and is justified: `docs/gate_e_ledger.csv` pins `module_sha1` `c833e200…` to these bytes and `tests/test_gate_e_ledger.py::test_row_still_describes_its_module` would flip the row to "Gate E owed" on any byte change. The receipt discloses this twice (§E1, "What a later session should know" item 2).
    fix:      Leave it until the next change to this module, then replace the "It is PENDING" sentence with the measured row ("Gate E on the PORT: DISCLOSE_GAP, 0.8776 vs `natr`, run `is124-j_kaufmanstop_dist-2d508b6b`") and re-record the Gate E row in the same change, as item 2 already instructs.
  - severity: MINOR
    location: docs/measure_j_kaufmanstop_dist.py:843-861 (`section_E`)
    problem:  The committed measurement script still prints "Gate E -- pending, and what the screen measured", "Gate E: pending, run by issue-solver after this session." and "No ledger row exists yet; the receipt session records it." The last is now plainly false, and unlike the module this file carries no ledger sha1 pin, so it could have been updated in this commit. The receipt's exception 3 excuses §E from the "every number is printed by this script" claim but says nothing about this file's own stale status prose, so this is the one stale claim in the change that is neither corrected nor disclosed.
    fix:      Retitle the section "Gate E -- the screen's PROTOTYPE figures; the port's own run is in §E of the receipt", drop the two pending sentences, and replace the last line with a pointer to run `is124-j_kaufmanstop_dist-2d508b6b` and `docs/gate_e_ledger.csv`, keeping the printed prototype figures (0.8776182137043917 etc.) exactly as they are.
  - severity: MINOR
    location: docs/JKaufmanstopDistMeasured.md:1043-1051 (§F, full-suite bullet)
    problem:  §F reports the full suite as "1 failed, 12,709 passed, 86 skipped"; the launcher's clean-worktree HEAD run reads 12,702 passed / 1 failed / 93 skipped (`tests.md`). Same total (12,796), same single known failure, zero regressions — the 7-test difference is environment-dependent skips that the launcher's *base* run already shows (93 at base too), so it is unrelated to this change. §F labels the counts as its own session's re-run, but a reader comparing the two reports has nothing telling them the pass/skip split moves with the worktree.
    fix:      Add one clause to that bullet: "the pass/skip split is environment-dependent — the launcher's clean worktree reads 12,702 passed / 93 skipped at this HEAD with the same one failure and 0 regressions."
  - severity: MINOR
    location: tests/test_j_kaufmanstop_dist.py:152-159 (module docstring)
    problem:  "Every number above is printed by `python docs/measure_j_kaufmanstop_dist.py` … with the exceptions `docs/JKaufmanstopDistMeasured.md` lists above its §A1, of which one matters here" undercounts. Item 8's figures (0.8776182137043913, 396,980, 0.8600682984579084, 398,849) are all the launcher's run output and fall under the receipt's exception 3, which the script prints none of — so two exceptions matter here, not one. The numbers themselves match `gatee/`; only the provenance claim is short.
    fix:      Change to "of which two matter here: the asserted bounds (exception 5) and every real-data figure in item 8, which is the launcher's Gate E run rather than this script's (exception 3)."
SUMMARY: The arithmetic is the issue's formula and nothing else — `(close - (low - 2*SMA22(high - low)))/close`, bit-equal to an independent naive-window oracle, to TA-Lib's spelling and to the screen prototype on all nine frames, with the prototype coincidence presented as a measured result rather than as Gate A's route, which is what the issue demanded. Causality is pinned in both directions, including the lagging blind spot the suffix sweep cannot see, and Gate D's 54 extreme-level cells and measured 1.839e+206 headroom are run rather than reasoned. Every Gate E digit in the receipt, the ledger row and the test module reconciles with the launcher's run folder, DISCLOSE_GAP is the band the measured pair (0.8776 pooled, 0.8601 per-frame median) actually gives, and Gate C's real-data limb is the run's own `non_nan`/`non_zero` instead of a synthetic stand-in. The receipt also refuses to flatter itself: the three input finite guards are called measured no-ops, §L's synthetic 0.1092 is declared useless as a floor against the real 0.8776, and the 0.022 margin to the strike line that killed `lean_avgrange_14` is written down as thin. What is left is bookkeeping, all of it prose: two "Gate E is pending" statements that the run has outlived — one correctly frozen by the ledger's sha1 pin and disclosed, one in a measure script that had no such excuse and no such disclosure — a full-suite pass/skip split 7 tests apart from the launcher's environment, and a provenance sentence that counts one exception where two apply. Nothing in that list touches the mathematics, the causality, the gates or a measured number. It ships.

Launcher checks

  • Paths: 16 changed, all inside the port allow-list.
  • PandasTa suite (clean worktrees): base 12313 passed, 1 failed, 0 errors, 93 skipped; HEAD 12702 passed, 1 failed, 0 errors, 93 skipped; regressions 0; new tests passing 389; new tests skipped 0.
  • Backtesting suite (gatee 9a4af209, PYTHONPATH = PandasTa): base 2022 passed, 32 failed, 4 errors, 15 skipped; HEAD 2022 passed, 32 failed, 4 errors, 15 skipped; regressions 0.
  • Gate E (the launcher's run):

pandas_ta.trend.j_kaufmanstop_dist (is124-j_kaufmanstop_dist-2d508b6b):

column,max_abs_rho,rho,against,against_set,n,perframe_median_abs_rho,perframe_n_frames,perframe_pct_frames_ge_090,perframe_max_median_abs_rho,perframe_max_against,verdict,verdict_pooled_only,max_abs_rho_compute_all,against_compute_all,n_compute_all,max_abs_rho_manifest,against_manifest,n_manifest,n_comparators,n_degenerate,non_nan,non_zero,verdict_schema
J_KAUFMANSTOP_DIST_22_2.0,0.8776182137043913,0.8776182137043913,natr,compute_all,396980,0.8600682984579084,89,7.865168539325842,0.8600682984579084,natr,DISCLOSE_GAP,DISCLOSE_GAP,0.8776182137043913,natr,396980,0.8776182137043913,Stop_2ATR_pct,396980,687,1,396980,396980,r3-perframe-0.90
  • /brutally-honest-review --auto run folders: docs/reviews/auto-2026-11-19-j-kaufmanstop-dist/.
  • Run folder on the owner's machine: /home/tolga/.issue-solver/runs/20261120-060217-124.

🤖 Generated with Claude Code

TolgaUyanik and others added 2 commits November 20, 2026 06:18
…fmanstop_dist (trend), Gates A-D, five wiring touch points, tests, docs/JKaufmanstopDistMeasured.md and the review folder. Gate E pending, run by issue-solver. Refs #124

J_KAUFMANSTOP_DIST_22_2.0 = (close - stop)/close, where the stop sits twice
the 22-bar average range below the bar's OWN low:

    rng[T]  = high[T] - low[T]
    avg[T]  = mean(rng[T-21..T])                                  SMA 22
    stop[T] = low[T] - 2 * avg[T]

22 and 2 are module constants, not arguments: the issue's quote and the
screen prototype spell exactly those two, and that pair is the whole of what
the 2026-10-24 screen measured at Gate E.

THE SCREEN PROTOTYPE IS THIS COLUMN'S ARITHMETIC, BIT FOR BIT, and that is
the first thing to read because it is the opposite of #122. A3 measures the
two bit-equal on all nine test frames; the prototype is readable here
(docs/issues/screen/ind_screen_r2.py:127, with ind_screen.py:47's
mean(x, n) = x.rolling(n).mean(), the same call `sma` makes). So the
screen's DISCLOSE_GAP figures describe THIS arithmetic rather than a
neighbouring column -- on 89 real frames and through an engine this
worktree can neither read nor run, so the port's own Gate E run still
decides the band.

Gate A also runs the formula two further ways. A bar-by-bar oracle with its
own naive 22-term window sum over plain Python floats, sharing no code with
the module, is BIT-EQUAL on 1,479 of 1,479 fired bars of each of six
varying frames; pandas' compensated rolling.mean() is itself bit-equal to
that naive sum on the walk frame, measured rather than assumed. TA-Lib
spells it third: (close - (low - 2*talib.SMA(high - low, 22)))/close is
bit-equal on all six at Spearman 1.0000, and talib.SMA, this module's `sma`
and the column all first fire at bar 21. The tests assert 1e-12/1e-9 rather
than the bit-equality, because the frames are built with np.exp/np.cumsum.

MIN_BARS IS PERIOD, NOT PERIOD + 1, which is the one structural number that
differs from j_chandelier_dist: nothing here reads a previous close, so the
SMA's input is defined at bar 0. Four readings are priced rather than
assumed close: SMA22 over the TRUE range (1,478 of 1,479 bars, up to
5.6e-02, Spearman 0.279 .. 0.534, and it fires a bar later), EMA22
(1.3e-03), the stop off YESTERDAY's low (up to 3.2e-01 at Spearman
-0.075 .. 0.020) and `high - low` through the fork's non_zero_range -- which
is bit-equal at a price level of 100 even on 215 tied bars, so the plain
subtraction buys nothing there, and fails Gate D's x8 and x64 cells at 1e-6,
where this module holds.

Nothing here claims what jesse's CODE says: the library is not installed,
web access is unavailable, and a test records that so the claim cannot rot
into "checked against jesse". Even "Kaufman's stop" is attributed to the
issue rather than asserted.

Gate B is the sweep AND the oracle. The module is caught 0 of 36 offsets on
six frames; six look-ahead mutants read off the shipped source are live and
caught 36 of 36 on each of three frames, the first catch moving a bar by
1.379e-05 .. 3.023e-02. Three edits that LAG a leg are caught 0 of 36 by
the sweep and all three by the oracle, by 6.152e-04 .. 3.224e-01. The
backward direction is measured too: truncating at bar 500 leaves all 979
later bars bit-equal.

Gate C/D: 1,479 of 1,500 bars on each of nine frames, 1,479 distinct values
on each of the six varying ones, 0.005961 .. 0.014415 pooled. THE COLUMN
DOES NOT CHANGE SIGN, which is where it parts from both sibling stop
distances -- (close - stop)/close = (close - low)/close + 2*avg/close, two
non-negative terms on well-formed OHLC -- so the signal is the SIZE: 8,874
of 8,874 bars positive, 0 exactly zero. x8/x64 bit-identical on all nine
frames and on all nine at each of 1e-6, 1e+6 and 1e+100 (54 cells), the
largest of the chain's ten series at 1e100 being 9.776e+101 against DBL_MAX,
1.839e+206 of headroom; x10/x3.7/x0.1/x1.0000001 within 5.160e-14, asserted
1e-9. A +10 level shift moves all 1,479 fired bars of the six varying
frames and 0 of the flat frame's, which is pinned separately.

A BAD PRICE EMPTIES A BOUNDED WINDOW AND MOVES NOTHING AFTER IT: a NaN,
+inf or -inf high or low blanks exactly bars max(T, 21) .. min(T+21, n-1) --
22 in mid-frame, 5 at bar 1,495, 6 at bar 5 -- and a bad close blanks its
own bar, or none inside the warm-up. 45 cells, and 0 later bars moved in
every one. The opposite of #122, where a bad low blanked nothing and moved
400 .. 658 bars, and the reason is structural: no recursion here.

THREE OF THE FIVE GUARDS ARE MEASURED DEAD CODE and the receipt says so
rather than claiming a load they do not carry -- the finding that cost this
run two MAJORs. The three input finite guards are bit-equal no-ops in all 42
guard-off cells measured, and they stay no-ops even with `sma` rebound to a
mean that PROPAGATES an infinity (G5). What absorbs a bad high or low is
pandas turning an infinite observation into a NaN before a rolling
aggregation sees it -- measured on three aggregations, mechanism NOT claimed
since pandas is outside this worktree -- and two tests would fail if that
went, not one: the ..._into_nan one and test_route_1_never_reaches_the_output,
whose zero becomes 99 of 120 under a propagating mean. What does bite is the
close-is-positive guard (without it a close of -50 ships 1.924 among bars of
0.006 .. 0.014) and the final finite mask (two of three overflow routes
reach the output without it, 99 of 120 each).

In-fork overlap (SYNTHETIC, a disclosure and not a gate) reads LOW here, the
reverse of #122: nearest is a retyped lean_avgrange_14 at a per-frame median
0.5506, then j_chandelier_dist 0.1436, a retyped Stop_2ATR_pct 0.1366, a
retyped true_range/close 0.1096 and natr:NATR_14 0.1092 -- and natr, the one
comparator with both figures, is 0.75 BELOW the screen's 0.8611. On these
frames the wick term carries more of the column than the range term does
(|rho| 0.857 .. 0.884 against 0.574 .. 0.620), so L cannot stand in for
Gate E in either direction.

THE NEAREST CANDIDATE OF THIS COLUMN'S OWN FAMILY WAS STRUCK, and that is
Gate E context no reading of the synthetic figures would give:
lean_avgrange_14, SMA(H - L, 14)/close, paired at 0.8646 with this candidate
and measured 0.9489 vs natr over n = 397,692 -- dropped, "Gate E STRUCK"
(candidates_r2.csv). The screen kept this candidate at 0.8776 and dropped
that one at 0.9489 on the same comparator, so the margin is the wick term
plus the x2. Earlier drafts of the receipt had this inverted, as a port to
go measure later.

FOUR Fletcher review rounds, 30 findings, every one applied, and NOT ONE
about the mathematics: every reviewer re-ran both measurement scripts
section by section on both numpy dispatches and reported every cell
reproducing, plus the three suite counts to the line. The arc is one defect
repeating -- a count or a mechanism written past the run, inside the fix for
the previous round's: one cell versus eight (r1), one test versus two (r2),
a refuted vehicle left in place and "the three identical-dispatch lines"
over twelve of them (r3), _prep_values left standing in two of six places
and the inverted screen verdict (r4). Even the corrections were not immune:
the replacement count for r3 came out eleven from a single-line grep that
missed a wrapped sentence. Three habits came out of it and are in the files:
count with a tool then state the number; measure the hypothetical instead of
reasoning about it (G5 refuted r2's proposed mechanism and confirmed its
conclusion by the right vehicle); and scope a universal to the cells that
ran. Round 4 was the loop's last round, so its seven fixes have no post-fix
review: there are no open findings and also no PASS, and
docs/reviews/auto-2026-11-19-j-kaufmanstop-dist/99-summary.md says so
instead of implying one.

Gate E owed: no ledger row, and tests/test_j_kaufmanstop_dist.py asserts
there is none, which is the receipt session's cue. Gate C's real-data limb
is owed from the same run; everything here is synthetic. Gate F: 380 tests
for the module, the same 380 under
NPY_DISABLE_CPU_FEATURES="AVX512F AVX512_SKX AVX2 FMA3" (via
docs/measure_j_kaufmanstop_dist_cpu.py, which prints the dispatchable
features still enabled and refuses to run if any of the four survived);
with tests/test_gate_e_ledger.py, 1,478 passed and 1 failed, the owed row
naming ['j_kaufmanstop_dist'] and nothing else; full suite 2 failed,
12,496 passed, 86 skipped -- that owed row and the
AlternativeRepos-dependent talib CSV test that CI deselects by name. The
parent repo's suite is the launcher's.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
…t (DISCLOSE_GAP, 0.8776 vs natr, n = 396,980, per-frame max median 0.8601 over 89 frames), fill Gate C's real-data limb (396,980 non-NaN and 396,980 non-zero of 398,849), and swap the two pending-Gate-E tests for three that pin the recorded row. Refs #124

The launcher ran gate_e_overlap.py run --module pandas_ta.trend.j_kaufmanstop_dist
on the code at c39dcf8; outputs is124-j_kaufmanstop_dist-2d508b6b, recorded into
docs/gate_e_ledger.csv by docs/gate_e_ledger.py record --measured 2026-11-20,
which printed
`j_kaufmanstop_dist:J_KAUFMANSTOP_DIST_22_2.0 DISCLOSE_GAP 0.8776 vs natr`.

DISCLOSE_GAP on both limbs of r3-perframe-0.90, so the column SHIPS with the
disclosure and nothing is removed: pooled max |rho| 0.8776182137043913 vs
compute_all's natr over n = 396,980, top-five per-frame max median
0.8600682984579084 against the same comparator over 89 frames,
verdict_pooled_only the same, 687 comparators with squeeze_SQZ_NO dropped as
constant -- the comparator fault c22_ami_timescale, j_acosc, j_safezone_dist and
j_chandelier_dist dropped too. A DISCLOSE_GAP row needs no waiver, so the waiver
column is empty and the new test asserts that.

THE RUN AGREES WITH THE SCREEN PROTOTYPE TO 15 SIGNIFICANT DIGITS --
0.8776182137043913 against 0.8776182137043917, same comparator, same n, same
per-frame figure digit for digit -- which is what section A3's bit-equality
predicted, and the receipt's new section E2 reads it out rather than leaving it
to a reader. Because an expected agreement is the easiest row to copy over from
the wrong run, the replacement test pins the run id and not only the arithmetic.
Section E2 also closes the four things the pre-run draft said the screen's figure
did not settle; the fourth stays OPEN and says so: what the engine computes under
the name natr is still not readable here, and that natr and Stop_2ATR_pct are
monotone transforms of each other is an inference from their identical Spearman
columns, not from their code.

THE DISCLOSURE IS THE POINT OF THE ROW, and the receipt and
docs/MLCompanionContract.md both carry it now: natr and the manifest's
Stop_2ATR_pct tie this column at 0.8776 pooled to every printed digit, 7 of 89
frames reach |rho| 0.90 individually (max 0.9150) and 82 of 89 sit at 0.80 or
above, so a miner fed this column and a normalised ATR double-weights one
volatility signal. The first comparator outside that family is Swing_Range_pct,
0.147 lower at 0.7305. The nearest candidate of the same screen round,
lean_avgrange_14, was STRUCK at 0.9489 vs natr -- this column came within 0.071
of it and sits 0.022 under the strike line.

Gate C's real-data limb is measured rather than owed: 396,980 of 398,849 pooled
BIST bars non-NaN, and the SAME 396,980 non-zero, so 0 real fired bar reads
exactly 0.0 -- the real-data limb of the no-sign-change structure section C1
measures synthetically. 398,849 - 396,980 = 1,869 = 89 x the 21-bar warm-up, and
the receipt states that as a recounted identity between two of the run's numbers
rather than as a per-frame measurement it did not make.

Section L is re-read against the run instead of being left as written: three of
its rows now have a real figure, and the synthetic ones are 0.72 .. 0.77 below
them (natr 0.1092 vs 0.8776, Stop_2ATR_pct 0.1366 vs 0.8776, Swing_Range_pct
0.0094 vs 0.7305). Its "a range-based comparator can only reach so far" is
refuted as a statement about real frames and kept as one about those six; which
of the two terms carries the real overlap is measured nowhere and the receipt
says so.

pandas_ta/trend/j_kaufmanstop_dist.py is deliberately NOT edited, so its
docstring still reads "Gate E ... It is PENDING": the ledger pins module_sha1
c833e200 to the bytes the harness imported and
tests/test_gate_e_ledger.py::test_row_still_describes_its_module re-derives it,
so fixing the paragraph would invalidate the measurement it describes. Section E1
and the later-session list disclose that and tell the next session to fix it in
the same change as any other edit to that file. README.md and
docs/IndicatorDictionary.md name the column in generated lists only.

Tests: tests/test_j_kaufmanstop_dist.py 381 passed (380 before, -2 pending tests
+3 that pin the ledger row, the receipt's copy of the numbers and the real-data
counts), the same 381 under NPY_DISABLE_CPU_FEATURES="AVX512F AVX512_SKX AVX2
FMA3" via docs/measure_j_kaufmanstop_dist_cpu.py; with
tests/test_gate_e_ledger.py, 1,495 passed, so the owed-row failure is gone. Full
suite 1 failed, 12,709 passed, 86 skipped in 417 s -- the AlternativeRepos-
dependent talib CSV test that CI deselects by name, and nothing else. The parent
repo's suite is the launcher's.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@TolgaUyanik
TolgaUyanik merged commit 601600c into dev Nov 20, 2026
6 checks passed
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