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

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

> docs/architecture/11-ml-and-dashboard.mmd

```mermaid theme={null}
%% Calendar Effects · 11 · The big-move model (Spark MLlib) and the live dashboard · Mahad · decisions 0007, 0008.
%% Paste into Miro: Creation bar > Diagram > Build with code.
flowchart LR
  signals[("data/stream/signals<br/>the stream's daily rows<br/>95,190 stock-days")]

  subgraph FEAT["src/ml/features.py · the same features for training and live"]
    f1["today's row<br/>|z_ar| · ar_sd · beta · |mkt_ret|<br/>z_views · spike · log vol_ratio"]
    f2["calendar<br/>days to / since an event<br/>day of week · month"]
    f3["config/retailers.csv<br/>is_online"]
  end

  subgraph TRAIN["src/ml/train.py · Spark MLlib Pipelines"]
    split["TIME SPLIT, purged<br/>train 2016–2022 · choose on 2023<br/>test 2024–2025"]
    cands["CANDIDATES<br/>logistic regression (scaled)<br/>gradient-boosted trees<br/>classes weighted equally"]
    pick["PICK on 2023 by PR-AUC<br/>→ trees, depth 3<br/>refit on 2016–2023"]
    test{"TEST 2024–2025<br/>ROC-AUC 0.69 · PR-AUC 0.135<br/>top 5% hit 21.5% vs 5.2% base<br/>baseline |z_ar|: 0.58"}
  end

  model[("data/models/big_move<br/>PipelineModel + alert cut-off")]
  results[("data/results/<br/>ml_metrics · ml_test_predictions<br/>ml_feature_importance · ml charts")]

  subgraph LIVE["src/streaming/job.py · each micro-batch"]
    score["score today's rows<br/>inside the JVM<br/>no Python on workers"]
    preds[("data/stream/predictions<br/>p_big_move_next<br/>big_move_alert = top 5%")]
  end

  subgraph DASH["src/dashboard/app.py · on a laptop and hosted · diagram 12"]
    d1["reads finished batches only<br/>_SUCCESS marker · refreshes every 5 s"]
    d2["today's alerts · tomorrow's watchlist<br/>event CARs as windows close<br/>alerts per day · one retailer's path"]
    d3["views: Live stream · Replay any years<br/>Event history & forecast · About"]
  end

  signals --> FEAT --> split --> cands --> pick --> test
  pick --> model
  test --> results
  model --> score --> preds
  signals --> d1
  preds --> d1
  d1 --> d2 --> d3
```

## Guide

```mermaid theme={null}
%% Calendar Effects · Guide 11 · The big-move model and the live dashboard · goes next to diagram 11-ml-and-dashboard.mmd
%% Miro: paste onto a board, or Creation bar > Diagram > Build with code. Read top to bottom.
flowchart TB
  T["GUIDE 11 · THE BIG-MOVE MODEL AND THE DASHBOARD<br/>src/ml/ · src/dashboard/ · decisions 0007, 0008"]

  subgraph S1["1 · THE QUESTION"]
    direction TB
    q1["WILL TOMORROW BE A BIG MOVE?<br/>for each retailer, from what<br/>the stream knows today"]
    q2["BIG MOVE<br/>tomorrow's |z_ar| ≥ 1.96<br/>= tomorrow's daily alert"]
    q3["WHY NOT DIRECTION?<br/>up or down is close to a coin toss<br/>a big move either way is predictable"]
  end

  subgraph S2["2 · WORDS"]
    direction TB
    w1["MLlib<br/>Spark's machine-learning library<br/>runs on the cluster"]
    w2["PIPELINE<br/>assemble features → scale → model<br/>saved and loaded as one object"]
    w3["GRADIENT-BOOSTED TREES<br/>many small decision trees,<br/>each fixing the last one's errors"]
    w4["ROC-AUC<br/>chance a big-move day ranks above<br/>a quiet day · 0.5 = chance"]
    w5["PR-AUC<br/>precision across recall levels<br/>compare with the base rate"]
  end

  subgraph S3["3 · DOING IT HONESTLY"]
    direction TB
    h1["TIME SPLIT<br/>never random rows: the model<br/>is tested on later days only"]
    h2["PURGED<br/>a row whose tomorrow falls<br/>in the next period is dropped"]
    h3["CLASS WEIGHTS<br/>big moves are 5% of days<br/>so each class counts equally"]
    h4["SAME FEATURES LIVE<br/>one function for training<br/>and for scoring"]
  end

  subgraph S4["4 · RESULTS · test years 2024–2025 · 18,696 stock-days"]
    direction TB
    r1["TREES · ROC-AUC 0.69<br/>top 5% flagged: 21.5% are big moves<br/>4.1× the 5.2% base rate"]
    r2["BASELINE · today's |z_ar|<br/>ROC-AUC 0.58 · 2.4× lift"]
    r3["WITHOUT ATTENTION<br/>same score: Wikipedia adds<br/>nothing to this model"]
    r4["WHAT MATTERS<br/>month · volume · market move<br/>volatility · days to an event"]
  end

  subgraph S5["5 · THE DASHBOARD"]
    direction TB
    d1["streamlit run<br/>src/dashboard/app.py<br/>→ localhost:8501"]
    d2["READS SAFELY<br/>only batches with _SUCCESS<br/>each batch cached once"]
    d3["SHOWS<br/>today's alerts · watchlist<br/>closing event CARs · charts"]
    d4["FOR THE DEMO<br/>job without --once replays<br/>one file every 5 seconds"]
  end

  subgraph S6["6 · SAY IT CAREFULLY"]
    direction TB
    c1["0.69 IS A RANKING EDGE<br/>not a trading strategy"]
    c2["CLUSTER<br/>a Spark 4 model may not load in 3.5<br/>retrain there with spark-submit"]
  end

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

  classDef head fill:#2C2C2A,stroke:#2C2C2A,color:#FFFFFF
  classDef idea fill:#E6F1FB,stroke:#185FA5,color:#0C447C
  classDef step fill:#E1F5EE,stroke:#0F6E56,color:#085041
  classDef win fill:#EAF3DE,stroke:#3B6D11,color:#27500A
  classDef warn fill:#FAECE7,stroke:#993C1D,color:#712B13
  classDef ask fill:#EEEDFE,stroke:#534AB7,color:#3C3489
  class T head
  class q1,q2,q3 ask
  class w1,w2,w3,w4,w5 idea
  class h1,h2,h3,h4 step
  class r1,r2,r4 win
  class r3 warn
  class d1,d2,d3,d4 step
  class c1,c2 warn
  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
  style S6 fill:#FFFFFF,stroke:#B4B2A9
```


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