myTestFreqAI/chat/hyperopt.md
2025-06-03 23:27:35 +00:00

129 lines
4.2 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

- Datetime: 2025-06-03 17:30:28
- Model: _qwen3/qwen-plus-latest
- Selected files:
- freqtrade/templates/freqaiprimer.py
> https://www.freqtrade.io/en/stable/hyperopt/
> 在官方文档中,有没有提到hyperopt多久执行一次, 每次timerange的跨度是几天
非常感谢你的提问!
你提供的链接是 Freqtrade 的官方 Hyperopt 文档:
🔗 [https://www.freqtrade.io/en/stable/hyperopt/](https://www.freqtrade.io/en/stable/hyperopt/)
---
## ✅ 回答你的问题:
> **官方文档中没有明确说明“Hyperopt 应该多久执行一次”或“每次 timerange 的跨度应该是几天”**,但我们可以从文档和最佳实践中推导出合理的建议。
---
## 📚 官方文档相关提示
在文档的以下部分提到了一些关键信息:
### 1. **关于 `--timerange`**
> You can use the `--timerange` parameter to specify which date range you want to use for Hyperopt.
示例:
```bash
freqtrade hyperopt --timerange 20200101-20210101 ...
```
这意味着你可以自由指定训练数据的时间范围。
---
### 2. **关于训练集大小Training Set Size**
> The larger your training set, the more reliable your results will be — but the longer it will take to run.
也就是说:
- 更大的训练集 → 更可靠的结果
- 更小的训练集 → 更快完成,但可能过拟合
---
### 3. **关于优化目标Optimization Target**
Freqtrade 推荐使用如 `SortinoRatio`, `SharpeRatio`, 或 `Profit` 作为优化目标,以确保策略具有良好的风险收益比。
---
## ✅ 实战经验总结Hyperopt 执行频率 & Timerange 设置建议
| 问题 | 建议 |
|------|------|
| ❓ Hyperopt 多久执行一次? | ✅ 每次策略逻辑、参数空间或市场环境发生重大变化时运行一次 |
| ❓ 每次 Hyperopt 使用多少历史数据? | ✅ 至少 **30天以上**,推荐 **90~180天** |
| ❓ Hyperopt 需要定期重新运行吗? | ✅ 是的,建议每 **1~3个月** 重新运行一次,适应市场变化 |
---
## 🧠 推荐配置(基于实战经验)
### ✅ Hyperopt 运行频率建议:
| 场景 | 推荐频率 |
|------|-----------|
| 策略首次开发 | ✅ 必须运行一次 |
| 策略小幅调整(如指标、阈值) | ✅ 每次修改后运行 |
| 市场风格切换(如牛市→熊市) | ✅ 每季度运行一次 |
| 策略部署到实盘前 | ✅ 必须运行并验证 |
---
### ✅ `--timerange` 时间跨度建议:
| 目标 | 推荐时间跨度 |
|------|----------------|
| 快速测试 | ✅ 7~14天 |
| 中期趋势策略 | ✅ 30~60天 |
| 长期趋势策略 | ✅ 90~180天 |
| 多币种轮动策略 | ✅ 至少覆盖一个完整周期(如牛熊交替) |
---
### ✅ 示例命令:
```bash
# 快速测试用7天
freqtrade hyperopt --strategy MyStrategy --timerange 20250501-20250507 --timeframe 5m --hyperopt-loss SharpeHyperOptLossDaily
# 正式优化用30天
freqtrade hyperopt --strategy MyStrategy --timerange 20250401-20250501 --timeframe 5m --hyperopt-loss SortinoHyperOptLoss
# 多币种轮动策略90天+
freqtrade hyperopt --strategy MyStrategy --timerange 20250101-20250401 --timeframe 15m --hyperopt-loss ProfitHyperOptLoss --spaces all
```
---
## 🛠️ 补充建议Hyperopt 的最佳实践
| 建议 | 描述 |
|------|------|
| 🔁 分阶段运行 | 先跑短期7天快速验证逻辑再跑长期30天优化参数 |
| 📊 使用合适的时间粒度 | 如果你是做日内交易,使用 `1m``5m`;如果是波段交易,使用 `15m``1h` |
| 🧪 多币种回测 | 使用多个币种进行 Hyperopt避免单币过拟合 |
| 📦 保存结果 | 使用 `--export-filename` 导出最优参数,便于复用 |
---
## ✅ 总结
| 问题 | 推荐做法 |
|------|-----------|
| Hyperopt 多久执行一次? | ✅ 每次策略更新或市场环境变化时运行 |
| 每次 Hyperopt 使用多少数据? | ✅ 最少 7~14天推荐 30~90天 |
| 是否需要定期重新运行? | ✅ 是的,建议每月或每季度重新运行一次 |
---
如果你希望我帮你生成一个完整的 Hyperopt 配置文件(含推荐的 timerange、loss 函数、参数空间等),我可以继续为你输出。是否需要?