Comprehensive algorithmic trading framework for Python with backtesting, simulation, and live trading capabilities
—
Command line tools for strategy execution, data management, configuration generation, and system administration. The RQAlpha CLI provides comprehensive tooling for all aspects of algorithmic trading workflow from development to production.
Primary command for running trading strategies with various options and configurations.
# Run a strategy file
rqalpha run strategy.py
# Run with custom configuration
rqalpha run strategy.py --config config.yml
# Run with inline parameters
rqalpha run strategy.py --start-date 2020-01-01 --end-date 2020-12-31 --stock-starting-cash 100000
# Paper trading mode
rqalpha run strategy.py --run-type p
# Enable analysis and plotting
rqalpha run strategy.py --plotCommands for managing market data bundles required for backtesting.
# Create data bundle using RQDatac
rqalpha create-bundle
# Update existing data bundle
rqalpha update-bundle
# Download pre-built data bundle
rqalpha download-bundle
# Check bundle integrity
rqalpha check-bundle
# Create bundle with specific parameters
rqalpha create-bundle --start-date 2015-01-01 --end-date 2023-12-31Commands for generating and managing strategy configurations.
# Generate default configuration file
rqalpha generate-config
# Generate config with specific parameters
rqalpha generate-config --config-path my_config.yml
# Generate minimal configuration
rqalpha generate-config --minimalCommands for creating example strategies and learning materials.
# Generate example strategies
rqalpha generate-examples
# Generate examples in specific directory
rqalpha generate-examples --output-dir examples/
# Generate specific example type
rqalpha generate-examples --type buy_and_holdCommands for managing RQAlpha modules (plugins) and extensions.
# List available mods
rqalpha mod list
# Install mod from source
rqalpha mod install path/to/mod
# Install mod from git repository
rqalpha mod install git+https://github.com/user/rqalpha-mod.git
# Uninstall mod
rqalpha mod uninstall mod_name
# Enable mod
rqalpha mod enable mod_name
# Disable mod
rqalpha mod disable mod_name
# Show mod information
rqalpha mod show mod_nameCommands for system information and version management.
# Show version information
rqalpha version
# Show detailed version and system info
rqalpha version --verboseExecute trading strategies with comprehensive options:
rqalpha run [OPTIONS] STRATEGY_FILE
Options:
--config PATH Configuration file path
--start-date TEXT Backtest start date (YYYY-MM-DD)
--end-date TEXT Backtest end date (YYYY-MM-DD)
--stock-starting-cash FLOAT Initial stock account cash
--future-starting-cash FLOAT Initial futures account cash
--bond-starting-cash FLOAT Initial bond account cash
--benchmark TEXT Benchmark instrument ID
--frequency TEXT Data frequency (1d, 1m, 5m, etc.)
--run-type TEXT Run type (b=backtest, p=paper, r=live)
--matching-type TEXT Order matching type
--commission-multiplier FLOAT Commission multiplier
--margin-multiplier FLOAT Margin multiplier
--slippage FLOAT Slippage factor
--account TEXT Account configuration
--position TEXT Initial position
--plot Enable plotting
--progress Show progress bar
--log-level TEXT Log level (debug, info, warning, error)
--logger TEXT Logger configuration
--output-file PATH Output file for results
--report PATH Generate report file
--help Show help messageCreate market data bundle:
rqalpha create-bundle [OPTIONS]
Options:
--start-date TEXT Bundle start date (YYYY-MM-DD)
--end-date TEXT Bundle end date (YYYY-MM-DD)
--bundle-path PATH Bundle output path
--adjust TEXT Price adjustment type (pre, post, none)
--frequency TEXT Data frequency
--help Show help messageManage RQAlpha modules:
# List all mods
rqalpha mod list [OPTIONS]
Options:
--enabled-only Show only enabled mods
--disabled-only Show only disabled mods
# Install mod
rqalpha mod install [OPTIONS] SOURCE
Options:
--force Force reinstall
--editable Install in development mode
# Uninstall mod
rqalpha mod uninstall [OPTIONS] MOD_NAME
Options:
--force Force uninstall
# Enable/disable mod
rqalpha mod enable MOD_NAME
rqalpha mod disable MOD_NAME
# Show mod info
rqalpha mod show MOD_NAMEbase:
start_date: 2020-01-01
end_date: 2020-12-31
frequency: 1d
accounts:
stock: 100000
benchmark: 000300.XSHG
strategy_file: strategy.py
extra:
log_level: info
context_vars:
my_var: value
mod:
sys_progress:
enabled: true
show: true
sys_analyser:
enabled: true
plot: true
output_file: results.pkl
report_save_path: report.html
sys_simulation:
enabled: true
matching_type: current_bar
slippage: 0.0001
commission_multiplier: 1.0base:
start_date: 2020-01-01
end_date: 2020-12-31
frequency: 1m
accounts:
stock: 1000000
future: 500000
bond: 200000
benchmark: 000300.XSHG
strategy_file: strategy.py
persist:
persist_mode: real_time
redis_url: redis://localhost:6379
extra:
log_level: debug
context_vars:
universe_size: 50
rebalance_frequency: 20
mod:
sys_progress:
enabled: true
show: true
sys_analyser:
enabled: true
plot: true
plot_save_file: plots.png
output_file: results.pkl
report_save_path: report.html
benchmark_save_path: benchmark.pkl
sys_simulation:
enabled: true
matching_type: next_bar
slippage: 0.0002
commission_multiplier: 1.5
margin_multiplier: 1.0
sys_transaction_cost:
enabled: true
stock_commission: 0.0003
stock_commission_min: 5
future_commission: 0.00003
sys_risk:
enabled: true
max_position_size: 0.1
max_drawdown: 0.2# Simple backtest
rqalpha run my_strategy.py \
--start-date 2020-01-01 \
--end-date 2020-12-31 \
--stock-starting-cash 100000
# With plotting and analysis
rqalpha run my_strategy.py \
--start-date 2020-01-01 \
--end-date 2020-12-31 \
--stock-starting-cash 100000 \
--plot \
--output-file results.pkl
# Paper trading
rqalpha run my_strategy.py \
--run-type p \
--stock-starting-cash 50000 \
--log-level debug# Initial setup - create data bundle
rqalpha create-bundle \
--start-date 2015-01-01 \
--end-date 2023-12-31
# Regular updates
rqalpha update-bundle
# Verify data integrity
rqalpha check-bundle
# Alternative: download pre-built bundle
rqalpha download-bundle# Generate default configuration
rqalpha generate-config --config-path my_config.yml
# Edit configuration file
vim my_config.yml
# Run strategy with configuration
rqalpha run my_strategy.py --config my_config.yml# Create example strategies for learning
rqalpha generate-examples --output-dir examples/
# Run example strategy
rqalpha run examples/buy_and_hold.py \
--start-date 2020-01-01 \
--end-date 2020-12-31 \
--stock-starting-cash 100000
# Install development mod
rqalpha mod install git+https://github.com/user/my-rqalpha-mod.git
# Enable the mod
rqalpha mod enable my_mod
# Test strategy with mod
rqalpha run my_strategy.py --config config_with_mod.yml# Test strategy thoroughly
rqalpha run production_strategy.py \
--config production_config.yml \
--output-file backtest_results.pkl \
--report production_report.html
# Switch to paper trading
rqalpha run production_strategy.py \
--config production_config.yml \
--run-type p \
--log-level info
# Deploy to live trading (with proper safeguards)
rqalpha run production_strategy.py \
--config live_config.yml \
--run-type r \
--log-level warning# Run multiple strategies with different configs
rqalpha run strategy1.py --config config1.yml --output-file results1.pkl &
rqalpha run strategy2.py --config config2.yml --output-file results2.pkl &
rqalpha run strategy3.py --config config3.yml --output-file results3.pkl &
# Wait for completion
wait
# Analyze results
python analyze_results.py results1.pkl results2.pkl results3.pkl# Check system status
rqalpha version --verbose
# List all installed mods
rqalpha mod list
# Update data bundle weekly
crontab -e
# Add: 0 6 * * 1 /usr/local/bin/rqalpha update-bundle
# Clean old result files
find . -name "*.pkl" -mtime +30 -delete# Generate configuration programmatically
python generate_config.py | rqalpha run strategy.py --config -
# Pipe results to analysis tool
rqalpha run strategy.py --output-file - | analysis_tool
# Use with Docker
docker run -v $(pwd):/workspace rqalpha/rqalpha \
run /workspace/strategy.py --config /workspace/config.ymlInstall with Tessl CLI
npx tessl i tessl/pypi-rqalpha