This project implements the FinBERT-LSTM model for predicting stock prices. The model combines financial news sentiment analysis with historical stock price data using deep learning techniques like Long Short-Term Memory (LSTM) networks and the FinBERT NLP model. The project is inspired by the research paper FinBERT-LSTM: Deep Learning based stock price prediction using News Sentiment Analysis.
- Stock Price Data: Collects historical stock price data using the Yahoo Finance API.
- News Sentiment Analysis: Uses the FinBERT NLP model to compute sentiment scores for financial news.
- Deep Learning Model: Combines stock prices and sentiment data into a FinBERT-LSTM model for accurate predictions.
- Performance Metrics: Evaluates model performance using metrics like MAE (Mean Absolute Error) and MAPE (Mean Absolute Percentage Error).
FinBERT_LSTM/
├── data/
│ ├── stock_prices.csv # Stock price data
│ ├── news_sentiment.csv # Sentiment scores from FinBERT
│ ├── merged_data.csv # Combined stock prices and sentiment data
├── notebooks/
│ ├── data_preprocessing.ipynb # Data collection and preprocessing
│ ├── model_training.ipynb # Model training and evaluation
├── models/
│ ├── finbert_lstm_model.keras # Trained FinBERT-LSTM model
│ ├── checkpoints/ # Checkpoints for intermediate training states
├── scripts/
│ ├── 1_collect_stock_data.py # Script to fetch stock prices
│ ├── 2_collect_news_data.py # Script to fetch financial news
│ ├── 3_compute_sentiments.py # Script to compute sentiment scores
│ ├── 4_merge_data.py # Script to merge data
│ ├── 5_create_sequences.py # Script to create training sequences
│ ├── 6_train_model.py # Script for training the FinBERT-LSTM model
│ ├── 7_evaluate_model.py # Script for evaluating and visualizing results
│ ├── 8_predict_next_day.py # Script for prediction
├── requirements.txt # List of dependencies
├── README.md # Project documentation
git clone https://github.com/your-username/FinBERT_LSTM.git
cd FinBERT_LSTMMake sure you have Python 3.7+ installed. Install the required packages using:
pip install -r requirements.txtRun 1_collect_stock_data.py to fetch stock price data.
python scripts/1_collect_stock_data.pyRun 2_collect_news_data.py to fetch financial news articles.
python scripts/2_collect_news_data.pyRun 3_compute_sentiments.py to calculate sentiment scores using FinBERT.
python scripts/3_compute_sentiments.pyRun 4_create_sequences.py to create rolling window sequences for LSTM training.
python scripts/4_create_sequences.pyRun 5_merge_data.py to merge the news_data.csv with the stock_data.csv
python scripts/5_merge_data.pyRun 6_train_model.py to train the FinBERT-LSTM model.
python scripts/6_train_model.pyRun 7_evaluate_model.py to evaluate and visualize predictions.
python scripts/7_evaluate_model.pyRun 8_predict_next_day.py to see next day prediction.
python scripts/8_predict_next_day.py- FinBERT: A financial sentiment analysis model based on BERT.
- LSTM: A recurrent neural network architecture for time-series prediction.
- Yahoo Finance API: For fetching historical stock price data.
- New York Times API: For collecting financial news articles.
The FinBERT-LSTM model achieves:
- Lower MAE and MAPE compared to traditional LSTM and MLP models.
- Enhanced accuracy by integrating news sentiment into stock price prediction.
- Python: Core programming language.
- TensorFlow/Keras: For building and training deep learning models.
- Transformers (Hugging Face): For FinBERT sentiment analysis.
- Pandas/Numpy: Data manipulation and preprocessing.
- Matplotlib: Visualization.
- Expand the dataset with global financial news sources.
- Experiment with additional deep learning architectures (e.g., CNN-LSTM).
- Develop a real-time prediction system for stock trading.
- Halder, S. (2022). FinBERT-LSTM: Deep Learning based stock price prediction using News Sentiment Analysis. arXiv.
Feel free to fork this project and submit pull requests. Contributions are always welcome!
For any inquiries, please email: [email protected]