- Date: 2026-11-24
- Status: Agreed 2026-11-25 (proposed by Mahad)
- Agreed by: Mahad (2026-11-25), for the team
Context
The project had no machine learning, and the ProjectSummary’s “Algorithmic work” category names “data mining and machine learning techniques”. The streaming job already flags a big move each day (abnormal_return, |z_ar| ≥ ABNORMAL_RETURN_Z). That flag only says what happened. A model can say what is likely to happen next, using what the stream knows today, which is a natural use of the live pipeline.
Decision
-
Question: from a retailer’s daily row today, will its next trading day be a big move? The label is the same stock’s
abnormal_returnon its next trading day. -
Features (
src/ml/features.py) use only today’s row, the event calendar andconfig/retailers.csv:- from today’s row: |z_ar|, z_ar, ar_sd, beta, |mkt_ret|, z_views, attention_spike, log(vol_ratio), abnormal_return;
- from the calendar: days to the next in-scope event and since the last one, capped at
ML_EVENT_DAYS_CAP; - day of the week, month, and is_online.
-
Training data: the streaming job’s own daily output (
stream_signals), which matches the direct computation exactly. The model learns from the same numbers it is later shown live. -
Time split, never random (
common.study): train on 2016–ML_TRAIN_END_YEAR, choose the model onML_VALIDATION_YEAR, refit on both, and report onML_TEST_START_YEAR–2025. Rows whose “tomorrow” falls in the next period are dropped (a purged split). -
Models (
src/ml/train.py, Spark MLlib Pipelines):- logistic regression on standardized features, a transparent baseline;
- gradient-boosted trees, for non-linear effects and interactions.
-
Judged against:
- chance, the base rate;
- a no-model baseline that ranks by today’s |z_ar|;
- the same model without the attention features, to measure what Wikipedia adds.
-
Live:
src/streaming/job.pyloads the savedPipelineModeland scores each micro-batch inside the JVM (no Python on the workers). It writesstream_predictions.big_move_alert= 1 for the topML_ALERT_TOP_SHAREof probabilities, with the cut-off taken from the training years.
Results (2026-11-24, 38 retailers; test years 2024–2025, 18,696 stock-days)
- The model ranks tomorrow’s big movers clearly better than chance and better than “big moves cluster”.
- Wikipedia attention adds nothing once volume, the market’s move, volatility and the calendar are known.
- The most important features are month (earnings seasons), log volume ratio, the market’s absolute move, volatility (ar_sd) and days to or since an event.
Alternatives considered
- Predicting the direction of tomorrow’s return: daily direction is close to a coin toss in liquid stocks. Predicting a big move in either direction is realistic, and it is what an alert system needs.
- Predicting each event’s CAR: only 2,280 windows across 49 event dates. Too few for a held-out test with any power.
- A random train/test split: it would let the model learn from days after the ones it is tested on, which flatters the result.
- scikit-learn instead of MLlib: fine at this size, but MLlib runs on the cluster, plugs into Structured Streaming, and scales with the data.
- Lagged features (yesterday’s values): they would need extra state in the streaming job. Today’s row already carries volatility (ar_sd) and the market regime.
Consequences
- Everyone:
python3 src/ml/train.pyafter the streaming job (about 1 minute locally). It writesdata/models/(gitignored) andml_metrics.csv,ml_test_predictions.parquet,ml_feature_importance.csv,charts/ml_roc_pr.pngandcharts/ml_feature_importance.pngindata/results/. Restart the streaming job to get live predictions. - Contracts: new
stream_predictions,ml_metrics,ml_test_predictions,ml_feature_importance. - Settings:
common.studygainsML_TRAIN_END_YEAR,ML_VALIDATION_YEAR,ML_TEST_START_YEAR,ML_ALERT_TOP_SHARE,ML_EVENT_DAYS_CAP.common.settingsgainsMODEL_DIR,BIG_MOVE_MODEL,BIG_MOVE_MODEL_INFO, andSTREAM_SUBDIRS["stream_predictions"]. - Cluster: a model saved by Spark 4 may not load in the cluster’s Spark 3.5. Train it there with
spark-submit src/ml/train.py --signals <HDFS signals folder>. - Report: results section and ProjectSummary “Algorithmic work”. State plainly that attention adds nothing to the model, and that a 0.69 AUC is a ranking edge, not a trading strategy.