Skip to main content
The stream already says whether today was abnormal. The model asks: will tomorrow be a big move (|z_ar| ≥ 1.96) for this retailer? Direction is close to a coin toss; size is more predictable, because big moves cluster.

The big idea

  • One feature builder (features.py) is used both for training and live scoring, so the model sees the same inputs in both: today’s |z_ar|, the volatility of abnormal returns, beta, the market’s absolute move, Wikipedia z-score and spike, log volume ratio, days to and since an event, day of week, month, and online vs store.
  • Training (train.py) uses Spark MLlib Pipelines: a VectorAssembler, then logistic regression (with a StandardScaler) or gradient-boosted trees.
  • The split is by time, never at random: fit on 2016–2022, choose the model on 2023, test once on 2024–2025. Rows whose “tomorrow” falls in the next period are dropped (purged), so no label leaks across the split.
  • Big moves are about 5% of days, so the classes are weighted equally during training.
  • The alert flags the top 5% of scores (the cut-off is set on the validation year), and the streaming job writes it each micro-batch.
On 2024–2025 the trees reach ROC-AUC 0.69; 21.5% of flagged days are big moves, 4.1 times the 5.2% base rate. Today’s |z_ar| alone gives 0.58. Removing the Wikipedia features changes nothing.

Words you will meet

The chance that a random big-move day gets a higher score than a random quiet day. 0.5 is guessing, 1 is perfect.
Precision (share of flags that were right) across recall levels. Compare it with the base rate; lift is precision divided by the base rate.
Many small decision trees, each correcting the errors of the ones before it.
Whether a score of 0.3 really means a 30% chance. These scores are not calibrated (the class weights shift them up), so the dashboard shows shares of flags, not raw scores, as rates.

The picture: The big-move model (Spark MLlib) and the live dashboard

The full diagram and its guide explain every box.

Read these files in this order

1

src/ml/init.py

The big-move model (decision 0007): Spark MLlib on the streaming job’s daily output. Read it
2

src/ml/features.py

Features for the big-move model (decision 0007). Read it
3

src/ml/train.py

Train and test the big-move model with Spark MLlib (decision 0007). Read it

Questions you should be able to answer

Days next to each other are alike. A random split puts tomorrow in training and today in testing, so the model looks better than it would be on the future. A time split tests it like it will be used.
It is a real ranking edge over the baseline (0.58), and flagged days are four times as likely to be big moves. It is not a trading strategy: it predicts size, not direction, and ignores costs.
Not for this model: the ablation without the two attention features scores the same. That is a finding worth reporting, not a failure.

Ideas to improve it

  • Predict the CAR of an upcoming event window directly, with event-level features.
  • Calibrate the scores (isotonic regression) so they can be read as probabilities.