Skip to content
All library documents

Using Backtests and Parameter Optimization to Validate Trading Strategies

Article vn.py

Summary

This guide explains how to use historical backtests and parameter optimization as research checks before deploying a trading strategy. It outlines setup choices such as the instrument and exchange, bar interval, date range, fees, slippage, contract multiplier, tick size, and starting capital. It recommends matching these assumptions to the intended trading environment because they affect the results. After a run, traders can review performance statistics, equity and drawdown curves, trade records, and logs rather than judging a strategy by return alone.

For optimization, the guide recommends varying a small number of important settings over controlled ranges and using the comparison to identify parameter regions that appear more stable. It cautions that the best historical result may be overfit and that past performance cannot establish future profitability. The evidence is procedural guidance rather than a worked strategy or empirical example. Data quality, cost assumptions, market regime, and risk controls all limit what a backtest can show, so results should inform further review rather than automate a live-trading decision.

Key ideas

  • A backtest checks whether strategy logic runs and how it behaved over a chosen historical period.
  • Trading costs, contract settings, dates, and bar intervals can materially change results.
  • Review drawdowns, trade frequency, and return concentration in addition to overall returns.
  • Parameter optimization is more informative when focused on a few important settings and restrained ranges.
  • Historical performance and optimized parameters do not guarantee future results and can reflect overfitting.

Tags

Full text
# 回测与优化


# 回测与优化

`回测` 是把策略放到历史数据上重新运行,以便观察其历史表现;`参数优化` 则是在一定范围内比较不同参数组合的结果。对于 Fusion 用户来说,回测与优化的意义不在于“证明策略一定赚钱”,而在于帮助你在进入实盘前完成必要验证。

## 为什么先做回测

在正式运行策略之前,建议先做回测,主要原因包括:

- 确认策略逻辑是否能正常运行;
- 检查参数设置是否合理;
- 观察策略在特定历史区间内的表现;
- 识别过度交易、过大回撤或明显不稳定的情形;
- 为后续参数优化提供基础。

对于初学者来说,先做回测是一种控制风险的基本习惯。

## 配置回测参数

打开 `【功能】->【CTA回测】` 后,可进入回测模块。开始回测前,通常需要配置以下内容:

- 策略名称;
- 合约代码与交易所;
- K 线周期;
- 开始时间和结束时间;
- 手续费、滑点等交易成本参数;
- 合约乘数、最小价格跳动和初始资金等基础设置。

这些参数会直接影响回测结果,因此应尽量按照真实交易环境填写,而不是随意估算。

![](https://vnpy-doc.oss-cn-shanghai.aliyuncs.com/fusion/23.png)

![](https://vnpy-doc.oss-cn-shanghai.aliyuncs.com/fusion/24.png)

## 查看回测结果

回测完成后,界面通常会展示:

- 统计指标;
- 收益曲线;
- 回撤曲线;
- 交易明细或成交概览;
- 日志输出。

阅读结果时,建议不要只看收益率,还应同时关注:

- 最大回撤是否可接受;
- 交易次数是否过多或过少;
- 收益是否集中在少量行情阶段;
- 结果是否与策略逻辑本身相一致。

![](https://vnpy-doc.oss-cn-shanghai.aliyuncs.com/fusion/54.png)

## 参数优化入门

当你已经完成基础回测,并希望进一步比较不同参数组合时,可以使用参数优化功能。参数优化通常用于:

- 比较不同指标周期、阈值或止损参数;
- 初步观察哪些参数区间相对稳定;
- 为后续策略微调提供参考。

使用参数优化时,建议:

- 先从少量关键参数开始;
- 控制参数区间和步长,避免组合数量过大;
- 不要把“最佳结果”直接等同于“最适合实盘”的参数。

![](https://vnpy-doc.oss-cn-shanghai.aliyuncs.com/fusion/25.png)

![](https://vnpy-doc.oss-cn-shanghai.aliyuncs.com/fusion/53.png)

## 如何理解回测结果

回测与优化是研究工具,不是结果承诺。理解结果时应特别注意:

- 历史表现不代表未来表现;
- 回测结果依赖历史数据质量、参数设置和成本设定;
- 参数优化可能产生“过拟合”,即参数只对过去样本有效;
- 即使回测收益较好,也仍需结合风控、市场环境和人工复核再决定是否进入实盘。

如果你的策略来自 [智策工作流](../agent/fusion_agent_workflow.md),那么回测与优化更应被视为“验证步骤”,而不是自动决策依据。

下一步建议继续阅读 [历史数据管理](fusion_data.md),了解如何为回测准备和维护数据。

Shown in full with attribution under the source's licence. Licence: MIT

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.