T-70: M1.2c — tools/curate-etl: pure corporate_actions builder (splits + dividends + OTC continuation / Shumway terminal delisting rows) with local benchmark (no new crates)
This commit is contained in:
parent
88625d6b70
commit
722fdea615
4 changed files with 85 additions and 6 deletions
|
|
@ -158,7 +158,7 @@ pub fn run_adj_benchmark(events: usize) -> Result<AdjBenchReport, AdjError> {
|
|||
let mut dividends: Vec<(i32, DividendEvent)> = Vec::with_capacity(events);
|
||||
|
||||
for _ in 0..events {
|
||||
let key = ((rng.next_u64() as usize) % BENCH_KEY_COUNT) as i32 + 1;
|
||||
let key = (rng.next_u64() % (BENCH_KEY_COUNT as u64)) as i32 + 1;
|
||||
let ex_date = min_date + (rng.next_u64() % date_span) as i32;
|
||||
let kind_roll = rng.next_u64() % 100;
|
||||
|
||||
|
|
@ -167,7 +167,7 @@ pub fn run_adj_benchmark(events: usize) -> Result<AdjBenchReport, AdjError> {
|
|||
let ratio = if ratio_roll == 0 {
|
||||
1.0
|
||||
} else {
|
||||
SAMPLE_RATIOS[(rng.next_u64() as usize) % SAMPLE_RATIOS.len()]
|
||||
SAMPLE_RATIOS[(rng.next_u64() % (SAMPLE_RATIOS.len() as u64)) as usize]
|
||||
};
|
||||
splits.push((key, SplitEvent { ex_date, ratio }));
|
||||
} else {
|
||||
|
|
@ -283,7 +283,7 @@ pub fn run_corporate_actions_benchmark(
|
|||
let mut delistings: Vec<(i32, DelistingOutcomeEvent<i32>)> = Vec::with_capacity(events / 20);
|
||||
|
||||
for _ in 0..events {
|
||||
let key = ((rng.next_u64() as usize) % BENCH_KEY_COUNT) as i32 + 1;
|
||||
let key = (rng.next_u64() % (BENCH_KEY_COUNT as u64)) as i32 + 1;
|
||||
let ex_date = min_date + (rng.next_u64() % date_span) as i32;
|
||||
let kind_roll = rng.next_u64() % 100;
|
||||
|
||||
|
|
@ -292,7 +292,7 @@ pub fn run_corporate_actions_benchmark(
|
|||
let ratio = if ratio_roll == 0 {
|
||||
1.0
|
||||
} else {
|
||||
SAMPLE_RATIOS[(rng.next_u64() as usize) % SAMPLE_RATIOS.len()]
|
||||
SAMPLE_RATIOS[(rng.next_u64() % (SAMPLE_RATIOS.len() as u64)) as usize]
|
||||
};
|
||||
let decl_roll = rng.next_u64() % 100;
|
||||
let declared_date = if decl_roll < 30 {
|
||||
|
|
|
|||
|
|
@ -107,7 +107,11 @@ pub struct DividendActionEvent {
|
|||
/// Input delisting outcome event (mirrors Pass 6 output) for [`build_corporate_actions`].
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct DelistingOutcomeEvent<K = String> {
|
||||
/// Effective delisting date as days since 1970-01-01 (UTC Gregorian).
|
||||
/// Effective date as days since 1970-01-01 (UTC Gregorian).
|
||||
///
|
||||
/// For OTC continuation transfers (`successor_key = Some(_)`), callers must pass the Pass 6
|
||||
/// continuity `effectiveDate` (the successor's first observed OTC trading date), not the
|
||||
/// primary listing's last exchange print / halt date.
|
||||
pub delist_date: i32,
|
||||
/// OTC continuation successor key (e.g. `SIVB` -> `SIVBQ`), mutually exclusive with `terminal_return`.
|
||||
pub successor_key: Option<K>,
|
||||
|
|
@ -944,6 +948,41 @@ mod tests {
|
|||
assert!(!err.to_string().is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn otc_transfer_carries_pass6_effective_date_not_primary_end_date() {
|
||||
// SIVB halted on Nasdaq on 2023-03-10 (primary listing end), then began quoting OTC as
|
||||
// SIVBQ on 2023-03-28 (Pass 6 continuity `effectiveDate`). The transfer row must carry
|
||||
// the successor's first OTC date so SIVBQ is never published as active before Mar 28.
|
||||
let primary_end = ymd_to_epoch_days(2023, 3, 10).unwrap();
|
||||
let otc_start = ymd_to_epoch_days(2023, 3, 28).unwrap();
|
||||
assert!(primary_end < otc_start);
|
||||
|
||||
let built = build_corporate_actions(
|
||||
empty_splits(),
|
||||
empty_dividends(),
|
||||
[(
|
||||
"SIVB".to_string(),
|
||||
DelistingOutcomeEvent {
|
||||
delist_date: otc_start,
|
||||
successor_key: Some("SIVBQ".to_string()),
|
||||
terminal_return: None,
|
||||
},
|
||||
)],
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
assert_stats_conservation(&built);
|
||||
assert_eq!(built.rows.len(), 1);
|
||||
let row = &built.rows[0];
|
||||
assert_eq!(row.kind, CorporateActionKind::OtcDelistTransfer);
|
||||
assert_eq!(row.successor_key.as_deref(), Some("SIVBQ"));
|
||||
assert_eq!(row.ex_date, otc_start);
|
||||
assert_eq!(row.known_at_date, otc_start);
|
||||
assert_ne!(row.ex_date, primary_end);
|
||||
assert_ne!(row.known_at_date, primary_end);
|
||||
assert_eq!(row.known_at_source, KnownAtSource::DelistDate);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn shuffled_mixed_fixture_is_bit_deterministic_and_conserves_stats() {
|
||||
let d1 = ymd_to_epoch_days(2023, 3, 28).unwrap();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue