双机会反转量化策略


创建日期: 2023-11-14 13:42:47 最后修改: 2023-11-14 13:42:47
复制: 0 点击次数: 676
avatar of ChaoZhang ChaoZhang
1
关注
1617
关注者

双机会反转量化策略

概述

双机会反转量化策略是一种综合运用123反转和Stochastic RSI两种策略思路的组合策略。该策略首先判断价格是否出现了123反转形态,然后结合Stochastic RSI指标再次确认反转信号,只有当两者同时发出信号时,才会开仓做多或做空。这种双重确认机制可以有效过滤误报信号,提高策略的稳定性。

策略原理

该策略由两部分组成:

  1. 123反转

该部分运用123形态来判断价格反转。具体逻辑是:

  • 如果收盘价低于昨日收盘价,且当前收盘价高于昨日收盘价,同时9日Slow Stochastic低于50,则做多

  • 如果收盘价高于昨日收盘价,且当前收盘价低于昨日收盘价,同时9日Fast Stochastic高于50,则做空

这样可以发现价格反转的早期信号。

  1. Stochastic RSI

该部分使用Stochastic指标对RSI进行再次分析,判断反转确认:

  • 计算RSI的值,长度为14

  • 对RSI应用Stochastic分析,长度14,获得K值

  • 计算K值的3日SMA D值

  • 如果K值超过80则看多,K值低于20则看空

只有当两部分策略同时发出信号时,才会开仓。

优势分析

该策略最大的优势是采用了双重确认的思路,可以有效过滤误报信号,提高稳定性。具体优势如下:

  1. 123反转可以较早判断价格反转趋势

  2. Stochastic RSI提供反转确认,避免错过反转点

  3. 两者结合可以提高胜率,降低误报概率

  4. 采用参数组合优化,可以针对不同市场调整参数

  5. 程序化实现简单清晰,易于实盘应用

风险分析

该策略也存在一些风险需要注意:

  1. 反转失败风险。市场可能出现假反转,导致亏损。

  2. 参数优化风险。不合适的参数组合可能导致策略效果不佳。

  3. 过优化风险。针对历史数据过度优化参数,而未来效果无法复制。

  4. 交易频率过高风险。双重信号可能增加交易频率,导致滑点成本升高。

  5. 代码实现风险。代码存在错漏可能导致实盘效果异常。

对应解决方法:

  1. 适当调整仓位规模,控制单笔亏损。

  2. 采用walk-forward方法进行参数优化。

  3. 注重参数稳定性,不追求过高收益。

  4. 适当调整开仓条件,降低交易频率。

  5. 仔细测试代码,确保逻辑正确。

优化方向

该策略可以从以下方面进行优化:

  1. 优化参数。可以调整Stochastic等参数,针对具体市场进行优化。

  2. 优化开仓条件。可以增加其他因子判断,避免冲动反转。

  3. 优化止损机制。可以设定移动止损、时间止损等方式。

  4. 降低交易频率。可增加交易过滤条件,降低交易频率。

  5. 增加仓位管理。根据市场情况调整仓位大小。

  6. 考虑手续费因素。根据实际手续费调整策略参数。

总结

双机会反转量化策略总体来说是一个稳定、实用的短线反转策略。它同时兼具捕捉反转的灵敏度以及双重过滤的稳定性。通过参数优化和适当修改,该策略可以成为量化策略体系中的一个有效组成部分。但我们也要注意防范过优化和误报风险,保持参数稳定性,在实盘中审慎验证。

策略源码
/*backtest
start: 2023-10-14 00:00:00
end: 2023-11-13 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=4
////////////////////////////////////////////////////////////
//  Copyright by HPotter v1.0 03/08/2021
// This is combo strategies for get a cumulative signal. 
//
// First strategy
// This System was created from the Book "How I Tripled My Money In The 
// Futures Market" by Ulf Jensen, Page 183. This is reverse type of strategies.
// The strategy buys at market, if close price is higher than the previous close 
// during 2 days and the meaning of 9-days Stochastic Slow Oscillator is lower than 50. 
// The strategy sells at market, if close price is lower than the previous close price 
// during 2 days and the meaning of 9-days Stochastic Fast Oscillator is higher than 50.
//
// Second strategy
// This strategy used to calculate the Stochastic RSI
//
// WARNING:
// - For purpose educate only
// - This script to change bars colors.
////////////////////////////////////////////////////////////
Reversal123(Length, KSmoothing, DLength, Level) =>
    vFast = sma(stoch(close, high, low, Length), KSmoothing) 
    vSlow = sma(vFast, DLength)
    pos = 0.0
    pos := iff(close[2] < close[1] and close > close[1] and vFast < vSlow and vFast > Level, 1,
	         iff(close[2] > close[1] and close < close[1] and vFast > vSlow and vFast < Level, -1, nz(pos[1], 0))) 
	pos


SRSI(lengthRSI,lengthStoch,smoothK,smoothD, TopBand,LowBand) =>
    pos = 0.0
    Source = close
    rsi1 = rsi(Source, lengthRSI)
    k = sma(stoch(rsi1, rsi1, rsi1, lengthStoch), smoothK)
    d = sma(k, smoothD)
    d_cross_80 = cross(d,TopBand) 
    pos := iff(k > TopBand, 1,
              iff(k < LowBand, -1, nz(pos[1], 0))) 
    pos

strategy(title="Combo Backtest 123 Reversal & Stochastic RSI", shorttitle="Combo", overlay = true)
line1 = input(true, "---- 123 Reversal ----")
Length = input(14, minval=1)
KSmoothing = input(1, minval=1)
DLength = input(3, minval=1)
Level = input(50, minval=1)
//-------------------------
line2 = input(true, "---- Stochastic RSI ----")
TopBand = input(80, step=0.01)
LowBand = input(20, step=0.01)
lengthRSI = input(14, minval=1)
lengthStoch = input(14, minval=1)
smoothK = input(3, minval=1)
smoothD = input(3, minval=1)
reverse = input(false, title="Trade reverse")
posReversal123 = Reversal123(Length, KSmoothing, DLength, Level)
posSRSI = SRSI(lengthRSI,lengthStoch,smoothK,smoothD, TopBand,LowBand)
pos = iff(posReversal123 == 1 and posSRSI == 1 , 1,
	   iff(posReversal123 == -1 and posSRSI == -1, -1, 0)) 
possig = iff(reverse and pos == 1, -1,
          iff(reverse and pos == -1 , 1, pos))	   
if (possig == 1 ) 
    strategy.entry("Long", strategy.long)
if (possig == -1 )
    strategy.entry("Short", strategy.short)	 
if (possig == 0) 
    strategy.close_all()
barcolor(possig == -1 ? #b50404: possig == 1 ? #079605 : #0536b3 )