- 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
applyInPandasWithStateper ticker, with an event-time timeoutforeachBatchwritesdata/stream/signals/anddata/stream/event_car/, one idempotentbatch_id=Nfolder per batch, and prints CARs as event windows close
- reads Kafka
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 asreplay_master.pyscripts/check_streaming.py: recomputes everything with numpytests/test_streaming_signals.py: 9 tests
- Repo setup:
requirements.txtandpyrightconfig.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, andKAFKA_TOPICS["master"]. - Existing contracts are unchanged.
- The contract-checker found no breakage. Its findings are in
.claude/agent-memory/contract-checker/MEMORY.md.
- New:
- Next:
- Run it on the cluster against Kafka while
replay_master.pysends, 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). - Review the code with Anushiya before merging to
main. - Pick the alerts to show in the demo video.
- Run it on the cluster against Kafka while
- 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’sevent_type. - Use the same day-0 rule, so CARs should match exactly.
- Import
- 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 thereplay_master.pydocstring example to showvolumeas an int andviewsas a float.
- Confirm or replace the attention spike settings in
- Anushiya:
docs/data-contracts.mdstill says theeventstable lives indata/clean/events/, but it was never built; code usesexpand_events.- Add the local run steps below to the README and the run-everything script.
- Areej: read decision 0004 before building the batch study.
- 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, sorequirements.txtpins 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, thenpython3 src/producers/replay_to_files.py && python3 src/streaming/job.py --source files --once --fresh && python3 scripts/check_streaming.py.
- Spark 4 needs Java 17 or 21, not the default 26:
Handoffs, newest first