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

# What is studied, and the rules every script follows

> docs/architecture/02-config-and-shared-rules.mmd

```mermaid theme={null}
%% Calendar Effects · 2 of 8 · What is studied, and the rules every script follows.
%% Paste into Miro: Creation bar > Diagram > Build with code.
flowchart LR
  subgraph CONFIG["config/ · WHAT is studied · hand-edited CSV registries (decisions 0003, 0005)"]
    retailers["retailers.csv<br/>one row per stock: ticker, company,<br/>country, retailer_type online or store, in_scope<br/>38 in scope: 7 online, 31 store<br/>e.g. AMZN WMT TGT COST LOW TJX KR"]
    etypes["event_types.csv<br/>one row per kind of event + a DATE RULE<br/>fixed:10-31 = same day every year<br/>nth_weekday:11:thu:4 = 4th Thursday of Nov<br/>offset:us_thanksgiving:+1 = day after another event<br/>listed = look the dates up"]
    edates["event_dates.csv<br/>dates for listed events with a source<br/>Prime Day, Chinese New Year"]
    wiki["wiki_articles.csv<br/>Wikipedia title per ticker<br/>2 titles when an article was renamed"]
    series["retail_series.csv<br/>FRED code to category, e.g. RSXFS = all retail"]
  end

  subgraph COMMON["src/common/ · HOW it is studied · imported by every script"]
    study["study.py · the numbers, defined once<br/>STUDY_START/END 2016–2025 · MARKET_TICKER SPY<br/>EVENT_WINDOW −5..+5 trading days<br/>ESTIMATION_DAYS 120 · ESTIMATION_GAP_DAYS 10<br/>ABNORMAL_RETURN_Z 1.96 · ATTENTION_SPIKE_Z 3.0<br/>CONFIDENCE 0.95"]
    settings["settings.py · WHERE things are<br/>raw/ clean/ data/ checkpoints/ paths<br/>clean_path name · KAFKA_BOOTSTRAP servers"]
    contracts["contracts.py · the DATA CONTRACTS in code<br/>CONTRACTS: exact columns and types of 15 tables<br/>load_retailers, load_event_types... read config/<br/>expand_events: date rules to real dates<br/>require_contract: refuse to save a wrong table<br/>spark_schema: the same contract for Spark"]
  end

  doc["docs/data-contracts.md<br/>the same contracts in words<br/>a test fails if doc and code disagree"]
  agents["AGENTS.md rules 1–11<br/>e.g. contracts are law · all times UTC<br/>no look-ahead · never type a value twice"]

  events[("events table, made in memory<br/>every occurrence of every in-scope event<br/>e.g. black_friday 2024-11-29<br/>never saved, so never out of date")]

  etypes --> contracts
  edates --> contracts
  retailers --> contracts
  wiki --> contracts
  series --> contracts
  contracts -->|expand_events| events
  doc <-->|kept in sync by tests/test_contracts.py| contracts
  agents --> COMMON
  events --> users["Used by: join_master.py, the streaming job,<br/>the batch study, the checks"]
  study --> users
  settings --> users
```

## Guide

```mermaid theme={null}
%% Calendar Effects · Guide 2 · What is studied, and the rules every script follows · goes next to diagram 02-config-and-shared-rules.mmd
%% Miro: paste onto a board, or Creation bar > Diagram > Build with code. Read top to bottom.
flowchart TB
  T["GUIDE 2 · CONFIG AND SHARED RULES<br/>config/ · src/common/ · AGENTS.md"]

  subgraph S1["1 · config/ · WHAT IS STUDIED · add a row, not code"]
    direction TB
    f1["retailers.csv<br/>38 in scope, online or store"]
    f2["event_types.csv<br/>6 in-scope events, each with a date rule"]
    f3["event_dates.csv<br/>hand-listed dates, each with a source"]
    f4["wiki_articles.csv<br/>Wikipedia title per ticker"]
    f5["retail_series.csv<br/>FRED code → category"]
  end

  subgraph S2["2 · DATE RULES · how event dates are worked out"]
    direction TB
    d1["fixed:10-31<br/>same day every year · Halloween"]
    d2["nth_weekday:11:thu:4<br/>4th Thursday · US Thanksgiving"]
    d3["offset:us_thanksgiving:+1<br/>days after another event · Black Friday"]
    d4["listed<br/>dates in event_dates.csv<br/>Prime Day, Chinese New Year"]
  end

  subgraph S3["3 · study.py · THE NUMBERS, written once"]
    direction TB
    n1["PERIOD<br/>2016 to 2025"]
    n2["MARKET<br/>SPY"]
    n3["EVENT WINDOW<br/>−5 to +5 trading days"]
    n4["ESTIMATION<br/>120 trading days, at least 100"]
    n5["ABNORMAL DAY<br/>z beyond ±1.96"]
    n6["ATTENTION SPIKE<br/>z ≥ 3 vs the last 28 days"]
  end

  subgraph S4["4 · DATA CONTRACTS · src/common/contracts.py"]
    direction TB
    c1["A CONTRACT<br/>a table's promised columns and types"]
    c2["WRITTEN TWICE<br/>data-contracts.md + contracts.py<br/>a test keeps them equal"]
    c3["require_contract<br/>refuses to save a wrong table"]
    c4["expand_events<br/>date rules → real dates, never saved"]
    c5["settings.py<br/>every path + the Kafka servers"]
  end

  subgraph S5["5 · TEAM RULES · AGENTS.md 1–11"]
    direction TB
    t1["DATA<br/>contracts are law · UTC<br/>no look-ahead"]
    t2["GIT<br/>commit your own work<br/>log AI help"]
    t3["CODE<br/>never type a value twice<br/>tests before every commit"]
  end

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

  classDef head fill:#2C2C2A,stroke:#2C2C2A,color:#FFFFFF
  classDef idea fill:#E6F1FB,stroke:#185FA5,color:#0C447C
  classDef num fill:#FAEEDA,stroke:#854F0B,color:#633806
  classDef file fill:#F1EFE8,stroke:#5F5E5A,color:#444441
  classDef step fill:#E1F5EE,stroke:#0F6E56,color:#085041
  class T head
  class f1,f2,f3,f4,f5,t1,t2,t3 file
  class d1,d2,d3,d4,c1,c2 idea
  class n1,n2,n3,n4,n5,n6 num
  class c3,c4,c5 step
  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
```


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