T-179: M2.3k — tools/curate-etl: bounded-memory file-to-file bars_1m runner (run_curate_bars_1m.rs: raw eodIntraday1M BSON dump + qmSplits dump + provider_mapping.tsv → chunked curate_and_write_bars_1m → per-shard ILP v2 output files) with tests (no new crates, no CLI/bench changes, no live Mongo/QuestDB)
This commit is contained in:
parent
0c39b7dfb6
commit
b017c78dda
1 changed files with 74 additions and 44 deletions
|
|
@ -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<Bar1mRow<i32>> = 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]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue