Qc Backtest Master
by @tltby12341
QuantConnect automated backtest pipeline — submit local strategies, compile, execute, monitor with early-stop, and download results in one command.
clawhub install qc-backtest-master📖 About This Skill
name: qc-backtest-master description: QuantConnect automated backtest pipeline — submit local strategies, compile, execute, monitor with early-stop, and download results in one command. version: 1.0.0 metadata: openclaw: requires: env: - QC_USER_ID - QC_API_TOKEN - QC_PROJECT_ID bins: - python3 primaryEnv: QC_API_TOKEN emoji: "\U0001F680"
QC Backtest Master
Automate the full QuantConnect backtest lifecycle from local code to cloud results, without ever opening the web UI.
What this skill does
When the user asks to backtest a strategy, run a backtest, or submit code to QuantConnect, follow this workflow:
1. Submit & Compile
Upload the user's local .py strategy file to a QuantConnect cloud project, replacing any existing main.py. Trigger compilation and report any errors with line numbers.
python3 submit_backtest.py \
--main-file \
--name "" \
--project-id $QC_PROJECT_ID
If the strategy has auxiliary data files (.json, .txt, .csv), upload those too.
2. Monitor with Early-Stop
Poll backtest progress in real time. If drawdown exceeds the user's threshold after 20% progress, automatically delete the backtest to save compute time.
python3 monitor_backtest.py \
--max-dd \
--check-after-progress 0.20 \
--timeout 3600
Exit codes:
| Code | Meaning |
|------|---------|
| 0 | Backtest completed normally |
| 1 | Runtime error (print full stack trace) |
| 2 | Timeout |
| 3 | Early stop: drawdown exceeded threshold, backtest deleted |
3. Download Results
Fetch the complete backtest statistics (JSON) and all order records (CSV, paginated at 100 per call to bypass QC's limit).
python3 get_results.py --output-dir ./results/
Output files:
_result.json — Full statistics, charts, runtime data_orders.csv — All orders with symbol, direction, quantity, fill price, fees, timestamps4. Full Pipeline (One Command)
Run the entire submit-compile-monitor-download pipeline:
python3 run_workflow.py \
--main-file \
--name "" \
--max-dd 40
5. List Historical Backtests
python3 list_backtests.py --limit 10
QC API Client
The qc_api/client.py module wraps the QuantConnect REST API v2:
create_backtest(project_id, name, compile_id) — Start a backtestread_backtest(project_id, backtest_id) — Get status and resultsread_backtest_orders(project_id, backtest_id, start, end) — Paginated order fetchdelete_backtest(project_id, backtest_id) — Delete (used for early-stop)update_project_file(project_id, name, content) — Upload codecompile_project(project_id) — Trigger compilationCredentials are read from environment variables QC_USER_ID and QC_API_TOKEN.
Rules
main.py. Old Main.py is auto-deleted to prevent conflicts. Do not manually rename files on the QC cloud project.self.log() output. View logs in the QC web UI manually.0.40) and percentage (40) formats. Early-stop permanently deletes the backtest — it cannot be recovered.QC_USER_ID, QC_API_TOKEN, and QC_PROJECT_ID must be set. The skill will raise a clear error if any are missing.main.py and will overwrite any manual changes on the next submission.🔒 Constraints
main.py. Old Main.py is auto-deleted to prevent conflicts. Do not manually rename files on the QC cloud project.self.log() output. View logs in the QC web UI manually.0.40) and percentage (40) formats. Early-stop permanently deletes the backtest — it cannot be recovered.QC_USER_ID, QC_API_TOKEN, and QC_PROJECT_ID must be set. The skill will raise a clear error if any are missing.main.py and will overwrite any manual changes on the next submission.