Skip to main content
src/streaming/compare.py · chapter Comparing the answers, file 1 · 133 lines · open in the repository

What it does

Compare the streaming job’s event CARs with the batch event study’s answer key (task #9). stream_event_car and batch_event_car have the same columns (decision 0006) and both sides use the settings in common.study (decision 0004), so every value should agree to rounding error. The two are written independently (day-by-day state in streaming.signals, whole arrays in eventstudy.car), so agreement checks both. The stream writes a window only once its day +5 has been processed and the watermark has passed it, so a replay’s last windows can still be open when it stops. A window missing from the stream counts as still open only if its day +5 is after the last trading day the stream processed (stream_end); any other missing window is a failure. Significance here is the per-window call |car_z| >= ABNORMAL_RETURN_Z, the same threshold as the daily alerts. It is a check that both sides flag the same windows, not the report’s test (stats.py’s clustered test at common.study.CONFIDENCE). Usage:

What is inside

  • KEYS · line 30
  • TOLERANCE · line 33: Largest difference between two doubles that still counts as rounding error. The two sides add the same numbers in a different order, which leaves about 1e-16.
  • _normalise(df, types) · line 36: The contract’s columns only, with one dtype per contract type, so the sides compare.
  • _window_ends(day0, trading_days) · line 49: Day +5 of each window; NaT when it falls after the last trading day given.
  • compare(stream, batch, stream_end, trading_days, tolerance) · line 56: Join the two on KEYS and compare every other contract column.

Connections

Uses: src/common/contracts.py, src/common/study.py Used by: scripts/compare_stream_batch.py, tests/test_compare.py

Source

src/streaming/compare.py