From d42ba8b34190c609d364b46bcb0b81471842c5f2 Mon Sep 17 00:00:00 2001 From: Studio Date: Fri, 27 Nov 2026 20:00:02 -0500 Subject: [PATCH] =?UTF-8?q?T-72:=20M1.2d=20=E2=80=94=20`tools/curate-etl`:?= =?UTF-8?q?=20pure=20`bars=5F1d`=20builder=20(un-adjust=20`eodPrices`=20vo?= =?UTF-8?q?lume=20via=20`SplitTable`=20+=20`qmPrices.sharevolume`=20cross-?= =?UTF-8?q?check)=20with=20local=20benchmark=20(no=20new=20crates)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tools/curate-etl/src/bars.rs | 2 ++ tools/curate-etl/tests/bars_contract.rs | 46 ++++++++++++++++++++++--- 2 files changed, 44 insertions(+), 4 deletions(-) diff --git a/tools/curate-etl/src/bars.rs b/tools/curate-etl/src/bars.rs index 2586d5fc..fc512b28 100644 --- a/tools/curate-etl/src/bars.rs +++ b/tools/curate-etl/src/bars.rs @@ -321,6 +321,8 @@ where } } stats.rows_out = rows.len(); + // Free the validated EOD buffer before allocating/sorting QM partners to cut peak RAM. + drop(valid_bars); // Filter, sort, and compact QM raw-volume partners. let qm_iter = qm_volumes.into_iter(); diff --git a/tools/curate-etl/tests/bars_contract.rs b/tools/curate-etl/tests/bars_contract.rs index 971e84e3..862a471b 100644 --- a/tools/curate-etl/tests/bars_contract.rs +++ b/tools/curate-etl/tests/bars_contract.rs @@ -215,18 +215,56 @@ fn shuffled_permutations_and_mismatch_cap_are_bitwise_deterministic() { let mut bars = Vec::new(); let mut qms = Vec::new(); + let mut expected_mismatches = Vec::new(); + // Create 140 mismatched rows with a deliberate 6-way rel tie straddling the 100-sample cutoff: + // - 98 rows with strictly higher rel (> 3.0) + // - 6 rows with identical rel == 3.0 (volumes 2000 vs share_volume 500) across keys 1..=4 + // so only the earliest 2 by (key ASC, session_date ASC) should survive the 100-sample cap + // - 36 rows with strictly lower rel (< 3.0, > 0.01) for i in 0..140_i32 { let key = (i % 4) + 1; let d = base + i; - let vol = 1000.0 + (i as f64) * 50.0; - bars.push(bar(key, d, 10.0, 11.0, 9.0, 10.5, vol)); - // Intentional mismatch for every row so we exceed MAX_MISMATCH_SAMPLES. - qms.push(qm(key, d, 500.0)); + let factor = splits.cum_factor_after(&key, d); + let target_raw_vol = if i < 98 { + 2500.0 + (i as f64) * 50.0 // rel >= 4.0 + } else if i < 104 { + 2000.0 // exact 6-way tie: rel == 3.0 + } else { + 600.0 + ((i - 104) as f64) * 20.0 // rel in [0.2, 1.6] + }; + let adj_vol = target_raw_vol * factor; + let share_vol = 500.0; + bars.push(bar(key, d, 10.0, 11.0, 9.0, 10.5, adj_vol)); + qms.push(qm(key, d, share_vol)); + + let unadj_vol = unadjust_volume(adj_vol, factor); + let rel = (unadj_vol - share_vol).abs() / share_vol; + expected_mismatches.push(curate_etl::VolumeMismatchSample { + key, + session_date: d, + volume: unadj_vol, + share_volume: share_vol, + rel, + }); } + expected_mismatches.sort_by(|a, b| { + b.rel + .total_cmp(&a.rel) + .then_with(|| a.key.cmp(&b.key)) + .then_with(|| a.session_date.cmp(&b.session_date)) + }); + assert_eq!( + expected_mismatches[MAX_MISMATCH_SAMPLES - 1].rel, + expected_mismatches[MAX_MISMATCH_SAMPLES].rel, + "fixture must have a tie straddling the MAX_MISMATCH_SAMPLES cutoff" + ); + expected_mismatches.truncate(MAX_MISMATCH_SAMPLES); + let baseline = build_bars_1d(bars.clone(), &splits, qms.clone(), 0.01).expect("valid build"); assert_accounting(&baseline.stats); assert_eq!(baseline.mismatch_samples.len(), MAX_MISMATCH_SAMPLES); + assert_eq!(baseline.mismatch_samples, expected_mismatches); for w in baseline.mismatch_samples.windows(2) { let ord = w[1] .rel