Skip to content

Commit 7239ab3

Browse files
luisleo526claude
andauthored
W15: a calendar bucket closes once; a late-opening day's intraday grid starts at its own open (#296)
* A calendar bucket closes once, on its period's actual last input bar (W15-KERNEL-CAL C) A session template knows Monday to Friday. NSE traded two whole sessions its template does not declare inside the lanes' feeds: the Budget-day sessions of Sat 2025-02-01 and Sun 2026-02-01 (and, earlier, Saturday sessions in 2024 and the Sunday Muhurat of 2023-11-12). TradingView keeps each in its week: Tue 2026-01-27 .. Sun 02-01 is one weekly bar whose bar_index advances once, on Sunday's 15:15 bar (lab tv w14-htf-w-nifty15, NSE:NIFTY 15, 2025-04-01 .. 2026-05-01, W14's synthetic tape). feed_calendar_mode (src/timeframe.cpp) ended that week with the W/M last-traded-close rule, which skips weekend trading dates, on Friday's 15:15 bar; each Sunday bar then merged back into the closed bucket and the same rule completed it again. The requested weekly series advanced 26 times for one week (W14 mechanism C). The intraday path already guarded against a second emission (feed_ratio_mode, current_emitted_complete); the calendar path had no such guard. Mechanism, two rules in feed_calendar_mode's merge branch: - close once: a bucket a completion rule has closed is not completed again by a later bar of its period; the bar merges into it, and the next period's first bar opens the next bucket without re-emitting it (the boundary branch already did that); - not while the next known bar is in the period: a completion rule that fires while the next input bar the run holds lies in the same period is withdrawn. The aggregator's own period key (period_changes: the native partition when installed, crosses_boundary otherwise) decides, the key its boundary test splits on. With no known successor (0: a stream, the feed's last bar) the template's rule stands, once. ADR-0001 (rule 2), new section "Wave W15 KERNEL-CAL: rule 2 rulings": - mechanism: the two rules above, reading only the run's input and the aggregator's period key; - generic: whether a bar is its period's last is a fact of the input the run holds, for any venue and calendar; a template that knows Monday to Friday fed a venue's weekend session ends the week on its last bar; nothing branches on a platform; - no knob: a second completion of one period is a defect, not a convention (no venue publishes a period's bar twice), and "is this the last bar" is already answered by the input, so a switch would restate it. docs/pages/native-engine.md states the rule beside the early-close one. Tape (W14's lab tv --no-note synthetic, NSE:NIFTY 15; replay tools in the lane scratch, lane feed ca2cb44a, no daily feed installed): w14-htf-w-nifty15, 742 sampled orders, requested "W" bar_index / time: engine 74491fa: 189 / 25 wrong; this commit: 0 / 0 (codegen main a060268 and cg/int5 1435ed0 alike). Open / close stay W14 mechanism A (TradingView's W bar is NSE's official daily OHLC; with the lane's daily feed installed both trees are 742/742 exact). Test: tests/test_calendar_bucket_closes_once.cpp (kernel-only): the Budget week with and without the next bar, the 2025 Saturday session, a daily input, a bare host's "W" subscription delivering the week once, and the controls (a regular week, January ending on the Friday before the Sunday, the daily buckets) completing where they did before. Fail-before (compiled against 74491fa's headers and library): "FAIL [W, Sunday session, next bar known] ... done.size() == 2 / completions: 27", the same for the next-bar-unknown, Saturday, daily-input and bare-host cases; "52 checks, 5 failures". After: "71 checks, 0 failures". Census (the kernel's aggregator over every exchange lane's registry chart feed, D/W/M/30/60/120/240 with the next bar, base vs this tree): AAPL, F, ES1!, NQ1!, EURUSD, XAUUSD 15 and 1D, BTCUSDT/ETHUSDT.P 1D identical; NSE:NIFTY moves only its weekend and evening sessions -- the weekly bucket of 2023-11-12, 2024-01-20, 03-02, 05-18, 2025-02-01, 2024-11-01 and 2026-02-01 completes once on the session's last bar, and the daily bucket of the four evening Muhurat sessions (2021-2024) once on its last bar. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> * A late-opening day's intraday grid starts at its own open, dated by the installed daily feed (W15-KERNEL-CAL B) The intraday higher-timeframe grid is anchored at the symbol's day stamp: 09:15 IST on NSE, so a "60" series buckets at 09:15, 10:15 .. 15:15 every day. NSE's Muhurat session of Tue 2025-10-21 traded 13:45 .. 14:45 IST only. TradingView laid that day's grid from the session's own open: one "60" bar stamped 13:45 (o 25904, h 25934.35, l 25826.3, c 25833.3), completed on the 14:30 chart bar, and the day's D bar is stamped 13:45 too (lab tv w14-htf-60-nifty15, w14-htf-d-nifty15, W14's synthetic tapes). The kernel's grid made two bars (13:15, 14:15), so the requested "60" bar_index ran one ahead from 10-21 14:00 to the end of the feed, and prathambaldawa3's 60m EMA200 filter drifted off TradingView's and opened an extra short on 2025-12-08 (W14 mechanism B). No session template holds that session; the venue's own daily bars do. The design takes the data source W14 named first -- the installed daily feed's stamps -- over a dated session-corrections input in the run spec: the daily feed is already a kernel input with a ruled contract (the authoritative-feed store), its stamps are the venue's own data, and the alternative would add hash-visible spec surface plus a special-session calendar every host would have to curate. Mechanism: - native_late_day_opens (timeframe.hpp/.cpp): the daily stamps that open their session-day late -- after the day stamp, before that day's scheduled close, with no input bar of the day before them. A stamp at the day stamp (every regular day), on an earlier session-day (a holiday-merged bar), at or after the scheduled close (a venue dating its bars at midnight or at the close; an evening session outside the template) or on a day the input shows trading earlier is not one. - intraday_grid_clock_ms: from such an open to the end of its session-day the grid clock moves back by the open's offset past the grid point at or below it, so the open is a bucket boundary for any width ("60", and "75", which does not divide the day) and the move, under one width, keeps the keys monotonic across the open; every other instant, and a day whose open already sits on the grid ("15", "30", "45"), reads the old clock exactly. - TimeframeAggregator::set_native_day_opens: a RATIO aggregator's buckets, labels, bucket_open_ms and period_changes (so the Pine host's lookahead projection too) read its own opens; CALENDAR / count-only ignore them. - the feed store's new rule (d) (prepare_native_security_feeds) installs the opens of the installed daily feed on every intraday evaluator, the kernel-routed subscriptions and a bare host's "D" authoritative bars alike; - NativeDayPartition::late_opens carries the same opens for the chart partition's readers, session_intraday_bucket_open_ms and tf_change's intraday form (time("60"), timeframe.change("60")), so the language runtime and request.security keep one grid. ADR-0001 (rule 2), row two of "Wave W15 KERNEL-CAL": - mechanism: above; - generic: a second venue is driven by installing its own daily bars; the kernel keeps no special-session calendar and branches on no platform; - no knob: the policy knob is the authoritative-feed ruling's, installing the daily feed or not; a grid-anchor field would restate the stamps. docs/pages/native-engine.md lists the rule with the feed store's others. Tapes (W14's lab tv --no-note synthetic, NSE:NIFTY 15, lane feeds ca2cb44a chart / b57ebb7b daily installed as the native "D" feed): - w14-htf-60-nifty15, 742 sampled orders, requested "60" bar_index / time / o / h / l / c: engine 74491fa 419 / 6 / 6 / 6 / 2 / 2 wrong; this commit 0 / 0 / 0 / 0 / 0 / 0 (codegen main a060268 and cg/int5 1435ed0). - w14-htf-60ema-nifty15 (171 trades): "60" bar_index 178 wrong -> 0 on both codegens; the EMA200 178 wrong -> 0 with cg/int5 (main keeps its own EMA-seeding difference, CG-CHART-EMA-SEED). - w15-time60-nifty15 (this lane's lab tv --no-note synthetic, same chart and range, 27 trades / 54 orders, pine 5b6ec32f, trades cba91626): the chart's own time("60") / timeframe.change("60") on every bar of 10-20, 10-21 and 10-23 are 13:45 and true on the 13:45 bar alone; with the daily feed installed engine 74491fa is 4 / 1 wrong, this commit 0 / 0. (time_close("60") keeps a separate, older difference on 2 bars: TradingView clips a day's last hour at the 15:30 close.) - Without the daily feed nothing moves: the 60 tape keeps 419 (the lab passes the feed to "D"-requesting sources only; see the lane report). Probe counterfactual (CGINT5's cg/int5 TU, local run): prathambaldawa3 NSE:NIFTY 15 with the lane's daily feed: 528/528 of TradingView's rows (74491fa: 530 rows, the extra 2025-12-08 08:30Z short); without the feed unchanged. Test: tests/test_intraday_grid_late_day_open.cpp (kernel-only): which stamps open a day late; the "60" aggregator with and without the opens (one bucket stamped 13:45 on the 14:30 bar, every regular day's bucket unchanged); "75" (a width that does not divide the day: one bucket from the open, its label mapping onto itself, every other day unchanged); a finer feed that printed before the open (one bucket, monotonic keys); the chart partition's grid readers; a bare host's "60" series with "D" authoritative bars. Fail-before: compiled against 74491fa's headers it stops at the first missing symbol, "error: use of undeclared identifier 'native_late_day_opens'". A first cut shifted the whole day by the open's offset past the day stamp, which split a "75" day into singletons (an independent review caught it): against that library the "75" and pre-open rows fail, "101 checks, 7 failures". After: "103 checks, 0 failures". Census (the kernel's aggregator over every exchange lane's registry chart feed with its daily feed, 30/60/120/240): the only late open in the registry is NSE:NIFTY 2025-10-21 13:45; its 60 buckets become one and the 120/240 buckets' stamp moves 13:15 -> 13:45; every other lane and day is identical. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> * Re-pin the doc anchors and the ctest floors for W15-KERNEL-CAL (C and B) on INT29 Done once, on the tree rebased onto engine main 9e6196c (INT29), for both items: - ctest floors (scripts/ci_verify.py), for the two source-free rows test_calendar_bucket_closes_once (C) and test_intraday_grid_late_day_open (B), which register in every profile: KERNEL_MIN_TESTS 296 -> 298, RELEASE_MIN_TESTS 759 -> 761 and EXCLUDED_REGISTERED_MIN debug / sanitizers / native 740 / 740 / 749 -> 742 / 742 / 751; each floor's comment names them, and scripts/test_ci_verify.py's pin of EXCLUDED_REGISTERED_MIN (test_pr_exclusion_proves_registered_minus_ labelled_equals_ran) moves with it, as INT29's did. - doc anchors: the lines C and B insert in src/timeframe.cpp, include/pineforge/timeframe.hpp and src/engine_aux_security.cpp, and the floor comments in scripts/ci_verify.py, moved 29 citations. check_doc_anchors.py --fix took the unambiguous ones and scripts/reanchor_doc_citations.py --ref 9e6196c the line-mapped ones, the sha256-claimed comment spans among them (content unchanged). Set by hand: the six citations of the two floor constants in CONTRIBUTING.md and contributing-llm.md, the HT2 hash span on native-feature-parity.md, and the lane's own ADR-0001 rows (Wave W15 KERNEL-CAL), whose commits carried their own trees' digits. check_doc_anchors.py: every documentation anchor resolves; check_doc_lint.py clean. No hash, fixture or test assertion moves: no existing test changes. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> --------- Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
1 parent 9e6196c commit 7239ab3

14 files changed

Lines changed: 1174 additions & 46 deletions

‎CONTRIBUTING.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,8 @@ What each gate refuses:
152152
### The floors
153153

154154
`ci_verify.py` counts the CTest rows that actually **ran** and fails below a
155-
floor — `KERNEL_MIN_TESTS` ci_verify.py:306 and `RELEASE_MIN_TESTS`
156-
ci_verify.py:527.
155+
floor — `KERNEL_MIN_TESTS` ci_verify.py:313 and `RELEASE_MIN_TESTS`
156+
ci_verify.py:537.
157157
A deleted or silently skipped row is a failure, not a quieter run. If your
158158
change adds rows, raise the floor in the same commit and say by how much; if it
159159
legitimately removes one, lower it deliberately and say why. `--min-tests`

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

Lines changed: 17 additions & 7 deletions
Large diffs are not rendered by default.

‎docs/design/native-feature-parity.md‎

Lines changed: 6 additions & 6 deletions
Large diffs are not rendered by default.

‎docs/native-refactor-progress.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ repository and were never pushed.
184184
| A checked-values handoff for executions (L3) | `execution_values` runs twice, in `check_execution` (`src/native_order.cpp:4791`) and again in `apply_execution` (`src/native_order.cpp:4805`); handing the checked values across needs a public type, an API addition with no layout change | L3, as above: 2.21 % of bracket for the two together, about 1.1 % recoverable | L3 ruling 2: "a public checked-values handoff for executions (~1.1% bracket) -> DEFERRED" | As above | An owner decision on the API addition |
185185
| A chunked `trades_` store (L3) | Closed trades in chunks rather than one vector; `trades_` (`include/pineforge/engine.hpp:546`) is protected `BacktestEngine` state, so script ABI | L3, as above: on bracket, vector growth 0.64 %, `Trade` moves 0.74 % and `record_close_trade` 0.43 % (at most about 1.4 %); at most 0.35 % on the 14 probes | L3 ruling 4: "chunked trades_ store (ABI) -> DEFERRED" | As above | An `engine_script_run` epoch that changes the engine's protected layout |
186186
| A zoned chart-day memo (D2-D finding 4) | On a chart with a timezone, `libc_chart_day_key` (`src/source/pine_adapter.cpp:14425`) takes the process timezone lock through `ScopedTimezone` and calls `localtime_r` on every bar, because `on_bar_open` (`src/source/pine_adapter.cpp:17567`) reads `chart_day_key` (`src/source/pine_adapter.cpp:17730`) unconditionally. The non-UTC monthly Sharpe/Sortino walk, `month_key_local` (`src/engine_metrics.cpp:33`), pays one `localtime_r` per equity point. UTC charts use D2-D's memo, `civil_chart_day_key` (`src/source/pine_adapter.cpp:14409`) | Not measured on a zoned chart. The UTC path cost 134 instructions a bar before D2-D's memo and 68 after (D2-D, spark, callgrind on the floor). PERF-K1: `ScopedTimezone` copies the zone name, which allocates for names of 16 or more characters under libstdc++ | TRIAGE1 §D: "D2-D finding 4 (the timezone `localtime_r` memo)", under the owner's cap. D2-D's report: an exact zoned memo "would need the zone's transition table, which belongs in `timezone.cpp`" | None; the UTC memo's witness is `tests/test_chart_day_memo.cpp` | A lane that owns `src/timezone.cpp` and builds an exact zone-transition memo (PERF-K1's Sitka case shows why a shortcut is not exact), byte-identical, with the zoned keys of `test_chart_day_memo` still equal to the computed ones |
187-
| Thread-local reads that remain per call | D2-C moved the three scopes' writes onto the pump's block, `pump_ambient` (`src/native_execution_consumer.hpp:444`). A reader still reaches the block through `tl_runtime_ambient` (`src/ta_extremes_volume.cpp:29`): `bar_context` (`src/ta_extremes_volume.cpp:82`), read by every `ExtremeRing::update` (`src/ta_extremes_volume.cpp:117`), which backs `ta.highest`, `ta.lowest`, `ta.highestbars` and `ta.lowestbars` and, through an embedded `Highest` and `Lowest`, `ta.stoch`, `ta.wpr` and `ta.range`; and `matching_day_partition` (`src/timeframe.cpp:559`), read by the default-anchored `ta.vwap` through `session_day_index`, by `crosses_boundary` on a DAY period (`timeframe.change("D")`) and by the session-period helpers. `decompose_ms_local` (`src/session_time.cpp:250`) reads two thread-locals per call on a zoned clock, and the prepared order storage's `free_blocks` (`src/native_order.cpp:605`) one per prepared mutation. `ema_na_warmup_flag` is read once per EMA, at its first compute | One thread-local access per reader call. AUDIT4, macOS arm64, a dlopen'd tutorial-MACD probe, counted by `_tlv_get_addr` breakpoints and by descriptor patching: 1.000 a bar for one `ta::Highest` and for one default `ta::VWAP`, 1.999 for one `pine_hour` on a New York clock, 0.000 on the no-order floor and with orders. On Linux a TLS-descriptor call costs about 20 instructions: D2-C's 13 → 4 calls a bar was 260 → 80 instructions (spark aarch64, GCC 13, callgrind). INT23: 2.00 a bar on the zoned probe 064, 0.08 on probe 008 | None for the TA and day-partition readers: "RULING: INT23 ACCEPTED" (ledger, 2026-09-24 23:30 UTC) reads "dlopen TLS 13->0/bar", and INT23's report names only the timezone and order-core residuals. This row is their record | `$EV/exec/AUDIT4-opus-scratch/perf/tls/` | A byte-identical lane that hands these readers the pump's block without a thread-local read. `ta::bar_context()` is script ABI, so its public declaration stays as it is |
187+
| Thread-local reads that remain per call | D2-C moved the three scopes' writes onto the pump's block, `pump_ambient` (`src/native_execution_consumer.hpp:444`). A reader still reaches the block through `tl_runtime_ambient` (`src/ta_extremes_volume.cpp:29`): `bar_context` (`src/ta_extremes_volume.cpp:82`), read by every `ExtremeRing::update` (`src/ta_extremes_volume.cpp:117`), which backs `ta.highest`, `ta.lowest`, `ta.highestbars` and `ta.lowestbars` and, through an embedded `Highest` and `Lowest`, `ta.stoch`, `ta.wpr` and `ta.range`; and `matching_day_partition` (`src/timeframe.cpp:605`), read by the default-anchored `ta.vwap` through `session_day_index`, by `crosses_boundary` on a DAY period (`timeframe.change("D")`) and by the session-period helpers. `decompose_ms_local` (`src/session_time.cpp:250`) reads two thread-locals per call on a zoned clock, and the prepared order storage's `free_blocks` (`src/native_order.cpp:605`) one per prepared mutation. `ema_na_warmup_flag` is read once per EMA, at its first compute | One thread-local access per reader call. AUDIT4, macOS arm64, a dlopen'd tutorial-MACD probe, counted by `_tlv_get_addr` breakpoints and by descriptor patching: 1.000 a bar for one `ta::Highest` and for one default `ta::VWAP`, 1.999 for one `pine_hour` on a New York clock, 0.000 on the no-order floor and with orders. On Linux a TLS-descriptor call costs about 20 instructions: D2-C's 13 → 4 calls a bar was 260 → 80 instructions (spark aarch64, GCC 13, callgrind). INT23: 2.00 a bar on the zoned probe 064, 0.08 on probe 008 | None for the TA and day-partition readers: "RULING: INT23 ACCEPTED" (ledger, 2026-09-24 23:30 UTC) reads "dlopen TLS 13->0/bar", and INT23's report names only the timezone and order-core residuals. This row is their record | `$EV/exec/AUDIT4-opus-scratch/perf/tls/` | A byte-identical lane that hands these readers the pump's block without a thread-local read. `ta::bar_context()` is script ABI, so its public declaration stays as it is |
188188
| "audit-off mode", "LTO", "data-oriented layout" | Named in "OWNER DECISION 2026-09-25 00:20 Taipei" among the post-release structural items: "S1 bulk quiet bars, S2 per-strategy specialization, audit-off mode, LTO+PGO, data-oriented layout". No engine or campaign document defines, designs or measures the three | None | The owner decision | None | Struck from this inventory until a design note defines one of them |
189189

190190
### Recorded witness drift

‎docs/pages/contributing-llm.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@ finding to report, not a step to take.
117117
`scripts/check_doc_reverts.py`.
118118

119119
10. **A test row never silently disappears.** Each profile counts the rows that
120-
*ran* against a floor: `KERNEL_MIN_TESTS` ci_verify.py:306 and
121-
`RELEASE_MIN_TESTS` ci_verify.py:527. Adding rows means raising the floor
120+
*ran* against a floor: `KERNEL_MIN_TESTS` ci_verify.py:313 and
121+
`RELEASE_MIN_TESTS` ci_verify.py:537. Adding rows means raising the floor
122122
in the same commit.
123123

124124
## The recipe for a lane
@@ -264,7 +264,7 @@ measurement that produced it, so a later change to it is visible as a change to
264264
the record, not as an edit to a literal.
265265

266266
**floor** — the minimum number of CTest rows a profile must actually run
267-
(`KERNEL_MIN_TESTS` ci_verify.py:306, `RELEASE_MIN_TESTS` ci_verify.py:527). It
267+
(`KERNEL_MIN_TESTS` ci_verify.py:313, `RELEASE_MIN_TESTS` ci_verify.py:537). It
268268
counts rows that ran, so a skipped row does not pad it.
269269

270270
**receipt** — the recorded evidence an ABI-comparison row needs (a prepared

‎docs/pages/native-engine.md‎

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2560,11 +2560,18 @@ TradingView-calibrated, and a host that supplies them inherits its rules:
25602560
and a data hole inside a stamped period is not a close.
25612561
- A period the supplied bars only partly cover yields a partial bucket,
25622562
exactly as a partly covered chart would.
2563+
- The installed **daily** bars also date where each day opened. A daily
2564+
stamp later than its session-day's day stamp and before its scheduled
2565+
close, with no input bar of that day before it, is a day that traded late,
2566+
and an intraday series lays that day's grid from the stamp: NSE's Muhurat
2567+
session of 2025-10-21 opens 13:45 IST, so its `"60"` bucket is one bar
2568+
stamped 13:45, not 13:15 and 14:15 from the 09:15 day stamp. Every other
2569+
day keeps the day-stamp grid.
25632570

25642571
Declare no `authoritative_bars` and the buckets are a plain aggregation of the
25652572
run's own input, with no calibration to inherit. That is the whole policy
25662573
knob, and it is a ruling of record (ADR-0001, "What the kernel-only archive
2567-
still names"): the three rules above follow from "the supplied
2574+
still names"): the rules above follow from "the supplied
25682575
bars are the venue's own bars of that timeframe", so the kernel gates them on
25692576
the feed's presence rather than on a separate partition field.
25702577

@@ -2576,6 +2583,16 @@ the continuous-session classes `"forex"`, `"cfd"` and `"crypto"`, whose period
25762583
completes on the next session's first bar instead. The vocabulary is the one
25772584
the C ABI's `strategy_set_syminfo_type` fixes.
25782585

2586+
Every calendar series also closes each bucket **once**, and not while the next
2587+
input bar the run holds still belongs to its period. A session template that
2588+
knows Monday to Friday ends a week at Friday's close; an exchange that trades a
2589+
weekend session inside that week (NSE's Budget-day Sunday of 2026-02-01) keeps
2590+
the week open until that session's last bar, where the series advances one
2591+
bucket. A bar with no known successor -- a stream, the feed's last bar --
2592+
keeps the template's rule, and a later bar of an already closed period merges
2593+
into it without completing it again. Pinned by
2594+
`tests/test_calendar_bucket_closes_once.cpp`.
2595+
25792596
**Declaring at begin.** A host whose series are known only to its own
25802597
begin-time registration calls
25812598
`declare_timeframe_subscriptions(std::vector<NativeTimeframeSubscription>)`
@@ -3010,7 +3027,7 @@ each feed's key, sha256 and bar count in the run provenance.
30103027

30113028
A host that wants only the running aggregate — no series instance, no
30123029
`gaps`/`lookahead` rule, nothing folded into the continuation identity —
3013-
aggregates the input itself. `TimeframeAggregator` (`timeframe.hpp:288`) is
3030+
aggregates the input itself. `TimeframeAggregator` (`timeframe.hpp:321`) is
30143031
public and engine-free; feed it from `on_native_input`, which runs once per
30153032
accepted confirmed input bar before that bar is aggregated or matched
30163033
(`on_native_input` `native_host.hpp:875`). Include
@@ -3052,7 +3069,7 @@ and not a way to register a series: registration is
30523069
`NativeRunSpec::subscriptions` or `declare_timeframe_subscriptions`. In-run the
30533070
setter is a source mutation and **throws**, latching `Failed`
30543071
(`UnsupportedSource`) through `guard_native_mutation`
3055-
(`engine_aux_security.cpp:78`, `guard_native_mutation` `engine_consumer.cpp:42`).
3072+
(`engine_aux_security.cpp:82`, `guard_native_mutation` `engine_consumer.cpp:42`).
30563073
30573074
## Batch OHLCV vs ticks vs quiet
30583075

‎include/pineforge/timeframe.hpp‎

Lines changed: 62 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,10 @@ int64_t session_period_open_ms(int64_t ms, const std::string& tz,
162162
/// time("60") on NYSE:F is 09:30 / 10:30 / .. / 15:30 ET, time("240") on
163163
/// NSE:NIFTY 09:15 / 13:15 IST, on OANDA:XAUUSD 17:00 ET + 4h*k). With
164164
/// tz="UTC" and session ""/"24x7" it is the epoch grid, bit-identical to
165-
/// the tz-less forms. bucket_sec <= 0 returns `ms`.
165+
/// the tz-less forms. bucket_sec <= 0 returns `ms`. Under the calling
166+
/// thread's native daily partition for this clock (below), a session-day
167+
/// that opened late -- NativeDayPartition::late_opens -- starts its grid at
168+
/// its own open instead of the day stamp, as tf_change's intraday form does.
166169
int64_t session_intraday_bucket_open_ms(int64_t ms, int64_t bucket_sec,
167170
const std::string& tz,
168171
const std::string& session);
@@ -228,6 +231,17 @@ int64_t session_period_last_traded_close_ms(int64_t ms, const std::string& tz,
228231
// session-day close, keeps the nominal rules. Without an installed partition
229232
// (no native daily feed, a 1D chart, another symbol's clock) every function
230233
// is bit-identical to the nominal session calendar.
234+
//
235+
// The stamps also date where a day OPENED. A stamp later than its
236+
// session-day's day stamp, with no input bar of that session-day before it,
237+
// is the open of a day that traded late (native_late_day_opens), and that
238+
// day's intraday grid starts there: session_intraday_bucket_open_ms and
239+
// tf_change's intraday form read the partition's late_opens, as a request
240+
// evaluator's RATIO aggregator reads the same opens from the daily feed
241+
// (TimeframeAggregator::set_native_day_opens). NSE's Muhurat session of
242+
// 2025-10-21 opens 13:45 IST, and its one 60-minute bar is stamped 13:45
243+
// on TradingView, not 13:15 and 14:15 from the 09:15 day stamp (lab tv
244+
// w14-htf-60-nifty15).
231245
struct NativeDayPartition {
232246
std::string tz;
233247
std::string session;
@@ -236,9 +250,28 @@ struct NativeDayPartition {
236250
std::vector<int64_t> week_open; // per stamp: the W group's first stamp
237251
std::vector<int64_t> month_open; // per stamp: the M group's first stamp
238252
int64_t last_bound = 0; // nominal session-day close of the last stamp
253+
std::vector<int64_t> late_opens; // the stamps that open their session-day late
239254
bool empty() const { return stamps.empty(); }
240255
};
241256

257+
/// The native daily stamps that open their session-day LATE: a stamp after
258+
/// the day stamp of the (nominal) session-day holding it and before that
259+
/// day's scheduled close, with no input bar between the day stamp and the
260+
/// stamp -- the day's first trade is the stamp itself, hours after the
261+
/// session template's open (NSE's Muhurat session of 2025-10-21, 13:45 IST).
262+
/// Every other stamp is left out: one at its day stamp (every regular day),
263+
/// one on an earlier session-day (a holiday-merged bar), one at or after
264+
/// its session-day's scheduled close (a venue dating its daily bars at
265+
/// midnight or at the close; an evening session the template does not
266+
/// hold, 18:00 IST on 2024-11-01, whose end it cannot know either), and one
267+
/// the input shows the day already trading before. Strictly increasing, as
268+
/// the stamps; empty for non-increasing stamps. `input_bars` may be null
269+
/// (n_input 0): nothing then contradicts a late stamp.
270+
std::vector<int64_t> native_late_day_opens(const std::string& tz,
271+
const std::string& session,
272+
const std::vector<int64_t>& stamps,
273+
const Bar* input_bars, int n_input);
274+
242275
/// Build the partition for the symbol clock (tz, session) from the native
243276
/// daily stamps and the chart's input bars (the trade instants: the last
244277
/// input bar before the next stamp, bounded by the last stamp's nominal
@@ -419,7 +452,27 @@ class TimeframeAggregator {
419452
void set_native_periods(std::vector<int64_t> stamps,
420453
std::vector<int64_t> trade_instants,
421454
CalendarPeriod feed_period);
422-
bool has_native_periods() const { return !native_stamps_.empty(); }
455+
456+
/// A RATIO aggregator's late day opens, from the installed native daily
457+
/// feed (native_late_day_opens over the evaluator's input): each opens a
458+
/// session-day that traded later than its day stamp, and the intraday
459+
/// grid of that session-day starts at it instead of the stamp -- the
460+
/// keys feed() splits on, bucket_open_ms and bar_label_ms alike. NSE's
461+
/// Muhurat session of 2025-10-21 (13:45 IST, four 15m bars) is one "60"
462+
/// bucket stamped 13:45, where the 09:15 day stamp made two (13:15, 14:15)
463+
/// and the bucket index ran one ahead for the rest of the feed (lab tv
464+
/// w14-htf-60-nifty15, w14-htf-60ema-nifty15). Every other session-day
465+
/// keeps the day-stamp grid bit for bit. Empty (the default) changes
466+
/// nothing; CALENDAR / PASSTHROUGH and a count-only ratio ignore the
467+
/// call; non-increasing opens install nothing.
468+
void set_native_day_opens(std::vector<int64_t> late_opens);
469+
470+
/// Whether an installed native daily feed keys this aggregator's
471+
/// buckets: its period partition (CALENDAR, set_native_periods) or late
472+
/// day opens (RATIO, set_native_day_opens).
473+
bool has_native_periods() const {
474+
return !native_stamps_.empty() || !native_late_opens_.empty();
475+
}
423476

424477
/// Whether a session ending BEFORE its nominal close completes the
425478
/// running D/W/M bucket on that session's actual last input bar
@@ -453,7 +506,9 @@ class TimeframeAggregator {
453506
/// CALENDAR: whether `prev_ms` and `curr_ms` lie in different periods
454507
/// of this aggregator -- different native periods / W-M groups when
455508
/// native periods are installed, crosses_boundary on the nominal
456-
/// session calendar otherwise. RATIO / PASSTHROUGH: false.
509+
/// session calendar otherwise. RATIO with late day opens installed:
510+
/// whether they lie in different buckets (bucket_open_ms). Any other
511+
/// RATIO, and PASSTHROUGH: false.
457512
bool period_changes(int64_t prev_ms, int64_t curr_ms) const;
458513

459514
/// Open (Unix ms) of the target-TF bucket an input bar stamped `ms`
@@ -462,7 +517,8 @@ class TimeframeAggregator {
462517
/// forex week opens Sunday 17:00 ET, its month on the session whose
463518
/// close date is the 1st); RATIO -> session_intraday_bucket_open_ms,
464519
/// the day-stamp-anchored grid bucket (the same key feed() splits on
465-
/// and time("<intraday tf>") reads); PASSTHROUGH, or a
520+
/// and time("<intraday tf>") reads), from its own late day opens
521+
/// (set_native_day_opens) rather than a thread's partition; PASSTHROUGH, or a
466522
/// count-only ratio with no wall-clock width, -> `ms` itself. Pure
467523
/// function of the configuration: it neither reads nor advances the
468524
/// aggregation state, so callers may query it before feeding the bar.
@@ -499,6 +555,8 @@ class TimeframeAggregator {
499555
std::vector<int64_t> native_stamps_;
500556
std::vector<int64_t> native_group_open_;
501557
int64_t native_last_bound_ = 0; // nominal close of the last stamp's period
558+
// RATIO: the late day opens the grid starts from (set_native_day_opens).
559+
std::vector<int64_t> native_late_opens_;
502560
// set_early_close_completes: the next-input-bar completion applies.
503561
bool early_close_completes_ = true;
504562

0 commit comments

Comments
 (0)