A simulated financial market where multiple intelligent agents trade simultaneously and learn strategies through reinforcement learning.
This project implements a custom trading environment where AI agents compete in a simulated stock market. Instead of predicting prices, agents learn trading behavior directly from reward signals - just like professional RL research at hedge funds and AI labs.
┌─────────────────────────────────────────────────────────────┐
│ Trading Environment │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────────────┐ │
│ │ Price Data │→ │ Features │→ │ State/Observation │ │
│ │ (AAPL) │ │ RSI, EMA, │ │ [returns, rsi, │ │
│ │ │ │ Volatility │ │ position, etc.] │ │
│ └─────────────┘ └─────────────┘ └─────────────────────┘ │
└─────────────────────────────────────────────────────────────┘
↓
┌─────────────────────────────────────────────────────────────┐
│ Agent Population │
│ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌────────────────┐ │
│ │ Random │ │Buy & Hold│ │ Momentum │ │ DQN │ PPO │ │
│ │ Agent │ │ Agent │ │ Agent │ │ RL Agents │ │
│ └──────────┘ └──────────┘ └──────────┘ └────────────────┘ │
└─────────────────────────────────────────────────────────────┘
↓
┌─────────────────────────────────────────────────────────────┐
│ Evaluation │
│ • Equity Curves • Sharpe Ratio • Max Drawdown • Win Rate│
└─────────────────────────────────────────────────────────────┘
# Create virtual environment
python -m venv venv
# Activate (Windows)
.\venv\Scripts\activate
# Activate (Mac/Linux)
source venv/bin/activate
# Install dependencies
pip install -r requirements.txt```bash
jupyter notebook multi_agent_trading_system.ipynbRun the interactive web app to watch agents trade:
streamlit run app.py| Agent | Type | Strategy |
|---|---|---|
| Random | Baseline | Random buy/sell/hold |
| Buy & Hold | Baseline | Buy once, hold forever |
| Momentum | Baseline | Follow trend using EMA |
| DQN | Learning | Deep Q-Network |
| PPO | Learning | Proximal Policy Optimization |
Observation Space:
- Price returns
- RSI (Relative Strength Index)
- EMA difference
- Volatility
- Volume change
- Current position
Action Space:
- 0: Hold
- 1: Buy
- 2: Sell
Reward Function:
reward = pnl - transaction_cost - drawdown_penalty
Performance metrics tracked:
- Total Return: Percentage gain/loss
- Sharpe Ratio: Risk-adjusted returns
- Max Drawdown: Largest peak-to-trough decline
- Win Rate: Percentage of profitable trades
- RL Framework: Stable-Baselines3, Gymnasium
- Deep Learning: PyTorch
- Data: yfinance, pandas, numpy
- Visualization: Plotly, Matplotlib
- Technical Analysis: ta-lib
Multi-Agent Reinforcement Learning Trading System(Agent)/
├── multi_agent_trading_system.ipynb # Main notebook
├── app.py # Streamlit Dashboard
├── save_data.py # Data download script
├── PROJECT_REPORT.md # Detailed technical report
├── requirements.txt # Dependencies
├── README.md # This file
├── data/ # Raw CSV data
│ ├── AAPL.csv
│ └── ...
├── models/ # Saved trained models
│ ├── dqn_AAPL.zip
│ └── ...
└── results/ # Generated outputs
- Hugging Face Models: AdityaaXD/Multi-Agent_Reinforcement_Learning_Trading_System_Models
- Hugging Face Data: AdityaaXD/Multi-Agent_Reinforcement_Learning_Trading_System_Data