From b017c78dda7ce49b398d986652a8d3d31edcfab8 Mon Sep 17 00:00:00 2001 From: Studio Date: Wed, 2 Dec 2026 18:16:40 -0500 Subject: [PATCH] =?UTF-8?q?T-179:=20M2.3k=20=E2=80=94=20`tools/curate-etl`?= =?UTF-8?q?:=20bounded-memory=20file-to-file=20`bars=5F1m`=20runner=20(`ru?= =?UTF-8?q?n=5Fcurate=5Fbars=5F1m.rs`:=20raw=20`eodIntraday1M`=20BSON=20du?= =?UTF-8?q?mp=20+=20`qmSplits`=20dump=20+=20`provider=5Fmapping.tsv`=20?= =?UTF-8?q?=E2=86=92=20chunked=20`curate=5Fand=5Fwrite=5Fbars=5F1m`=20?= =?UTF-8?q?=E2=86=92=20per-shard=20ILP=20v2=20output=20files)=20with=20tes?= =?UTF-8?q?ts=20(no=20new=20crates,=20no=20CLI/bench=20changes,=20no=20liv?= =?UTF-8?q?e=20Mongo/QuestDB)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/run_curate_bars_1m_tests.rs | 118 +++++++++++------- 1 file changed, 74 insertions(+), 44 deletions(-) diff --git a/tools/curate-etl/src/run_curate_bars_1m_tests.rs b/tools/curate-etl/src/run_curate_bars_1m_tests.rs index ea33bdee..3465a8dd 100644 --- a/tools/curate-etl/src/run_curate_bars_1m_tests.rs +++ b/tools/curate-etl/src/run_curate_bars_1m_tests.rs @@ -376,25 +376,28 @@ fn assert_report_conservation(report: &CurateBars1mRunReport) { /// Split-boundary replay fixture (`run_curate_bars_1m_tests::split_boundary_nvda_and_nexm_match_raw_bars_1d_closes`): /// -/// Provenance & unavailable-evidence note: -/// - Offline synthetic BSON inputs pinned to the empirical split-boundary figures documented in -/// `design/DATA-CONTRACTS.md` §1 (lines 13, 15, 25) and `tools/curate-etl/src/curate_bars_1m_tests.rs`: -/// - `NVDA.US` (`listing_id=1001`, `eod: NVDA.US`, `qm: NVDA`, 10:1 forward split ex-date -/// `2024-06-10`, `forfactor=1, tofactor=10, splitratio=0.1`): -/// - `2024-06-07` (pre-split): adj 1m close `120.888`, adj vol `412_390.0` -> raw `1208.88`, -/// vol `41_239.0`; raw `bars_1d` close baseline `1208.88` (`DATA-CONTRACTS.md` §1 line 13). -/// - `2024-06-10` (ex-date): 1m close `121.79`, vol `350_000.0` (unchanged); raw `bars_1d` -/// close baseline `121.79`. -/// - `NEXM.V` (`listing_id=2002`, `eod: NEXM.V`, `qm: NEXM:VNX`, 1:20 reverse split ex-date -/// `2025-06-18`, `forfactor=20, tofactor=1, splitratio=20.0`): -/// - `2025-06-17` (pre-split): adj 1m close `24.29`, adj vol `5_000.0` -> raw `1.2145`, -/// vol `100_000.0`; raw `bars_1d` close baseline `1.215` (~0.041% rel diff, matching -/// `24.29` vs `~1.21` in `DATA-CONTRACTS.md` §1 line 15). -/// - `2025-06-18` (ex-date): 1m close `24.30`, vol `12_500.0` (unchanged); raw `bars_1d` -/// close baseline `24.30`. -/// - Live QA MongoDB extracts (`stock.eodIntraday1M`, `stock.qmSplits`) and curated `bars_1d` -/// Parquet baselines are not committed in this repository and are unavailable in the offline -/// sandbox; independent live-extract comparison remains for the live-host verification follow-up. +/// SYNTHETIC fixture built from the figures in `REVIEW.md:88` and `design/DATA-CONTRACTS.md` §1 +/// (lines 13, 15, 25): +/// - `NVDA.US` (`listing_id=1001`, `eod: NVDA.US`, `qm: NVDA`, 10:1 forward split ex-date +/// `2024-06-10`, `forfactor=1, tofactor=10, splitratio=0.1`): +/// - `2024-06-07` (pre-split): adj 1m close `120.888`, adj vol `412_390.0` -> raw `1208.88`, +/// vol `41_239.0`; synthetic daily baseline `1208.88`. +/// - `2024-06-10` (ex-date): 1m close `121.79`, vol `350_000.0` (unchanged); synthetic daily +/// baseline `121.79`. +/// - `NEXM.V` (`listing_id=2002`, `eod: NEXM.V`, `qm: NEXM:CA`, 1:20 reverse split ex-date +/// `2025-06-20`, `forfactor=20, tofactor=1, splitratio=20.0`, aligned to `REVIEW.md:88`): +/// - `2025-06-18` (pre-split): adj 1m close `24.29`, adj vol `5_000.0` -> raw `1.2145`, +/// vol `100_000.0`; synthetic daily baseline `1.215` (~0.041% rel diff, matching `~1.21`). +/// - `2025-06-19` (intervening pre-split session): adj 1m close `24.40`, adj vol `4_000.0` -> +/// raw `1.22`, vol `80_000.0`; synthetic daily baseline `1.22`. +/// - `2025-06-20` (ex-date): 1m close `24.28` (`REVIEW.md:88` records `24.2799`), vol `12_500.0` +/// (unchanged); synthetic daily baseline `24.28`. +/// +/// Scope of this test: +/// - Proves split arithmetic, listing resolution, and ex-date boundary handling in the runner. +/// - Does NOT prove provider mapping, ex-date, or RTH close against retained `bars_1d` data. +/// - Open item: M2 exit criterion 3 observed-data split-boundary check (NEXM.V, NVDA.US vs +/// retained raw `bars_1d` closes) — open, owned by the live-host `bars_1m` load verification task. #[test] fn split_boundary_nvda_and_nexm_match_raw_bars_1d_closes() { let dir = TempDirGuard::new("bars1m-split"); @@ -408,15 +411,15 @@ fn split_boundary_nvda_and_nexm_match_raw_bars_1d_closes() { &format!("eod\tNVDA.US\t2020-01-01\t\t{nvda_id}"), &format!("qm\tNVDA\t2020-01-01\t\t{nvda_id}"), &format!("eod\tNEXM.V\t2020-01-01\t\t{nexm_id}"), - &format!("qm\tNEXM:VNX\t2020-01-01\t\t{nexm_id}"), + &format!("qm\tNEXM:CA\t2020-01-01\t\t{nexm_id}"), ], ); let splits_bytes = concat_docs(&[ // NVDA 10:1 forward split on 2024-06-10 (QM: forfactor=1, tofactor=10, splitratio=0.1 -> ratio=10.0) make_split_doc("NVDA", "2024-06-10", 1.0, 10.0), - // NEXM.V 1:20 reverse split on 2025-06-18 (QM: forfactor=20, tofactor=1, splitratio=20.0 -> ratio=0.05) - make_split_doc("NEXM:VNX", "2025-06-18", 20.0, 1.0), + // NEXM.V / NEXM:CA 1:20 reverse split on 2025-06-20 (QM: forfactor=20, tofactor=1, splitratio=20.0 -> ratio=0.05) + make_split_doc("NEXM:CA", "2025-06-20", 20.0, 1.0), ]); let intraday_bytes = concat_docs(&[ @@ -449,7 +452,7 @@ fn split_boundary_nvda_and_nexm_match_raw_bars_1d_closes() { ), make_intraday_doc( "NEXM.V", - et_ts_sec(2025, 6, 17, 9, 30), + et_ts_sec(2025, 6, 18, 9, 30), 24.00, 24.60, 23.80, @@ -458,7 +461,7 @@ fn split_boundary_nvda_and_nexm_match_raw_bars_1d_closes() { ), make_intraday_doc( "NEXM.V", - et_ts_sec(2025, 6, 17, 15, 59), + et_ts_sec(2025, 6, 18, 15, 59), 24.20, 24.40, 24.10, @@ -467,11 +470,20 @@ fn split_boundary_nvda_and_nexm_match_raw_bars_1d_closes() { ), make_intraday_doc( "NEXM.V", - et_ts_sec(2025, 6, 18, 15, 59), + et_ts_sec(2025, 6, 19, 15, 59), + 24.30, + 24.50, + 24.10, + 24.40, + 4_000.0, + ), + make_intraday_doc( + "NEXM.V", + et_ts_sec(2025, 6, 20, 15, 59), 24.10, 24.50, 23.90, - 24.30, + 24.28, 12_500.0, ), ]); @@ -500,18 +512,19 @@ fn split_boundary_nvda_and_nexm_match_raw_bars_1d_closes() { .expect("split-boundary run should succeed"); assert_report_conservation(&report); - assert_eq!(report.rows_written, 6); + assert_eq!(report.rows_written, 7); assert_eq!(report.split_rekey.splits_applied, 2); let mut decoded = decode_ilp_bars_1m(&sink0); decoded.extend(decode_ilp_bars_1m(&sink1)); - assert_eq!(decoded.len(), 6); + assert_eq!(decoded.len(), 7); for row in &decoded { assert_eq!(row.known_at, known_at_micros); assert_eq!(row.source, BARS_1M_SOURCE_EOD); } - // Verify inverse volume scaling on pre-split bars and unchanged OHLCV on ex-date bars. + // Verify inverse volume scaling on pre-split bars (including intervening session 2025-06-19) + // and unchanged OHLCV on ex-date bars. let find_row = |id: i32, ts_sec: i64| -> &DecodedIlpBar1m { decoded .iter() @@ -530,18 +543,25 @@ fn split_boundary_nvda_and_nexm_match_raw_bars_1d_closes() { assert_eq!(nvda_ex.close.to_bits(), 121.79_f64.to_bits()); assert_eq!(nvda_ex.volume.to_bits(), 350_000.0_f64.to_bits()); - let nexm_pre = find_row(nexm_id, et_ts_sec(2025, 6, 17, 15, 59)); - assert!((nexm_pre.close - 1.2145).abs() < 1e-9); - assert!((nexm_pre.volume - 100_000.0).abs() < 1e-9); + let nexm_pre_18 = find_row(nexm_id, et_ts_sec(2025, 6, 18, 15, 59)); + assert!((nexm_pre_18.close - 1.2145).abs() < 1e-9); + assert!((nexm_pre_18.volume - 100_000.0).abs() < 1e-9); - let nexm_ex = find_row(nexm_id, et_ts_sec(2025, 6, 18, 15, 59)); + let nexm_pre_19 = find_row(nexm_id, et_ts_sec(2025, 6, 19, 15, 59)); + assert!((nexm_pre_19.open - 1.215).abs() < 1e-9); + assert!((nexm_pre_19.high - 1.225).abs() < 1e-9); + assert!((nexm_pre_19.low - 1.205).abs() < 1e-9); + assert!((nexm_pre_19.close - 1.22).abs() < 1e-9); + assert!((nexm_pre_19.volume - 80_000.0).abs() < 1e-9); + + let nexm_ex = find_row(nexm_id, et_ts_sec(2025, 6, 20, 15, 59)); assert_eq!(nexm_ex.open.to_bits(), 24.10_f64.to_bits()); assert_eq!(nexm_ex.high.to_bits(), 24.50_f64.to_bits()); assert_eq!(nexm_ex.low.to_bits(), 23.90_f64.to_bits()); - assert_eq!(nexm_ex.close.to_bits(), 24.30_f64.to_bits()); + assert_eq!(nexm_ex.close.to_bits(), 24.28_f64.to_bits()); assert_eq!(nexm_ex.volume.to_bits(), 12_500.0_f64.to_bits()); - // Check all four RTH session closes against raw daily baselines within 0.5%. + // Check all five synthetic RTH session closes against synthetic daily baselines within 0.5%. let mut rows_1m: Vec> = decoded.iter().map(DecodedIlpBar1m::to_bar_1m_row).collect(); rows_1m.sort_by_key(|r| (r.key, r.ts)); @@ -566,20 +586,29 @@ fn split_boundary_nvda_and_nexm_match_raw_bars_1d_closes() { }, Bar1dRow { key: nexm_id, - session_date: day(2025, 6, 17), + session_date: day(2025, 6, 18), open: 1.20, high: 1.23, low: 1.19, - close: 1.215, // ~0.041% rel diff vs 1.2145 (DATA-CONTRACTS.md §1: ~1.21 raw) + close: 1.215, // ~0.041% rel diff vs 1.2145 (REVIEW.md:88 / DATA-CONTRACTS.md §1: ~1.21 raw) volume: 100_000.0, }, Bar1dRow { key: nexm_id, - session_date: day(2025, 6, 18), + session_date: day(2025, 6, 19), + open: 1.215, + high: 1.225, + low: 1.205, + close: 1.22, + volume: 80_000.0, + }, + Bar1dRow { + key: nexm_id, + session_date: day(2025, 6, 20), open: 24.10, high: 24.50, low: 23.90, - close: 24.30, + close: 24.28, volume: 12_500.0, }, ]; @@ -591,13 +620,14 @@ fn split_boundary_nvda_and_nexm_match_raw_bars_1d_closes() { 0.005, ) .expect("session close check should succeed"); - assert_eq!(check.stats.checked, 4); - assert_eq!(check.stats.within_tolerance, 4); + assert_eq!(check.stats.checked, 5); + assert_eq!(check.stats.within_tolerance, 5); assert_eq!(check.stats.mismatched, 0); assert!(check.stats.max_rel_diff < 0.005); // Negative control: omitting qmSplits leaves pre-split bars retroactively adjusted and fails - // the 0.5% check on both pre-split sessions (NVDA 2024-06-07 and NEXM 2025-06-17). + // the 0.5% check on all three pre-split sessions (NVDA 2024-06-07, NEXM 2025-06-18, and + // intervening NEXM 2025-06-19). let mut neg_sink = Vec::new(); let neg_writer = IlpShardedWriter::new(vec![&mut neg_sink], IlpWriterOptions::default()).unwrap(); @@ -629,9 +659,9 @@ fn split_boundary_nvda_and_nexm_match_raw_bars_1d_closes() { 0.005, ) .expect("negative-control close check should succeed"); - assert_eq!(neg_check.stats.checked, 4); + assert_eq!(neg_check.stats.checked, 5); assert_eq!(neg_check.stats.within_tolerance, 2); - assert_eq!(neg_check.stats.mismatched, 2); + assert_eq!(neg_check.stats.mismatched, 3); } #[test]