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

# src/common/study.py

> Study settings shared by the streaming job (src/streaming/) and the batch event study (src/eventstudy/).

`src/common/study.py` · chapter [Shared rules](https://calendar-effects.mintlify.site/tour/02-shared-rules.md), file 2 · 74 lines · [open in the repository](https://github.sfu.ca/aba395/Calendar-Effects/blob/main/src/common/study.py)

## What it does

Study settings shared by the streaming job (src/streaming/) and the batch event
study (src/eventstudy/).

The streaming vs batch comparison only lines up if both sides use the same return
definition, market index and window lengths, so they are defined here once
(decision 0004). Import them; never copy the numbers into another file.

Usage:

```text theme={null}
from common.study import EVENT_WINDOW, ESTIMATION_DAYS, MARKET_TICKER
```

## What is inside

* **`STUDY_START_YEAR`** · [line 16](https://github.sfu.ca/aba395/Calendar-Effects/blob/main/src/common/study.py#L16): The study period. Every download, cleaning step and event list uses these. To change the period, change these two lines, delete raw/prices/ and raw/wiki/ (the downloads skip files that already exist), and re-run the ETL.
* **`STUDY_END_YEAR`** · [line 17](https://github.sfu.ca/aba395/Calendar-Effects/blob/main/src/common/study.py#L17)
* **`STUDY_START`** · [line 18](https://github.sfu.ca/aba395/Calendar-Effects/blob/main/src/common/study.py#L18)
* **`STUDY_END`** · [line 19](https://github.sfu.ca/aba395/Calendar-Effects/blob/main/src/common/study.py#L19)
* **`MARKET_TICKER`** · [line 24](https://github.sfu.ca/aba395/Calendar-Effects/blob/main/src/common/study.py#L24): Market model: ret\_stock = alpha + beta \* ret\_market + error, fitted by OLS. The market index is downloaded alongside the retailers but is not one of them, so it is not in config/retailers.csv.
* **`MARKET_COUNTRY`** · [line 26](https://github.sfu.ca/aba395/Calendar-Effects/blob/main/src/common/study.py#L26): Labels the market index gets in master. Retailers get theirs from config/retailers.csv.
* **`MARKET_RETAILER_TYPE`** · [line 27](https://github.sfu.ca/aba395/Calendar-Effects/blob/main/src/common/study.py#L27)
* **`RETURN_TYPE`** · [line 29](https://github.sfu.ca/aba395/Calendar-Effects/blob/main/src/common/study.py#L29): Simple returns, ret = adj\_close / previous adj\_close - 1, as stored in clean/prices.parquet.
* **`EVENT_WINDOW`** · [line 34](https://github.sfu.ca/aba395/Calendar-Effects/blob/main/src/common/study.py#L34): Event window in trading days around day 0, both ends included. Day 0 is the first trading day on or after the calendar date, so an event on a weekend or market holiday (US Thanksgiving, some Halloweens) starts on the next open day.
* **`ESTIMATION_DAYS`** · [line 37](https://github.sfu.ca/aba395/Calendar-Effects/blob/main/src/common/study.py#L37): Estimation window: this many trading days, ending right before the event window.
* **`MIN_ESTIMATION_DAYS`** · [line 39](https://github.sfu.ca/aba395/Calendar-Effects/blob/main/src/common/study.py#L39): Fewer usable days than this (start of the data, missing returns) means no estimate.
* **`ESTIMATION_GAP_DAYS`** · [line 45](https://github.sfu.ca/aba395/Calendar-Effects/blob/main/src/common/study.py#L45): The streaming job re-estimates the model every day. Skipping the most recent ESTIMATION\_GAP\_DAYS trading days keeps every day of an event window out of its own baseline: for day +5 the estimation window then ends on day -6, exactly where the batch study's fixed window ends.
* **`CONFIDENCE`** · [line 48](https://github.sfu.ca/aba395/Calendar-Effects/blob/main/src/common/study.py#L48): Confidence level of the intervals in the batch study's tables (src/eventstudy/stats.py).
* **`ABNORMAL_RETURN_Z`** · [line 51](https://github.sfu.ca/aba395/Calendar-Effects/blob/main/src/common/study.py#L51): Streaming alerts. |abnormal return| / its standard deviation at or above this is "abnormal".
* **`ATTENTION_BASELINE_DAYS`** · [line 58](https://github.sfu.ca/aba395/Calendar-Effects/blob/main/src/common/study.py#L58): Attention spike: views at least this many standard deviations above a baseline of ATTENTION\_BASELINE\_DAYS trading days (with the same gap as the market model). Anushiya owns the spike rule, settled 2026-11-17. Confirmed against 10 years of real data: \~6% of ticker-days flag at z>=3, and Black Friday/Cyber Monday windows flag about 3x as often as other days; z=2.5 or z=3.5 give the same lift, just a different count, so 3.0 is kept as a reasonable middle choice (see docs/decisions/0004).
* **`MIN_ATTENTION_DAYS`** · [line 59](https://github.sfu.ca/aba395/Calendar-Effects/blob/main/src/common/study.py#L59)
* **`ATTENTION_SPIKE_Z`** · [line 60](https://github.sfu.ca/aba395/Calendar-Effects/blob/main/src/common/study.py#L60)
* **`ML_TRAIN_END_YEAR`** · [line 67](https://github.sfu.ca/aba395/Calendar-Effects/blob/main/src/common/study.py#L67): Machine learning (decision 0007): from what the stream knows about a stock today, will tomorrow be a big move, i.e. tomorrow's daily alert (|z\_ar| >= ABNORMAL\_RETURN\_Z)? The split follows time, never random rows, so the model is always judged on days after the ones it learned from: fit on the training years, pick the model on the validation year, then refit on both and report on the test years.
* **`ML_VALIDATION_YEAR`** · [line 68](https://github.sfu.ca/aba395/Calendar-Effects/blob/main/src/common/study.py#L68)
* **`ML_TEST_START_YEAR`** · [line 69](https://github.sfu.ca/aba395/Calendar-Effects/blob/main/src/common/study.py#L69)
* **`ML_ALERT_TOP_SHARE`** · [line 72](https://github.sfu.ca/aba395/Calendar-Effects/blob/main/src/common/study.py#L72): The live job flags this share of stock-days, the highest predicted probabilities, as likely big movers. The cut-off comes from the training years' predictions.
* **`ML_EVENT_DAYS_CAP`** · [line 74](https://github.sfu.ca/aba395/Calendar-Effects/blob/main/src/common/study.py#L74): Days to and since the nearest in-scope event are capped here (a quiet stretch is quiet).

## Connections

**Used by:** [`src/common/contracts.py`](https://calendar-effects.mintlify.site/reference/src/common/contracts), [`etl/prices_download.py`](https://calendar-effects.mintlify.site/reference/etl/prices_download), [`etl/prices_clean.py`](https://calendar-effects.mintlify.site/reference/etl/prices_clean), [`etl/pageviews_download.py`](https://calendar-effects.mintlify.site/reference/etl/pageviews_download), [`etl/pageviews_clean.py`](https://calendar-effects.mintlify.site/reference/etl/pageviews_clean), [`etl/retail_clean.py`](https://calendar-effects.mintlify.site/reference/etl/retail_clean), [`etl/build_events.py`](https://calendar-effects.mintlify.site/reference/etl/build_events), [`etl/join_master.py`](https://calendar-effects.mintlify.site/reference/etl/join_master), [`src/streaming/job.py`](https://calendar-effects.mintlify.site/reference/src/streaming/job), [`src/streaming/signals.py`](https://calendar-effects.mintlify.site/reference/src/streaming/signals), [`scripts/check_streaming.py`](https://calendar-effects.mintlify.site/reference/scripts/check_streaming), [`src/eventstudy/car.py`](https://calendar-effects.mintlify.site/reference/src/eventstudy/car), [`src/eventstudy/stats.py`](https://calendar-effects.mintlify.site/reference/src/eventstudy/stats), [`src/eventstudy/charts.py`](https://calendar-effects.mintlify.site/reference/src/eventstudy/charts), [`scripts/export_results.py`](https://calendar-effects.mintlify.site/reference/scripts/export_results), [`src/streaming/compare.py`](https://calendar-effects.mintlify.site/reference/src/streaming/compare), [`scripts/compare_stream_batch.py`](https://calendar-effects.mintlify.site/reference/scripts/compare_stream_batch), [`src/ml/features.py`](https://calendar-effects.mintlify.site/reference/src/ml/features), [`src/ml/train.py`](https://calendar-effects.mintlify.site/reference/src/ml/train), [`src/dashboard/app.py`](https://calendar-effects.mintlify.site/reference/src/dashboard/app), [`src/hosting/snapshot.py`](https://calendar-effects.mintlify.site/reference/src/hosting/snapshot), [`src/hosting/publish_hf.py`](https://calendar-effects.mintlify.site/reference/src/hosting/publish_hf), [`tests/test_config.py`](https://calendar-effects.mintlify.site/reference/tests/test_config), [`tests/test_event_calendar.py`](https://calendar-effects.mintlify.site/reference/tests/test_event_calendar), [`tests/test_clean_files.py`](https://calendar-effects.mintlify.site/reference/tests/test_clean_files), [`tests/test_no_hardcoding.py`](https://calendar-effects.mintlify.site/reference/tests/test_no_hardcoding), [`tests/test_streaming_signals.py`](https://calendar-effects.mintlify.site/reference/tests/test_streaming_signals), [`tests/test_eventstudy.py`](https://calendar-effects.mintlify.site/reference/tests/test_eventstudy), [`tests/test_compare.py`](https://calendar-effects.mintlify.site/reference/tests/test_compare), [`tests/test_ml_features.py`](https://calendar-effects.mintlify.site/reference/tests/test_ml_features), [`tests/test_dashboard.py`](https://calendar-effects.mintlify.site/reference/tests/test_dashboard), [`tests/test_hosting.py`](https://calendar-effects.mintlify.site/reference/tests/test_hosting)

## Source

```python title="src/common/study.py" lines expandable theme={null}
"""Study settings shared by the streaming job (src/streaming/) and the batch event
study (src/eventstudy/).

The streaming vs batch comparison only lines up if both sides use the same return
definition, market index and window lengths, so they are defined here once
(decision 0004). Import them; never copy the numbers into another file.

Usage:
    from common.study import EVENT_WINDOW, ESTIMATION_DAYS, MARKET_TICKER
"""
from datetime import date

# The study period. Every download, cleaning step and event list uses these. To change
# the period, change these two lines, delete raw/prices/ and raw/wiki/ (the downloads
# skip files that already exist), and re-run the ETL.
STUDY_START_YEAR = 2016
STUDY_END_YEAR = 2025
STUDY_START = date(STUDY_START_YEAR, 1, 1)
STUDY_END = date(STUDY_END_YEAR, 12, 31)

# Market model: ret_stock = alpha + beta * ret_market + error, fitted by OLS.
# The market index is downloaded alongside the retailers but is not one of them,
# so it is not in config/retailers.csv.
MARKET_TICKER = "SPY"
# Labels the market index gets in master. Retailers get theirs from config/retailers.csv.
MARKET_COUNTRY = "US"
MARKET_RETAILER_TYPE = "market"
# Simple returns, ret = adj_close / previous adj_close - 1, as stored in clean/prices.parquet.
RETURN_TYPE = "simple"

# Event window in trading days around day 0, both ends included.
# Day 0 is the first trading day on or after the calendar date, so an event on a
# weekend or market holiday (US Thanksgiving, some Halloweens) starts on the next open day.
EVENT_WINDOW = (-5, 5)

# Estimation window: this many trading days, ending right before the event window.
ESTIMATION_DAYS = 120
# Fewer usable days than this (start of the data, missing returns) means no estimate.
MIN_ESTIMATION_DAYS = 100

# The streaming job re-estimates the model every day. Skipping the most recent
# ESTIMATION_GAP_DAYS trading days keeps every day of an event window out of its own
# baseline: for day +5 the estimation window then ends on day -6, exactly where the
# batch study's fixed window ends.
ESTIMATION_GAP_DAYS = EVENT_WINDOW[1] - EVENT_WINDOW[0]

# Confidence level of the intervals in the batch study's tables (src/eventstudy/stats.py).
CONFIDENCE = 0.95

# Streaming alerts. |abnormal return| / its standard deviation at or above this is "abnormal".
ABNORMAL_RETURN_Z = 1.96
# Attention spike: views at least this many standard deviations above a baseline of
# ATTENTION_BASELINE_DAYS trading days (with the same gap as the market model).
# Anushiya owns the spike rule, settled 2026-11-17. Confirmed against 10 years of
# real data: ~6% of ticker-days flag at z>=3, and Black Friday/Cyber Monday windows
# flag about 3x as often as other days; z=2.5 or z=3.5 give the same lift, just a
# different count, so 3.0 is kept as a reasonable middle choice (see docs/decisions/0004).
ATTENTION_BASELINE_DAYS = 28
MIN_ATTENTION_DAYS = 20
ATTENTION_SPIKE_Z = 3.0

# Machine learning (decision 0007): from what the stream knows about a stock today, will
# tomorrow be a big move, i.e. tomorrow's daily alert (|z_ar| >= ABNORMAL_RETURN_Z)?
# The split follows time, never random rows, so the model is always judged on days after
# the ones it learned from: fit on the training years, pick the model on the validation
# year, then refit on both and report on the test years.
ML_TRAIN_END_YEAR = 2022
ML_VALIDATION_YEAR = ML_TRAIN_END_YEAR + 1
ML_TEST_START_YEAR = ML_VALIDATION_YEAR + 1
# The live job flags this share of stock-days, the highest predicted probabilities, as
# likely big movers. The cut-off comes from the training years' predictions.
ML_ALERT_TOP_SHARE = 0.05
# Days to and since the nearest in-scope event are capped here (a quiet stretch is quiet).
ML_EVENT_DAYS_CAP = 60
```


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