QuantAI

AI 驱动的量化回测平台

策略对话

用自然语言描述你的交易策略

AI 助手

你好!我可以帮你生成量化交易策略并进行回测。请描述你想要的策略,例如:

"双均线策略,5日线上穿20日线买入"

帮我写一个双均线策略,5日均线上穿20日均线买入,下穿卖出。回测沪深300指数,时间范围是2022年到2024年,初始资金100万

AI 助手

已为你生成双均线交叉策略,参数配置如下:

策略类型 双均线交叉
回测标的 沪深300
时间范围 2022-2024
初始资金 ¥1,000,000
快线周期 5 日
慢线周期 20 日
查看生成的代码
def initialize(context):
    context.security = '000300.SH'
    context.fast_period = 5
    context.slow_period = 20

def handle_data(context, data):
    fast_ma = data.history('close', context.fast_period).mean()
    slow_ma = data.history('close', context.slow_period).mean()

    if fast_ma > slow_ma and not context.portfolio.positions:
        order_target_percent(context.security, 1.0)
    elif fast_ma < slow_ma and context.portfolio.positions:
        order_target_percent(context.security, 0)

回测结果

双均线交叉策略 · 沪深300 · 2022-2024

回测完成

总收益率

+32.5%

vs 基准 -8.2%

年化收益

+10.8%

3年复合

夏普比率

1.35

风险调整后

最大回撤

-15.3%

2022-10-31

胜率

58.3%

35/60 笔

盈亏比

1.82

平均盈/亏

收益曲线

策略净值 沪深300

月度收益

1
2
3
4
5
6
7
8
9
10
11
24
+3.2
+1.8
-2.1
+0.9
+2.5
-1.2
+4.1
+1.5
-3.0
+0.8
-
23
+2.4
-4.2
+1.6
+0.7
-2.3
+3.5
+1.9
-1.1
+2.8
+0.5
+4.3
22
-3.1
-2.0
-5.2
+1.4
+3.8
+2.6
-0.9
+0.6
-4.5
-6.8
+5.2

最近交易

买入

2024-10-15 09:35

3,842.50

260 手

卖出

2024-09-28 14:52

3,756.20

+2.8%

买入

2024-09-05 09:31

3,654.80

273 手

卖出

2024-08-12 10:15

3,521.40

-1.5%

AI 优化建议

  • 最大回撤 15.3% 略高,建议添加 5% 止损ATR 动态止损
  • 2022年10月回撤集中,可考虑添加 趋势过滤器 避免震荡市假信号
  • 夏普比率 1.35 表现良好,可尝试 参数优化 进一步提升