Skip to main content
Every number the study depends on (years, window lengths, thresholds) and every list it studies (retailers, events, Wikipedia articles) is written down once. Code imports it; it never types it again. This is what lets four people work on separate parts and still get answers that line up.

The big idea

There are three kinds of shared rules:
  • How the study works (src/common/study.py): the study years, the market ticker, the event window (−5..+5), the estimation window (120 days, at least 100), the alert thresholds (|z| ≥ 1.96 for an abnormal return, z ≥ 3 for an attention spike) and the model’s split years.
  • Where things live (src/common/settings.py): every folder and file path, and the Kafka servers.
  • What the data looks like (src/common/contracts.py): the columns and types of every dataset (the data contracts), the loaders for the config/ lists, and the expander that turns event rules into dates.
The config/ folder holds the lists as CSV files. Adding a retailer or an event is adding a row, with no code change.

Words you will meet

A promise about a dataset’s columns and types. It is written in docs/data-contracts.md and repeated in contracts.py; a test keeps the two equal, and every script calls require_contract before it writes a file.
How an event’s date is found each year: fixed:10-31 (Halloween), nth_weekday:11:thu:4 (US Thanksgiving), offset:us_thanksgiving:+1 (Black Friday), or listed (dates typed into event_dates.csv with a source, for Prime Day and Chinese New Year).
A yes in a config row means the study uses it; candidates stay listed with no so they can be switched on later.

The picture: What is studied, and the rules every script follows

The full diagram and its guide explain every box.

Read these files in this order

1

src/common/init.py

Code shared by every part of the pipeline (schemas, helpers). Read it
2

src/common/study.py

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

src/common/settings.py

Where the project’s files live, and how to reach Kafka. Read it
4

src/common/contracts.py

Single source of truth for dataset schemas, in code, plus the loaders for the config/ registries that are themselves contracts. Read it
5

config/event_types.csv

A registry with 12 rows. Columns: event_type, name, category, region, date_rule, in_scope, notes. Read it
6

config/event_dates.csv

A registry with 20 rows. Columns: event_type, event_date, event_end_date, source. Read it
7

config/retailers.csv

A registry with 40 rows. Columns: ticker, company, country, retailer_type, in_scope, notes. Read it
8

config/wiki_articles.csv

A registry with 44 rows. Columns: article, ticker, notes. Read it
9

config/retail_series.csv

A registry with 6 rows. Columns: series_id, category, notes. Read it

Questions you should be able to answer

tests/test_no_hardcoding.py scans every script’s literals and fails, naming the file and line and what to import instead (common.study.STUDY_START_YEAR). The commit is refused until it is fixed.
The streaming job re-fits the market model every day. Skipping the latest 10 trading days means that on day +5 of an event its baseline ends at day −6, so no day of the window is inside its own baseline, exactly as in the batch study (decision 0004).
Articles get renamed (Amazon.com became Amazon (company) in 2017). Views follow the title readers asked for, so both titles are listed and their views are added together per day.

Ideas to improve it

  • Load config/ into a small database so the dashboard can edit the study’s scope.
  • Generate docs/data-contracts.md from contracts.py instead of keeping two copies in step with a test.