This project demonstrates a simple Q-Learning algorithm applied to stock trading using Apple's historical price data. The agent learns to buy, sell, or hold shares to maximize profit over time.
Q-Learning is a reinforcement learning algorithm where an agent interacts with an environment, receives feedback, and learns the best actions to take. The agent updates its knowledge (Q-table) based on rewards received from its actions.
Below is a visual explanation of how Q-Learning works:
- Input: The agent receives an input (state).
- Response: The agent makes a prediction or takes an action.
- Feedback: The environment provides feedback (reward or penalty).
- Learns: The agent updates its knowledge based on feedback.
- Reinforced Response: The agent improves its future responses.
- Loads historical stock data for Apple.
- Sets up a trading environment with three actions: buy, sell, hold.
- Trains a Q-Learning agent to maximize profit.
- Tests the agent's performance on the data.
-
Place your dataset as
dataset.csvin the project folder. -
Run the script:
python app.py
-
The script will display candlestick charts and print the trading results.
- Python 3.x
- pandas
- numpy
- plotly
Install dependencies with:
pip install pandas numpy plotlyapp.py: Main script with Q-Learning implementation.dataset.csv: Historical stock data.readme.md: Project documentation.
