Skip to content

Add earnings-profit → 3–5 day price trend model - #2

Draft
ax3301 wants to merge 1 commit into
mainfrom
claude/earnings-profit-trend-model-5ac8xd
Draft

Add earnings-profit → 3–5 day price trend model#2
ax3301 wants to merge 1 commit into
mainfrom
claude/earnings-profit-trend-model-5ac8xd

Conversation

@ax3301

@ax3301 ax3301 commented Jul 23, 2026

Copy link
Copy Markdown
Owner

What

A model relating quarterly earnings / profit data to a stock's post-earnings price drift over the next 3 and 5 trading days.

New folder earnings_trend_model/:

File Purpose
earnings_trend.py Reusable pipeline: yfinance data → profit features → forward-trend labels → direction classifier + magnitude regressor
earnings_trend_model.ipynb Self-contained, Colab-friendly notebook (data → EDA → model → scoring)
README.md Usage, Robinhood data-source swap, and limitations (bilingual EN/中文)

How it works

  1. Per earnings event, engineer profit features: EPS surprise (%), revenue YoY, net-income YoY, net margin & its YoY change, pre-earnings 5/20-day momentum.
  2. Label each event with the forward return over 3 / 5 trading days after the announcement (entry = first trading day on/after the report), plus up/down direction.
  3. Model on the pooled, time-ordered event table: RandomForestClassifier for direction + Ridge for magnitude, with a chronological train/test split so the score reflects real forward use (no look-ahead leakage).
  4. Score the latest reported earnings per ticker → up-probability and expected N-day return.

Verified

Ran the full pipeline end-to-end on 8 large caps → 388 real earnings events. Data collection, both models, feature importances, and upcoming-earnings scoring all work.

Honest limitations (also in the README)

  • Free yfinance ships only ~5 quarters of income statements, so net_income_yoy / revenue_yoy are NaN for older events and show ~0 importance. The signal that actually drives the model is EPS surprise + pre-earnings momentum (earnings-date data covers ~25 quarters).
  • Direction accuracy sits near the majority-class baseline (~50%) — post-earnings drift is genuinely weak signal; the code reports numbers as-is. Widen TICKERS for statistical power, or swap in a longer-history fundamentals source (e.g. the Robinhood connector) to activate the YoY features.
  • Research only, not investment advice.

Notes

  • Data source is yfinance (no API key). An optional set_session() hook routes calls through a plain requests session for TLS-terminating proxy environments where curl_cffi gets reset.
  • To use the Robinhood connector instead, swap the three data-fetch functions in earnings_trend.py (documented in the README).

🤖 Generated with Claude Code


Generated by Claude Code

Model relating quarterly earnings/profit data to post-earnings price drift
over 3 and 5 trading days.

- earnings_trend.py: reusable pipeline (yfinance data -> profit features ->
  forward-trend labels -> direction classifier + magnitude regressor), with
  a chronological train/test split to avoid look-ahead leakage and an
  optional requests-session hook for restricted-proxy environments.
- earnings_trend_model.ipynb: self-contained, Colab-friendly notebook running
  data collection, EDA (correlation heatmap, EPS-surprise scatter, surprise
  buckets), modeling, and upcoming-earnings scoring.
- README.md: usage, data-source swap to Robinhood, and an honest write-up of
  limitations (free yfinance only ships ~5 quarters of income statements, so
  EPS surprise + pre-earnings momentum carry the usable signal).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QpxV7kVFiBk9JmdcW73iGb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants