Skip to content

Repository files navigation

🤖📈 Multi-Agent Reinforcement Learning Trading System

A simulated financial market where multiple intelligent agents trade simultaneously and learn strategies through reinforcement learning.

🎯 Project Overview

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.

🏗️ Architecture

┌─────────────────────────────────────────────────────────────┐
│                    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│
└─────────────────────────────────────────────────────────────┘

🚀 Quick Start

1. Setup Environment

# 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

2. Run the Notebook

```bash
jupyter notebook multi_agent_trading_system.ipynb

3. Launch Dashboard

Run the interactive web app to watch agents trade:

streamlit run app.py

📊 Agents

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

🎮 Trading Environment

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

📈 Results

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

🛠️ Tech Stack

  • RL Framework: Stable-Baselines3, Gymnasium
  • Deep Learning: PyTorch
  • Data: yfinance, pandas, numpy
  • Visualization: Plotly, Matplotlib
  • Technical Analysis: ta-lib

📁 Project Structure

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

📚 References

🌐 External Resources

About

No description, website, or topics provided.

Resources

Stars

3 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages