T-72: M1.2d — tools/curate-etl: pure bars_1d builder (un-adjust eodPrices volume via SplitTable + qmPrices.sharevolume cross-check) with local benchmark (no new crates)
This commit is contained in:
parent
be6be46920
commit
d42ba8b341
2 changed files with 44 additions and 4 deletions
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue