A tool for predicting stock movements using reinforcement learning techniques with interactive visualizations and a web dashboard.
- Multi-stock training and prediction
- Real-time stock data visualization
- Interactive stock selection
- Technical indicators display
- Model prediction visualization
- Trade history and performance metrics
- Portfolio analysis
- Top 10 stocks tracking
- Automatic model selection based on stock ticker
- Robust error handling and data validation
- Flexible data fetching with multiple time intervals
- Python 3.8+
- pip
- make
- virtualenv (optional, but recommended)
-
Clone the repository:
git clone https://github.com/yourusername/stockPred.git cd stockPred -
Set up the development environment using make:
# This will create a virtual environment and install all dependencies make setupAlternatively, you can install the package directly:
make install
-
Create a
.envfile in the project root:# Sets the PYTHONPATH to the project root directory PYTHONPATH=/path/to/your/stockPred
The project includes several make commands for common tasks:
make setup # Set up development environment
make install # Install package
make test # Run tests
make lint # Run linters
make format # Format code
make clean # Clean up build files
make train # Train models
make dashboard # Start dashboard
make benchmark # Run performance benchmarksThe system supports training on multiple stocks simultaneously:
# Train on predefined stocks
python src/train_models.py
# Train on top 10 stocks (default)
make train
# Or with custom parameters
python src/main.py --start-date 2020-01-01 --end-date 2023-12-31 --episodes 100Training will:
- Train models for predefined stock tickers
- Train separate optimized and default models
- Save models to the
modelsdirectory - Display training progress and metrics
- Show a final summary of results
make testThe test suite includes:
- Unit tests for all components
- Performance benchmarks
- Integration tests
- Real-time data handling tests
- Model architecture tests
# Start the dashboard
make dashboard
# Or with custom parameters
python src/dashboard/run.py --port 8050 --debug --auto-openThe dashboard will be available at http://localhost:8050 (or your specified port).
- Real-time stock data visualization
- Interactive stock selection with automatic model loading
- Technical indicators display
- Model prediction visualization
- Trade history and performance metrics
- Portfolio analysis
- Top 10 stocks tracking with:
- Current prices
- Price changes
- Trading volume
- Color-coded performance indicators
- Robust error handling and status display
- Automatic data refresh and model updates
stockPred/
├── src/
│ ├── data/
│ │ ├── stock_data.py # Stock data fetching and preprocessing
│ │ ├── realtime_data.py # Real-time data streaming with error handling
│ │ └── top_stocks.py # Top stocks tracking
│ ├── models/
│ │ └── dqn_agent.py # DQN agent with improved state handling
│ ├── env/
│ │ └── trading_env.py # Trading environment with enhanced rewards
│ ├── dashboard/
│ │ ├── app.py # Main dashboard with error handling
│ │ └── run.py # Dashboard runner with port configuration
│ └── main.py # Main training script
├── tests/ # Comprehensive test suite
├── models/ # Trained model files (optimized and default)
├── results/ # Training results and plots
├── requirements.txt # Project dependencies
├── Makefile # Make commands for common tasks
└── README.md # This file
The system uses a Deep Q-Network (DQN) with:
- 3-layer neural network architecture:
- Input layer: State size (varies by stock)
- Hidden layers: 64 units each with ReLU activation
- Output layer: 3 units (buy, sell, hold)
- Experience replay for stable learning
- Target network for stable Q-value estimation
- Epsilon-greedy exploration strategy
- Huber loss for robust training
- Improved state handling for various input formats
- Automatic model selection based on stock characteristics
- Multiple time interval support (1d, 1h, 5m)
- Robust error handling for data fetching
- Automatic retry mechanism for data streams
- Graceful fallback for missing data
- Enhanced technical indicators
- Fork the repository
- Create a feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.