Analyzes correlation between news sentiment and stock price movements, trains a classifier to predict next-day price direction, and visualizes everything in an interactive Streamlit dashboard.
pip install yfinance nltk scikit-learn pandas streamlit matplotlib joblib-
Prepare data (fetches price history + scores headline sentiment):
python data_prep.py
This creates
merged_data.csv. Editheadlines.csvto add more headlines (Date, Ticker, Headline columns) for richer sentiment signal. -
Train the model:
python train_model.py
This creates
model.pklandbacktest_results.csv, and prints accuracy + Sharpe ratio metrics. -
Launch the dashboard:
streamlit run app.py
data_prep.py— fetches OHLCV data via yfinance, scores headlines with VADER sentiment, merges intomerged_data.csvheadlines.csv— sample news headlines (replace/expand with real data from a news API for better results)train_model.py— feature engineering (rolling averages, volatility, lagged sentiment) + RandomForest classifier + backtesting with Sharpe ratioapp.py— Streamlit dashboard: price charts, sentiment bars, predictions table, and strategy vs buy-and-hold backtest plot
- Talk through: why VADER (fast, no training needed, decent for short text),
why RandomForest (handles non-linear feature interactions, robust to
small datasets), and why
shuffle=Falsein train/test split (avoids lookahead bias in time-series). - To improve: swap VADER for a transformer-based sentiment model (e.g. FinBERT), add more tickers/headlines, try XGBoost or LSTM.
- The provided
headlines.csvis a small sample — for real numbers, scrape headlines from a news API (e.g. NewsAPI, Finnhub) matching the price data's date range.