Strategy Workflow
Comprehensive strategy development workflow for quantitative trading, from hypothesis to validated production deployment.
Overview
This skill provides a complete framework for developing, testing, and validating trading strategies. It supports:
- - Hypothesis-driven strategy development
- Multi-GPU backtesting on Vast.ai
- Bayesian hyperparameter optimization with Optuna
- Walk-forward validation and out-of-sample testing
- Automated tearsheet generation
Entry Points
Control Plane (Swarm Orchestration)
Always-on watchdog loops that manage hardware utilization and self-healing:
CODEBLOCK0
For local environments, set explicit paths:
CODEBLOCK1
Work Plane (Parallel Execution)
Unified wrapper that starts control plane and launches parallel work:
CODEBLOCK2
Multi-GPU, multi-symbol execution:
CODEBLOCK3
Single-Symbol Pipeline
For focused optimization on a single asset:
CODEBLOCK4
Strategy Development
1. Hypothesis Formulation
Define your strategy hypothesis in measurable terms:
- - What market inefficiency are you exploiting?
- What is the expected holding period?
- What are the entry/exit conditions?
- What is the target risk-adjusted return?
2. Feature Selection
Identify relevant features for signal generation:
- - Price-based (OHLCV, returns, volatility)
- Technical indicators (EMA, RSI, Bollinger Bands)
- Multi-timeframe features (MTF resampling)
- Volume analysis (PVSRA, VWAP)
- Market microstructure (order flow, spread)
3. Signal Generation
Convert features into actionable signals:
- - Directional bias (trend following, mean reversion)
- Entry conditions (threshold crossings, pattern recognition)
- Exit conditions (take-profit, stop-loss, trailing stops)
- Position sizing rules
4. Position Sizing
Implement risk-aware position sizing:
- - Fixed fractional
- Kelly criterion
- Volatility-adjusted
- Regime-dependent scaling
Backtesting
Pre-Flight Validation
MANDATORY before every optimization run:
CODEBLOCK5
Validation checks:
- - Data >= 90 days with no gaps/NaN
- Min trades >= 30 for statistical significance
- MTF resampling implemented correctly
- No look-ahead bias
Multi-GPU Execution on Vast.ai
Deploy to cloud GPU instances for large-scale parameter sweeps:
CODEBLOCK6
Prescreening with Vectorized Backtests
Phase 0: GPU-accelerated parameter screening:
- - Generate N random parameter combinations
- Batch evaluate on GPU
- Filter by minimum trades (30+)
- Return top K by Sharpe ratio
Performance baseline (RTX 5090, 730d lookback, 250k combos): ~4s per mode.
Full Backtests with NautilusTrader
Phase 1: Event-driven backtesting for top candidates:
- - High-fidelity simulation with realistic execution
- Slippage and commission modeling
- Multi-asset portfolio backtests
Parameter Optimization
Optuna for Hyperparameter Search
Phase 2: Bayesian optimization with warm-start from prescreening:
CODEBLOCK7
Grid Search vs Bayesian Optimization
| Method | Use Case |
|---|
| Grid Search | Small parameter space, exhaustive coverage needed |
| Random Search |
Large space, quick exploration |
| Bayesian (TPE) | Efficient optimization, exploitation/exploration balance |
| CMA-ES | Continuous parameters, smooth objective |
Pruning Strategies
- - MedianPruner: Prune if worse than median of completed trials
- PercentilePruner: Prune bottom X% of trials
- HyperbandPruner: Multi-fidelity optimization
- SuccessiveHalvingPruner: Aggressive early stopping
Distributed Optimization
For large-scale runs, use persistent storage:
CODEBLOCK8
Walk-Forward Validation
Rolling Window Validation
Slide the training/test window through time:
CODEBLOCK9
Parameters:
- -
train_window: Training period length - INLINECODE1 : Out-of-sample test length
- INLINECODE2 : Window advancement increment
Anchored Walk-Forward
Expand training window while sliding test window:
CODEBLOCK10
Use when historical regime diversity improves model robustness.
Epoch Selection Criteria
Intelligent selection of training periods:
- - Regime-aware: Match training regimes to expected deployment conditions
- Volatility-adjusted: Include both high and low volatility periods
- Event-inclusive: Ensure major market events are represented
- Recency-weighted: Emphasize recent data while maintaining diversity
Out-of-Sample Testing
Final validation phase:
- - Hold out 20-30% of data for final OOS test
- No parameter tuning on OOS data
- Monte Carlo stress testing
- Regime-conditional performance analysis
SLOs and Guardrails
Utilization Targets
- - CPU utilization target: >= 70%
- GPU utilization target: >= 70%
- No silent GPU fallback for GPU sweeps
Hardware Watchdog Hooks
Enforced by:
Capacity Monitoring
Control plane loops monitor:
- - Worker health and liveness
- Progress artifact freshness
- Resource utilization
- Job queue depth
Self-healing actions:
- - Automatic worker restart on crash
- Fill lanes for underutilized resources
- Cooldown guardrails to prevent thrashing
Tearsheet Generation
Generate QuantStats-style performance reports:
CODEBLOCK11
See tearsheet-generator skill for detailed visualization options.
Multi-Provider Orchestration
PAL MCP Integration
Attach PAL as an MCP server for research/consensus across multiple model providers:
- - Config template: INLINECODE6
- Docs: INLINECODE7
- Providers: OpenRouter, OpenAI, Anthropic, xAI, local models
Resources
Documentation
Project References
- -
config/workflow_defaults.yaml - Default configuration - INLINECODE9 - Model policy (advisory)
- INLINECODE10 - Detailed runbook
- INLINECODE11 - Hook contracts
- INLINECODE12 - VectorBT PRO integration
Results Structure
CODEBLOCK12
策略工作流
从假设到验证的生产部署的完整量化交易策略开发工作流。
概述
该技能提供了开发、测试和验证交易策略的完整框架。它支持:
- - 假设驱动的策略开发
- 在Vast.ai上进行多GPU回测
- 使用Optuna进行贝叶斯超参数优化
- 向前验证和样本外测试
- 自动生成绩效报告
入口点
控制平面(集群编排)
管理硬件利用率和自我修复的常驻看门狗循环:
bash
bash scripts/startswarmwatchdogs.sh
对于本地环境,设置显式路径:
bash
VENV_PATH=/path/to/.venv/bin/activate \
RESULTS_ROOT=/path/to/backtests \
STATE_ROOT=/path/to/backtests/state \
LOGS_ROOT=/path/to/backtests/logs \
bash scripts/startswarmwatchdogs.sh
工作平面(并行执行)
启动控制平面并启动并行工作的统一封装器:
bash
scripts/backtest-optimize --parallel
多GPU、多品种执行:
bash
cd WORKFLOW && ./launch_parallel.sh
单品种流水线
针对单一资产的聚焦优化:
bash
scripts/backtest-optimize --single --symbol SYMBOL --engine native --prescreen 50000 --paths 1000 --by-regime
策略开发
1. 假设制定
以可衡量的方式定义你的策略假设:
- - 你在利用什么市场低效性?
- 预期持有期是多长?
- 入场/出场条件是什么?
- 目标风险调整后收益是多少?
2. 特征选择
识别用于信号生成的相关特征:
- - 基于价格的特征(OHLCV、收益率、波动率)
- 技术指标(EMA、RSI、布林带)
- 多时间框架特征(MTF重采样)
- 成交量分析(PVSRA、VWAP)
- 市场微观结构(订单流、价差)
3. 信号生成
将特征转化为可执行的信号:
- - 方向性偏向(趋势跟踪、均值回归)
- 入场条件(阈值穿越、模式识别)
- 出场条件(止盈、止损、移动止损)
- 仓位规模规则
4. 仓位规模
实施风险感知的仓位规模:
回测
飞行前验证
强制要求 在每次优化运行之前:
bash
python validation.py --check-all --data-path DATA_PATH --symbol SYMBOL
验证检查:
- - 数据 >= 90天,无缺口/NaN
- 最小交易次数 >= 30次,以保证统计显著性
- MTF重采样正确实现
- 无前视偏差
在Vast.ai上执行多GPU
部署到云GPU实例进行大规模参数扫描:
bash
复制工作流文件
scp -P PORT workflow_files root@HOST:/root/WORKFLOW/
运行优化
ssh -p PORT root@HOST cd /root/WORKFLOW && python optimize_strategy.py \
--data-path /root/data --symbol SYMBOL --mode aggressive \
--prescreen 5000 --paths 200 --engine gpu
使用向量化回测进行预筛选
阶段0:GPU加速的参数筛选:
- - 生成N个随机参数组合
- 在GPU上批量评估
- 按最小交易次数(30+)过滤
- 按夏普比率返回前K个
性能基准(RTX 5090,730天回溯,25万组合):每个模式约4秒。
使用NautilusTrader进行完整回测
阶段1:针对顶级候选策略的事件驱动回测:
- - 具有真实执行模拟的高保真模拟
- 滑点和佣金建模
- 多资产组合回测
参数优化
使用Optuna进行超参数搜索
阶段2:使用预筛选结果进行热启动的贝叶斯优化:
python
import optuna
study = optuna.create_study(
direction=maximize,
sampler=optuna.samplers.TPESampler(seed=42),
pruner=optuna.pruners.MedianPruner()
)
study.optimize(objective, n_trials=1000)
网格搜索与贝叶斯优化
| 方法 | 使用场景 |
|---|
| 网格搜索 | 小参数空间,需要穷举覆盖 |
| 随机搜索 |
大空间,快速探索 |
| 贝叶斯(TPE) | 高效优化,探索/利用平衡 |
| CMA-ES | 连续参数,平滑目标函数 |
剪枝策略
- - MedianPruner:如果比已完成试验的中位数差则剪枝
- PercentilePruner:剪枝底部X%的试验
- HyperbandPruner:多保真度优化
- SuccessiveHalvingPruner:激进的早期停止
分布式优化
对于大规模运行,使用持久化存储:
python
用于多进程的JournalStorage
storage = optuna.storages.JournalStorage(
optuna.storages.JournalFileStorage(journal.log)
)
用于分布式集群的RDBStorage
storage = optuna.storages.RDBStorage(postgresql://...)
向前验证
滚动窗口验证
在时间上滑动训练/测试窗口:
[训练1][测试1]
[训练2][测试2]
[训练3][测试3]
参数:
- - trainwindow:训练期长度
- testwindow:样本外测试长度
- step_size:窗口前进增量
锚定向前验证
在滑动测试窗口的同时扩展训练窗口:
[训练1 ][测试1]
[训练1 + 2 ][测试2]
[训练1 + 2 + 3 ][测试3]
当历史制度多样性提高模型稳健性时使用。
时期选择标准
训练期的智能选择:
- - 制度感知:将训练制度与预期部署条件匹配
- 波动率调整:同时包含高波动率和低波动率时期
- 事件包含:确保主要市场事件被代表
- 近期加权:在保持多样性的同时强调近期数据
样本外测试
最终验证阶段:
- - 保留20-30%的数据用于最终OOS测试
- 不在OOS数据上进行参数调优
- 蒙特卡洛压力测试
- 制度条件绩效分析
SLO和护栏
利用率目标
- - CPU利用率目标:>= 70%
- GPU利用率目标:>= 70%
- GPU扫描无静默GPU回退
硬件看门狗钩子
由以下强制执行:
- - hooks/hardwarecapacitywatchdog.py
- scripts/process_auditor.py
容量监控
控制平面循环监控:
- - 工作进程健康与存活
- 进度工件新鲜度
- 资源利用率
- 作业队列深度
自我修复操作:
- - 崩溃时自动重启工作进程
- 为未充分利用的资源填充通道
- 冷却护栏以防止抖动
绩效报告生成
生成QuantStats风格的绩效报告:
bash
scripts/generate-tearsheet STRATEGY_NAME \
--trades /path/to/trades.csv \
--capital 10000 \
--output ./tearsheets
有关详细的可视化选项,请参阅tearsheet-generator技能。
多提供商编排
PAL MCP集成
将PAL作为MCP服务器附加,用于跨多个模型提供商的研究/共识:
- - 配置模板:config/mcp/pal.mcp.json.example
- 文档:docs/reference/PALMCPINTEGRATION.md
- 提供商:OpenRouter、OpenAI、Anthropic、xAI、本地模型
资源
文档
项目参考
- - config/workflowdefaults.yaml - 默认配置
- config/modelpolicy.yaml - 模型策略(建议性)
- docs/guides/SWARMOPTIMIZATIONRUNBOOK.md - 详细运行手册
- hooks/pipeline-hooks.md - 钩子合约
- docs/reference/VECTORBTGRAPHINGEST.md - VectorBT PRO集成
结果结构
Backtests/optimizations/{SYMBOL}/{MODE}/
best_sharpe/
config.json # 最佳夏普配置
metrics.json # 绩效指标
best_returns/
lowest_drawdown/
best_winrate/
all_trials