- Date: 2026-11-16
- Status: Agreed 2026-11-25 (proposed by Mahad; attention spike rule settled by Anushiya, 2026-11-17; see Consequences below)
- Agreed by: Mahad (2026-11-25), for the team
Context
The streaming job and the batch event study must use the same return definition, market index and windows, or the streaming vs batch comparison will not line up. The ETL phase also changed what Kafka carries: one joined master table instead of the separateprices and attention topics in the original contracts. The job also needed a watermark delay and a way to handle events on days the market is closed.
Decision
- Kafka message: the
mastercontract, one row ofclean/master.parquetper message oncalendar-effects-master, keyed by ticker (whatreplay_master.pyalready sends). - Study settings live once in
src/common/study.py, imported by both sides:- simple returns; SPY as the market index; market model fitted by OLS
- event window of trading days −5 to +5
- estimation window of 120 trading days ending right before the event window, with at least 100 usable days
- Day 0 is the first trading day on or after the event’s calendar date, so weekend and holiday events (US Thanksgiving, some Halloweens and Chinese New Years) still get a window.
- Event CAR in the stream, computed exactly like the batch study: when day 0 arrives, the job fits one market model on the 120 days before day −5 (days −125 to −6), which are still in its state. It applies that model to all 11 window days. With the same data, streaming CAR equals batch CAR.
- Daily alerts: a second model, re-fitted every day on the 120 days that end 10 trading days earlier. A stream doesn’t know a day belongs to an event window until day 0 arrives. The 10-day gap still keeps every window day out of its own baseline.
- Watermark: 7 days on the trading day at 00:00 UTC. That covers the producer’s 3-trading-day late test, even across weekends and holidays.
- Alert thresholds: abnormal return when |AR / σ| ≥ 1.96. Attention spike when views are 3 standard deviations above a 28-day baseline, with the same 10-day gap. Settled by Anushiya against 10 years of real data (see Consequences below).
Alternatives considered
- CAR as the sum of the daily rolling ARs: simpler, but each day would use a different model, so it could never match the batch study exactly. Checked on our data, about 1% of significance calls would flip.
- Using master’s
event_typecolumn for events: it drops events on non-trading days; US Thanksgiving never appears. The job reads the calendar itself. - Separate price and attention streams joined in Spark: that was the original plan. The team built one master table instead, which is simpler and already on Kafka.
- Longer estimation window (250 days): it would lose every 2016 event to warm-up.
Consequences
- Areej (batch study): import the settings from
common.study.- Take events from
common.contracts.expand_events(STUDY_START_YEAR, STUDY_END_YEAR), not from master’sevent_type, and key on itsevent_date. - Use the same day-0 rule.
- Skip windows without enough history; in the stream they have
n_days= 0. - Add the batch CAR output to
docs/data-contracts.mdwith keysticker,event_type,event_date. - The comparison then expects equal CARs, not merely close ones.
- Take events from
- Anushiya (spike rule, settled 2026-11-17): ran the real
streaming.signalslogic against all 10 years ofclean/master.parquet(10 tickers, excluding SPY), cross-checked against an independent numpy version to 1.7e-10. At z≥3.0, 6.05% of scored ticker-days flag, and Black Friday/Cyber Monday windows flag about 3.1x as often as other days (17.2% vs 5.5%) — a real, clean signal. Other events (Prime Day, Halloween, Chinese New Year) show little to no lift, which is worth stating plainly in the report rather than overselling. z=2.5 and z=3.5 give the same ~3.1–3.3x lift, just a different count, so the threshold itself doesn’t sharpen the signal — 28/20/3.0 is kept as a reasonable middle choice, not an arbitrary placeholder. US Thanksgiving’s window is identical to Black Friday’s, because both start on the Friday; still open whether to report both, same as before. - Mahad and Anushiya (streaming): outputs follow the
stream_signalsandstream_event_carcontracts.scripts/check_streaming.pyrecomputes both fromclean/master.parquetwithout any streaming machinery. - Tested locally (all 10 years, 600 event windows):
- In order, and with 2% of messages 3 days late, every daily AR and every CAR matches the direct computation to rounding error.
- With messages 10 days late, 97 of 99 were still used and 2 were dropped. A watermark only promises to keep data newer than it.
- A message with a wrongly typed field the job uses stops it (FAILFAST).
- Contracts touched: new
master,stream_signals,stream_event_car;KAFKA_TOPICS["master"].