RQAlpha is an algorithmic trading system for quantitative trading with backtesting and live trading capabilities.
License: Non-commercial use only (Apache 2.0). Commercial use requires authorization from Ricequant.
# Run backtest
rqalpha run -f strategy.py -s 2014-01-01 -e 2016-01-01 --account stock 100000
# With RQData connection
rqalpha run --rqdatac-uri tcp://user:password@host:port -f strategy.py -s 2014-01-01 -e 2016-01-01 --account stock 100000
# Download bundle data
rqalpha download-bundle
# Update bundle
rqalpha update-bundle --rqdatac-uri tcp://user:password@host:port
# Generate examples
rqalpha examples -d ./examples
# Run tests
pytest
pytest tests/unittest/
pytest tests/integration_tests/- Always consult documentation first: Read
docs/source/intro/tutorial.rstanddocs/source/api/base_api.rstbefore writing strategies - Use correct API signatures: Check
docs/source/api/base_api.rstfor function parameters and return types - Follow strategy lifecycle: Implement
init(),before_trading(),handle_bar(),after_trading()in correct order - Stock code format: Always use format like "000001.XSHE" (code + exchange)
- Date format: Use 'YYYY-MM-DD' format for dates
- Write minimal reproducible examples: Create smallest possible strategy that reproduces the bug
- Use logger, not print: Use
logger.info()instead ofprint()in strategies - Add assertions: Verify expected behavior with assertions in test code
- Short date ranges: Use 1-3 month ranges for faster iteration during testing
- Chinese comments OK: Domain-specific logic can use Chinese comments
- Follow PEP 8: Standard Python style guide
- Test before commit: Run pytest to ensure tests pass
- Environment singleton: Access via
Environment.get_instance()- central registry for all components - Event-driven: Mods subscribe to events (BAR, TICK, BEFORE_TRADING, etc.)
- Mod system: Extensibility through
AbstractModinterface - Data bundle: HDF5 format stored in
~/.rqalpha/bundle/ - Config hierarchy: CLI args > strategy
__config__> config file > defaults
For detailed information, see:
- Architecture:
docs/claude/architecture.md- Core components and system design - Strategy Writing:
docs/claude/strategy-guide.md- How to write strategies with API reference - Bug Reproduction:
docs/claude/bug-reproduction.md- Writing backtests to reproduce bugs - Development:
docs/claude/development.md- Development guidelines and debugging
Official documentation:
- Tutorial:
docs/source/intro/tutorial.rst - API Reference:
docs/source/api/base_api.rst - Examples:
docs/source/intro/examples.rst