> ## 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-16 · Mahad · Streaming job runs end to end and matches a direct computation

* **Done:**
  * **`src/streaming/job.py`, the Spark job:**
    * reads Kafka `calendar-effects-master`, or JSON files for local runs, failing fast on bad messages
    * 7-day watermark
    * stream-stream join to SPY for the market return
    * `applyInPandasWithState` per ticker, with an event-time timeout
    * `foreachBatch` writes `data/stream/signals/` and `data/stream/event_car/`, one idempotent `batch_id=N` folder per batch, and prints CARs as event windows close
  * **`src/streaming/signals.py`, the per-ticker logic in plain Python:**
    * rolling market model for the daily alerts
    * attention z-score
    * event windows from the calendar, each with one market model fitted on days −125 to −6, like the batch study
  * **`src/common/study.py`:** the shared settings both sides must import (SPY, simple returns, window −5..+5, 120-day estimation).
  * **Testing tools:**
    * `src/producers/replay_to_files.py`: a local replay without Kafka, with the same late-data option as `replay_master.py`
    * `scripts/check_streaming.py`: recomputes everything with numpy
    * `tests/test_streaming_signals.py`: 9 tests
  * **Repo setup:** `requirements.txt` and `pyrightconfig.json` (the editor now uses `.venv`).
* **Results (local, all 10 years):**
  * 25,050 daily rows and 600 event CARs match the direct computation to about 1e-16, both in order and with 2% of messages 3 days late.
  * With messages 10 days late, 2 of 99 were dropped by the watermark.
  * A full replay takes about 5 minutes.
* **Decisions:** `docs/decisions/0004-streaming-job-design.md` (proposed): the shared study settings, day 0 = first trading day on or after the event date, the 7-day watermark, and the alert thresholds.
* **Contracts:**
  * New: `master` (what Kafka actually carries), `stream_signals`, `stream_event_car`, and `KAFKA_TOPICS["master"]`.
  * Existing contracts are unchanged.
  * The contract-checker found no breakage. Its findings are in `.claude/agent-memory/contract-checker/MEMORY.md`.
* **Next:**
  1. Run it on the cluster against Kafka while `replay_master.py` sends, e.g. `spark-submit src/streaming/job.py --source kafka --max-per-trigger 110`. Kafka has not been tested yet; the connector version must match the cluster's Spark (`--kafka-package`).
  2. Review the code with Anushiya before merging to `main`.
  3. Pick the alerts to show in the demo video.
* **Blocked on / needs from others:**
  * **Areej:** read decision 0004 before building the batch study.
    * Import `common.study`.
    * Take events from `expand_events`, not from master's `event_type`.
    * Use the same day-0 rule, so CARs should match exactly.
  * **Sanchi:**
    * Confirm or replace the attention spike settings in `common.study`.
    * Decide whether to report US Thanksgiving, whose window is identical to Black Friday's.
    * Small fixes in your files: import `KAFKA_TOPICS["master"]` instead of the hard-coded topic, and update the `replay_master.py` docstring example to show `volume` as an int and `views` as a float.
  * **Anushiya:**
    * `docs/data-contracts.md` still says the `events` table lives in `data/clean/events/`, but it was never built; code uses `expand_events`.
    * Add the local run steps below to the README and the run-everything script.
* **Local setup that bit us:**
  * Spark 4 needs Java 17 or 21, not the default 26: `export JAVA_HOME=/opt/homebrew/opt/openjdk@21`.
  * pyarrow 21+ breaks `applyInPandasWithState`, so `requirements.txt` pins it below 21.
  * Spark's file source reads files by modification time, not by name.
  * Run steps: `source .venv/bin/activate && pip install -r requirements.txt`, then `python3 src/producers/replay_to_files.py && python3 src/streaming/job.py --source files --once --fresh && python3 scripts/check_streaming.py`.


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