test-trading-strategies

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Test Trading Strategies

交易策略测试

Quick Start

快速开始

This skill validates strategy performance on historical data before risking real capital. Testing is fast (20-60s), cheap ($0.001), and essential for safe trading.
Load the tools first:
Use MCPSearch to select: mcp__workbench__run_backtest
Use MCPSearch to select: mcp__workbench__get_latest_backtest_results
Basic backtest:
run_backtest(
    strategy_name="MyStrategy",
    start_date="2024-01-01",
    end_date="2024-12-31",
    symbol="BTC-USDT",
    timeframe="1h"
)
Returns performance metrics in 20-40 seconds:
  • Sharpe ratio: 1.4 (good risk-adjusted return)
  • Max drawdown: 12% (moderate risk)
  • Win rate: 52% (realistic)
  • Profit factor: 1.8 (profitable)
When to use this skill:
  • After building new strategy (validate it works)
  • After improving strategy (confirm improvement)
  • Before deploying to live trading (ALWAYS)
  • Comparing multiple strategy versions
  • Testing parameter variations
Critical rule: NEVER deploy without backtesting 6+ months of data
该技能可在投入真实资金前,基于历史数据验证策略绩效。测试速度快(20-60秒),成本低廉(0.001美元),是安全交易的必备环节。
先加载工具:
Use MCPSearch to select: mcp__workbench__run_backtest
Use MCPSearch to select: mcp__workbench__get_latest_backtest_results
基础回测:
run_backtest(
    strategy_name="MyStrategy",
    start_date="2024-01-01",
    end_date="2024-12-31",
    symbol="BTC-USDT",
    timeframe="1h"
)
20-40秒后返回绩效指标:
  • Sharpe ratio: 1.4 (良好的风险调整后收益)
  • 最大回撤: 12% (中等风险)
  • 胜率: 52% (符合实际)
  • 盈利因子: 1.8 (可盈利)
何时使用该技能:
  • 构建新策略后(验证其有效性)
  • 优化策略后(确认优化效果)
  • 部署到实盘交易前(必须使用)
  • 对比多个策略版本
  • 测试参数变体
关键规则: 绝对不要在未回测至少6个月数据的情况下部署策略

Available Tools (3)

可用工具(3个)

run_backtest

run_backtest

Purpose: Test crypto trading strategy performance on historical data
Parameters:
  • strategy_name
    (required): Strategy to test
  • start_date
    (required): Start date (YYYY-MM-DD)
  • end_date
    (required): End date (YYYY-MM-DD)
  • symbol
    (required): Trading pair (e.g., "BTC-USDT")
  • timeframe
    (required): Timeframe (1m, 5m, 15m, 30m, 1h, 2h, 4h, 6h, 8h, 12h, 1d)
  • config
    (optional): Backtest configuration object:
    • fee
      : Trading fee per side (default: 0.0005 = 0.05%)
    • slippage
      : Slippage per trade (default: 0.0005 = 0.05%)
    • leverage
      : Position multiplier (default: 1, max: 5)
Returns: Performance metrics:
  • Net profit: Total profit/loss in USDC
  • Total return: Percentage return
  • Annual return: Annualized return percentage
  • Sharpe ratio: Risk-adjusted return (industry standard metric)
  • Max drawdown: Largest peak-to-trough decline
  • Win rate: Percentage of profitable trades
  • Profit factor: Gross profit / gross loss
  • Trade statistics: Total trades, average trade duration, consecutive losses
  • Equity curve: Balance over time (for visualization)
Pricing: $0.001 (essentially free)
Execution Time: ~20-40 seconds
Use when: Testing crypto perpetual strategies on Hyperliquid
用途: 基于历史数据测试加密货币交易策略的绩效
参数:
  • strategy_name
    (必填): 待测试的策略
  • start_date
    (必填): 起始日期(YYYY-MM-DD)
  • end_date
    (必填): 结束日期(YYYY-MM-DD)
  • symbol
    (必填): 交易对(例如:"BTC-USDT")
  • timeframe
    (必填): 时间周期(1m, 5m, 15m, 30m, 1h, 2h, 4h, 6h, 8h, 12h, 1d)
  • config
    (可选): 回测配置对象:
    • fee
      : 单边交易手续费(默认: 0.0005 = 0.05%)
    • slippage
      : 每笔交易滑点(默认: 0.0005 = 0.05%)
    • leverage
      : 仓位乘数(默认: 1,最大值: 5)
返回: 绩效指标:
  • 净利润: 以USDC计算的总盈利/亏损
  • 总收益率: 收益率百分比
  • 年化收益率: 年化收益率百分比
  • Sharpe ratio: 风险调整后收益(行业标准指标)
  • 最大回撤: 最大峰值到谷底的跌幅
  • 胜率: 盈利交易的百分比
  • 盈利因子: 总盈利 / 总亏损
  • 交易统计: 总交易次数、平均交易时长、连续亏损次数
  • 权益曲线: 随时间变化的账户余额(用于可视化)
定价: 0.001美元(几乎免费)
执行时间: ~20-40秒
适用场景: 在Hyperliquid上测试加密货币永续合约策略

run_prediction_market_backtest

run_prediction_market_backtest

Purpose: Test Polymarket prediction market strategy on historical data
Parameters:
  • strategy_name
    (required): PolymarketStrategy to test
  • start_date
    (required): Start date (YYYY-MM-DD)
  • end_date
    (required): End date (YYYY-MM-DD)
  • condition_id
    (for single market): Specific Polymarket condition ID
  • asset
    (for rolling markets): Asset symbol ("BTC", "ETH")
  • interval
    (for rolling markets): Market interval ("15m", "1h")
  • initial_balance
    (optional): Starting USDC (default: 10000)
  • timeframe
    (optional): Execution timeframe (default: 1m)
Returns: Backtest metrics:
  • Profit/loss
  • Win rate
  • Position history for YES/NO tokens
  • Market resolution outcomes
Pricing: $0.001
Execution Time: ~20-60 seconds
Use when: Testing Polymarket prediction market strategies
用途: 基于历史数据测试Polymarket预测市场策略
参数:
  • strategy_name
    (必填): 待测试的PolymarketStrategy
  • start_date
    (必填): 起始日期(YYYY-MM-DD)
  • end_date
    (必填): 结束日期(YYYY-MM-DD)
  • condition_id
    (单一市场): 特定Polymarket标的ID
  • asset
    (滚动市场): 资产符号("BTC", "ETH")
  • interval
    (滚动市场): 市场时间间隔("15m", "1h")
  • initial_balance
    (可选): 初始USDC余额(默认: 10000)
  • timeframe
    (可选): 执行时间周期(默认: 1m)
返回: 回测指标:
  • 盈利/亏损
  • 胜率
  • YES/NO代币的仓位历史
  • 市场结算结果
定价: 0.001美元
执行时间: ~20-60秒
适用场景: 测试Polymarket预测市场策略

get_latest_backtest_results

get_latest_backtest_results

Purpose: View recent backtest results without re-running
Parameters:
  • strategy_name
    (optional): Filter by strategy name
  • limit
    (optional, 1-100): Number of results (default: 10)
  • include_equity_curve
    (optional): Include equity curve data
  • equity_curve_max_points
    (optional, 50-1000): Curve resolution
Returns: List of recent backtest records with metrics
Pricing: Free
Use when: Checking if backtest already exists, comparing strategies, avoiding redundant backtests
用途: 查看最近的回测结果,无需重新运行
参数:
  • strategy_name
    (可选): 按策略名称筛选
  • limit
    (可选,1-100): 返回结果数量(默认: 10)
  • include_equity_curve
    (可选): 是否包含权益曲线数据
  • equity_curve_max_points
    (可选,50-1000): 权益曲线分辨率
返回: 包含指标的最近回测记录列表
定价: 免费
适用场景: 检查回测是否已存在、对比策略、避免重复回测

Core Concepts

核心概念

Performance Metrics Interpretation

绩效指标解读

Sharpe Ratio (risk-adjusted return):
Formula: (Mean Return - Risk-Free Rate) / Standard Deviation of Returns

Interpretation:
>2.0  → Excellent (very rare for algo strategies)
1.0-2.0 → Good (achievable with solid strategy)
0.5-1.0 → Acceptable (worth testing further)
<0.5  → Poor (likely not profitable after costs)

Why it matters:
- Accounts for volatility (high return with high volatility = lower Sharpe)
- Industry standard for comparing strategies
- More useful than total return alone
Max Drawdown (largest peak-to-trough decline):
Example: Strategy grows from $10k → $15k → $12k
Drawdown: ($15k - $12k) / $15k = 20%

Interpretation:
<10%  → Conservative (lower returns, safer)
10-20% → Moderate (balanced risk/reward)
20-40% → Aggressive (higher returns, higher risk)
>40%  → Very risky (difficult to recover from)

Why it matters:
- Measures worst-case scenario
- Predicts emotional difficulty of holding strategy
- 50% drawdown requires 100% return to recover
Win Rate (percentage of profitable trades):
Formula: (Winning Trades / Total Trades) × 100%

Interpretation:
45-65% → Realistic for most strategies
>70%  → Suspicious (possible overfitting or unrealistic fills)
<40%  → Needs improvement (unless very high profit factor)

Why it matters:
- High win rate doesn't guarantee profitability
- Can have 40% win rate but profitable (if winners > losers)
- Very high win rate (>75%) often indicates overfitting

Common misconception: Higher is always better
Reality: 40% win rate with 3:1 reward:risk is better than 60% win rate with 1:1
Profit Factor (gross profit / gross loss):
Formula: Sum of All Winning Trades / Sum of All Losing Trades

Interpretation:
>2.0  → Excellent
1.5-2.0 → Good
1.2-1.5 → Acceptable
<1.2  → Marginal (risky to deploy)
<1.0  → Unprofitable (losses exceed profits)

Why it matters:
- Simple profitability measure
- <1.5 means small edge, vulnerable to slippage/fees
- Combines win rate and win size into single metric

Example:
10 trades: 6 winners ($100 each), 4 losers ($50 each)
Gross profit: $600, Gross loss: $200
Profit factor: $600 / $200 = 3.0 (excellent)
Total Return vs Annual Return:
Total Return: 50% over 6 months
Annual Return: ~100% (extrapolated to 12 months)

Why both matter:
- Total return: Actual profit over test period
- Annual return: Standardized for comparison across time periods
- Longer test periods more reliable (6-12 months minimum)
Sharpe Ratio(风险调整后收益):
Formula: (Mean Return - Risk-Free Rate) / Standard Deviation of Returns

解读:
>2.0  → 优秀(算法策略中极为罕见)
1.0-2.0 → 良好(稳健策略可达到)
0.5-1.0 → 可接受(值得进一步测试)
<0.5  → 较差(扣除成本后可能无法盈利)

重要性:
- 考虑了波动率(高收益伴随高波动率会导致Sharpe比率降低)
- 是行业内比较策略的标准指标
- 比单纯的总收益更具参考价值
最大回撤(最大峰值到谷底的跌幅):
示例: 策略账户从1万美元增长到1.5万美元,再回落至1.2万美元
回撤率: (1.5万 - 1.2万) / 1.5万 = 20%

解读:
<10%  → 保守型(收益较低,更安全)
10-20% → 平衡型(风险与收益均衡)
20-40% → 激进型(收益较高,风险也高)
>40%  → 高风险(难以恢复)

重要性:
- 衡量最坏情况
- 预测持有策略时的心理压力
- 回撤50%需要100%的收益才能回本
胜率(盈利交易的百分比):
公式: (盈利交易数 / 总交易数) × 100%

解读:
45-65% → 多数策略的合理范围
>70%  → 可疑(可能存在过拟合或不切实际的成交假设)
<40%  → 需要优化(除非盈利因子极高)

重要性:
- 高胜率不保证盈利
- 即使胜率40%,若盈利交易的收益远大于亏损交易,仍可盈利
- 胜率过高(>75%)通常意味着过拟合

常见误区: 胜率越高越好
实际情况: 胜率40%但盈亏比3:1,优于胜率60%但盈亏比1:1的策略
盈利因子(总盈利 / 总亏损):
公式: 所有盈利交易的总和 / 所有亏损交易的总和

解读:
>2.0  → 优秀
1.5-2.0 → 良好
1.2-1.5 → 可接受
<1.2  → 边际盈利(部署风险高)
<1.0  → 亏损(总亏损超过总盈利)

重要性:
- 简单的盈利性衡量指标
- <1.5意味着策略优势微弱,易受滑点和手续费影响
- 将胜率和盈亏比整合为单一指标

示例:
10笔交易: 6笔盈利(每笔100美元),4笔亏损(每笔50美元)
总盈利: 600美元,总亏损: 200美元
盈利因子: 600 / 200 = 3.0(优秀)
总收益率 vs 年化收益率:
总收益率: 6个月内50%
年化收益率: ~100%(外推至12个月)

两者的重要性:
- 总收益率: 测试周期内的实际盈利
- 年化收益率: 标准化指标,用于跨周期对比策略
- 测试周期越长越可靠(至少6-12个月)

Testing Methodology

测试方法

Minimum data requirements:
Quick test: 1-3 months
- Limited validation
- Use for initial screening only
- High risk of luck/overfitting

Standard test: 6-12 months (RECOMMENDED MINIMUM)
- Captures multiple market regimes
- Sufficient trades for statistical significance
- Industry standard for strategy validation

Robust test: 12-24 months
- Ideal for high-confidence validation
- Includes bull, bear, and ranging markets
- Best for strategies before live deployment
Multi-period testing (essential for robustness):
1. Train period: 2024-01-01 to 2024-08-31
   run_backtest(..., start_date="2024-01-01", end_date="2024-08-31")
   → Sharpe: 1.5

2. Validation period: 2024-09-01 to 2024-12-31
   run_backtest(..., start_date="2024-09-01", end_date="2024-12-31")
   → Sharpe: 1.3

3. Compare:
   Performance similar → Robust strategy ✓
   Performance degraded significantly → Overfit to train period ✗
Market regime testing:
Test strategy across different market conditions:

1. Trending up (bull market): 2023-10 to 2024-03
   → Sharpe: 1.8

2. Trending down (bear market): 2024-04 to 2024-07
   → Sharpe: 0.9

3. Ranging (sideways): 2024-08 to 2024-12
   → Sharpe: 1.1

Analysis:
- Works well in all regimes ✓
- Or works in specific regime (trend-following good in trends)
- Fails in all regimes → Fundamentally broken ✗
最低数据要求:
快速测试: 1-3个月
- 验证程度有限
- 仅用于初步筛选
- 运气或过拟合的风险高

标准测试: 6-12个月(推荐最低要求)
- 覆盖多个市场周期
- 交易次数足够具备统计显著性
- 是行业内策略验证的标准

稳健测试: 12-24个月
- 是高置信度验证的理想选择
- 包含牛市、熊市和震荡市
- 最适合实盘部署前的策略测试
多周期测试(稳健性必备):
1. 训练周期: 2024-01-01 至 2024-08-31
   run_backtest(..., start_date="2024-01-01", end_date="2024-08-31")
   → Sharpe: 1.5

2. 验证周期: 2024-09-01 至 2024-12-31
   run_backtest(..., start_date="2024-09-01", end_date="2024-12-31")
   → Sharpe: 1.3

3. 对比:
   表现相似 → 策略稳健 ✓
   表现大幅下滑 → 过拟合至训练周期 ✗
市场周期测试:
在不同市场环境下测试策略:

1. 上涨趋势(牛市): 2023-10 至 2024-03
   → Sharpe: 1.8

2. 下跌趋势(熊市): 2024-04 至 2024-07
   → Sharpe: 0.9

3. 震荡市(横盘): 2024-08 至 2024-12
   → Sharpe: 1.1

分析:
- 在所有周期表现良好 ✓
- 或仅在特定周期表现良好(趋势跟踪策略在趋势市表现佳)
- 在所有周期表现不佳 → 策略存在根本性缺陷 ✗

Red Flags (Overfitting Indicators)

警示信号(过拟合指标)

Warning signs that backtest results may not persist:
1. Unrealistically high win rate (>70%):
Win rate: 82%
Problem: Markets are noisy; >70% suggests strategy memorized past data
Solution: Test on out-of-sample data; expect performance degradation
2. Very few trades (<20 in 6 months):
Total trades: 8 over 6 months
Problem: Not enough data for statistical significance; could be luck
Solution: Test longer period or adjust strategy to generate more trades
3. Excellent backtest, terrible out-of-sample:
Train period (Jan-Aug): Sharpe 2.5
Test period (Sep-Dec): Sharpe 0.3
Problem: Overfitted to training data
Solution: Simplify strategy, reduce parameters, test on more data
4. Performance concentrated in short period:
6-month test: 50% return
- Month 1-5: -5% return
- Month 6: 55% return (one lucky trade)
Problem: Performance driven by single event, not consistent edge
Solution: Analyze equity curve; look for consistent growth, not spikes
5. Strategy complexity doesn't match performance:
Strategy uses 12 indicators, 20+ parameters
Sharpe ratio: 1.3 (only modest improvement)
Problem: Complex strategies should dramatically outperform simple ones
Solution: Simplify; complexity without performance = overfitting
6. Backtest perfect, live trading fails:
Backtest: Win rate 75%, Sharpe 2.3
Live: Win rate 45%, Sharpe 0.6
Problem: Backtest didn't account for slippage, fees, execution delays
Solution: Use realistic fees (0.05-0.1%), slippage (0.05-0.1%), and test on higher timeframes
回测结果可能无法持续的警告信号:
1. 胜率过高(>70%):
胜率: 82%
问题: 市场存在噪音;胜率>70%意味着策略可能记住了历史数据中的特定模式
解决方案: 在样本外数据上测试;预期表现会下滑
2. 交易次数极少(6个月内<20笔):
总交易次数: 6个月内8笔
问题: 数据量不足,不具备统计显著性;可能只是运气
解决方案: 延长测试周期或调整策略以增加交易次数
3. 回测表现极佳,样本外表现极差:
训练周期(1-8月): Sharpe 2.5
测试周期(9-12月): Sharpe 0.3
问题: 过拟合至训练数据
解决方案: 简化策略,减少参数,在更多数据上测试
4. 绩效集中在短周期内:
6个月测试: 50%收益率
- 1-5月: -5%收益率
- 6月: 55%收益率(一次幸运交易)
问题: 绩效由单一事件驱动,而非持续的策略优势
解决方案: 分析权益曲线;寻找持续增长,而非突发峰值
5. 策略复杂度与表现不匹配:
策略使用12个指标,20+参数
Sharpe比率: 1.3(仅小幅提升)
问题: 复杂策略应显著优于简单策略
解决方案: 简化策略;无表现提升的复杂度等同于过拟合
6. 回测完美,实盘交易失败:
回测: 胜率75%,Sharpe 2.3
实盘: 胜率45%,Sharpe 0.6
问题: 回测未考虑滑点、手续费、执行延迟
解决方案: 使用真实的手续费(0.05-0.1%)和滑点(0.05-0.1%),在更高时间周期上测试

Pre-Deployment Validation Checklist

部署前验证清单

Before deploying to live trading, verify:
  • Backtest duration: Tested on 6+ months minimum (12+ preferred)
  • Sharpe ratio: >1.0 (preferably >1.5)
  • Max drawdown: <20% (acceptable risk level)
  • Win rate: 45-65% (realistic range)
  • Profit factor: >1.5 (sufficient edge)
  • Trade count: 50+ trades in test period (statistical significance)
  • Multi-period validation: Tested on multiple time ranges with consistent results
  • Out-of-sample test: Performed well on data not used for development
  • Regime testing: Works in different market conditions (or you understand when it fails)
  • Realistic fees: Configured with actual trading fees (0.05-0.1%)
  • Realistic slippage: Configured with expected slippage (0.05-0.1%)
  • No red flags: Win rate not >70%, sufficient trades, consistent performance
  • Equity curve review: Growth is steady, not driven by single lucky trade
  • Risk management verified: Stop loss and position sizing are reasonable
If any item fails, DO NOT DEPLOY. Improve strategy first.
在部署到实盘交易前,请确认:
  • 回测周期: 至少测试了6个月(推荐12个月以上)
  • Sharpe ratio: >1.0(最好>1.5)
  • 最大回撤: <20%(可接受的风险水平)
  • 胜率: 45-65%(合理范围)
  • 盈利因子: >1.5(足够的策略优势)
  • 交易次数: 测试周期内至少50笔交易(具备统计显著性)
  • 多周期验证: 在多个时间范围测试,表现一致
  • 样本外测试: 在未用于策略开发的数据上表现良好
  • 市场周期测试: 在不同市场环境下有效(或明确了解策略的失效场景)
  • 真实手续费: 配置了实际的交易手续费(0.05-0.1%)
  • 真实滑点: 配置了预期的滑点(0.05-0.1%)
  • 无警示信号: 胜率不超过70%,交易次数足够,表现持续稳定
  • 权益曲线审核: 账户余额持续增长,而非由单一幸运交易驱动
  • 风险管理验证: 止损和仓位大小设置合理
如果任何一项未通过,请勿部署。请先优化策略。

Best Practices

最佳实践

Configuration Best Practices

配置最佳实践

Realistic fees and slippage:
config = {
    "fee": 0.0005,      # 0.05% per trade (Hyperliquid taker fee)
    "slippage": 0.0005,  # 0.05% slippage (liquid markets)
    "leverage": 1        # Start with 1x (no leverage)
}

run_backtest(
    ...,
    config=config
)
Why realistic configuration matters:
Without fees/slippage:
- Backtest: 50% return, Sharpe 2.0
- Reality: Fees eat 5-10% of profit → 40% return, Sharpe 1.5

With realistic fees/slippage:
- Backtest: 40% return, Sharpe 1.5
- Reality: Matches expectation → 38-42% return
Leverage testing:
undefined
真实的手续费和滑点:
config = {
    "fee": 0.0005,      # 单边0.05%手续费(Hyperliquid taker fee)
    "slippage": 0.0005,  # 0.05%滑点(流动性充足的市场)
    "leverage": 1        # 先使用1倍杠杆(无杠杆)
}

run_backtest(
    ...,
    config=config
)
为什么真实配置很重要:
未设置手续费和滑点:
- 回测: 50%收益率,Sharpe 2.0
- 实际: 手续费吞噬5-10%的收益 → 40%收益率,Sharpe 1.5

设置真实的手续费和滑点:
- 回测: 40%收益率,Sharpe 1.5
- 实际: 与预期一致 → 38-42%收益率
杠杆测试:
undefined

Test without leverage first

先测试无杠杆

run_backtest(..., config={"leverage": 1}) → Sharpe: 1.5, Drawdown: 12%
run_backtest(..., config={"leverage": 1}) → Sharpe: 1.5,回撤率:12%

Then test with leverage (if deploying with leverage)

若部署时使用杠杆,再测试杠杆场景

run_backtest(..., config={"leverage": 2}) → Sharpe: 1.4, Drawdown: 24% (doubled)
Risk assessment:
  • Leverage amplifies returns AND drawdowns
  • 2x leverage doesn't mean 2x Sharpe (risk increases faster)
  • Start deployment at 1x, increase cautiously
undefined
run_backtest(..., config={"leverage": 2}) → Sharpe:1.4,回撤率:24%(翻倍)
风险评估:
  • 杠杆会放大收益和回撤
  • 2倍杠杆并不意味着Sharpe也翻倍(风险增长更快)
  • 部署时先从1倍开始,谨慎提升杠杆
undefined

Comparing Strategy Versions

策略版本对比

Systematic comparison:
1. Backtest all versions on SAME date range:
   run_backtest(strategy_name="Strategy_v1", start_date="2024-01-01", end_date="2024-12-31", ...)
   run_backtest(strategy_name="Strategy_v2", start_date="2024-01-01", end_date="2024-12-31", ...)
   run_backtest(strategy_name="Strategy_v3", start_date="2024-01-01", end_date="2024-12-31", ...)

2. Compare all metrics (not just one):
   | Version | Sharpe | Drawdown | Win Rate | Profit Factor |
   |---------|--------|----------|----------|---------------|
   | v1      | 1.2    | 15%      | 50%      | 1.6           |
   | v2      | 1.5    | 12%      | 52%      | 1.8           |
   | v3      | 1.8    | 25%      | 48%      | 2.2           |

3. Analyze trade-offs:
   v1: Baseline (acceptable)
   v2: Better across all metrics ✓ (clear winner)
   v3: Higher Sharpe but excessive drawdown ✗ (too risky)

4. Decision:
   Deploy v2 (balanced improvement without excessive risk)
系统化对比:
1. 在相同日期范围内回测所有版本:
   run_backtest(strategy_name="Strategy_v1", start_date="2024-01-01", end_date="2024-12-31", ...)
   run_backtest(strategy_name="Strategy_v2", start_date="2024-01-01", end_date="2024-12-31", ...)
   run_backtest(strategy_name="Strategy_v3", start_date="2024-01-01", end_date="2024-12-31", ...)

2. 对比所有指标(而非单一指标):
   | 版本 | Sharpe | 回撤率 | 胜率 | 盈利因子 |
   |---------|--------|----------|----------|---------------|
   | v1      | 1.2    | 15%      | 50%      | 1.6           |
   | v2      | 1.5    | 12%      | 52%      | 1.8           |
   | v3      | 1.8    | 25%      | 48%      | 2.2           |

3. 分析权衡:
   v1: 基准版本(可接受)
   v2: 所有指标均更优 ✓(明显的最优选择)
   v3: Sharpe更高但回撤率过高 ✗(风险太大)

4. 决策:
   部署v2(在无过度风险的情况下实现了均衡的提升)

Avoiding Redundant Backtests

避免重复回测

Check if backtest already exists:
1. Before running backtest:
   get_latest_backtest_results(strategy_name="MyStrategy")

2. Review results:
   - If recent backtest exists with same parameters → Use cached result
   - If parameters differ (date range, symbol, timeframe) → Run new backtest

3. Saves time and clutter:
   - Backtests are fast (20-40s) but avoiding duplicates is cleaner
   - Easier to find specific backtest results later
检查回测是否已存在:
1. 在运行回测前:
   get_latest_backtest_results(strategy_name="MyStrategy")

2. 查看结果:
   - 若存在参数相同的近期回测 → 使用缓存结果
   - 若参数不同(日期范围、交易对、时间周期)→ 运行新的回测

3. 节省时间并保持整洁:
   - 回测速度快(20-40秒),但避免重复更高效
   - 后续更容易找到特定的回测结果

Common Workflows

常见工作流

Workflow 1: Initial Strategy Validation

工作流1: 初始策略验证

Goal: Test newly created strategy for first time
1. Check data availability (use browse-robonet-data):
   get_data_availability(symbols=["BTC-USDT"], only_with_data=true)
   → Verify 6+ months of history available

2. Run initial backtest (6 months):
   run_backtest(
       strategy_name="NewStrategy",
       start_date="2024-06-01",
       end_date="2024-12-31",
       symbol="BTC-USDT",
       timeframe="1h",
       config={"fee": 0.0005, "slippage": 0.0005, "leverage": 1}
   )

3. Evaluate results:
   Sharpe: 1.3 ✓ (good)
   Drawdown: 14% ✓ (moderate)
   Win rate: 51% ✓ (realistic)
   Profit factor: 1.7 ✓ (profitable)
   Total trades: 87 ✓ (sufficient)

4. Decision:
   → Strong initial results
   → Proceed to multi-period validation (Workflow 2)
Cost: $0.001 (~free)
目标: 首次测试新创建的策略
1. 检查数据可用性(使用browse-robonet-data):
   get_data_availability(symbols=["BTC-USDT"], only_with_data=true)
   → 确认有6个月以上的历史数据

2. 运行初始回测(6个月):
   run_backtest(
       strategy_name="NewStrategy",
       start_date="2024-06-01",
       end_date="2024-12-31",
       symbol="BTC-USDT",
       timeframe="1h",
       config={"fee": 0.0005, "slippage": 0.0005, "leverage": 1}
   )

3. 评估结果:
   Sharpe:1.3 ✓(良好)
   回撤率:14% ✓(中等)
   胜率:51% ✓(符合实际)
   盈利因子:1.7 ✓(可盈利)
   总交易次数:87 ✓(足够)

4. 决策:
   → 初始表现优异
   → 进入多周期验证(工作流2)
成本: 0.001美元(几乎免费)

Workflow 2: Multi-Period Validation

工作流2: 多周期验证

Goal: Verify strategy robustness across different time periods
1. Test Period 1 (Train):
   run_backtest(..., start_date="2024-01-01", end_date="2024-06-30")
   → Sharpe: 1.5, Drawdown: 12%

2. Test Period 2 (Validation):
   run_backtest(..., start_date="2024-07-01", end_date="2024-12-31")
   → Sharpe: 1.3, Drawdown: 15%

3. Compare:
   Period 2 slightly worse but consistent ✓
   Sharpe drop: 13% (acceptable variation)
   Drawdown increase: 3% (acceptable)

4. Test Period 3 (Recent):
   run_backtest(..., start_date="2024-10-01", end_date="2024-12-31")
   → Sharpe: 1.4, Drawdown: 11%

5. Analysis:
   Consistent performance across all periods ✓
   No significant degradation ✓
   Strategy is robust ✓

6. Decision:
   → Ready for deployment consideration
   → Review pre-deployment checklist
Cost: $0.003 (3 backtests)
目标: 验证策略在不同时间周期的稳健性
1. 测试周期1(训练期):
   run_backtest(..., start_date="2024-01-01", end_date="2024-06-30")
   → Sharpe:1.5,回撤率:12%

2. 测试周期2(验证期):
   run_backtest(..., start_date="2024-07-01", end_date="2024-12-31")
   → Sharpe:1.3,回撤率:15%

3. 对比:
   周期2表现略差但一致 ✓
   Sharpe下降:13%(可接受的波动)
   回撤率上升:3%(可接受)

4. 测试周期3(近期):
   run_backtest(..., start_date="2024-10-01", end_date="2024-12-31")
   → Sharpe:1.4,回撤率:11%

5. 分析:
   所有周期表现一致 ✓
   无显著下滑 ✓
   策略稳健 ✓

6. 决策:
   → 可考虑部署
   → 检查部署前清单
成本: 0.003美元(3次回测)

Workflow 3: Before/After Improvement Testing

工作流3: 优化前后对比测试

Goal: Validate that improvements actually helped
1. Baseline (before improvement):
   run_backtest(
       strategy_name="Strategy_original",
       start_date="2024-01-01",
       end_date="2024-12-31",
       ...
   )
   → Sharpe: 1.0, Drawdown: 18%, Win rate: 48%

2. Improve strategy (use improve-trading-strategies):
   refine_strategy(strategy_name="Strategy_original", changes="Add trailing stop", mode="new")

3. Test improvement:
   run_backtest(
       strategy_name="Strategy_original_refined",
       start_date="2024-01-01",  # SAME date range!
       end_date="2024-12-31",
       ...
   )
   → Sharpe: 1.3, Drawdown: 14%, Win rate: 52%

4. Compare (apples-to-apples on same data):
   Sharpe: +0.3 (+30%) ✓
   Drawdown: -4% (-22%) ✓
   Win rate: +4% (+8%) ✓
   → Clear improvement across all metrics

5. Validate on different period (avoid overfitting to test data):
   run_backtest(
       strategy_name="Strategy_original_refined",
       start_date="2023-07-01",  # Different period
       end_date="2023-12-31",
       ...
   )
   → Sharpe: 1.2 (still better than original's 1.0)
   → Improvement is real, not overfitted

6. Decision:
   → Keep improved version
   → Consider further optimization or deployment
Cost: $0.003 (3 backtests)
目标: 验证优化是否真的有效
1. 基准版本(优化前):
   run_backtest(
       strategy_name="Strategy_original",
       start_date="2024-01-01",
       end_date="2024-12-31",
       ...
   )
   → Sharpe:1.0,回撤率:18%,胜率:48%

2. 优化策略(使用improve-trading-strategies):
   refine_strategy(strategy_name="Strategy_original", changes="Add trailing stop", mode="new")

3. 测试优化后的版本:
   run_backtest(
       strategy_name="Strategy_original_refined",
       start_date="2024-01-01",  # 相同的日期范围!
       end_date="2024-12-31",
       ...
   )
   → Sharpe:1.3,回撤率:14%,胜率:52%

4. 在相同数据上进行同类对比:
   Sharpe:+0.3(+30%) ✓
   回撤率:-4%(-22%) ✓
   胜率:+4%(+8%) ✓
   → 所有指标均有明显提升

5. 在不同周期验证(避免过拟合至测试数据):
   run_backtest(
       strategy_name="Strategy_original_refined",
       start_date="2023-07-01",  # 不同的周期
       end_date="2023-12-31",
       ...
   )
   → Sharpe:1.2(仍优于原版本的1.0)
   → 优化效果真实,未过拟合

6. 决策:
   → 保留优化后的版本
   → 考虑进一步优化或部署
成本: 0.003美元(3次回测)

Workflow 4: Parameter Sensitivity Testing

工作流4: 参数敏感性测试

Goal: Understand how sensitive strategy is to parameters
1. Baseline (default parameters):
   Strategy uses RSI(14) threshold of 30
   run_backtest(...) → Sharpe: 1.3

2. Test parameter variations:
   Create variants: RSI threshold 25, 30, 35

   run_backtest(strategy_name="Strategy_RSI25", ...) → Sharpe: 1.1
   run_backtest(strategy_name="Strategy_RSI30", ...) → Sharpe: 1.3
   run_backtest(strategy_name="Strategy_RSI35", ...) → Sharpe: 1.2

3. Analysis:
   Performance varies only slightly (1.1 to 1.3)
   → Strategy is robust (not overly sensitive to exact parameters) ✓

   vs. High sensitivity:
   RSI25: Sharpe 2.5
   RSI30: Sharpe 1.3
   RSI35: Sharpe 0.4
   → Overfitted to specific parameter value ✗

4. Decision:
   Robust strategy (small variation) → Safe to deploy
   Sensitive strategy (large variation) → Likely overfit, risky to deploy
Cost: $0.003 (3 backtests)
目标: 了解策略对参数的敏感性
1. 基准版本(默认参数):
   策略使用RSI(14)阈值30
   run_backtest(...) → Sharpe:1.3

2. 测试参数变体:
   创建变体: RSI阈值25、30、35

   run_backtest(strategy_name="Strategy_RSI25", ...) → Sharpe:1.1
   run_backtest(strategy_name="Strategy_RSI30", ...) → Sharpe:1.3
   run_backtest(strategy_name="Strategy_RSI35", ...) → Sharpe:1.2

3. 分析:
   表现仅略有波动(1.1至1.3)
   → 策略稳健(对参数的具体值不敏感) ✓

   对比高敏感性情况:
   RSI25: Sharpe2.5
   RSI30: Sharpe1.3
   RSI35: Sharpe0.4
   → 过拟合至特定参数值 ✗

4. 决策:
   稳健策略(波动小)→ 可安全部署
   高敏感性策略(波动大)→ 可能过拟合,部署风险高
成本: 0.003美元(3次回测)

Troubleshooting

故障排除

"No Data Available"

"无可用数据"

Issue: Backtest fails with "insufficient data"
Solutions:
1. Check data availability first (use browse-robonet-data):
   get_data_availability(symbols=["YOUR-SYMBOL"], only_with_data=true)

2. Adjust date range:
   - BTC-USDT, ETH-USDT: Available from 2020-present
   - Altcoins: Typically 6-24 months
   - Use date range within available data

3. Try different symbol:
   - BTC-USDT and ETH-USDT have longest history
   - Start testing on these, then expand to altcoins
问题: 回测因"数据不足"失败
解决方案:
1. 先检查数据可用性(使用browse-robonet-data):
   get_data_availability(symbols=["YOUR-SYMBOL"], only_with_data=true)

2. 调整日期范围:
   - BTC-USDT、ETH-USDT: 数据可追溯至2020年至今
   - 山寨币: 通常有6-24个月的数据
   - 使用可用数据范围内的日期

3. 尝试其他交易对:
   - BTC-USDT和ETH-USDT的历史数据最长
   - 先在这些交易对上测试,再扩展到山寨币

"No Trades Generated"

"未生成任何交易"

Issue: Backtest completes but zero trades executed
Solutions:
1. Entry conditions too restrictive:
   - Review strategy code (use browse-robonet-data: get_strategy_code)
   - Conditions may never be met simultaneously
   - Example: "RSI < 20 AND price > 200 EMA" (RSI rarely gets to 20)

2. Test on longer period:
   - 6 months may not have ideal conditions
   - Try 12-24 months

3. Adjust thresholds (use improve-trading-strategies):
   - Loosen entry conditions slightly
   - Example: Change "RSI < 25" to "RSI < 30"
问题: 回测完成但未执行任何交易
解决方案:
1. 入场条件过于严格:
   - 查看策略代码(使用browse-robonet-data: get_strategy_code)
   - 可能多个条件从未同时满足
   - 示例: "RSI <20 且 价格>200日均线"(RSI很少低于20)

2. 延长测试周期:
   - 6个月可能未出现理想的条件
   - 尝试12-24个月

3. 调整阈值(使用improve-trading-strategies):
   - 略微放宽入场条件
   - 示例: 将"RSI <25"改为"RSI <30"

"Backtest Takes >2 Minutes"

"回测耗时超过2分钟"

Issue: Backtest runs for a long time
Solutions:
1. Long date range + high-frequency timeframe:
   - 2+ years on 1m timeframe = slow
   - Solution: Test shorter range or use 5m/15m timeframe

2. Complex strategy with many indicators:
   - Some indicators are computationally expensive
   - Solution: Simplify strategy if possible

3. Normal for prediction markets:
   - run_prediction_market_backtest can take 30-60s
   - This is expected
问题: 回测运行时间过长
解决方案:
1. 长日期范围+高频时间周期:
   - 2年以上的1分钟周期数据会导致速度缓慢
   - 解决方案: 缩短测试范围或使用5分钟/15分钟周期

2. 包含多个指标的复杂策略:
   - 部分指标计算成本高
   - 解决方案: 尽可能简化策略

3. 预测市场回测的正常情况:
   - run_prediction_market_backtest可能需要30-60秒
   - 这是预期情况

"Results Look Too Good"

"结果看起来好得离谱"

Issue: Sharpe >3.0, win rate >75%, profit factor >5.0
Solutions:
1. Likely overfitted to historical data
2. Test on out-of-sample period (different dates)
3. Check for look-ahead bias (using future data)
4. Verify realistic fees and slippage configured
5. If too-good-to-be-true persists, be very skeptical
6. Start with tiny deployment size to validate in live market
问题: Sharpe>3.0,胜率>75%,盈利因子>5.0
解决方案:
1. 很可能过拟合至历史数据
2. 在样本外周期(不同日期)测试
3. 检查是否存在前瞻偏差(使用了未来数据)
4. 确认配置了真实的手续费和滑点
5. 若好得离谱的表现持续存在,请保持高度怀疑
6. 先以极小的资金规模部署,在实盘中验证

Next Steps

后续步骤

After backtesting strategies:
Improve underperforming strategies:
  • Use
    improve-trading-strategies
    skill to refine
  • Cost: $0.50-$4.00 per operation
  • Test improvements with this skill again
Deploy passing strategies (HIGH RISK):
  • Use
    deploy-live-trading
    skill ONLY after thorough testing
  • Cost: $0.50 deployment fee
  • Verify all pre-deployment checklist items passed
  • Start with small capital, monitor closely
Browse other strategies:
  • Use
    browse-robonet-data
    skill to see existing strategies
  • Compare your results to others
  • Learn from high-performing strategies
完成策略回测后:
优化表现不佳的策略:
  • 使用
    improve-trading-strategies
    技能进行优化
  • 成本: 每次操作0.50-4.00美元
  • 再次使用本技能测试优化效果
部署通过测试的策略(高风险):
  • 仅在充分测试后使用
    deploy-live-trading
    技能
  • 成本: 0.50美元部署费
  • 确认所有部署前清单项目均已通过
  • 先投入少量资金,密切监控
浏览其他策略:
  • 使用
    browse-robonet-data
    技能查看现有策略
  • 将你的结果与其他策略对比
  • 从表现优异的策略中学习

Summary

总结

This skill provides strategy validation through backtesting:
  • 3 tools: run_backtest (crypto), run_prediction_market_backtest (Polymarket), get_latest_backtest_results (cached)
  • Cost: $0.001 per backtest (essentially free)
  • Execution: 20-60 seconds
  • Purpose: Validate strategy performance before risking capital
Core principle: Thorough backtesting (6+ months, multiple periods) is the only way to validate strategies. Past performance doesn't guarantee future results, but lack of past performance guarantees future losses.
Critical warning: NEVER deploy strategies without backtesting. Backtesting is cheap ($0.001) and fast (20-60s). Deploying untested strategies risks real capital and will almost certainly result in losses.
Pre-deployment checklist: Verify Sharpe >1.0, drawdown <20%, win rate 45-65%, profit factor >1.5, 50+ trades, tested on 6+ months, multi-period validation, realistic fees/slippage, no red flags. If ANY item fails, improve strategy before deploying.
Best practice: Test → Improve → Test → Improve (iterate). Each improvement should be validated with new backtest on same data to confirm actual improvement vs. noise.
该技能通过回测实现策略验证:
  • 3个工具: run_backtest(加密货币)、run_prediction_market_backtest(Polymarket)、get_latest_backtest_results(缓存结果)
  • 成本: 每次回测0.001美元(几乎免费)
  • 执行时间: 20-60秒
  • 用途: 在投入资金前验证策略绩效
核心原则: 充分的回测(6个月以上,多周期)是验证策略的唯一可靠方式。过往表现不代表未来结果,但缺乏过往有效表现则必然会导致未来亏损。
重要警告: 绝对不要在未进行回测的情况下部署策略。回测成本低廉(0.001美元)且速度快(20-60秒)。部署未测试的策略会面临真实资金损失的风险,且几乎必然会亏损。
部署前清单: 确认Sharpe>1.0、回撤<20%、胜率45-65%、盈利因子>1.5、测试周期内至少50笔交易、多周期验证、配置真实的手续费和滑点、无警示信号。如果任何一项未通过,请先优化策略再部署。
最佳实践: 测试→优化→测试→优化(循环迭代)。每次优化后,需在相同数据上重新回测以确认优化效果是真实的,而非噪音。