Training ground simulation environment for backtesting AI agents against historical market regimes.
AgentDojo is a comprehensive backtesting and simulation platform for Permalator AI trading agents. It allows you to test agent strategies against historical data, simulate different market regimes, and analyze performance metrics before deploying to live markets.
- Historical Backtesting: Test agents against historical market data
- Regime Simulation: Simulate trend, chop, panic, compression, and cascade regimes
- Performance Metrics: Sharpe ratio, max drawdown, win rate, and more
- Agent Comparison: Compare multiple agents side-by-side
- Monte Carlo Simulation: Run multiple simulations for statistical validation
- Visual Analytics: Charts and reports for strategy analysis
- Backend: Python FastAPI
- Database: PostgreSQL + SQLAlchemy (async)
- Math: NumPy, Pandas, Statsmodels
- Market Data: CCXT integration
# Install dependencies
poetry install
# Set up environment
cp env.example .env
# Edit .env with your configuration
# Run database migrations
alembic upgrade head
# Start server
poetry run uvicorn agent_dojo.main:app --reloadAgentDojo uses CCXT to fetch real historical market data from cryptocurrency exchanges. The default exchange is Binance, but can be configured to use any CCXT-supported exchange (e.g., Bybit, OKX, Kraken).
Data fetched includes:
- Open, High, Low, Close prices
- Volume
- Timestamps
| Variable | Description | Default |
|---|---|---|
DATABASE_URL |
PostgreSQL connection string | postgresql://agentdojo:agentdojo123@localhost:5432/agent_dojo |
REDIS_URL |
Redis connection string (optional) | redis://localhost:6379/0 |
SECRET_KEY |
JWT signing secret | Generate new one! |
DEBUG |
Debug mode | False |
LOG_LEVEL |
Logging level | INFO |
agent-dojo/
├── agent_dojo/
│ ├── main.py # FastAPI app
│ ├── core/ # Config, logging, security
│ ├── models/ # Database models
│ ├── providers/ # Market data providers
│ ├── backtest/ # Backtesting engine
│ ├── simulation/ # Regime simulation
│ └── api/ # API routes
├── tests/ # Test suite
├── alembic/ # Database migrations
├── logs/ # Log files
├── pyproject.toml # Poetry dependencies
├── Dockerfile # Docker build
├── docker-compose.yml # Docker Compose
├── env.example # Environment template
└── README.md # This file
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/v1/backtest |
Run backtest |
| POST | /api/v1/simulate |
Run regime simulation |
| GET | /api/v1/backtests |
List backtests |
| GET | /api/v1/backtests/{id} |
Get backtest results |
| GET | /api/v1/backtests/{id}/metrics |
Get performance metrics |
| POST | /api/v1/compare |
Compare multiple agents |
| GET | /api/v1/agents/{id}/performance |
Get agent performance history |
from agent_dojo import BacktestEngine, SimulationConfig
# Configure backtest
config = SimulationConfig(
agent_id="agent_001",
symbol="BTC/USDT:USDT",
start_date="2024-01-01",
end_date="2024-12-31",
initial_capital=10000,
leverage=10
)
# Run backtest
engine = BacktestEngine()
results = await engine.run(config)
# Analyze results
print(f"Sharpe Ratio: {results.metrics.sharpe_ratio}")
print(f"Max Drawdown: {results.metrics.max_drawdown}")
print(f"Total Return: {results.metrics.total_return}%")MIT License - see LICENSE for details.