This project leverages quantum annealing and reinforcement learning to create a sophisticated trading bot for the stock market. The bot uses historical stock data to train a model that makes trading decisions based on support and resistance levels, moving averages, RSI, and stop-loss thresholds.
Table of Contents Prerequisites Setup Training the Model Paper Trading with Alpaca Files Prerequisites Before you begin, ensure you have met the following requirements:
Python 3.6 or later Necessary Python libraries: numpy pandas matplotlib dwave-ocean-sdk dimod alpaca-trade-api You can install the required packages using pip:
bash Copy code pip install numpy pandas matplotlib dwave-ocean-sdk dimod alpaca-trade-api Setup
Create a virtual environment and activate it:
bash
Copy code
python -m venv venv
source venv/bin/activate # On Windows use venv\Scripts\activate
Install the required packages:
bash Copy code pip install -r requirements.txt Training the Model Run the training script to train the model:
bash Copy code python BQC.py The training script will:
Load historical stock data. Calculate support and resistance levels, moving averages, and RSI. Train the trading model using a quantum annealer and Q-learning. Save the trained model to a file (model_episode_100.pkl). Paper Trading with Alpaca Ensure you have an Alpaca account and have obtained your API key and secret key. Replace 'your_api_key' and 'your_secret_key' in the paper_trading.py script with your actual Alpaca API credentials.
Run the paper trading script:
bash Copy code python paper_trading.py The paper trading script will:
Load the trained model. Fetch live market data from the Alpaca API. Make trading decisions and execute trades based on the model's predictions. Iterate this process for 30 days to simulate trading. Files BQC.py: Main script for training the trading model. paper_trading.py: Script for paper trading using the Alpaca API. data/Historic_data_SPY.csv: Historical stock data file (place your own data here). model_episode_100.pkl: Saved model file (generated after training). requirements.txt: List of required Python packages. License This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgments Alpaca for providing the API for live trading data. D-Wave for the quantum annealing technology.