Skip to main content
src/ml/features.py · chapter The big-move model, file 2 · 101 lines · open in the repository

What it does

Features for the big-move model (decision 0007). The same code builds the features for training (src/ml/train.py, on the stream’s daily output) and for live scoring (src/streaming/job.py), so the model never meets a feature computed differently from the way it was trained (“training/serving skew”). Every feature uses only today’s row, the event calendar and config/retailers.csv, never a later day: today’s stream row |z_ar|, z_ar, ar_sd, beta, |mkt_ret|, z_views, attention_spike, log(vol_ratio), abnormal_return the event calendar days to the next in-scope event day and since the last one the date day of the week, month config/retailers.csv is_online The label, used only in training, is the same stock’s abnormal_return on its next trading day: did tomorrow bring a big move? Usage:

What is inside

  • FEATURES · line 32
  • ATTENTION_FEATURES · line 38: Dropped together to measure what Wikipedia attention adds to the model.
  • LABEL · line 39
  • event_days(start_year, end_year) · line 42: Every calendar day covered by an in-scope event, sorted (Prime Day spans several).
  • calendar_table(start_year, end_year, cap) · line 53: One row per calendar day: days to the next event day and since the last one.
  • retailer_table() · line 72: ticker -> is_online (1 for online retailers, 0 for store retailers).
  • add_features(df, calendar, retailers) · line 78: Spark: rows with the stream_signals columns, plus every column in FEATURES.
  • add_label(df) · line 96: Spark: the label, each stock’s abnormal_return on its next trading day.

Connections

Uses: src/common/contracts.py, src/common/study.py Used by: src/streaming/job.py, src/ml/train.py, tests/test_ml_features.py

Source

src/ml/features.py