> ## Documentation Index
> Fetch the complete documentation index at: https://calendar-effects.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# 2026-11-17 · Mahad · Streaming matches the batch answer key: 600 of 600 event windows (task #9)

* **Done:**
  * **`src/streaming/compare.py`:** `compare(stream, batch)` joins `stream_event_car` to Areej's `batch_event_car` on `ticker`, `event_type`, `event_date`, and compares every other contract column. Doubles must agree within 1e-9 (rounding error); dates, counts and day 0 must be exactly equal. A window missing from the stream counts as still open (not a failure) only if its day +5 is after the last trading day the stream processed; an empty stream or a repeated key fails. The column list comes from the contract.
  * **`scripts/compare_stream_batch.py`:** runs it on the stream's output folder (`--stream`, default `data/stream/`) and `data/results/batch_event_car.parquet`, checks all three files against their contracts first, prints the report, and exits 1 on any disagreement.
  * **`tests/test_compare.py`:** 12 tests: rounding error passes; a real difference, an empty or truncated stream, a repeated key or a window on one side only fails; still-open windows; nulls on both sides; flipped significance calls; and the two contracts having the same columns (decision 0006).
  * **Contract-checker:** run before committing. It found that an empty or truncated stream and repeated keys passed, that the batch file was validated after reading, and gaps in the contract text. All are fixed: `docs/data-contracts.md` now names the comparison, lists every column that is null without a model, and uses one meaning for `n_days` and `n_spike_days` in both contracts.
* **Results** (stream from `./run_everything.sh --skip-etl` on the current `master`; batch from `python3 src/eventstudy/car.py`):
  * 600 windows on each side, 600 in both, none on one side only.
  * Every column matches: all dates and counts exactly, and the largest difference in a double is 1.8e-15 (`beta`, `car_z`); `car` is within 1.1e-16.
  * Same significance call (|`car_z`| ≥ 1.96, the alert threshold; the report's test is the clustered one in `stats.py`) in 590 of 590 windows with a CAR. The other 10 are Chinese New Year 2016 windows, which have too little history before them for a model on either side.
  * Mean CAR by event, identical on both sides: Black Friday 1.43%, Cyber Monday 0.77%, Prime Day 1.31%, Halloween −1.83%, Chinese New Year 0.13% (US Thanksgiving = Black Friday, as decision 0004 notes).
  * Because the two sides were written independently (day-by-day state vs whole numpy arrays), the match checks both.
* **Decisions:** none. This is what decisions 0004 and 0006 asked for.
* **Contracts:** no column changes. In `docs/data-contracts.md`, the Outputs intro names the comparison and its 1e-9 tolerance. `stream_event_car`'s note lists `alpha`, `beta` and `ar_sd` as null without a model too. `n_days` and `n_spike_days` have one shared meaning in both output contracts (Areej: wording only in your section).
* **Next:**
  1. \#3 on the cluster: done on 2026-11-18, and its output also matches the answer key 600 of 600 (`docs/handoffs/2026-11-18-mahad-cluster-kafka.md`).
  2. Pick the alerts for the demo video; the per-event table above is a starting point.
* **Blocked on / needs from others:**
  * **Anushiya:** when adding Areej's scripts to `run_everything.sh` (#11), add `python3 scripts/compare_stream_batch.py` after `src/eventstudy/car.py` and the streaming check, so one command ends with the comparison.
  * **Sanchi:** after the late-data test (#7), run `python3 scripts/compare_stream_batch.py` too; with 2% late messages it should still print OK.
  * **Sanchi (report, results):** quote the comparison as "600 of 600 windows equal to 1.8e-15; 590 of 590 same significance call".


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.