CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-rqalpha

Comprehensive algorithmic trading framework for Python with backtesting, simulation, and live trading capabilities

Pending
Overview
Eval results
Files

cli-commands.mddocs/

CLI Commands

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.

Capabilities

Strategy Execution

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 --plot

Data Bundle Management

Commands 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-31

Configuration Management

Commands 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 --minimal

Example Generation

Commands 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_hold

Mod Management

Commands 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_name

System Information

Commands for system information and version management.

# Show version information
rqalpha version

# Show detailed version and system info
rqalpha version --verbose

Command Reference

run Command

Execute 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 message

create-bundle Command

Create 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 message

mod Command

Manage 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_NAME

Configuration File Structure

Basic Configuration

base:
  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.0

Advanced Configuration

base:
  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

CLI Usage Examples

Basic Strategy Execution

# 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

Data Management Workflow

# 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

Configuration Workflow

# 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

Development Workflow

# 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

Production Workflow

# 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

Multi-Strategy Management

# 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

System Administration

# 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

Integration with External Tools

# 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.yml

Install with Tessl CLI

npx tessl i tessl/pypi-rqalpha

docs

cli-commands.md

constants-enums.md

data-access.md

data-models.md

framework-core.md

index.md

portfolio-management.md

strategy-execution.md

trading-api.md

tile.json