This directory contains example YAML configuration files for running backtests.
Run a backtest using the CLI:
ai-trader run config/backtest/sma_example.yamlOverride parameters from command line:
ai-trader run config/backtest/bbands_example.yaml --cash 100000 --commission 0.002Each YAML file has the following structure:
broker:
cash: 1000000 # Initial capital
commission: 0.001425 # Commission rate per tradeFor single stock:
data:
file: "data/AAPL.csv" # Path to CSV file
start_date: "2020-01-01" # Optional: filter start date
end_date: "2023-12-31" # Optional: filter end date
date_col: "date" # Date column name ("date" or "Date")For portfolio (multiple stocks):
data:
directory: "./data/tw_stock/" # Directory with CSV files
start_date: "2020-01-01"
end_date: "2023-12-31"
date_col: "date"strategy:
class: "SMAStrategy" # Strategy class name
params: # Strategy-specific parameters
fast_period: 10
slow_period: 30sizer:
type: "percent" # "percent" or "fixed"
params:
percents: 95 # For percent sizer
# stake: 100 # For fixed sizeranalyzers:
- sharpe # Sharpe ratio
- drawdown # Maximum drawdown
- returns # Return metrics
- trades # Trade statistics
- sqn # System Quality Number- Copy an example config that matches your use case
- Modify the data source (file or directory)
- Choose your strategy and set parameters
- Adjust broker settings (cash, commission)
- Select desired analyzers
- Run with:
ai-trader run your_config.yaml
SMAStrategy- Simple Moving Average crossoverEMAStrategy- Exponential Moving Average crossoverBBandsStrategy- Bollinger BandsRSIStrategy- Relative Strength IndexMACDStrategy- Moving Average Convergence DivergenceKDJStrategy- KDJ oscillatorStochasticStrategy- Stochastic oscillatorWilliamsRStrategy- Williams %RCCIStrategy- Commodity Channel IndexATRStrategy- Average True RangeDMIStrategy- Directional Movement IndexOBVStrategy- On-Balance VolumeBuyHoldStrategy- Buy and hold benchmark
ROCRotationStrategy- Rate of Change rotationVolumeRotationStrategy- Volume-based rotationMomentumRotationStrategy- Momentum rotationLowVolatilityStrategy- Low volatility selection
- Always include at least 'sharpe', 'drawdown', 'returns' analyzers
- Test date ranges that include both bull and bear markets
- Compare results against BuyHoldStrategy benchmark