Files
docker-configs/backtest/strategy/emotional-damage/README_CONFIG.md
2025-07-19 00:00:01 -05:00

4.1 KiB
Raw Blame History

Enhanced Emotional Damage Strategy - 配置化运行指南

🚀 快速开始

只需要两个步骤就能运行策略并生成完整报告:

  1. 修改配置文件 config.json
  2. 运行策略 python3 run_strategy_with_config.py

📝 配置文件说明

config.json 主要参数:

策略参数 (strategy_params)

{
  "initial_capital": 100000,        // 初始资金
  "fear_threshold": 25,             // 恐慌阈值
  "greed_threshold": 75,            // 贪婪阈值  
  "stop_loss_threshold": 0.15,      // 止损阈值 (15%)
  "transition_steps": 4,            // 转换步数
  "top_stocks_count": 4,            // 选股数量
  "volatility_threshold": 0.1,      // 波动率阈值 (10%)
  "volatility_calculation_days": 30 // 波动率计算天数
}

技术指标参数 (technical_indicators)

{
  "rsi_threshold": 30,              // RSI阈值
  "required_indicators": 2,         // 需要满足的指标数量 (2/3)
  "sma5_above_sma20": true,         // 是否要求SMA5>SMA20
  "macd_convergence": true,         // MACD收敛而非金叉
  "ema_periods": {
    "fast": 12, "slow": 26, "signal": 9
  },
  "sma_periods": {
    "fast": 5, "slow": 20
  },
  "rsi_period": 14
}

输出设置 (output_settings)

{
  "generate_pdf": true,             // 生成PDF报告
  "generate_csv": true,             // 生成CSV文件  
  "generate_detailed_trades": true, // 生成详细交易记录
  "show_console_output": true,      // 显示控制台输出
  "save_strategy_object": true      // 保存策略对象
}

🎯 常用修改场景

场景1调整风险参数

{
  "stop_loss_threshold": 0.10,     // 改为10%止损
  "fear_threshold": 20,            // 更激进的恐慌阈值
  "greed_threshold": 80            // 更保守的贪婪阈值
}

场景2修改选股逻辑

{
  "top_stocks_count": 6,           // 选择6只股票
  "required_indicators": 3,        // 要求所有3个指标都满足
  "volatility_threshold": 0.15     // 提高波动率要求
}

场景3技术指标调优

{
  "rsi_threshold": 40,             // 提高RSI要求
  "sma5_above_sma20": false,       // 取消SMA要求
  "macd_convergence": false        // 改为传统MACD金叉
}

场景4只生成特定报告

{
  "generate_pdf": false,           // 不生成PDF
  "generate_csv": true,            // 只要CSV
  "generate_detailed_trades": true,
  "show_console_output": false     // 静默运行
}

📊 运行和输出

运行命令

cd /home/will/docker/backtest/strategy/emotional-damage/
python3 run_strategy_with_config.py

输出文件

运行后会在以下目录生成文件:

/home/will/docker/backtest/reports/

  • enhanced_strategy_report_YYYYMMDD_HHMMSS.pdf - PDF综合报告
  • enhanced_trades_YYYYMMDD_HHMMSS.csv - 交易记录CSV
  • detailed_trades_YYYYMMDD_HHMMSS.txt - 详细交易报告

/home/will/docker/backtest/results/

  • enhanced_strategy_YYYYMMDD_HHMMSS.pkl - 策略对象(用于进一步分析)

🔧 常见问题

Q: 如何测试不同的参数组合?

A: 复制config.json为不同文件名如config_test1.json修改run_strategy_with_config.py中的文件名

Q: 如何只测试特定时间段?

A: 修改config.json中的data_settings

{
  "start_date": "2020-01-01",
  "end_date": "2023-12-31"
}

Q: 如何加快运行速度?

A: 设置output_settings

{
  "generate_pdf": false,
  "show_console_output": false
}

Q: 如何分析特定股票的表现?

A: 查看生成的CSV文件按ticker列筛选

📈 性能调优建议

  1. 保守策略提高fear_threshold到30降低greed_threshold到70
  2. 激进策略降低fear_threshold到20提高greed_threshold到80
  3. 严格选股设置required_indicators为3提高volatility_threshold
  4. 宽松选股设置required_indicators为1降低rsi_threshold

🚨 注意事项

  1. 修改配置后记得保存文件
  2. 确保数据库路径正确
  3. 首次运行可能需要几分钟时间
  4. 大幅修改参数可能导致无交易或过度交易

Happy Trading! 🎯