A professional-grade algorithmic trading backtesting framework with seamless integration with Futu OpenAPI, designed for quantitative traders and researchers.
-
Data Integration
- Seamless integration with Futu OpenAPI for real-time and historical data
- Support for multiple timeframes (1m to 1d)
- Efficient data caching and storage options (SQLite, CSV, in-memory)
-
Strategy Development
- Flexible strategy implementation framework
- Built-in technical indicators and analysis tools
- Easy-to-extend base strategy class
- Strategy parameter optimization capabilities
-
Backtesting Engine
- High-performance event-driven architecture
- Realistic simulation with slippage and commission modeling
- Comprehensive position and portfolio management
- Detailed performance metrics and analysis
-
Risk Management
- Position size control
- Maximum position limits
- Customizable risk parameters
- Python 3.8 or higher
- Futu OpenD installed and running
- Futu trading account (demo account available)
- Installation
git clone https://github.com/billpwchan/strategy-powerbacktest.git
cd strategy-powerbacktest
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
pip install -r requirements.txt
- Configure Futu OpenD
- Install and launch Futu OpenD
- Log in to your Futu trading account
- Ensure OpenD is running on localhost:11111 (default)
- Run a Sample Backtest
python main.py --strategy macd --symbol HK.00700 HK.09988 --start-date 2023-01-01 --end-date 2023-12-31 --initial-capital 100000 --commission 0.001
from src.strategy.base_strategy import BaseStrategy
class MovingAverageCrossStrategy(BaseStrategy):
def init(self, parameters):
super().init(parameters)
self.short_window = parameters.get('short_window', 20)
self.long_window = parameters.get('long_window', 50)
The system is highly configurable through config.yaml
. Key configuration sections:
- Futu API connection settings
- Backtesting parameters
- Data storage options
- Strategy-specific parameters
- Logging preferences
See config.yaml
for detailed configuration options.
The backtester provides comprehensive performance analytics:
- Total Return
- Sharpe Ratio
- Maximum Drawdown
- Win Rate
- Profit Factor
- Position Analysis
- Inherit from BaseStrategy
- Implement generate_signals method
- Register your strategy
- Configure parameters in config.yaml
strategy-powerbacktest/
├── src/
│ ├── data/ # Data handling
│ ├── strategy/ # Trading strategies
│ ├── engine/ # Backtesting engine
│ ├── templates/ # HTML report templates
│ └── utils/ # Helper functions
├── tests/ # Test suite
├── config.yaml # Configuration
└── main.py # Entry point
Apache License 2.0 - see LICENSE file for details
Contributions are welcome! Please feel free to submit a Pull Request.
For detailed documentation:
This software is for educational and research purposes only. Do not risk money which you are afraid to lose. USE THE SOFTWARE AT YOUR OWN RISK. THE AUTHORS ASSUME NO RESPONSIBILITY FOR YOUR TRADING RESULTS.