Ai全自动编写策略:十大经典策略之Aberration

松鼠Quant
2025-06-19

图片
量化策略开发,高质量社群,交易思路分享等相关内容

工具推荐

· 参数筛选工具

·Ai帮你编写策略

· 订单流图表

· 加入2025俱乐部

· Ai投研助手课程


『正文』

ˇ

Ai编写策略是量化领域的新常态,松鼠Quant在早些时候推出了开源项目《gitee官方推荐,松鼠QuantAi+回测框架详细版教程(图文)让Ai自动编写策略,自动回测,给出总结和迭代意见。

Aberration策略 是一种基于统计和价格波动分析的交易策略,主要用于捕捉市场趋势的延续或反转机会。该策略由凯文·戴维(Kevin Davey)提出,核心思想是利用价格通道(如布林带)和波动率过滤来识别潜在的交易信号。以下是该策略的详细解析:

核心原理

  1. 价格通道构建

  • 使用**布林带(Bollinger Bands)**或类似通道指标(如移动平均线±标准差)定义价格的“正常波动范围”。

  • 中轨:中期移动平均线(如20日均线)。

  • 上下轨:中轨±N倍标准差(N通常为2-3),反映价格的波动性。

  1. 趋势与反转信号

  • 趋势延续:当价格突破通道上轨或下轨时,可能预示趋势加速,策略会顺势入场。

  • 均值回归:若价格突破后重新回到通道内,可能预示反转,触发平仓或反向交易。

  1. 波动率过滤

  • 仅在高波动率市场(如通道宽度扩大)时交易,避免低波动市场的无效信号。


这不就是BOLL通道吗?
Aberration策略确实与布林带(BOLL)通道有高度相似性,但两者在设计初衷、应用逻辑和细节处理上存在关键差异。以下是详细对比分析:

1. 核心区别:目标不同

维度

BOLL通道

Aberration策略

主要目的

衡量价格波动区间和超买超卖

捕捉趋势延续或反转的交易信号

设计者

约翰·布林格(John Bollinger)

凯文·戴维(Kevin Davey)

理论背景

统计学标准差

统计学+趋势跟踪+均值回归


2. 使用逻辑差异

(1) BOLL通道的典型用法

  • 超买超卖判断:价格触及上轨可能卖出,触及下轨可能买入。

  • 均值回归:假设价格会回归中轨(20日均线),适合震荡市。

  • 无明确规则:布林带本身是工具,不提供具体交易信号。

(2) Aberration的策略化改进

  • 趋势跟踪:突破上轨后顺势做多(非反向做空),下破下轨后顺势做空

  • 动态止损:以中轨作为移动止损点,而非直接反向操作。

  • 波动率过滤:仅当通道宽度(标准差)扩大时交易,避免低波动假突破。



3. 关键增强点(Aberration的优化)

改进项

BOLL通道

Aberration策略

突破方向

逆势操作(回归中轨)

顺势操作(趋势延续)

波动率控制

必须满足通道宽度阈值

止损规则

无固定规则

中轨动态止损+时间止损

参数敏感性

默认20日均线+2倍标准差

需优化周期/倍数适应不同品种

接下来让Ai帮我们编写到松鼠Quant回测框架内,我们不需要写一行代码!!!

github地址(国外):

https://github.com/songshuquant/ssquant-ai

gitee地址(国内):

https://gitee.com/ssquant/ssquant-ai

如何使用,手把手教程:《gitee官方推荐,松鼠QuantAi+回测框架详细版教程(图文)
Python源码:





























































































































import pandas as pdimport numpy as npfrom ssquant.backtest.multi_source_backtest import MultiSourceBacktesterfrom ssquant.api.strategy_api import StrategyAPIdef initialize(api: StrategyAPI):    api.log("Aberration策略初始化")    # 设置策略参数    api.log(f"布林带周期: {api.get_param('bb_period', 20)}")    api.log(f"布林带标准差倍数: {api.get_param('bb_std', 2)}")    api.log(f"ATR周期: {api.get_param('atr_period', 14)}")    api.log(f"ATR倍数止损: {api.get_param('atr_multiplier', 2)}")def strategy_function(api: StrategyAPI):    # 获取参数    bb_period = api.get_param('bb_period', 20)    bb_std = api.get_param('bb_std', 2)    atr_period = api.get_param('atr_period', 14)    atr_multiplier = api.get_param('atr_multiplier', 2)    current_idx = api.get_idx()        # 数据验证    if current_idx < max(bb_period, atr_period):        return        close = api.get_close()    high = api.get_high()    low = api.get_low()        if close is None or len(close) == 0:        api.log("警告: 数据为空")        return        # 计算布林带指标    ma = close.rolling(bb_period).mean()    std = close.rolling(bb_period).std()    upper_band = ma + bb_std * std    lower_band = ma - bb_std * std        # 计算ATR指标    tr = pd.DataFrame({        'hl': high - low,        'hc': abs(high - close.shift(1)),        'lc': abs(low - close.shift(1))    }).max(axis=1)    atr = tr.rolling(atr_period).mean()        # 获取当前价格和仓位    current_price = close.iloc[current_idx]    current_pos = api.get_pos()        # 交易逻辑    # 做多信号:价格突破上轨    if current_price > upper_band.iloc[current_idx]:        if current_pos <= 0:            api.close_all(order_type='next_bar_open')            api.buy(volume=1, order_type='next_bar_open')            api.log(f"做多信号触发,价格{current_price:.2f}突破上轨{upper_band.iloc[current_idx]:.2f}")            # 设置止损            stop_loss_price = current_price - atr.iloc[current_idx] * atr_multiplier            api.log(f"设置止损价: {stop_loss_price:.2f}")        # 做空信号:价格跌破下轨    elif current_price < lower_band.iloc[current_idx]:        if current_pos >= 0:            api.close_all(order_type='next_bar_open')            api.sellshort(volume=1, order_type='next_bar_open')            api.log(f"做空信号触发,价格{current_price:.2f}跌破下轨{lower_band.iloc[current_idx]:.2f}")            # 设置止损            stop_loss_price = current_price + atr.iloc[current_idx] * atr_multiplier            api.log(f"设置止损价: {stop_loss_price:.2f}")        # 平仓信号:价格回归中轨    elif (current_pos > 0 and current_price < ma.iloc[current_idx]) or \         (current_pos < 0 and current_price > ma.iloc[current_idx]):        api.close_all(order_type='next_bar_open')        api.log(f"平仓信号触发,价格{current_price:.2f}回归中轨{ma.iloc[current_idx]:.2f}")if __name__ == "__main__":    # 导入API认证信息    try:        from ssquant.config.auth_config import get_api_auth        API_USERNAME, API_PASSWORD = get_api_auth()    except ImportError:        print("警告:未找到 auth_config.py 文件,请在下方填写您的认证信息:API_USERNAME和API_PASSWORD")        API_USERNAME = ""        API_PASSWORD = ""    # 创建多数据源回测器    backtester = MultiSourceBacktester()        # 设置基础配置    backtester.set_base_config({        'username': API_USERNAME,       # 使用配置文件中的用户名        'password': API_PASSWORD,       # 使用配置文件中的密码        'use_cache': True,              # 是否使用缓存数据        'save_data': True,              # 是否保存数据        'align_data': False,            # 是否对齐数据        'fill_method': 'ffill',         # 填充方法        'debug': True                   # 启用调试模式    })        # 修改点:将品种从rb888改为au888,并调整合约参数    backtester.add_symbol_config(        symbol='au888',   # 黄金期货主力合约        config={               'start_date': '2024-01-01',      # 回测开始日期            'end_date': '2025-12-31',        # 回测结束日期            'initial_capital': 100000.0,     # 初始资金(黄金价格较高,保持10万)            'commission': 0.0002,            # 黄金手续费率较低(万分之二)            'margin_rate': 0.08,             # 黄金保证金率8%            'contract_multiplier': 1000,     # 黄金期货每点1000元            'periods': [                                     {'kline_period': '1d', 'adjust_type': '1'},   # 日线数据            ]        }    )        # 运行回测(保持原参数)    results = backtester.run(        strategy=strategy_function,        initialize=initialize,        strategy_params={            'bb_period': 20,     # 布林带周期            'bb_std': 2,         # 布林带标准差倍数            'atr_period': 14,    # ATR周期            'atr_multiplier': 2   # ATR倍数止损        },    )
回测绩效
图片
图片
图片
没错,整个开发过程我们没有手写一行代码,松鼠QuantAi助手会编写,回测,分析,修改。基于松鼠Quant的MCP服务器+Deepseek开启全新量化学习的路径,即使0基础也能完成策略的编写与验证!
如果你喜欢这个系列,请点赞,转发,在看三连。我们根据受欢迎程度决定是否继续更新,感谢您的支持。

防迷路


           图片

微   信|小松鼠-松鼠Quant

微信号|viquant01

25俱乐部源码VIP20》

加入2025量化俱乐部



分享