Skip to main content
The ETL (extract, transform, load) turns three outside sources into one clean table, clean/master.parquet: one row per stock per trading day, with that day’s return, volume ratio, Wikipedia views and event name. Everything downstream reads only this table.

The big idea

Each source gets a download script that saves raw files untouched (raw/, never committed) and a clean script that checks them and writes a Parquet table that matches its contract (clean/, small and committed so teammates can skip the downloads).
  • Prices come from Yahoo Finance: adjusted close and volume for every retailer and SPY. Cleaning (with Spark) computes the daily return and the volume ratio (today’s volume against its recent average).
  • Pageviews come from the Wikimedia REST API, counting real users only (no bots). Renamed articles are added together per ticker and day.
  • Retail sales come from the US Census via FRED. They are cleaned but not analysed (decision 0012).
  • Events are not downloaded: they come from config/ through expand_events.
join_master.py then joins prices, pageviews and events on ticker and date.

Words you will meet

A column-oriented file format: compact, typed, and fast for Spark and pandas to read.
The closing price corrected for splits and dividends, so returns across those days are real returns.
A day’s trading volume divided by its recent average. Above 1 means unusually busy; the model uses its logarithm.

The picture: ETL: Extract (download), Transform (clean), Load (save)

The full diagram and its guide explain every box.

Read these files in this order

1

etl/prices_download.py

Download daily prices for every in-scope retailer in config/retailers.csv, plus the market index (common.study.MARKET_TICKER), from Yahoo Finance, over the study period. Read it
2

etl/prices_clean.py

Clean the raw price files with Spark and save clean/prices.parquet. Read it
3

etl/pageviews_download.py

Download daily Wikipedia page views (real users only, no bots) for each article of an in-scope retailer in config/wiki_articles.csv, over the study period, and save them to raw/wiki/<article>.json. Read it
4

etl/pageviews_clean.py

Clean the raw page view files and save clean/pageviews.parquet. Read it
5

etl/retail_clean.py

Clean the US Census monthly retail sales series listed in config/retail_series.csv (downloaded from FRED) into one file. Read it
6

etl/build_events.py

Build the events table (see docs/data-contracts.md) from config/event_types.csv and config/event_dates.csv, and write a copy to data/events.parquet for browsing. Read it
7

etl/join_master.py

Join prices, page views and events into clean/master.parquet, the one table Kafka replays later. Read it

Questions you should be able to answer

Raw files are exactly what the source sent, so cleaning can be re-run and changed without downloading again, and a mistake in cleaning never destroys the original.
No. The market index has no article, so its views are empty in master, and the streaming job only scores attention for retailers.
Prime Day spans several days, so event_type is set on every day from its start to its end date. The analysis still uses one day 0 per occurrence, from the calendar.

Ideas to improve it

  • Use the retail sales series: does a strong monthly sales report move retailers’ CARs?
  • Add news volume (for example GDELT) as a second attention measure.