> ## 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.

# The batch event study (src/eventstudy/)

> docs/architecture/06-batch-event-study.mmd

```mermaid theme={null}
%% Calendar Effects · 6 of 8 · The batch event study (src/eventstudy/) · Areej.
%% Paste into Miro: Creation bar > Diagram > Build with code.
flowchart TB
  master[("clean/master.parquet<br/>all 10 years at once")]
  calendar["expand_events()<br/>every event occurrence 2016–2025"]

  subgraph CAR["src/eventstudy/car.py · the ANSWER KEY · numpy on whole arrays, written apart from the stream"]
    est["1 · ESTIMATION WINDOW · days −125..−6<br/>120 trading days BEFORE the event window<br/>no look-ahead: the event never leaks into normal"]
    mm["2 · MARKET MODEL by OLS, ordinary least squares<br/>ret_stock = alpha + beta × ret_SPY + error<br/>beta: how much the stock usually follows the market"]
    ar["3 · ABNORMAL RETURN on each day −5..+5<br/>AR = actual return − what the model expected"]
    carsum["4 · CAR, cumulative abnormal return = sum of the 11 ARs<br/>CAR 0.03 = the stock beat its normal by about 3%<br/>car_z = CAR / (ar_sd × √n_days)"]
    attn["5 · attention scored exactly like the stream<br/>max_z_views, n_spike_days"]
  end
  out[("data/results/batch_event_car.parquet<br/>2,280 rows = 38 retailers × 60 event occurrences<br/>same 15 columns as the stream's event_car, decision 0006")]

  subgraph STATS["src/eventstudy/stats.py · is it real or luck? · uses scipy"]
    t["t-test · is the mean CAR different from 0?<br/>assumes every window is independent"]
    w["Wilcoxon signed-rank · the same without assuming a bell curve<br/>a few extreme CARs cannot drive it alone"]
    bmp["BMP-style test · a t-test on car_z<br/>so a jumpy stock counts the same as a calm one"]
    cl["CLUSTERED by event date · the MAIN test<br/>38 retailers share each Black Friday, so they move together<br/>each event date counts once, not 38 times"]
    grp["groups: all, online, store, online minus store"]
    trend["trend: mean CAR of each year regressed on the year<br/>is the effect growing or shrinking?"]
  end
  summary[("batch_car_summary.csv<br/>per event and group: mean, median,<br/>95% clustered CI, p_t, p_wilcoxon, p_bmp, p_clustered")]
  trendcsv[("batch_car_trend.csv<br/>slope per year, CI, p_value")]

  subgraph CHARTS["src/eventstudy/charts.py · the report's 5 charts · data/results/charts/"]
    c1["car_path.png · average CAR day −5 to +5 per event"]
    c2["car_by_event.png · mean CAR per event + 95% CI"]
    c3["online_vs_store.png · the same, split by retailer type"]
    c4["car_over_years.png · each year's mean CAR per event"]
    c5["attention_vs_returns.png · spikes vs CAR, one dot per window"]
  end

  master --> est
  calendar --> est
  est --> mm --> ar --> carsum --> out
  attn --> out
  out --> t
  out --> w
  out --> bmp
  out --> cl
  grp -.-> cl
  t --> summary
  w --> summary
  bmp --> summary
  cl --> summary
  out --> trend --> trendcsv
  summary --> CHARTS
  trendcsv --> CHARTS
  out --> CHARTS
```

## Guide

```mermaid theme={null}
%% Calendar Effects · Guide 6 · The batch event study · goes next to diagram 06-batch-event-study.mmd
%% Miro: paste onto a board, or Creation bar > Diagram > Build with code. Read top to bottom.
flowchart TB
  T["GUIDE 6 · THE BATCH EVENT STUDY<br/>src/eventstudy/ · Areej · decision 0006"]

  subgraph S1["1 · AN EVENT STUDY IN 4 STEPS · car.py"]
    direction LR
    e1["LEARN NORMAL<br/>days −125 to −6<br/>no look-ahead"] --> e2["MARKET MODEL<br/>OLS: ret vs SPY"] --> e3["ABNORMAL RETURNS<br/>days −5 to +5<br/>actual − expected"] --> e4["CAR<br/>sum of the 11 ARs<br/>0.03 = beat normal by 3%"]
  end

  subgraph S2["2 · THE ANSWER KEY"]
    direction TB
    a1[("batch_event_car.parquet<br/>2,280 rows<br/>38 retailers × 60 events")]
    a2["SAME 15 COLUMNS<br/>as the stream's event_car"]
    a3["WRITTEN APART<br/>whole numpy arrays, no state<br/>so agreement checks both"]
    a4["car_z<br/>CAR in units of<br/>the stock's usual noise"]
  end

  subgraph S3["3 · REAL OR LUCK? · stats.py"]
    direction TB
    p1["p-VALUE<br/>below 0.05 = probably not luck"]
    p2["t-TEST<br/>is the mean CAR ≠ 0?"]
    p3["WILCOXON<br/>same, without a bell curve"]
    p4["BMP-STYLE<br/>every stock counts equally"]
    p5["CLUSTERED · MAIN TEST<br/>each event date counts once"]
    p6["WHY CLUSTER<br/>Prime Day: p 0.014 plain<br/>but 0.054 clustered"]
  end

  subgraph S4["4 · GROUPS AND TREND"]
    direction TB
    g1["GROUPS<br/>all · online · store"]
    g2["ONLINE − STORE<br/>tested across event dates"]
    g3["TREND<br/>each year's mean CAR vs year<br/>growing or shrinking?"]
  end

  subgraph S5["5 · THE 5 REPORT CHARTS · data/results/charts/"]
    direction TB
    h1["car_path<br/>average CAR, day −5 to +5"]
    h2["car_by_event<br/>mean CAR + 95% interval"]
    h3["online_vs_store<br/>the same, split by type"]
    h4["car_over_years<br/>mean CAR per year"]
    h5["attention_vs_returns<br/>spikes vs CAR"]
  end

  subgraph S6["6 · RUN IT"]
    direction LR
    r1["car.py<br/>≈ 2 seconds"] --> r2["stats.py"] --> r3["charts.py"]
  end

  T --> S1 --> S2 --> S3 --> S4 --> S5 --> S6

  classDef head fill:#2C2C2A,stroke:#2C2C2A,color:#FFFFFF
  classDef idea fill:#E6F1FB,stroke:#185FA5,color:#0C447C
  classDef step fill:#E1F5EE,stroke:#0F6E56,color:#085041
  classDef warn fill:#FAECE7,stroke:#993C1D,color:#712B13
  classDef win fill:#EAF3DE,stroke:#3B6D11,color:#27500A
  classDef file fill:#F1EFE8,stroke:#5F5E5A,color:#444441
  class T head
  class e1,e2,e3,e4,r1,r2,r3 step
  class a2,a3,a4,p1,p2,p3,p4,g1,g2,g3 idea
  class a1,p5 win
  class p6 warn
  class h1,h2,h3,h4,h5 file
  style S1 fill:#FFFFFF,stroke:#B4B2A9
  style S2 fill:#FFFFFF,stroke:#B4B2A9
  style S3 fill:#FFFFFF,stroke:#B4B2A9
  style S4 fill:#FFFFFF,stroke:#B4B2A9
  style S5 fill:#FFFFFF,stroke:#B4B2A9
  style S6 fill:#FFFFFF,stroke:#B4B2A9
```


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