Your First Backtest¶
Run your first strategy backtest in under 5 minutes.
Fastest Path
Use tradai backtest quick PascalStrategy --local with the pre-bundled sample data to run a backtest in seconds without starting any services.
Prerequisites¶
- TradAI workspace set up (
just setupcompleted) - Exchange API keys configured (optional, for live data)
Quick Start¶
1. Start Services¶
# Start all services (Backend, Data Collection, Strategy Service, MLflow)
just up
# Verify services are running
just docker ps
Expected output:
NAME STATUS PORTS
tradai-backend Up 0.0.0.0:8000->8000/tcp
tradai-data Up 0.0.0.0:8002->8002/tcp
tradai-strategy Up 0.0.0.0:8003->8003/tcp
tradai-mlflow Up 0.0.0.0:5001->5001/tcp
2. Use Sample Data or Sync Fresh Data¶
Option A: Use Pre-bundled Sample Data (Fastest)
Sample Data Included
Sample market data is pre-bundled in the repository so you can run backtests immediately without any exchange API setup.
Sample market data is included in the repository for quick testing:
user_data/data/binance/futures/
├── BTC_USDT_USDT-1h-futures.feather
├── BTC_USDT_USDT-4h-futures.feather
├── ETH_USDT_USDT-1h-futures.feather
├── SOL_USDT_USDT-1h-futures.feather
└── ... (multiple timeframes)
This data allows you to run backtests immediately without syncing from an exchange.
Option B: Sync Fresh Data from Exchange
To get the latest data or custom date ranges:
# Sync BTC/USDT futures data for January 2024
tradai data sync BTC/USDT:USDT \
--start 2024-01-01 \
--end 2024-01-31 \
--timeframe 1h
# Verify data is available
tradai data check-freshness BTC/USDT:USDT
3. Run a Backtest¶
Option A: Quick Local Backtest (No Services Required)
For rapid local development without starting any services:
# Quick backtest using freqtrade directly (no backend required)
tradai backtest quick PascalStrategy --local
# With custom period and symbol
tradai backtest quick PascalStrategy --local --period 7d --symbol ETH/USDT:USDT
This runs freqtrade directly as a subprocess, perfect for: - Quick strategy validation during development - Testing when services are not running - CI/CD pipelines
Option B: Full Backtest via Backend Service
Production Recommended
Use the backend service for production backtests - it provides comprehensive metrics, MLflow tracking, and proper error handling.
For production-quality backtests with full metrics and tracking:
# Start services first
just up
# Run backtest via backend service
tradai backtest quick PascalStrategy --period 30d
# Or use the strategy backtest command for more options
tradai strategy backtest \
--strategy PascalStrategy \
--start 2024-01-01 \
--end 2024-01-31 \
--symbol BTC/USDT:USDT \
--timeframe 1h
Example output:
=== Backtest Results ===
Strategy: PascalStrategy
Period: 2024-01-01 to 2024-01-31
Timeframe: 1h
Symbols: BTC/USDT:USDT
=== Performance ===
Total Trades: 15
Winning: 9 | Losing: 6
Win Rate: 60.0%
Total Profit: $127.50 (12.75%)
=== Risk Metrics ===
Sharpe Ratio: 1.45
Sortino Ratio: 2.10
Calmar Ratio: 0.95
Max Drawdown: -3.25%
Profit Factor: 1.85
4. View in MLflow (Optional)¶
Track experiments with MLflow:
# Run backtest with MLflow tracking
tradai strategy backtest \
--strategy PascalStrategy \
--start 2024-01-01 \
--end 2024-01-31 \
--symbol BTC/USDT:USDT \
--experiment "my-first-backtest"
Open MLflow UI at http://localhost:5001 to view: - Run metrics (Sharpe, Sortino, Calmar, etc.) - Parameters (stoploss, stake amount) - Artifacts (trade logs)
Using Just Commands¶
For convenience, the justfile provides shortcuts:
# Run backtest for specific strategy
just run-backtest PascalStrategy 2.0.0
# Start strategy service in dev mode
just run-strategy
Backtest Configuration Options¶
Quick Backtest (tradai backtest quick)¶
| Option | Description | Default |
|---|---|---|
--period, -p | Backtest period (e.g., 30d, 7d, 2w) | 30d |
--symbol, -s | Trading pair | BTC/USDT:USDT |
--timeframe, -t | Candle timeframe | 1h |
--stake | Stake amount per trade | 1000.0 |
--local | Run locally without backend | False |
--config, -c | Path to freqtrade config | Auto-detected |
--skip-validation | Skip preflight checks | False |
--no-wait | Return job ID immediately | False |
Full Backtest (tradai strategy backtest)¶
| Option | Description | Default |
|---|---|---|
--strategy, -s | Strategy name | Required |
--start | Start date (YYYY-MM-DD) | Required |
--end | End date (YYYY-MM-DD) | Required |
--symbol | Trading symbol(s) | BTC/USDT:USDT |
--timeframe, -t | Candle timeframe | 1h |
--stake | Stake amount per trade | 1000.0 |
--stoploss | Stoploss ratio (e.g., -0.1) | None |
--experiment, -e | MLflow experiment name | None |
--json, -j | Output as JSON | False |
Common Issues¶
"No data available for symbol"¶
Sync the data first:
"Strategy not found"¶
List available strategies:
"Service connection refused"¶
Ensure services are running:
Next Steps¶
- Create a New Strategy - Build your own strategy
- Collect Market Data - Sync more trading pairs