An AI-powered quantitative trading system featuring a Multi-Agent Reinforcement Learning Framework designed for transparency, robustness, and trust.
ReinforceTrade is a Python-based algorithmic trading platform that combines multiple specialized AI agents to make intelligent trading decisions. Unlike traditional black-box trading systems, ReinforceTrade provides complete transparency into its decision-making process through detailed visualizations and comprehensive backtest reports.
- Multi-Agent Architecture: Three specialized agents (Environment, Short-Term, Trend) work together under a central Decision Tower
- Reinforcement Learning: RL agents continuously improve through self-reinforcement using Stable Baselines3
- Risk Management: Advanced risk controls including dynamic position sizing and stop-loss mechanisms
- Transparent Reporting: Visual backtest reports showing every decision made by the system
- Strategy Optimization: Grid search and genetic algorithm optimization with walk-forward validation
graph TD
subgraph AI_Core [Multi-Agent Reinforcement Learning Framework]
A[Environment Perception Agent] --> |Identify Volatility & Trend| B{Central Decision Control Tower}
C[Short-Term Wave Agent] --> |Provide Buy/Sell Signals| B
D[Trend Tracking Agent] --> |Provide Direction Prediction| B
B -->|Dynamic Position Weight| E[Execution Agent]
end
E -->|Millisecond-level Order| F[Multiple Market Maker LPs]
F -->|Real-time Execution Feedback| A
style B fill:#f96,stroke:#333,stroke-width:2px
How It Works:
-
Environment Perception Agent (A): Continuously monitors market conditions, identifying volatility patterns and overall market trends.
-
Short-Term Wave Agent (C): Focuses on high-frequency trading opportunities, providing specific buy/sell signals based on momentum indicators.
-
Trend Tracking Agent (D): Provides macro-level direction predictions using longer-term moving averages and trend analysis.
-
Central Decision Control Tower (B): The brain of the system. It aggregates intelligence from all three agents, weighs their signals based on current market conditions, and makes the final trading decision including position sizing.
-
Execution Agent (E): Receives orders from the Control Tower and executes them through trading APIs with millisecond-level precision.
-
Reinforcement Learning Loop: Order execution results (prices, slippage, latency) are fed back to the Environment Perception Agent, allowing the AI system to continuously evaluate and improve its decisions.
The system enters a position only when:
- Confidence Threshold: The Decision Tower's confidence score exceeds 60% (configurable)
- Agent Consensus: At least 2 out of 3 agents signal the same direction
- Risk Limits: Position size does not exceed exposure limits
- Dynamic Stop Loss: Adjusted based on market volatility (default: 5%, increases to 7.5% in high volatility)
- Take Profit: Set at 10% by default
- Reversal Detection: System exits immediately if opposite signal with high confidence detected
- Position Sizing: Kelly Criterion-based sizing with confidence scaling
- Exposure Limits: Maximum 10% of portfolio per trade, 20% per symbol
- Consecutive Loss Protection: Reduces exposure after 3 consecutive losses
- Drawdown Control: Hard stop at 20% maximum drawdown
Our backtester provides:
- Realistic Simulation: Includes transaction costs and slippage
- Walk-Forward Validation: Prevents overfitting by testing on out-of-sample data
- Comprehensive Metrics: Sharpe ratio, Calmar ratio, profit factor, win rate
- Visual Reports: HTML reports with equity curves, drawdown analysis, and trade distributions
Every backtest report includes:
- Individual agent signals at key decision points
- Decision rationale and confidence scores
- Risk metrics and exposure tracking
- Comparison of in-sample vs out-of-sample performance
# Clone the repository
git clone https://github.com/EthanWalkerSV/ReinforceTrade.git
cd reinforcetrade
# Install dependencies
pip install -r requirements.txt
# Set up environment variables
cp .env.example .env
# Edit .env with your API keysfrom data import DataLoader
from agents import TrainingPipeline
from strategies import MultiAgentStrategy
from backtesting import EnhancedBacktester
# Load data
data_loader = DataLoader()
data = data_loader.fetch_historical_data('BTC/USDT', timeframe='1h', limit=5000)
# Train RL agents
pipeline = TrainingPipeline(agent_type='ppo')
pipeline.train_on_exchange_data('BTC/USDT', total_timesteps=50000)
# Run backtest
strategy = MultiAgentStrategy(use_rl=True)
backtester = EnhancedBacktester(strategy, initial_balance=10000)
results = backtester.run(data)
# Generate report
from reports import ReportGenerator
report_gen = ReportGenerator()
report_dir = report_gen.generate_full_report(results)- Architecture Overview - Detailed system architecture and component interactions
- Getting Started - Step-by-step setup and first run guide
- API Reference - Complete API documentation
- Transparency & Trust - How we ensure transparency in AI decisions
ReinforceTrade/
├── agents/ # Multi-agent system
│ ├── base_agent.py
│ ├── environment_agent.py
│ ├── short_term_agent.py
│ ├── trend_agent.py
│ ├── decision_tower.py
│ ├── rl_agent.py
│ └── training_pipeline.py
├── strategies/ # Trading strategies
│ ├── base_strategy.py
│ ├── multi_agent_strategy.py
│ └── risk_manager.py
├── backtesting/ # Backtest engine
│ ├── backtester.py
│ └── enhanced_backtester.py
├── environments/ # RL environments
│ └── trading_env.py
├── data/ # Data loading and preprocessing
│ └── data_loader.py
├── trading/ # Exchange interfaces
│ └── exchange.py
├── reports/ # Report generation
│ └── report_generator.py
├── optimization/ # Strategy optimization
│ ├── strategy_optimizer.py
│ └── walk_forward_validation.py
├── utils/ # Utilities
│ └── logger.py
├── config/ # Configuration
│ └── settings.py
├── docs/ # Documentation
└── tests/ # Unit tests
The system continuously improves through:
- Experience Collection: Every trade's outcome is recorded
- Performance Analysis: Win/loss patterns are analyzed by agent
- Model Updates: RL models are periodically retrained on new data
- Hyperparameter Tuning: Strategy parameters are optimized using genetic algorithms
- Validation: Walk-forward validation ensures improvements generalize to new data
- Circuit Breakers: Automatic trading halt on extreme volatility
- Maximum Drawdown: Hard stop at 20% portfolio loss
- Position Limits: Prevents over-concentration in single assets
- API Safety: Rate limiting and error handling for all exchange operations
MIT License - See LICENSE file for details.
This software is for educational and research purposes only. Trading cryptocurrencies involves substantial risk of loss. Past performance does not guarantee future results. Always conduct thorough backtesting and risk assessment before using with real capital.
For questions or support, please open an issue on GitHub or contact the development team.
ReinforceTrade: Building trust through transparency in AI-powered trading.