DELTA_HEDGING_CHECKLIST.md 5.8 KB

Delta 对冲检查清单

快速诊断步骤

1. 运行诊断工具

npm run diagnose:delta

这会输出:

  • ✅ Delta 检测配置状态
  • ✅ 当前净敞口(BTC + USDC)
  • ✅ 配置建议

2. 检查日志关键输出

期望看到的日志:

每个交易周期都应该有:

📊 Delta Assessment {
  symbol: 'BTC',
  totalPositionBTC: '0.00150',        # 当前净敞口
  positionValueUSDC: '150.00',
  weightedDelta: '0.0075%',           # 加权 Delta
  currentTolerance: '0.5000%',        # 当前容忍度
  exceedsTolerance: '✅ NO',          # 是否超限
  recommendation: 'hold'              # 建议操作
}

当 Delta 超限时应该看到:

⚖️ Delta exceeds tolerance, generating rebalance signal {
  totalPositionBTC: 0.00150,
  deltaAssessment: 'adjust',
  balanceAmount: 0.00075,
  balanceSide: 'ask'
}

对冲执行:

Executing signal {
  type: 'balance',
  accountId: 'account1',
  symbol: 'BTC',
  side: 'ask',
  amount: 0.00075
}

Signal executed successfully {
  orderId: '12345',
  clientOrderId: 'uuid-...'
}

3. 实时监控命令

窗口1 - 运行策略:

npm run trade

窗口2 - 监控 Delta:

tail -f logs/strategy.log | grep "Delta Assessment"

窗口3 - 监控对冲:

tail -f logs/strategy.log | grep -E "exceeds tolerance|Hedging signal|Executing signal"

窗口4 - 监控错误:

tail -f logs/strategy.log | grep -E "error|failed|ERROR"

4. 配置检查

trading-strategy.json

{
  "deltaRebalancing": {
    "enabled": true,                    # ← 必须启用
    "checkInterval": 60,
    "rebalanceThreshold": 0.05,         # ← 当前 5%,建议降到 0.01
    "maxDeltaDeviation": 0.001
  }
}

delta-strategy-config.json

{
  "deltaControl": {
    "baseDeltaTolerance": 0.005,        # ← 当前 0.5%,建议降到 0.001
    "stableDeltaTolerance": 0.005,
    "volatileDeltaTolerance": 0.02
  }
}

5. 常见问题快速修复

问题:敞口持续存在 (>0.001 BTC)

修复1:降低阈值(使用绝对值)

编辑 src/strategies/SimpleStrategyEngine.ts:326-362

// 当前逻辑(基于百分比)
if (deltaAssessment.exceedsTolerance) {
  // ...
}

// 改为绝对值阈值(推荐)
const ABSOLUTE_THRESHOLD_BTC = 0.0001;  // 0.0001 BTC ≈ $10
if (Math.abs(totalPositionBTC) > ABSOLUTE_THRESHOLD_BTC) {
  const balanceAmount = Math.abs(totalPositionBTC);  // 全部对冲
  // ... 生成对冲信号
}

修复2:更新配置

# 编辑 config/trading-strategy.json
{
  "deltaRebalancing": {
    "rebalanceThreshold": 0.01,      # 从 5% 改为 1%
    "maxDeltaDeviation": 0.0005      # 从 0.1% 改为 0.05%
  }
}

问题:对冲信号未生成

检查步骤:

  1. 确认 exceedsTolerance: YES 出现在日志中
  2. 如果没有,降低 rebalanceThreshold
  3. 如果有但无对冲信号,检查策略引擎代码

问题:对冲订单失败 (420 错误)

这是正常的! 表示账户无持仓可减。

SignalExecutor 已自动处理,跳过重试:

⚠️ Reduce-only order failed: position not found (skip retry)

问题:频繁误触发对冲

修复:提高波动容忍度

{
  "deltaControl": {
    "volatileDeltaTolerance": 0.03,    # 从 2% 提高到 3%
    "volatilityThreshold": 0.015        # 从 1% 提高到 1.5%
  }
}

6. 验证对冲生效

运行策略并观察:

  1. 初始状态:

    totalPositionBTC: 0.00150    # 有敞口
    exceedsTolerance: ⚠️  YES
    
  2. 触发对冲:

    ⚖️ Delta exceeds tolerance, generating rebalance signal
    Executing signal { type: 'balance', side: 'ask', amount: 0.00075 }
    Signal executed successfully { orderId: '12345' }
    
  3. 对冲后:

    totalPositionBTC: 0.00075    # 敞口减少
    exceedsTolerance: ✅ NO
    
  4. 最终:

    totalPositionBTC: <0.0001    # 接近零
    

推荐配置(零敞口目标)

Step 1: 修改策略引擎使用绝对阈值

编辑 src/strategies/SimpleStrategyEngine.ts:326

// 在 checkDeltaRebalance 方法中

// 替换原有的百分比检查
const ABSOLUTE_THRESHOLD_BTC = 0.0001;  // 约 $10 USDC
if (Math.abs(totalPositionBTC) > ABSOLUTE_THRESHOLD_BTC) {
  const balanceAmount = Math.abs(totalPositionBTC);
  // ... 生成 100% 对冲信号
}

Step 2: 更新配置文件

config/trading-strategy.json:

{
  "deltaRebalancing": {
    "enabled": true,
    "checkInterval": 30,
    "rebalanceThreshold": 0.01,      # 1%(作为后备)
    "maxDeltaDeviation": 0.0005      # 0.05%
  },
  "intervals": {
    "volumeTrading": 3,
    "deltaMonitoring": 30
  }
}

config/delta-strategy-config.json:

{
  "deltaControl": {
    "baseDeltaTolerance": 0.001,      # 0.1%(严格)
    "stableDeltaTolerance": 0.001,
    "volatileDeltaTolerance": 0.02,
    "predictiveDelta": true
  }
}

Step 3: 重新编译并运行

npm run build
npm run trade

总结

已完成的优化:

  1. ✅ 增强了 Delta 评估日志(实时输出净敞口)
  2. ✅ 创建了诊断工具 npm run diagnose:delta
  3. ✅ 优化了 SignalExecutor 错误处理(420 不重试)
  4. ✅ 完善了对冲对原子性检测
  5. ✅ 提供了详细的配置优化指南

📋 下一步行动:

  1. 运行 npm run diagnose:delta 检查当前状态
  2. 根据诊断结果调整配置阈值
  3. 实时监控日志确认 Delta 检测生效
  4. 如问题持续,使用绝对阈值替代百分比
  5. 收集日志片段进行进一步分析

🔍 关键指标:

  • totalPositionBTC 应该 < 0.0001 BTC
  • exceedsTolerance 超限时应生成对冲信号
  • 对冲执行成功率 > 90%
  • 每个周期都有 Delta Assessment 日志