Performance Optimization Solutions
To address the problem of slow backtesting, efficiency can be improved by the following methods:
- Data preprocessing::
1. CSV historical data pre-imported into MongoDB/MySQL
2. Establishment of timestamp indexesdb.bar_data.create_index([("datetime", ASCENDING)]) - backtest in batches::
- utilizationoptimize()Setting a reasonable step size for the function
- Consolidated results after piecemeal testing by year/quarter - hardware acceleration::
- Enable multi-process mode (requires modification)backtesting.py)
- Using GPU acceleration libraries such as Numba to modify policy core functions - Code-Level Optimization::
- Avoid executing database queries inside loops
- Replacing Native Python List Operations with NumPy
- Disable real-time chart output (setting)output=False)
Advancement Program:
- Using the distributed backtesting component vnpy_portfoliostrategy
- Rent a cloud server to improve standalone performance (recommended 16-core + 32GB configuration)
This answer comes from the articleVeighNa: a popular open source quantitative trading framework in ChinaThe































