Skip to content

Commit 37090e1

Browse files
committed
H-MEASURE: measure excursions, short-seed swaps, the dust sweep, ismarket
AUDIT4 X14 rows E19 (the excursion model, G2-22), G2-21 (short-seed report swaps), G2-32 (the 1e-10 dust sweep) and G2-36 (session.ismarket, the CME weekend and 0000-2400 classes), each measured against the kernel on the same fills and against TradingView's own trades (lab tv, ws-report-v1, rangeProof covered; each fixture README names its tapes): - tests/test_e19_excursion_tape.cpp (E19): a corpus probe's own script re-exported (1580 trades, its excursion cells equal to the corpus tape's) and a calc_on_order_fills scratch tape. Where the host-owned model (RULING A48) and the kernel sampler differ, the kernel's number is TradingView's: entry-bar over-mask, exit-bar over-fold after an at-open exit, the COOF scratch TradingView reports as 0/0. One trade per class pinned; corpus-wide the kernel is TradingView's on 315 of the 326 identified disagreements and the host on none. Recorded divergences. - tests/test_short_seed_report_swap.cpp (G2-21): the swap relabels two rows' entry_incarnation into ab9714b's numbering, read against the kernel's own lot identities in the same run; TradingView exports no incarnation, and the Pine host books the collision tape's 13 rows. - tests/test_pine_dust_sweep_paired.cpp (G2-32): the sweep erases a dust lot inside a live book, unlike ab9714b's whole-book reset; TradingView's decimal quantities leave no remnant row, which the Pine host books and a bare host does not (four 2.8e-17-unit rows). - tests/test_session_ismarket_tape.cpp (G2-36): six tapes (ES1!, EURUSD, XAUUSD, ETH; both 2025 DST switches, Thanksgiving) flag every bar in market; the kernel's in_session matches every spelling, the generated predicate misses every Sunday open under a :23456 mask and every bar of 0000-2400. Routing session.ismarket is a codegen change, not made here. Docs: ADR-0001 (the excursion seam, the dust sweep as a quirk, the session.ismarket selection, the excursion columns being report-only), design RP1, RP5 (its "measured in §3.7 part 2" named no short-seed row) and the excursion-mode alternative, native-settlement.md's sweep paragraph ("restates" the legacy rule, it does not), pine-to-native.md and pine_v6_coverage_detail.md on session.ismarket. No src/ or include/ change. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> (cherry picked from commit fd3c72e2d6cc22a77b86a73d2efc36aeed7c968f) INT26 pick note: docs/native-settlement.md conflicted in text. INT25 (K-ULP4) had appended the sentences on the adapter not declaring the kernel's quantity tolerance to the paragraph this commit rewrites; the merged paragraph is this commit's measured text followed by those INT25 sentences unchanged. The ADR, design and pine-to-native pages conflicted on citation digits only (int16_digit_merge, digits carried from the pre-pick tree). hunkcheck: every hunk of fd3c72e2 carried; design and pine-to-native differ from its diff in anchor digits only.
1 parent e1d0fa3 commit 37090e1

57 files changed

Lines changed: 5139 additions & 13 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎docs/adr/0001-kernel-adapter-boundary.md‎

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,13 @@ kernel and own these quirks, each at its site:
212212
`validate_precommit` (`pine_adapter.cpp:13034`) returns `AdmitWithHostMargin`
213213
(`pine_adapter.cpp:13279`) to own the opening margin decision; `owns_lot_excursions() = true`
214214
(`pine_strategy_host.hpp:284-285`) with `closed_lot_excursion` (`pine_strategy_host.cpp:786`), so
215-
MFE/MAE are measured on TV tick-quantized prices; and `on_native_tick`
215+
the Pine host keeps its own per-lot MFE/MAE, `ab9714be`'s model (RULING A48). Measured against
216+
TradingView by R5 lane H-MEASURE (`tests/test_e19_excursion_tape.cpp`, `lab tv` tapes): where
217+
the host's model and the kernel sampler differ, the kernel's number is TradingView's — the host
218+
masks an entry-bar extreme a stop filled at the open never saw, folds the exit bar's extreme
219+
after an at-open exit, and folds the whole entry bar into a `calc_on_order_fills` scratch
220+
TradingView reports as 0 / 0. The retention is `ab9714be` compatibility, a recorded
221+
divergence; `on_native_tick`
216222
(`pine_strategy_host.cpp:381`) / `on_native_applied` (`pine_strategy_host.cpp:477`) for
217223
`calc_on_order_fills` re-entry. `process_orders_on_close` becomes
218224
`NativeCloseExecution::AfterCalculation` in the projected spec (`pine_adapter.cpp:2318-2319`);
@@ -231,6 +237,13 @@ kernel and own these quirks, each at its site:
231237
adapter's terms seam (`resolve_terms` `pine_adapter.cpp:11671`).
232238
- **Money arithmetic.** Ten-significant-digit half-up money (`source_money_round`
233239
`pine_adapter.cpp:454-460`, twin `tv_money_round` `pine_policy_support.hpp:9-15`).
240+
- **Quantity dust.** After every applied execution the Pine host erases any lot of at most
241+
`kQtyEpsilon` (`1e-10`) from the book it shares with the kernel, with no closing row
242+
(`on_native_applied` `pine_strategy_host.cpp:478`), inside a live book as well as at a flat
243+
reset — broader than `ab9714be`, which reset only a whole book at or under that size. Measured
244+
by R5 lane H-MEASURE (`tests/test_pine_dust_sweep_paired.cpp`): TradingView's decimal
245+
quantities leave no remnant row on a `lab tv` tape, which the Pine host books row for row
246+
while a bare host books four 2.8e-17-unit dust rows beside them.
234247
- **Close reservations.** `strategy.close` callsite batching, two-call provenance and the entry-id
235248
ledger (`close_logical_units_` `pine_adapter.hpp:2023-2034`); the POOC reservation-growth population predicate
236249
(`sha256:f524cf2b9e21e231672451db30ab94184ba3125d8ad6e4f9f614a0f4c538919e` src/compat/pine/reservation_expansion.cpp:9-20).
@@ -272,11 +285,16 @@ kernel and own these quirks, each at its site:
272285
own loop guard (`kFirstOpenLoopGuard` `pine_scheduler_native.cpp:680`), and the two fills Pine refuses to
273286
recalculate on (`suppress_grouped_stop_recalc` `pine_adapter.cpp:5641`).
274287
- **Pine language state and harness flags.** Series, the tick-level barstate flags and
275-
position-view freezing (`PineLanguageState` `pine_language_state.hpp:12`); the three session flags generated code
276-
reads, `PineStrategyHost` members since R5 lane F5 (`session_ismarket_`
288+
position-view freezing (`PineLanguageState` `pine_language_state.hpp:12`); the three session flags,
289+
`PineStrategyHost` members since R5 lane F5 (`session_ismarket_`
277290
`pine_strategy_host.hpp:857`), which `scheduler_update_session_state`
278291
(`pine_strategy_host.cpp:1764`) selects from the kernel's session-day facts before each source
279-
callback — the host computes no session-day rule of its own; `barstate_islast_`, still a
292+
callback — the host computes no session-day rule of its own. Generated code reads two of them;
293+
a generated `session.ismarket` still calls the time-of-day predicate
294+
(`pine_session_ismarket` `pine_strategy_host.hpp:606`), which on six `lab tv` tapes misses every
295+
Sunday open of a weekday-masked overnight session and every bar of `0000-2400`, where the
296+
kernel's fact matches TradingView on every bar (R5 lane H-MEASURE,
297+
`tests/test_session_ismarket_tape.cpp`; routing it is a codegen change); `barstate_islast_`, still a
280298
`BacktestEngine` member (`engine.hpp:378`) only this host writes; the live-tail /
281299
probe-suppress overrides (`set_realtime_tail` `pine_strategy_host.hpp:446`,
282300
`set_probe_suppress_tail_logic` `pine_strategy_host.hpp:472`), whose live-probe protocol is
@@ -695,7 +713,7 @@ The table records, at the tree the doc wave read, what each block described and
695713
| the neutral utility spellings — `map.hpp`, `drawing.hpp`, `series.hpp`, `window_sum.hpp`, `math.hpp`, `matrix.hpp`, `session_time.hpp`, `str_utils.hpp` | neutral public names with exact deprecated `pine_*` aliases for generated code | already ruled: "Neutral spellings" above | dropping the aliases breaks generated code | the ruled-name gate |
696714
| `native_matching::ladder_trail_stop` `src/native_matching.hpp`, reaching the core as `native_order::ActivationGrid::ladder_tick` | a trailing stop that stands a whole number of price ticks from a running best that is itself a ladder point IS the ladder point that many ticks away, spelled so no binary64 ULP hides it from the side it is reached from; everything off the ladder keeps `best -/+ offset` raw | a stop `ticks` ticks behind a best is a ladder distance at every venue with a tick ladder, and the rule reads the run's own declared `price_tick` — data, never a platform. It is a defect of arithmetic, not a policy: `11.44 - 5 * 0.01` is `11.389999999999998792` against the ladder point `11.390000000000000568`, so a print that IS 11.39 missed a stop the run had put five ticks under 11.44. Both ends are decimal numbers measured on the host's ladder and only the ladder index is exact between them | nothing, because the run had already decided it — it declared the ladder (`NativeRunSpec::price_tick`) and the host spelled the distance on that ladder (`TrailTicks`, or an equal price distance), so a "raw subtraction or ladder point" switch would put a hash-visible choice on the public surface for an answer already given. Nor is this the per-order-kind quantization the `price_grid` row rejects: nothing is rounded ONTO the ladder, and a sub-tick best, a fractional-tick offset or a run with no declared tick keep the raw level bit for bit | `tests/test_native_trail_stop_ladder.cpp` (kernel-only, batch and stream: lane E14's own 11.44 / 5-tick case against a low of exactly 11.39, its buy mirror, and the three off-ladder shapes pinned bit for bit), with the tape row in `tests/test_trail_activation_tick_reach.cpp` (`e14-f-long-shallow-next` 7/7) and the two paths agreeing in `tests/test_adapter_grid_relower.cpp` section 5. Measured by TradingView's tape (R5 lane E14) and by the price-grid trial from the other side (lane R7: one ULP off on ~14% of (best, offset) pairs), closed by lane E16; design `native-feature-parity.md` §3.6.2 |
697715
| `native_order::Trail::best_seed` `include/pineforge/native_order.hpp` | where a trail's running best STARTS: absent, the arm's own print; present, a floor on it — the favourable one of the seed and that print | the level is a number the host hands over exactly as it hands over an `arm_price`: the kernel neither derives it nor knows what named it, and a second venue drives it by passing a different number. A trailing stop that rides from its activation rather than from the next print is an ordinary broker shape | nothing, because the old start was not a choice the run had made another way — it was wherever the arm happened to land (the arm threshold on a crossing, the first live print when the request was born already armed), so there is no second spelling to defer to and nothing for a hook to answer; a request field is admissible, opt-in and hashed only when present | `tests/test_native_trail_best_seed.cpp` (kernel-only, batch and stream, the absent-seed controls pinned as same-host properties of the continuation digest rather than as its pre-field values, because that digest folded the host's own zoneinfo root when the lane landed — E23 made it portable across hosts, but it still moves with the installed tzdata release, so the properties stay); the C tail by `check_trail_best_seed_tail` in `tests/test_native_c_api.c`. The need was measured by R5 lanes E5 and E9 — TradingView's `lab tv` tapes book every trail exit at activation ∓ the offset, never at the kernel's own start — and closed by lane E14; design `native-feature-parity.md` §3.6.2 |
698-
| `build_close_trade_with_costs` and `record_close_trade` `src/engine_orders.cpp` | a closing row's percent P&L is its NET P&L (both commissions deducted) over its entry cost at the same account-currency rate; its excursions include the exit fill itself and sit on the net open-profit basis (the entry commission deducted, the favorable magnitude floored at 0); a row whose P&L is exactly zero counts as even | accounting definitions over the row's own booked numbers -- entry cost, commissions, fill price -- so another venue is driven by its own fees and fills; nothing branches on a platform | a gross/net or tolerance switch over report arithmetic the run's fee terms already decide. One question stays open, recorded at the site: the net basis is applied to a host-owned excursion's magnitudes too (RULING A48's hook) | the corpus parity gate (`scripts/check_corpus_parity.sh`: 312 recorded trade lists carrying the percent P&L and both excursion columns, graded against TradingView's exports) and `tests/test_max_contracts_held.cpp` (a zero-P&L row counted even); the calibration records are the comments at the site (R5 lane F6 reworded them to the mechanism) |
716+
| `build_close_trade_with_costs` and `record_close_trade` `src/engine_orders.cpp` | a closing row's percent P&L is its NET P&L (both commissions deducted) over its entry cost at the same account-currency rate; its excursions include the exit fill itself and sit on the net open-profit basis (the entry commission deducted, the favorable magnitude floored at 0); a row whose P&L is exactly zero counts as even | accounting definitions over the row's own booked numbers -- entry cost, commissions, fill price -- so another venue is driven by its own fees and fills; nothing branches on a platform | a gross/net or tolerance switch over report arithmetic the run's fee terms already decide. One question stays open, recorded at the site: the net basis is applied to a host-owned excursion's magnitudes too (RULING A48's hook) | the corpus parity gate (`scripts/check_corpus_parity.sh`: 312 recorded trade lists carrying the percent P&L and both excursion columns, byte-pinned to the baseline; the excursion columns are read against TradingView's exports as report-only deltas, not graded, `scripts/verify_corpus.py`) and `tests/test_max_contracts_held.cpp` (a zero-P&L row counted even); the calibration records are the comments at the site (R5 lane F6 reworded them to the mechanism) |
699717
| the indicator library -- `include/pineforge/ta.hpp`, `src/ta_moving_averages.cpp`, `src/ta_oscillators.cpp`, `src/ta_extremes_volume.cpp`, `src/ta_volatility_trend.cpp`, `src/ta_misc.cpp`, `include/pineforge/window_sum.hpp`, `include/pineforge/math.hpp` | each indicator implements its Pine `ta.*` / `math.*` definition -- warm-up and na rules, the window call-site ring, the compensated window sum, tie and epsilon rules -- and its comments record the TradingView tape or export that calibrated each number (the `ta::ATR` and standard-deviation rows above are two of them) | an indicator is a function of its inputs, the same for every venue; generated strategies call exactly these classes, and where two textbook conventions genuinely compete the choice is a per-instance option (`ta::EmaSeeding`), never a branch on the platform | a convention switch on every indicator, for a choice the script already made by calling that Pine function | the kernel-only TA suites `tests/test_ta_*.cpp` and the corpus parity gate |
700718
| the formatting library -- `include/pineforge/str_utils.hpp`, `src/str_utils.cpp` (`str_tostring`, `str_format_values`, `str_format`) | the number text of Pine's `str.tostring` / `str.format` built-ins: a number's shortest round-trip decimal spelling, scaled and rounded half-up on its digits, the default, `percent`, `volume` (K / M / B / T) and pattern modes, MessageFormat placeholders and quoting, `NaN` and `Infinity` -- the published rendering TradingView's exported tapes pin (R5 lane C6), ported from the codegen formatter (lane C6b) by R5 lane B-ENGINE; the `mintick` mode, which generated code delegates to it, is kept as it was | a formatting library is a function of its inputs, the same for every venue, as the indicator library is: it spells a number the way the source language's own `str.*` library defines, and no kernel order, fill, settlement, margin or hash code calls it -- of the thirty-five kernel translation units only `src/str_utils.cpp` names these functions | a rendering switch on functions whose definition the calling script chose by calling them | `tests/test_str_number_format.cpp` (lane C6b's 42-case edge battery, every numeric string of lane C6's TradingView exports, byte-identical output on macOS arm64 and Linux x86-64) and `tests/test_str_utils.cpp` |
701719
| the language calendar functions -- `include/pineforge/session_time.hpp`, `src/session_time.cpp` (`timeframe_time`, `local_hour` and its siblings, `session_in_market`, `session_trading_day_open_ms`, ...) | the definitions of Pine's `time()` / `time_close()` / bare-time / `session.is*` built-ins for generated code: session and timezone parsing, the invalid- and 24-hour-session spellings, `time("60")` day keying, `session.is*` on daily charts, each comment naming the tape that pinned it | the inputs are data -- a session string, a timezone, a timeframe -- so another venue is driven by its own session template; nothing branches on a platform, and a native host's calendar is the separate generic `native_calendar` | a rules switch on functions whose definition the generated script chose by calling them | `tests/test_session_time.cpp`, `tests/test_pine_time_day_stamp_grid.cpp` and the corpus parity gate |

0 commit comments

Comments
 (0)