Skip to main content
Before any detail, know the shape: data comes in, gets cleaned into one table, is replayed as a stream, is analysed twice (live and in batch), and the two answers are compared. A model and a dashboard sit on top. One shell script, run_everything.sh, runs all of it in order, so it is the best map of the project.

The big idea

An event study asks: did something unusual happen to a stock around an event? “Unusual” needs a baseline. For each stock we learn how it normally moves with the market (its market model: when the market goes up 1%, this stock usually goes up β%). On an event day, the abnormal return is the actual move minus the move the market model expected. Add the abnormal returns over a window of days around the event and you get the cumulative abnormal return (CAR). For example, if Walmart rises 2% on a day the model expected 0.5%, its abnormal return is +1.5 percentage points. If that happens on several days around Black Friday, its CAR is large, and if CARs are large for many retailers across many years, Black Friday has a “calendar effect”.

Words you will meet

How much a price changed in a day, as a fraction: 100 → 102 is a return of 0.02 (+2%). We use simple returns of the adjusted close price.
A straight line fitted by ordinary least squares (OLS): stock return = alpha + beta × market return. The market is SPY, a fund that follows the S&P 500.
Trading days −5 to +5 around day 0, the first trading day on or after the event date.
The 120 trading days before the event window, on which the market model is fitted, so the event never influences its own baseline.
A message broker: producers write messages to a topic, consumers read them in order. Here it carries one message per stock per trading day.
Spark’s streaming engine. It treats a stream as a table that keeps growing and processes it in small micro-batches.

How it runs

run_everything.sh sets up Python and Java, optionally re-runs the ETL, replays the data (through Kafka, or through files when Kafka is not available), runs the streaming job, checks it against a direct computation, runs the batch study, compares the two, and trains the model. ./run_everything.sh --help lists every option; --skip-etl reuses the committed clean tables and takes about 20 minutes.

The picture: The big picture

The full diagram and its guide explain every box.

The picture: How to run it: on a laptop, or on the SFU cluster

The full diagram and its guide explain every box.

Read these files in this order

1

README.md

Calendar Effects Read it
2

run_everything.sh

Run the whole Calendar Effects pipeline in one command: ETL -> master table -> streaming job -> check against a direct computation -> batch event study -> stream vs batch comparison -> big-move model. See README “Running it locally”. Read it
3

requirements.txt

Everything the pipeline needs: python3 -m pip install -r requirements.txt (tests also need requirements-dev.txt) Read it
4

requirements-dev.txt

Tools for running the tests locally: python3 -m pip install -r requirements-dev.txt Read it
5

pyproject.toml

Makes src/ an installable package, so import common works from any script and any folder. requirements.txt installs it (the -e . line); dependencies are pinned there. Read it

Questions you should be able to answer

Because a streaming job is easy to get subtly wrong: late messages, out-of-order days, state kept between batches. An independent batch computation of the same numbers is an answer key. When all 2,280 event windows agree to about 1e-15, both are almost certainly right.
Ten years of history make the statistics meaningful, and a replay is repeatable: the same run gives the same answer, so it can be checked. The job does not know the data is old; it processes each message as it arrives.
Spark runs on the Java virtual machine. PySpark 4.0 needs Java 17 or 21 (not newer), so the script picks a supported one.

Ideas to improve it

  • Run the pipeline in CI on a small sample, so a teammate’s push is tested on a clean machine.
  • Stream live prices for the current week alongside the replay, to show the job works on real time too.