An end-to-end Python project that tests whether financial news sentiment for EGX-listed companies helps explain next-day stock movement.
This project combines web scraping, bilingual sentiment analysis, market data collection, lag correlation analysis, and chart generation into a portfolio-ready research pipeline.
Does the sentiment of Mubasher headlines on day T show any relationship with EGX stock returns on day T+1?
Most public sentiment-trading examples focus on US equities and English-only data. This project explores a harder and more interesting setting:
- Egyptian listed stocks on the EGX
- Mubasher financial headlines
- Mixed Arabic and English coverage
- Small-sample, real-world financial data where null results are still informative
- Scrapes stock-specific news headlines from Mubasher.
- Detects headline language and scores sentiment.
- Downloads historical EGX prices through
yfinance. - Merges sentiment and price data by trading date.
- Computes lag correlations between sentiment and next-day returns.
- Generates charts for visual inspection.
- Optionally prepares an LLM-ready findings context and report stage.
- Python
- Pandas
- BeautifulSoup
- yfinance
- TextBlob
- langdetect
- Matplotlib / Seaborn
- SciPy
- OpenAI API for optional findings generation
EGX/
|-- data/
| |-- processed/
| `-- raw/
|-- docs/
| `-- assets/
|-- notebooks/
| `-- analysis.ipynb
|-- outputs/
| |-- charts/
| `-- reports/
|-- src/
| |-- config.py
| |-- llm_analysis.py
| |-- pipeline.py
| |-- prices.py
| |-- scraper.py
| |-- sentiment.py
| `-- visualize.py
|-- tests/
|-- requirements.txt
`-- run_pipeline.py
These are exploratory results from the broader sample window 2024-01-01 to 2026-03-27.
| Ticker | Company | Headlines | Merged Days | Strongest Observed Lag | Pearson r | Takeaway |
|---|---|---|---|---|---|---|
| TMGH | Talaat Moustafa Group | 32 | 31 | 1 day | -0.184 | Mildly negative relationship across the expanded window |
| COMI | Commercial International Bank | 32 | 31 | 3 days | 0.300 | Clearest delayed positive relationship in the current sample |
| ETEL | Telecom Egypt | 23 | 22 | 2 days | 0.301 | Noticeable lag signal, but still on a smaller sample |
TMGHno longer looks weakly positive in the broader sample. It trends mildly negative across all tested lags.COMIhas the clearest delayed effect in the current run, with the strongest observed correlation at a 3-day lag.ETELstill produces a noticeable 2-day lag signal, but on a smaller sample thanCOMI.- The project already surfaces an important lesson for financial ML: signal quality is uneven, and weak or null findings are valid outputs.
- Mubasher stock news pages for ticker-level headlines
- Yahoo Finance via
yfinancefor EGX OHLCV price data
- English headlines:
TextBlob - Arabic headlines: normalized lexicon-based scoring with finance-oriented phrase handling
- Language detection:
langdetect
- Daily mean sentiment aggregation
- Next-day return calculation
- Pearson correlation across lags
0to3 - Scatter and dual-axis charting for visual inspection
python -m venv .venv
.venv\Scripts\activate
pip install -r requirements.txt
python -m unittest discover -s tests -v
python run_pipeline.py --tickers TMGH COMI ETEL --start 2024-01-01 --end 2026-03-27 --pages 6 --delay 1.0Optional LLM report stage:
set OPENAI_API_KEY=your_key_here
python run_pipeline.py --tickers TMGH COMI ETEL --start 2024-01-01 --end 2026-03-27 --pages 6 --delay 1.0 --with-llm-analysisThe notebook at notebooks/analysis.ipynb is written as a rendered narrative artifact for GitHub, with visible findings tables and embedded visuals rather than acting as a blank scratchpad.
python -m unittest discover -s tests -vCurrent automated coverage includes:
- scraper parsing behavior
- Arabic sentiment normalization and scoring
- sentiment aggregation
- lag-correlation calculations
- LLM report formatting helpers
- Sample sizes are still small for each ticker
- The Arabic sentiment model is a hardened fallback, not a full pretrained financial transformer
- Mubasher page structure may change over time
- Correlation does not imply predictive causation
- The optional LLM stage depends on API access and account quota
- Expand to more EGX tickers and longer time windows
- Add a stronger Arabic sentiment backend such as
camel-toolsor a Hugging Face model - Compare sector-level behavior across banking, telecom, and real estate
- Improve notebook storytelling and publish a final research-style write-up
This project demonstrates:
- practical data engineering
- scraper robustness against messy live HTML
- bilingual NLP handling
- market data alignment and lag analysis
- test-driven hardening of a research pipeline
- turning exploratory work into a shareable GitHub portfolio project


