Skill Positioning
Provides financial engineering researchers withlightweight, fast-respondingstrategy backtesting capabilities, supports parsing and validation of simple strategy rules, quickly outputs core performance metrics, and systematically flags overfitting risks.
Applicable scenarios: rapid validation of strategy ideas, quick strategy evaluation at morning meetings, instant calculations during investment research discussions, preliminary screening of strategy frameworks. Inapplicable scenarios: high-frequency strategy backtesting, complex multi-factor models, live-trading-grade backtesting requiring fine-grained transaction cost simulation.
Data Collection Guidelines (gildata-aidata Tool Mapping)
All market data must be obtained through the gildata-aidata service, with specific tool calls as follows:
1. Index market data (as benchmark or underlying)
finx gildata-aidata IndexDailyQuote --body '{"query": "查询沪深300指数过去3年的每日收盘价、涨跌幅、成交量"}'
- Purpose: obtain historical daily market data of broad-based indices (such as CSI 300, CSI 500, ChiNext Index), used to calculate benchmark returns or as the underlying for ETF rotation strategies.
2. Individual stock market data (as strategy underlying)
finx gildata-aidata StockDailyQuote --body '{"query": "查询贵州茅台过去3年的每日收盘价、开盘价、最高价、最低价、成交量"}'
- Purpose: obtain historical daily market data of individual stocks, used for single-underlying strategy backtesting or constructing a stock pool.
3. Financial/valuation data (for fundamental strategies)
finx gildata-aidata StockValueAnalysis --body '{"query": "查询全市场A股最新PE(TTM)、PB(LF)"}'
- Purpose: obtain cross-sectional valuation data to assist in constructing value stock selection strategies.
Execution Process
Step 1: Parse Strategy Rules
Extract the following key information from user input:
| Element | Description | Example |
|---|---|---|
| Strategy type | Moving average/momentum/reversal/breakout/rotation/custom | Dual moving average crossover |
| Underlying scope | Individual stock/index/ETF/industry/custom pool | CSI 300 constituent stocks |
| Entry condition | Signal rule that triggers buying | MA5 crosses above MA20 |
| Exit condition | Signal rule that triggers selling | MA5 crosses below MA20 / 8% stop loss |
| Position weight | Equal weight/market-cap weighted/custom | Equal-weight allocation |
| Rebalancing frequency | Daily/weekly/monthly/signal-driven | Signal-driven |
| Backtest period | Start and end time (default last 3 years) | 2023-01-01 to 2026-04-27 |
| Benchmark index | Comparison benchmark (default CSI 300) | CSI 300 |
Handling missing parameters: if the user does not explicitly specify, use the following default values:
- Backtest period: last 3 years
- Initial capital: 1 million yuan
- Benchmark index: CSI 300 (000300.SH)
- Transaction cost: one-thousandth per side (including commission + stamp duty + slippage)
- Rebalancing frequency: signal-driven
Step 2: Obtain market data
Try the following data sources in order of priority:
- gildata-aidata: call
IndexDailyQuoteorStockDailyQuoteto obtain historical daily market data for the target (open price, close price, high price, low price, volume).This is the preferred data source. - eastmoney-mx: if
gildata-aidatadoes not cover it, you may try callingsearch-datato obtain supplementary data. - Python code + open-source libraries: use
akshareoryfinancein the sandbox to obtain data. - Web search: use
web_searchto search for key data points and assist in building the dataset. - Simulated data: if none of the above is available, generate simulated data that matches the statistical characteristics, and clearly annotate this in the report.
Data requirements:
- Frequency: daily level (minimum requirement)
- Fields: date, open price, close price, high price, low price, volume (at least close price is required)
- Length: cover the full backtest period, including at least 250 trading days/year
Step 3: Execute backtest calculation
Use Python code to execute the backtest in a sandbox environment, with the core logic:
# 回测计算核心框架
import pandas as pd
import numpy as np
class QuickBacktest:
def __init__(self, prices, signals, initial_capital=1000000, cost_rate=0.001):
self.prices = prices # 价格序列
self.signals = signals # 交易信号(1=买入,-1=卖出,0=持有)
self.initial_capital = initial_capital
self.cost_rate = cost_rate
def run(self):
# 计算每日持仓权重
positions = self.signals.cumsum().clip(-1, 1) # 简化为多空或纯多
# 计算每日收益(扣除交易成本)
daily_returns = prices.pct_change()
strategy_returns = positions.shift(1) * daily_returns
# 扣除交易成本
trades = positions.diff().abs()
strategy_returns -= trades * self.cost_rate
# 计算净值曲线
nav = (1 + strategy_returns).cumprod() * self.initial_capital
return nav, strategy_returns
Step 4: Calculate core performance metrics
The following metrics must be calculated:
| Metric | Calculation formula | Description |
|---|---|---|
| Annualized return | (总收益率 + 1)^(252/交易日数) - 1 |
Annualized compound return |
| Maximum drawdown | max((nav_peak - nav_trough) / nav_peak) |
Largest historical loss magnitude |
| Sharpe ratio | (年化收益 - 无风险利率) / 年化波动率 |
Risk-adjusted return, with a risk-free rate of 2.5% |
| Win rate | 盈利交易次数 / 总交易次数 |
Proportion of successful trades |
| Profit-loss ratio | 平均盈利 / 平均亏损 |
Ratio of profits to losses |
| Annualized volatility | 日收益率标准差 × √252 |
Degree of return fluctuation |
| Calmar ratio | 年化收益 / 最大回撤 |
Return-to-drawdown ratio |
| Excess return | 策略年化收益 - 基准年化收益 |
Alpha relative to the benchmark |
| Information ratio | 超额收益均值 / 超额收益标准差 × √252 |
Stability of excess returns |
Step 5: Overfitting risk detection
Systematically check the following overfitting signals and evaluate each item:
Overfitting detection checklist
| Detection item | Evaluation criteria | Risk level |
|---|---|---|
| Number of parameters | 3 or fewer free parameters is safe, > 5 is high risk | 🟢🟡🔴 |
| Out-of-sample performance | A difference of > 50% between training-period and test-period Sharpe is a warning sign | 🟢🟡🔴 |
| Trading frequency | More than 100 annualized trades may indicate overfitting to noise | 🟢🟡🔴 |
| Parameter sensitivity | A Sharpe change of > 30% caused by fine-tuning parameters by ±10% is a warning sign | 🟢🟡🔴 |
| Economic logic | Whether the strategy has a reasonable economic explanation | 🟢🟡🔴 |
| Data snooping | Whether the best result is reported after screening a large number of strategies | 🟢🟡🔴 |
| Survivorship bias | Whether only currently surviving targets are used in the backtest | 🟢🟡🔴 |
Overfitting Risk Rating:
- 🟢 Low Risk: 0-1 warning(s)
- 🟡 Medium Risk: 2-3 warning(s)
- 🔴 High Risk: ≥4 warning(s)
Step 6: Generate Backtest Report
Generate a Markdown-format report strictly according to the following template:
# [策略名称] 速回测报告
> **报告日期**:YYYY-MM-DD
> **回测区间**:YYYY-MM-DD 至 YYYY-MM-DD
> **数据频率**:日线
> **标的范围**:[标的描述]
---
## 一、策略概要
| 要素 | 内容 |
|------|------|
| 策略类型 | [均线/动量/反转/突破/轮动] |
| 入场信号 | [具体规则] |
| 出场信号 | [具体规则] |
| 持仓方式 | [等权/市值加权/自定义] |
| 调仓频率 | [每日/每周/每月/信号驱动] |
| 交易成本 | 单边 ‰ |
---
## 二、核心绩效指标
| 指标 | 策略 | 基准(沪深300) | 超额 |
|------|------|-----------------|------|
| 年化收益率 | **%** | % | +.% |
| 最大回撤 | **.%** | .% | -.% |
| 夏普比率 | **.** | . | — |
| Calmar比率 | **.** | . | — |
| 年化波动率 | .% | .% | — |
| 胜率 | **.%** | — | — |
| 盈亏比 | **.** | — | — |
| 信息比率 | **.** | — | — |
| 总交易次数 | **次** | — | — |
---
## 三、净值曲线与关键统计
[如有条件,生成并插入净值曲线对比图]
### 分年度表现
| 年份 | 策略收益 | 基准收益 | 超额收益 |
|------|----------|----------|----------|
| 2024 | .% | .% | +.% |
| 2025 | .% | .% | +.% |
| 2026 | .% | .% | +.% |
### 最大回撤区间
- **最大回撤**:.%
- **回撤区间**:YYYY-MM-DD 至 YYYY-MM-DD(持续 个交易日)
- **恢复时间**:个交易日(若未恢复则标注"尚未恢复")
---
## 四、过拟合风险评估
### 风险检测清单
| 检测项 | 结果 | 风险等级 |
|--------|------|----------|
| 参数数量 | [ ] 个 | 🟢/🟡/🔴 |
| 样本外表现 | [描述] | 🟢/🟡/🔴 |
| 交易频率 | [ ] 次/年 | 🟢/🟡/🔴 |
| 参数敏感性 | [描述] | 🟢/🟡/🔴 |
| 经济逻辑 | [描述] | 🟢/🟡/🔴 |
| 数据窥探 | [描述] | 🟢/🟡/🔴 |
| 幸存者偏差 | [描述] | 🟢/🟡/🔴 |
### 综合评级:🟢低风险 / 🟡中风险 / 🔴高风险
### 风险解读
[针对每一项预警项,给出具体解释和改进建议。例如:
- **参数数量**:策略使用2个自由参数(MA5、MA20周期),在安全范围内。但需注意,若后续优化中增加止损、止盈、仓位管理等参数,可能引发参数过拟合。
- **交易频率**:年化交易次数45次,处于合理区间。若超过100次/年,需警惕策略可能在拟合市场噪音。]
---
## 五、策略评价与建议
### 优势
1. [列出策略的核心优势]
2. [...]
### 局限
1. [列出策略的已知局限]
2. [...]
### 改进建议
1. [给出具体可操作的改进方向]
2. [...]
---
## 六、重要声明
> ⚠️ **本回测为轻量化快速验证,不构成投资建议。**
>
> 1. 回测结果基于历史数据,不代表未来表现
> 2. 交易成本采用简化假设,实际交易摩擦可能更高
> 3. 未考虑流动性约束、涨跌停限制、停牌等实盘因素
> 4. 过拟合风险评估为定性判断,建议进一步进行样本外检验和蒙特卡洛模拟
> 5. 实盘部署前,请务必进行更严格的回测验证和模拟盘测试
Common Strategy Templates
Template 1: Dual Moving Average Crossover Strategy
策略规则:
- 短期均线:MA_N(N=5/10/20)
- 长期均线:MA_M(M=20/60/120)
- 入场:MA_N 上穿 MA_M
- 出场:MA_N 下穿 MA_M
- 持仓:全仓或等权
Template 2: Momentum Strategy
策略规则:
- 观察窗口:过去N日(N=20/60/120)
- 排序指标:区间收益率
- 买入:排名前K%的标的
- 卖出:排名后K%或持仓跌出排名
- 调仓:每月/每季度末
Template 3: Mean Reversion Strategy
策略规则:
- 参考基准:MA_N 或布林带
- 入场:价格跌破下轨 / 偏离均线超过X个标准差
- 出场:价格回归均线 / 触及上轨
- 止损:固定百分比或ATR倍数
Template 4: Breakout Strategy
策略规则:
- 突破参考:N日最高/最低价、唐奇安通道
- 入场:收盘价突破N日高点
- 出场:收盘价跌破M日低点
- 过滤:突破时需伴随成交量放大
Notes
- Data Source Priority: Prefer using
gildata-aidatato obtain market data, ensuring data quality and consistency. - Parameter Robustness: It is recommended to present parameter sensitivity analysis in the report (e.g., performance changes with parameters ±20%).
- Benchmark Selection: The benchmark should match the risk characteristics of the strategy; use CSI 300 for equity strategies and China Bond Composite for bond strategies.
- Report Transparency: If simulated data is used, it must be prominently noted at the beginning of the report.
- Iteration Suggestions: Quick backtesting is only for preliminary screening; strategies with potential should proceed to the in-depth backtesting process.