T-169: tests
This commit is contained in:
parent
1332d2c9b0
commit
f24dc4260d
1 changed files with 598 additions and 48 deletions
|
|
@ -114,7 +114,14 @@ fn obs(
|
|||
}
|
||||
}
|
||||
|
||||
fn sample_fields(rev: f64, ni: f64, ocf: f64, assets: f64, equity: f64, shares: f64) -> FundamentalsFields {
|
||||
fn sample_fields(
|
||||
rev: f64,
|
||||
ni: f64,
|
||||
ocf: f64,
|
||||
assets: f64,
|
||||
equity: f64,
|
||||
shares: f64,
|
||||
) -> FundamentalsFields {
|
||||
FundamentalsFields {
|
||||
revenue: Some(rev),
|
||||
net_income: Some(ni),
|
||||
|
|
@ -148,7 +155,9 @@ fn assert_stage_conservation(stats: &CurateFundamentalsStats) {
|
|||
+ stats.build.observations_dropped_unknown_key
|
||||
+ stats.build.observations_dropped_non_finite
|
||||
+ stats.build.observations_dropped_date_out_of_range
|
||||
+ stats.build.observations_dropped_report_date_not_after_period_end
|
||||
+ stats
|
||||
.build
|
||||
.observations_dropped_report_date_not_after_period_end
|
||||
+ stats.build.observations_dropped_unanchored_vintage
|
||||
+ stats.build.observations_dropped_stale_estimate
|
||||
+ stats.build.duplicate_collapsed
|
||||
|
|
@ -498,7 +507,9 @@ fn read_parquet_rows_by_name(path: &Path) -> Vec<DecodedParquetRow> {
|
|||
}
|
||||
|
||||
fn decoded_from_curated(row: &FundamentalsPitParquetRow) -> DecodedParquetRow {
|
||||
let latest = row.latest_period().expect("curated row must have latest_period");
|
||||
let latest = row
|
||||
.latest_period()
|
||||
.expect("curated row must have latest_period");
|
||||
DecodedParquetRow {
|
||||
listing_id: row.listing_id,
|
||||
effective_known_at: row.effective_known_at_micros,
|
||||
|
|
@ -525,14 +536,9 @@ fn decoded_from_curated(row: &FundamentalsPitParquetRow) -> DecodedParquetRow {
|
|||
|
||||
#[test]
|
||||
fn restatement_after_q2_preserves_prior_snapshots_and_never_displaces_q2() {
|
||||
let mapping = ProviderMappingTable::from_rows([mapping_row(
|
||||
"qm",
|
||||
"ACME",
|
||||
day(2024, 1, 1),
|
||||
None,
|
||||
1001,
|
||||
)])
|
||||
.expect("valid mapping");
|
||||
let mapping =
|
||||
ProviderMappingTable::from_rows([mapping_row("qm", "ACME", day(2024, 1, 1), None, 1001)])
|
||||
.expect("valid mapping");
|
||||
let venues = BTreeMap::from([(1001, StatutoryLagVenue::UsTsx)]);
|
||||
|
||||
let q1_end = day(2024, 3, 31);
|
||||
|
|
@ -645,7 +651,14 @@ fn statutory_lag_deadlines_and_filing_timestamp_provenance() {
|
|||
|
||||
// 1. UsTsx quarterly (+45d -> 2024-05-15 16:05 EDT = 20:05 UTC)
|
||||
let us_q = curate_fundamentals(
|
||||
[obs("US_CO", q_end, FiscalPeriod::Quarterly, "USD", None, fields)],
|
||||
[obs(
|
||||
"US_CO",
|
||||
q_end,
|
||||
FiscalPeriod::Quarterly,
|
||||
"USD",
|
||||
None,
|
||||
fields,
|
||||
)],
|
||||
Vec::<QmFiling<String>>::new(),
|
||||
"qm",
|
||||
&mapping,
|
||||
|
|
@ -657,12 +670,22 @@ fn statutory_lag_deadlines_and_filing_timestamp_provenance() {
|
|||
let expected_us_q = et_to_utc_micros(q_end + 45, 16, 5, 0).expect("us q et");
|
||||
assert_eq!(expected_us_q, utc_micros(2024, 5, 15, 20, 5, 0));
|
||||
assert_eq!(us_q.rows[0].effective_known_at_micros, expected_us_q);
|
||||
assert_eq!(us_q.rows[0].known_at_source.as_ref(), KNOWN_AT_SOURCE_STATUTORY_LAG);
|
||||
assert_eq!(
|
||||
us_q.rows[0].known_at_source.as_ref(),
|
||||
KNOWN_AT_SOURCE_STATUTORY_LAG
|
||||
);
|
||||
assert!(us_q.rows[0].has_estimated_lag);
|
||||
|
||||
// 2. UsTsx annual (+90d -> 2025-03-31 16:05 EDT = 20:05 UTC)
|
||||
let us_fy = curate_fundamentals(
|
||||
[obs("US_CO", fy_end, FiscalPeriod::Annual, "USD", None, fields)],
|
||||
[obs(
|
||||
"US_CO",
|
||||
fy_end,
|
||||
FiscalPeriod::Annual,
|
||||
"USD",
|
||||
None,
|
||||
fields,
|
||||
)],
|
||||
Vec::<QmFiling<String>>::new(),
|
||||
"qm",
|
||||
&mapping,
|
||||
|
|
@ -674,12 +697,22 @@ fn statutory_lag_deadlines_and_filing_timestamp_provenance() {
|
|||
let expected_us_fy = et_to_utc_micros(fy_end + 90, 16, 5, 0).expect("us fy et");
|
||||
assert_eq!(expected_us_fy, utc_micros(2025, 3, 31, 20, 5, 0));
|
||||
assert_eq!(us_fy.rows[0].effective_known_at_micros, expected_us_fy);
|
||||
assert_eq!(us_fy.rows[0].known_at_source.as_ref(), KNOWN_AT_SOURCE_STATUTORY_LAG);
|
||||
assert_eq!(
|
||||
us_fy.rows[0].known_at_source.as_ref(),
|
||||
KNOWN_AT_SOURCE_STATUTORY_LAG
|
||||
);
|
||||
assert!(us_fy.rows[0].has_estimated_lag);
|
||||
|
||||
// 3. TsxvCse quarterly (+60d -> 2024-05-30 16:05 EDT = 20:05 UTC)
|
||||
let tsxv_q = curate_fundamentals(
|
||||
[obs("TSXV_CO", q_end, FiscalPeriod::Quarterly, "CAD", None, fields)],
|
||||
[obs(
|
||||
"TSXV_CO",
|
||||
q_end,
|
||||
FiscalPeriod::Quarterly,
|
||||
"CAD",
|
||||
None,
|
||||
fields,
|
||||
)],
|
||||
Vec::<QmFiling<String>>::new(),
|
||||
"qm",
|
||||
&mapping,
|
||||
|
|
@ -699,7 +732,14 @@ fn statutory_lag_deadlines_and_filing_timestamp_provenance() {
|
|||
|
||||
// 4. TsxvCse annual (+120d -> 2025-04-30 16:05 EDT = 20:05 UTC)
|
||||
let tsxv_fy = curate_fundamentals(
|
||||
[obs("TSXV_CO", fy_end, FiscalPeriod::Annual, "CAD", None, fields)],
|
||||
[obs(
|
||||
"TSXV_CO",
|
||||
fy_end,
|
||||
FiscalPeriod::Annual,
|
||||
"CAD",
|
||||
None,
|
||||
fields,
|
||||
)],
|
||||
Vec::<QmFiling<String>>::new(),
|
||||
"qm",
|
||||
&mapping,
|
||||
|
|
@ -765,10 +805,38 @@ fn ticker_remap_across_utc_midnight_separates_listings_and_prevents_cross_listin
|
|||
// 2023-08-05 (listing 101), whereas UTC date is 2023-08-06 (listing 202).
|
||||
// Listing 202 gets Q3 (2023-09-30) and Q4 (2023-12-31).
|
||||
let observations = vec![
|
||||
obs("REUSED", day(2023, 3, 31), FiscalPeriod::Quarterly, "USD", Some(day(2023, 5, 10)), f),
|
||||
obs("REUSED", day(2023, 6, 30), FiscalPeriod::Quarterly, "USD", Some(day(2023, 8, 5)), f),
|
||||
obs("REUSED", day(2023, 9, 30), FiscalPeriod::Quarterly, "USD", Some(day(2023, 11, 8)), f),
|
||||
obs("REUSED", day(2023, 12, 31), FiscalPeriod::Quarterly, "USD", Some(day(2024, 2, 12)), f),
|
||||
obs(
|
||||
"REUSED",
|
||||
day(2023, 3, 31),
|
||||
FiscalPeriod::Quarterly,
|
||||
"USD",
|
||||
Some(day(2023, 5, 10)),
|
||||
f,
|
||||
),
|
||||
obs(
|
||||
"REUSED",
|
||||
day(2023, 6, 30),
|
||||
FiscalPeriod::Quarterly,
|
||||
"USD",
|
||||
Some(day(2023, 8, 5)),
|
||||
f,
|
||||
),
|
||||
obs(
|
||||
"REUSED",
|
||||
day(2023, 9, 30),
|
||||
FiscalPeriod::Quarterly,
|
||||
"USD",
|
||||
Some(day(2023, 11, 8)),
|
||||
f,
|
||||
),
|
||||
obs(
|
||||
"REUSED",
|
||||
day(2023, 12, 31),
|
||||
FiscalPeriod::Quarterly,
|
||||
"USD",
|
||||
Some(day(2024, 2, 12)),
|
||||
f,
|
||||
),
|
||||
];
|
||||
let filings = vec![
|
||||
filing("REUSED", "2023-05-10T16:00:00 EDT", "10-Q"),
|
||||
|
|
@ -926,13 +994,42 @@ fn permutation_invariance_and_strict_ascending_order() {
|
|||
let f3 = sample_fields(20.0, 3.0, 4.0, 60.0, 30.0, 6.0);
|
||||
|
||||
let base_obs = vec![
|
||||
obs("ALPHA", day(2024, 3, 31), FiscalPeriod::Quarterly, "CAD", Some(day(2024, 5, 1)), f1),
|
||||
obs("ALPHA", day(2024, 6, 30), FiscalPeriod::Quarterly, "CAD", Some(day(2024, 8, 1)), f2),
|
||||
obs("BETA", day(2024, 3, 31), FiscalPeriod::Quarterly, "USD", Some(day(2024, 5, 1)), f3),
|
||||
obs(
|
||||
"ALPHA",
|
||||
day(2024, 3, 31),
|
||||
FiscalPeriod::Quarterly,
|
||||
"CAD",
|
||||
Some(day(2024, 5, 1)),
|
||||
f1,
|
||||
),
|
||||
obs(
|
||||
"ALPHA",
|
||||
day(2024, 6, 30),
|
||||
FiscalPeriod::Quarterly,
|
||||
"CAD",
|
||||
Some(day(2024, 8, 1)),
|
||||
f2,
|
||||
),
|
||||
obs(
|
||||
"BETA",
|
||||
day(2024, 3, 31),
|
||||
FiscalPeriod::Quarterly,
|
||||
"USD",
|
||||
Some(day(2024, 5, 1)),
|
||||
f3,
|
||||
),
|
||||
];
|
||||
let base_filings = vec![
|
||||
filing("ALPHA", "2024-05-01T16:00:00 EDT", "Interim financial statements"),
|
||||
filing("ALPHA", "2024-08-01T16:00:00 EDT", "Interim financial statements"),
|
||||
filing(
|
||||
"ALPHA",
|
||||
"2024-05-01T16:00:00 EDT",
|
||||
"Interim financial statements",
|
||||
),
|
||||
filing(
|
||||
"ALPHA",
|
||||
"2024-08-01T16:00:00 EDT",
|
||||
"Interim financial statements",
|
||||
),
|
||||
// Same-instant filing for BETA
|
||||
filing("BETA", "2024-05-01T16:00:00 EDT", "10-Q"),
|
||||
];
|
||||
|
|
@ -979,14 +1076,9 @@ fn permutation_invariance_and_strict_ascending_order() {
|
|||
|
||||
#[test]
|
||||
fn typed_errors_and_untouched_out_dir_on_curation_failure() {
|
||||
let mapping = ProviderMappingTable::from_rows([mapping_row(
|
||||
"qm",
|
||||
"ACME",
|
||||
day(2024, 1, 1),
|
||||
None,
|
||||
10,
|
||||
)])
|
||||
.expect("valid mapping");
|
||||
let mapping =
|
||||
ProviderMappingTable::from_rows([mapping_row("qm", "ACME", day(2024, 1, 1), None, 10)])
|
||||
.expect("valid mapping");
|
||||
let venues = BTreeMap::from([(10, StatutoryLagVenue::UsTsx)]);
|
||||
let invalid_writer_opts = FundamentalsPitWriteOptions {
|
||||
row_group_rows: 0,
|
||||
|
|
@ -1024,7 +1116,9 @@ fn typed_errors_and_untouched_out_dir_on_curation_failure() {
|
|||
CurateFundamentalsWriteError::Curate(CurateFundamentalsError::EmptyMappingSource)
|
||||
));
|
||||
assert!(write_err.source().is_some());
|
||||
assert!(write_err.to_string().contains("fundamentals curation failed"));
|
||||
assert!(write_err
|
||||
.to_string()
|
||||
.contains("fundamentals curation failed"));
|
||||
assert!(
|
||||
!tmp.path().join("fundamentals_pit").exists(),
|
||||
"out_dir must remain untouched on curation failure"
|
||||
|
|
@ -1072,14 +1166,9 @@ fn typed_errors_and_untouched_out_dir_on_curation_failure() {
|
|||
|
||||
#[test]
|
||||
fn curate_and_write_fundamentals_round_trips_four_quarters_and_ttm_by_column_name() {
|
||||
let mapping = ProviderMappingTable::from_rows([mapping_row(
|
||||
"qm",
|
||||
"GROW",
|
||||
day(2023, 1, 1),
|
||||
None,
|
||||
777,
|
||||
)])
|
||||
.expect("valid mapping");
|
||||
let mapping =
|
||||
ProviderMappingTable::from_rows([mapping_row("qm", "GROW", day(2023, 1, 1), None, 777)])
|
||||
.expect("valid mapping");
|
||||
let venues = BTreeMap::from([(777, StatutoryLagVenue::UsTsx)]);
|
||||
|
||||
let q1_f = sample_fields(100.0, 10.0, 15.0, 500.0, 200.0, 10.0);
|
||||
|
|
@ -1088,10 +1177,38 @@ fn curate_and_write_fundamentals_round_trips_four_quarters_and_ttm_by_column_nam
|
|||
let q4_f = sample_fields(140.0, 16.0, 22.0, 575.0, 242.0, 10.0);
|
||||
|
||||
let observations = vec![
|
||||
obs("GROW", day(2023, 3, 31), FiscalPeriod::Quarterly, "USD", Some(day(2023, 5, 1)), q1_f),
|
||||
obs("GROW", day(2023, 6, 30), FiscalPeriod::Quarterly, "USD", Some(day(2023, 8, 1)), q2_f),
|
||||
obs("GROW", day(2023, 9, 30), FiscalPeriod::Quarterly, "USD", Some(day(2023, 11, 1)), q3_f),
|
||||
obs("GROW", day(2023, 12, 31), FiscalPeriod::Quarterly, "USD", Some(day(2024, 2, 15)), q4_f),
|
||||
obs(
|
||||
"GROW",
|
||||
day(2023, 3, 31),
|
||||
FiscalPeriod::Quarterly,
|
||||
"USD",
|
||||
Some(day(2023, 5, 1)),
|
||||
q1_f,
|
||||
),
|
||||
obs(
|
||||
"GROW",
|
||||
day(2023, 6, 30),
|
||||
FiscalPeriod::Quarterly,
|
||||
"USD",
|
||||
Some(day(2023, 8, 1)),
|
||||
q2_f,
|
||||
),
|
||||
obs(
|
||||
"GROW",
|
||||
day(2023, 9, 30),
|
||||
FiscalPeriod::Quarterly,
|
||||
"USD",
|
||||
Some(day(2023, 11, 1)),
|
||||
q3_f,
|
||||
),
|
||||
obs(
|
||||
"GROW",
|
||||
day(2023, 12, 31),
|
||||
FiscalPeriod::Quarterly,
|
||||
"USD",
|
||||
Some(day(2024, 2, 15)),
|
||||
q4_f,
|
||||
),
|
||||
];
|
||||
let filings = vec![
|
||||
filing("GROW", "2023-05-01T16:10:00 EDT", "10-Q"),
|
||||
|
|
@ -1156,7 +1273,11 @@ fn curate_and_write_fundamentals_round_trips_four_quarters_and_ttm_by_column_nam
|
|||
.join("fundamentals_pit")
|
||||
.join(format!("year={year}"))
|
||||
.join("part.parquet");
|
||||
assert!(part_path.exists(), "missing partition {}", part_path.display());
|
||||
assert!(
|
||||
part_path.exists(),
|
||||
"missing partition {}",
|
||||
part_path.display()
|
||||
);
|
||||
let part_rows = read_parquet_rows_by_name(&part_path);
|
||||
for row in &part_rows {
|
||||
assert_eq!(partition_year_utc(row.effective_known_at), year);
|
||||
|
|
@ -1167,3 +1288,432 @@ fn curate_and_write_fundamentals_round_trips_four_quarters_and_ttm_by_column_nam
|
|||
let expected: Vec<DecodedParquetRow> = curated.rows.iter().map(decoded_from_curated).collect();
|
||||
assert_eq!(read_back, expected);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// QA additions (T-169): amendment TTM propagation, UTC-year partitioning, Eastern-date filing
|
||||
// resolution, builder venue misses, cutoff-truncation PIT replay, and empty input.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
fn grow_four_quarters() -> (Vec<FinancialObservation<String>>, Vec<QmFiling<String>>) {
|
||||
let observations = vec![
|
||||
obs(
|
||||
"GROW",
|
||||
day(2023, 3, 31),
|
||||
FiscalPeriod::Quarterly,
|
||||
"USD",
|
||||
Some(day(2023, 5, 1)),
|
||||
sample_fields(100.0, 10.0, 15.0, 500.0, 200.0, 10.0),
|
||||
),
|
||||
obs(
|
||||
"GROW",
|
||||
day(2023, 6, 30),
|
||||
FiscalPeriod::Quarterly,
|
||||
"USD",
|
||||
Some(day(2023, 8, 1)),
|
||||
sample_fields(110.0, 12.0, 18.0, 520.0, 212.0, 10.0),
|
||||
),
|
||||
obs(
|
||||
"GROW",
|
||||
day(2023, 9, 30),
|
||||
FiscalPeriod::Quarterly,
|
||||
"USD",
|
||||
Some(day(2023, 11, 1)),
|
||||
sample_fields(125.0, 14.0, 20.0, 545.0, 226.0, 10.0),
|
||||
),
|
||||
obs(
|
||||
"GROW",
|
||||
day(2023, 12, 31),
|
||||
FiscalPeriod::Quarterly,
|
||||
"USD",
|
||||
Some(day(2024, 2, 15)),
|
||||
sample_fields(140.0, 16.0, 22.0, 575.0, 242.0, 10.0),
|
||||
),
|
||||
];
|
||||
let filings = vec![
|
||||
filing("GROW", "2023-05-01T16:10:00 EDT", "10-Q"),
|
||||
filing("GROW", "2023-08-01T16:10:00 EDT", "10-Q"),
|
||||
filing("GROW", "2023-11-01T16:10:00 EDT", "10-Q"),
|
||||
filing("GROW", "2024-02-15T16:10:00 EST", "10-Q"),
|
||||
];
|
||||
(observations, filings)
|
||||
}
|
||||
|
||||
fn grow_mapping() -> (ProviderMappingTable, BTreeMap<i32, StatutoryLagVenue>) {
|
||||
let mapping =
|
||||
ProviderMappingTable::from_rows([mapping_row("qm", "GROW", day(2023, 1, 1), None, 777)])
|
||||
.expect("valid mapping");
|
||||
(mapping, BTreeMap::from([(777, StatutoryLagVenue::UsTsx)]))
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn q1_amendment_after_q4_first_changes_ttm_at_its_filing_instant_and_keeps_q4_latest() {
|
||||
let (mapping, venues) = grow_mapping();
|
||||
let (observations, filings) = grow_four_quarters();
|
||||
|
||||
let baseline = curate_fundamentals(
|
||||
observations.clone(),
|
||||
filings.clone(),
|
||||
"qm",
|
||||
&mapping,
|
||||
&venues,
|
||||
4,
|
||||
)
|
||||
.expect("baseline");
|
||||
assert_eq!(baseline.rows.len(), 4);
|
||||
let baseline_ttm = baseline.rows[3].ttm.clone().expect("baseline ttm");
|
||||
assert_eq!(baseline_ttm.flows.revenue, Some(475.0));
|
||||
|
||||
let mut revised_obs = observations;
|
||||
revised_obs.push(obs(
|
||||
"GROW",
|
||||
day(2023, 3, 31),
|
||||
FiscalPeriod::Quarterly,
|
||||
"USD",
|
||||
Some(day(2024, 3, 20)),
|
||||
sample_fields(80.0, 4.0, 9.0, 480.0, 190.0, 10.0),
|
||||
));
|
||||
let mut revised_filings = filings;
|
||||
revised_filings.push(filing("GROW", "2024-03-20T17:45:00 EDT", "10-Q/A"));
|
||||
|
||||
let revised = curate_fundamentals(revised_obs, revised_filings, "qm", &mapping, &venues, 4)
|
||||
.expect("revised");
|
||||
assert_stage_conservation(&revised.stats);
|
||||
assert_eq!(revised.rows.len(), 5);
|
||||
|
||||
// Every pre-amendment snapshot is unchanged (no look-back leak of the restated Q1).
|
||||
assert_eq!(&revised.rows[..4], &baseline.rows[..]);
|
||||
|
||||
let amend_at = utc_micros(2024, 3, 20, 21, 45, 0);
|
||||
let amended = &revised.rows[4];
|
||||
assert_eq!(amended.effective_known_at_micros, amend_at);
|
||||
assert_eq!(
|
||||
amended.known_at_source.as_ref(),
|
||||
KNOWN_AT_SOURCE_FILING_TIMESTAMP
|
||||
);
|
||||
|
||||
// Latest period stays Q4 with Q4's fields and Q4's original availability.
|
||||
let latest = amended.latest_period().expect("latest");
|
||||
assert_eq!(latest.period_end, day(2023, 12, 31));
|
||||
assert_eq!(
|
||||
latest.fields,
|
||||
sample_fields(140.0, 16.0, 22.0, 575.0, 242.0, 10.0)
|
||||
);
|
||||
assert_eq!(
|
||||
latest.period_known_at_micros,
|
||||
utc_micros(2024, 2, 15, 21, 10, 0)
|
||||
);
|
||||
|
||||
// The TTM total first reflects the restated Q1 at the amendment instant.
|
||||
let ttm = amended.ttm.as_ref().expect("amended ttm");
|
||||
assert_eq!(ttm.ending_period_end, day(2023, 12, 31));
|
||||
assert_eq!(ttm.flows.revenue, Some(80.0 + 110.0 + 125.0 + 140.0));
|
||||
assert_eq!(ttm.flows.net_income, Some(4.0 + 12.0 + 14.0 + 16.0));
|
||||
assert_eq!(
|
||||
ttm.flows.operating_cash_flow,
|
||||
Some(9.0 + 18.0 + 20.0 + 22.0)
|
||||
);
|
||||
assert_ne!(ttm.flows, baseline_ttm.flows);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn late_december_eastern_filing_partitions_into_next_utc_year() {
|
||||
// Listing 900 is valid through 2023-12-31 ET only; a 21:00 EST filing on Dec 31 is
|
||||
// 2024-01-01T02:00Z, so it must resolve on the Eastern date but partition by UTC year.
|
||||
let mapping = ProviderMappingTable::from_rows([mapping_row(
|
||||
"qm",
|
||||
"NYE",
|
||||
day(2023, 1, 1),
|
||||
Some(day(2023, 12, 31)),
|
||||
900,
|
||||
)])
|
||||
.expect("valid mapping");
|
||||
let venues = BTreeMap::from([(900, StatutoryLagVenue::UsTsx)]);
|
||||
|
||||
let observations = vec![
|
||||
obs(
|
||||
"NYE",
|
||||
day(2023, 8, 31),
|
||||
FiscalPeriod::Quarterly,
|
||||
"USD",
|
||||
Some(day(2023, 10, 10)),
|
||||
sample_fields(5.0, 1.0, 1.0, 20.0, 10.0, 1.0),
|
||||
),
|
||||
obs(
|
||||
"NYE",
|
||||
day(2023, 11, 30),
|
||||
FiscalPeriod::Quarterly,
|
||||
"USD",
|
||||
Some(day(2023, 12, 31)),
|
||||
sample_fields(6.0, 1.5, 1.2, 22.0, 11.0, 1.0),
|
||||
),
|
||||
];
|
||||
let filings = vec![
|
||||
filing("NYE", "2023-10-10T16:00:00 EDT", "10-Q"),
|
||||
filing("NYE", "2023-12-31T21:00:00 EST", "10-Q"),
|
||||
];
|
||||
|
||||
let tmp = TempDirGuard::new("nye");
|
||||
let report = curate_and_write_fundamentals(
|
||||
tmp.path(),
|
||||
observations.clone(),
|
||||
filings.clone(),
|
||||
"qm",
|
||||
&mapping,
|
||||
&venues,
|
||||
4,
|
||||
FundamentalsPitWriteOptions::default(),
|
||||
)
|
||||
.expect("curate and write");
|
||||
assert_stage_conservation(&report.curate_stats);
|
||||
assert_eq!(report.curate_stats.filings_dropped_unmapped, 0);
|
||||
assert_eq!(report.curate_stats.build.rows_linked_to_filing, 2);
|
||||
assert_eq!(
|
||||
report.write_stats.rows_by_year,
|
||||
BTreeMap::from([(2023, 1), (2024, 1)])
|
||||
);
|
||||
|
||||
let curated =
|
||||
curate_fundamentals(observations, filings, "qm", &mapping, &venues, 4).expect("curate");
|
||||
let nye_row = &curated.rows[1];
|
||||
assert_eq!(
|
||||
nye_row.effective_known_at_micros,
|
||||
utc_micros(2024, 1, 1, 2, 0, 0)
|
||||
);
|
||||
|
||||
let y2024 = read_parquet_rows_by_name(
|
||||
&tmp.path()
|
||||
.join("fundamentals_pit")
|
||||
.join("year=2024")
|
||||
.join("part.parquet"),
|
||||
);
|
||||
assert_eq!(y2024, vec![decoded_from_curated(nye_row)]);
|
||||
let y2023 = read_parquet_rows_by_name(
|
||||
&tmp.path()
|
||||
.join("fundamentals_pit")
|
||||
.join("year=2023")
|
||||
.join("part.parquet"),
|
||||
);
|
||||
assert_eq!(y2023, vec![decoded_from_curated(&curated.rows[0])]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn filing_matching_mapping_only_by_utc_date_is_dropped_unmapped() {
|
||||
// Mapping starts 2024-05-02 ET. The filing is 2024-05-01T21:00 EDT (= 2024-05-02T01:00Z):
|
||||
// mapped on its UTC date it would link; on its Eastern date it must not.
|
||||
let mapping =
|
||||
ProviderMappingTable::from_rows([mapping_row("qm", "EDGE", day(2024, 5, 2), None, 42)])
|
||||
.expect("valid mapping");
|
||||
let venues = BTreeMap::from([(42, StatutoryLagVenue::UsTsx)]);
|
||||
|
||||
let out = curate_fundamentals(
|
||||
[obs(
|
||||
"EDGE",
|
||||
day(2024, 6, 30),
|
||||
FiscalPeriod::Quarterly,
|
||||
"USD",
|
||||
None,
|
||||
sample_fields(1.0, 1.0, 1.0, 1.0, 1.0, 1.0),
|
||||
)],
|
||||
[filing("EDGE", "2024-05-01T21:00:00 EDT", "10-Q")],
|
||||
"qm",
|
||||
&mapping,
|
||||
&venues,
|
||||
4,
|
||||
)
|
||||
.expect("curate");
|
||||
assert_stage_conservation(&out.stats);
|
||||
assert_eq!(out.stats.filings_in, 1);
|
||||
assert_eq!(out.stats.filings_dropped_unmapped, 1);
|
||||
assert_eq!(out.stats.build.filings_in, 0);
|
||||
assert_eq!(out.stats.observations_dropped_unmapped, 0);
|
||||
assert_eq!(out.rows.len(), 1);
|
||||
assert_eq!(out.rows[0].listing_id, 42);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn wrong_mapping_source_drops_everything_and_mapped_listing_without_venue_is_counted_by_builder() {
|
||||
let mapping = ProviderMappingTable::from_rows([
|
||||
mapping_row("qm", "NOVENUE", day(2024, 1, 1), None, 7),
|
||||
mapping_row("qm", "OK", day(2024, 1, 1), None, 8),
|
||||
])
|
||||
.expect("valid mapping");
|
||||
let venues = BTreeMap::from([(8, StatutoryLagVenue::TsxvCse)]);
|
||||
let f = sample_fields(3.0, 1.0, 1.0, 9.0, 4.0, 1.0);
|
||||
let observations = vec![
|
||||
obs(
|
||||
"NOVENUE",
|
||||
day(2024, 3, 31),
|
||||
FiscalPeriod::Quarterly,
|
||||
"CAD",
|
||||
Some(day(2024, 5, 20)),
|
||||
f,
|
||||
),
|
||||
obs(
|
||||
"OK",
|
||||
day(2024, 3, 31),
|
||||
FiscalPeriod::Quarterly,
|
||||
"CAD",
|
||||
Some(day(2024, 5, 21)),
|
||||
f,
|
||||
),
|
||||
];
|
||||
let filings = vec![
|
||||
filing(
|
||||
"NOVENUE",
|
||||
"2024-05-20T16:00:00 EDT",
|
||||
"Interim financial statements",
|
||||
),
|
||||
filing(
|
||||
"OK",
|
||||
"2024-05-21T16:00:00 EDT",
|
||||
"Interim financial statements",
|
||||
),
|
||||
];
|
||||
|
||||
let out = curate_fundamentals(
|
||||
observations.clone(),
|
||||
filings.clone(),
|
||||
"qm",
|
||||
&mapping,
|
||||
&venues,
|
||||
4,
|
||||
)
|
||||
.expect("curate");
|
||||
assert_stage_conservation(&out.stats);
|
||||
assert_eq!(out.stats.observations_dropped_unmapped, 0);
|
||||
assert_eq!(out.stats.build.observations_dropped_unknown_key, 1);
|
||||
assert_eq!(out.stats.build.filings_dropped_unknown_key, 1);
|
||||
assert_eq!(out.stats.listings_out, 1);
|
||||
assert_eq!(out.stats.rows_out, 1);
|
||||
assert_eq!(out.rows[0].listing_id, 8);
|
||||
|
||||
let other = curate_fundamentals(observations, filings, "eodhd", &mapping, &venues, 4)
|
||||
.expect("other source");
|
||||
assert_stage_conservation(&other.stats);
|
||||
assert_eq!(other.stats.observations_dropped_unmapped, 2);
|
||||
assert_eq!(other.stats.filings_dropped_unmapped, 2);
|
||||
assert!(other.rows.is_empty());
|
||||
assert_eq!(other.stats.listings_out, 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rebuilding_from_inputs_available_by_each_cutoff_reproduces_the_published_prefix() {
|
||||
// PIT audit: for each published instant t, rebuild from only the (observation, filing)
|
||||
// pairs available at or before t; the result must equal the full run's rows with
|
||||
// effective_known_at <= t. Then append an extreme far-future revision and require every
|
||||
// earlier row to stay byte-identical.
|
||||
let mapping = ProviderMappingTable::from_rows([
|
||||
mapping_row("qm", "GROW", day(2023, 1, 1), None, 777),
|
||||
mapping_row("qm", "SMALL", day(2023, 1, 1), None, 555),
|
||||
])
|
||||
.expect("valid mapping");
|
||||
let venues = BTreeMap::from([
|
||||
(777, StatutoryLagVenue::UsTsx),
|
||||
(555, StatutoryLagVenue::TsxvCse),
|
||||
]);
|
||||
let (mut observations, mut filings) = grow_four_quarters();
|
||||
observations.push(obs(
|
||||
"SMALL",
|
||||
day(2023, 6, 30),
|
||||
FiscalPeriod::Quarterly,
|
||||
"CAD",
|
||||
Some(day(2023, 8, 1)),
|
||||
sample_fields(2.0, 0.5, 0.4, 8.0, 3.0, 50.0),
|
||||
));
|
||||
filings.push(filing(
|
||||
"SMALL",
|
||||
"2023-08-01T16:10:00 EDT",
|
||||
"Interim financial statements",
|
||||
));
|
||||
observations.push(obs(
|
||||
"SMALL",
|
||||
day(2023, 9, 30),
|
||||
FiscalPeriod::Quarterly,
|
||||
"CAD",
|
||||
Some(day(2023, 11, 20)),
|
||||
sample_fields(2.5, 0.6, 0.5, 9.0, 3.4, 50.0),
|
||||
));
|
||||
filings.push(filing(
|
||||
"SMALL",
|
||||
"2023-11-20T09:00:00 EST",
|
||||
"Interim financial statements",
|
||||
));
|
||||
|
||||
let full = curate_fundamentals(
|
||||
observations.clone(),
|
||||
filings.clone(),
|
||||
"qm",
|
||||
&mapping,
|
||||
&venues,
|
||||
4,
|
||||
)
|
||||
.expect("full");
|
||||
assert_eq!(full.rows.len(), 6);
|
||||
|
||||
let pair_known_at: Vec<i64> = filings
|
||||
.iter()
|
||||
.map(|f| parse_filing_timefiled(&f.timefiled).expect("ts").utc_micros)
|
||||
.collect();
|
||||
for cutoff in full.rows.iter().map(|r| r.effective_known_at_micros) {
|
||||
let keep: Vec<usize> = (0..filings.len())
|
||||
.filter(|&i| pair_known_at[i] <= cutoff)
|
||||
.collect();
|
||||
let truncated = curate_fundamentals(
|
||||
keep.iter().map(|&i| observations[i].clone()),
|
||||
keep.iter().map(|&i| filings[i].clone()),
|
||||
"qm",
|
||||
&mapping,
|
||||
&venues,
|
||||
4,
|
||||
)
|
||||
.expect("truncated");
|
||||
let mut expected: Vec<FundamentalsPitParquetRow> = full
|
||||
.rows
|
||||
.iter()
|
||||
.filter(|r| r.effective_known_at_micros <= cutoff)
|
||||
.cloned()
|
||||
.collect();
|
||||
expected.sort_by_key(|r| (r.listing_id, r.effective_known_at_micros));
|
||||
assert_eq!(truncated.rows, expected, "cutoff {cutoff}");
|
||||
}
|
||||
|
||||
let mut future_obs = observations.clone();
|
||||
future_obs.push(obs(
|
||||
"GROW",
|
||||
day(2023, 3, 31),
|
||||
FiscalPeriod::Quarterly,
|
||||
"USD",
|
||||
Some(day(2030, 1, 2)),
|
||||
sample_fields(1.0e12, -1.0e12, 1.0e12, 1.0e13, -1.0e12, 1.0),
|
||||
));
|
||||
let mut future_filings = filings.clone();
|
||||
future_filings.push(filing("GROW", "2030-01-02T16:00:00 EST", "10-Q/A"));
|
||||
let with_future = curate_fundamentals(future_obs, future_filings, "qm", &mapping, &venues, 4)
|
||||
.expect("with future revision");
|
||||
assert_stage_conservation(&with_future.stats);
|
||||
let future_at = utc_micros(2030, 1, 2, 21, 0, 0);
|
||||
let before: Vec<_> = with_future
|
||||
.rows
|
||||
.iter()
|
||||
.filter(|r| r.effective_known_at_micros < future_at)
|
||||
.cloned()
|
||||
.collect();
|
||||
assert_eq!(before, full.rows);
|
||||
assert_eq!(with_future.rows.len(), full.rows.len() + 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn empty_inputs_yield_no_rows_and_zero_stats() {
|
||||
let (mapping, venues) = grow_mapping();
|
||||
let out = curate_fundamentals(
|
||||
Vec::<FinancialObservation<String>>::new(),
|
||||
Vec::<QmFiling<String>>::new(),
|
||||
"qm",
|
||||
&mapping,
|
||||
&venues,
|
||||
4,
|
||||
)
|
||||
.expect("empty");
|
||||
assert!(out.rows.is_empty());
|
||||
assert_eq!(out.stats, CurateFundamentalsStats::default());
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue