A sentiment-driven trading algorithm that leverages social media sentiment analysis to make stock market predictions. This project uses deep learning neural networks to analyze sentiment from social media platforms like Twitter, StockTwits, and Reddit to predict market movements.
- Sentiment Analysis: LSTM-based neural network for sentiment classification
- Social Media Integration: StockTwits API integration for real-time data collection
- Web Scraping: Automated data collection from social platforms
- Database Integration: MySQL database for storing sentiment data and predictions
- Machine Learning Pipeline: Complete ML workflow from data collection to prediction
- Python 3.7.4 or higher
- MySQL database
- StockTwits API access (optional)
-
Clone the repository
git clone https://github.com/your-username/feels-trader.git cd feels-trader -
Install dependencies
pip install -r requirements.txt
-
Set up configuration files
# Copy and configure database settings cp databaseconfig.py.example databaseconfig.py # Copy and configure API keys (optional) cp config.py.example config.py
-
Configure your credentials
- Edit
databaseconfig.pywith your MySQL database credentials - Edit
config.pywith your StockTwits API credentials (if using API features)
- Edit
-
Create a MySQL database and user:
CREATE DATABASE feelstrader_dev; CREATE USER 'your_username'@'localhost' IDENTIFIED BY 'your_password'; GRANT ALL PRIVILEGES ON feelstrader_dev.* TO 'your_username'@'localhost'; FLUSH PRIVILEGES;
-
Run the database schema:
mysql -u your_username -p feelstrader_dev < res/FeelsTrader_Schema.sql
For StockTwits integration, you'll need:
- StockTwits User ID
- StockTwits Username
- StockTwits Access Token
Add these to your config.py file or set as environment variables.
import dbio
# Initialize database connection
db = dbio.DbIO()
# Write a sentiment data point
db.write_datapoint_record('AAPL', 1, 'This stock is going places!')
# Read data points
results = db.read_datapoint_record(1)# Train or load sentiment model
python sentiment.py
# Run sentiment prediction
python test_sentiment_prediction.py# Collect data from StockTwits API
python stocktwitAPI.py
# Run web scraper (requires credentials)
python webscraper.pyfeels-trader/
├── data/ # Data files and datasets
├── drivers/ # Selenium WebDriver files
├── models/ # Trained ML models
├── research/ # Research papers and documentation
├── res/ # Resources (database schema, etc.)
├── dbio.py # Database I/O operations
├── sentiment.py # Sentiment analysis model
├── stocktwitAPI.py # StockTwits API integration
├── webscraper.py # Web scraping functionality
├── nlp.py # Natural language processing utilities
└── feelstrader.py # Main application entry point
The sentiment analysis model uses:
- Architecture: LSTM (Long Short-Term Memory) neural network
- Dataset: IMDB movie reviews for initial training
- Framework: Keras/TensorFlow
- Features: Text preprocessing, tokenization, and sequence padding
# The model trains on IMDB dataset with the following parameters:
- Vocabulary size: 5000 words
- Max sequence length: 500 words
- Batch size: 64
- Epochs: 3- StockTwits: Real-time social sentiment data
- IMDB Dataset: For initial model training
- Web Scraping: Additional social media platforms
- Security: Never commit sensitive credentials to version control
- API Limits: Be mindful of API rate limits when collecting data
- Legal: Ensure compliance with platform terms of service when scraping
- Performance: Model predictions should be validated before making trading decisions
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- TensorFlow Text Classification Tutorial
- Beginner's Guide to Sentiment Analysis with RNN
- LSTM RNN Network for Sentiment Analysis
- See
research/directory for academic papers on sentiment-based trading
This software is for educational and research purposes only. Trading decisions should not be made solely based on sentiment analysis. Always conduct thorough research and consider consulting with financial advisors before making investment decisions.