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

# 6. The batch event study

> The same numbers computed a second, independent way, with the statistics and charts for the report.

The batch study is the textbook version of the analysis, written separately from the streaming job on purpose. It produces the **answer key** (`car.py`), the **significance tests** (`stats.py`) and the **report's charts** (`charts.py`).

## The big idea

`car.py` takes each stock and each event occurrence, fits the market model on the 120 trading days that end right before day −5, and sums the abnormal returns over days −5..+5. It works on whole numpy arrays at once, not day by day, so if its numbers equal the stream's, both are right.

`stats.py` asks, for each event type (and for online vs store retailers): **could the average CAR be zero and we just got unlucky?** It runs four tests, because each answers that question under different assumptions:

| Test | Answers the question assuming… |
| - | - |
| t-test | every window is independent and roughly bell-shaped |
| Wilcoxon signed-rank | nothing about the shape, so a few extreme CARs cannot drive it |
| BMP-style | volatile and calm stocks count equally (it tests standardized CARs) |
| **clustered by event date** | retailers sharing an event date move together, so each date counts once (the main test) |

It also fits a **trend** for each event type: each year's average CAR against the year, to see whether an effect grows or fades.

## Words you will meet

> [accordion] p-value
>
> If the true average were zero, the chance of seeing an average at least this far from zero. Small (below 0.05) means "unlikely to be luck".

> [accordion] Confidence interval
>
> A range that would contain the true average in 95% of repeated studies. If it excludes zero, the effect is significant at 5%.

> [accordion] Clustering
>
> Treating related observations as one group. All 38 retailers share each Black Friday; a market-wide shock that day hits all of them, so they are not 38 independent pieces of evidence.

> [accordion] car\_z
>
> A window's CAR divided by its expected spread (the residual standard deviation × √days), so windows of volatile and calm stocks can be compared.

### The picture: The batch event study (src/eventstudy/)

```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
```

The [full diagram and its guide](https://calendar-effects.mintlify.site/diagrams/06-batch-event-study.md) explain every box.

### Read these files in this order

**1. src/eventstudy/**init**.py**

See the file. [Read it](https://calendar-effects.mintlify.site/reference/src/eventstudy/init.md)

**2. src/eventstudy/car.py**

Batch event study: one cumulative abnormal return (CAR) per stock per event. This is the "answer key" the streaming job is compared against (decision 0004). [Read it](https://calendar-effects.mintlify.site/reference/src/eventstudy/car.md)

**3. src/eventstudy/stats.py**

Significance tests on the batch CARs: is the average CAR around an event really different from zero, does it differ between online and store retailers, and does it change over the years? Reads the output of src/eventstudy/car.py. [Read it](https://calendar-effects.mintlify.site/reference/src/eventstudy/stats.md)

**4. src/eventstudy/charts.py**

Final charts for the report (task #10), made from the batch event study's outputs. [Read it](https://calendar-effects.mintlify.site/reference/src/eventstudy/charts.md)

**5. scripts/export\_results.py**

Gather the final results into docs/results/ for the report, the slides and the video (decision 0013). [Read it](https://calendar-effects.mintlify.site/reference/scripts/export_results.md)

## Questions you should be able to answer

> [accordion] Why is the clustered test the main one?
>
> Without clustering, 38 retailers × 10 years look like 380 independent windows and p-values come out far too small. Clustering by event date counts each date once, which is honest about how much evidence there really is.

> [accordion] Why does the estimation window end before day −5?
>
> So the event cannot leak into its own baseline. If the model were fitted on days that include the event, an event effect would partly become "normal" and the abnormal return would shrink.

> [accordion] What did the study find?
>
> With 38 retailers, store retailers' mean CAR over all events is about +1.1% (clustered p ≈ 0.03), Halloween is negative for online retailers (about −3.6%, p ≈ 0.04), and Black Friday is positive for stores (about +2.5%, p ≈ 0.09). The [Results](https://calendar-effects.mintlify.site/results.md) page has every number, from the latest run.

## Ideas to improve it

* Use a Fama-French three-factor model instead of the one-factor market model.
* Correct the p-values for testing many event types at once (Holm or Benjamini-Hochberg).


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