基于标准化对数收益的自适应动态交易策略

SZI SMA LOG STD
创建日期: 2024-12-27 14:39:32 最后修改: 2024-12-27 14:39:32
复制: 1 点击次数: 163
avatar of ChaoZhang ChaoZhang
1
关注
1264
关注者

基于标准化对数收益的自适应动态交易策略

概述

该策略是一个基于Shiryaev-Zhou指数(SZI)的自适应交易系统。它通过计算对数收益率的标准化得分来识别市场的超买和超卖状态,从而捕捉价格的均值回归机会。策略结合了动态的止损和获利目标,实现风险的精确控制。

策略原理

策略的核心是通过对数收益率的滚动统计特征来构建标准化指标。具体步骤如下: 1. 计算对数收益率,以实现收益率的正态化处理 2. 使用50周期窗口计算滚动均值和标准差 3. 构建SZI指标: (对数收益率-滚动均值)/滚动标准差 4. 当SZI低于-2.0时产生做多信号,高于2.0时产生做空信号 5. 设置基于入场价格的2%止损和4%止盈水平

策略优势

  1. 理论基础扎实:基于对数正态分布假设,具有良好的统计学支持
  2. 自适应性强:通过滚动窗口计算,能够适应市场波动特征的变化
  3. 风险控制完善:采用百分比止损策略,实现对每笔交易风险的精确控制
  4. 可视化友好:在图表上清晰标注交易信号和风险控制水平

策略风险

  1. 参数敏感性:滚动窗口长度和阈值的选择会显著影响策略表现
  2. 市场环境依赖:在趋势市场中可能产生频繁的虚假信号
  3. 滑点影响:在剧烈波动时期,实际成交价格可能显著偏离理想水平
  4. 计算延迟:实时计算统计指标可能产生一定的信号滞后

策略优化方向

  1. 动态阈值:可考虑根据市场波动率动态调整信号阈值
  2. 多时间周期:引入多个时间周期的信号确认机制
  3. 波动率过滤:在极端波动期间暂停交易或调整仓位
  4. 信号确认:增加成交量、动量等辅助指标进行信号确认
  5. 仓位管理:实现基于波动率的动态仓位管理

总结

这是一个建立在扎实统计学基础上的量化交易策略,通过标准化对数收益捕捉价格波动机会。策略的主要优势在于其自适应性和完善的风险控制,但在参数选择和市场环境适应性方面仍有优化空间。通过引入动态阈值和多维度信号确认机制,策略的稳定性和可靠性有望进一步提升。

策略源码
/*backtest
start: 2019-12-23 08:00:00
end: 2024-12-25 08:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=5
strategy("Jalambi Paul model", overlay=true)

// Define the length for the rolling window
window = input.int(50, title="Window Length", minval=1)
threshold = 2.0 // Fixed threshold value
risk_percentage = input.float(1.0, title="Risk Percentage per Trade", step=0.1) / 100

// Calculate the logarithmic returns
log_return = math.log(close / close[1])

// Calculate the rolling mean and standard deviation
rolling_mean = ta.sma(log_return, window)
rolling_std = ta.stdev(log_return, window)

// Calculate the Shiryaev-Zhou Index (SZI)
SZI = (log_return - rolling_mean) / rolling_std

// Generate signals based on the fixed threshold
long_signal = SZI < -threshold
short_signal = SZI > threshold

// Plot the signals on the main chart (overlay on price)
plotshape(series=long_signal, location=location.belowbar, color=color.green, style=shape.labelup, title="Buy Signal", text="BUY", offset=-1)
plotshape(series=short_signal, location=location.abovebar, color=color.red, style=shape.labeldown, title="Sell Signal", text="SELL", offset=-1)

// Strategy logic: Buy when SZI crosses below the negative threshold, Sell when it crosses above the positive threshold
if (long_signal)
    strategy.entry("Buy", strategy.long, comment="Long Entry")
    
if (short_signal)
    strategy.entry("Sell", strategy.short, comment="Short Entry")

// Calculate the stop loss and take profit levels based on the percentage of risk
stop_loss_pct = input.float(2.0, title="Stop Loss (%)") / 100
take_profit_pct = input.float(4.0, title="Take Profit (%)") / 100

// Set the stop loss and take profit levels based on the entry price
strategy.exit("Take Profit / Stop Loss", "Buy", stop=close * (1 - stop_loss_pct), limit=close * (1 + take_profit_pct))
strategy.exit("Take Profit / Stop Loss", "Sell", stop=close * (1 + stop_loss_pct), limit=close * (1 - take_profit_pct))

// Plot the stop loss and take profit levels for visualization (optional)
plot(stop_loss_pct != 0 ? close * (1 - stop_loss_pct) : na, color=color.red, linewidth=1, title="Stop Loss Level")
plot(take_profit_pct != 0 ? close * (1 + take_profit_pct) : na, color=color.green, linewidth=1, title="Take Profit Level")
相关推荐