该策略采用了一种混合的量化分析方法,结合了二项分布模型和回归分析,以识别不同的市场状态。策略首先计算简单移动平均线(SMA)和布林带(BB)指标,然后基于历史回报的均值和标准差计算Z评分。当Z评分低于下阈值且价格低于下轨时,策略开仓做多;当Z评分高于上阈值且价格高于上轨时,策略平仓。
该策略的核心原理是利用Z评分来衡量当前回报相对于历史回报分布的位置。Z评分的计算公式为:(当前回报 - 历史回报均值) / 历史回报标准差。Z评分越高,表示当前回报越极端,超买可能性越大;Z评分越低,表示当前回报越极端,超卖可能性越大。同时,策略还结合了布林带指标,以价格突破上下轨作为二次确认。只有在Z评分和布林带信号同时满足条件时,策略才会产生交易信号。这种组合方式可以有效降低假信号的出现。
混合双态Z评分量化策略是一个基于统计学原理的量化交易策略,通过比较当前回报与历史回报分布,识别潜在的超买超卖机会。同时,策略采用布林带指标进行二次确认,提高信号可靠性。策略规则明确,易于实现和优化,但同时也面临参数敏感、趋势风险、过拟合风险等挑战。未来可以从动态参数、趋势过滤、组合优化、止损止盈等方面对策略进行优化,以提升其适应性和稳健性。总的来说,该策略为量化交易提供了一种简单而有效的思路,值得进一步探索和改进。
/*backtest
start: 2023-05-22 00:00:00
end: 2024-05-27 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("Estratégia Híbrida Quantitativa", overlay=true)
// Definição de parâmetros
sma_length = input.int(20, title="Período da SMA")
threshold_high = input.float(1.5, title="Threshold Alto")
threshold_low = input.float(-1.5, title="Threshold Baixo")
lookback_period = input.int(252, title="Período de Retorno Histórico (dias)")
// Funções auxiliares
f_sma(source, length) =>
ta.sma(source, length)
f_bollinger_band(source, length, mult) =>
basis = ta.sma(source, length)
dev = mult * ta.stdev(source, length)
[basis + dev, basis - dev]
// Cálculo dos indicadores
sma = f_sma(close, sma_length)
[upper_band, lower_band] = f_bollinger_band(close, sma_length, 2)
// Regime de Mercado: Binomial
retornos = ta.change(close, 1)
media_retornos = ta.sma(retornos, lookback_period)
desvio_padrao_retornos = ta.stdev(retornos, lookback_period)
// Indicador de Regime: Z-Score
z_score = (retornos - media_retornos) / desvio_padrao_retornos
// Sinal de Compra e Venda
sinal_compra = z_score < threshold_low and close < lower_band
sinal_venda = z_score > threshold_high and close > upper_band
// Execução de Ordem
if (sinal_compra)
strategy.entry("Long", strategy.long)
if (sinal_venda)
strategy.close("Long")
// Plotagem dos Indicadores
plot(sma, title="SMA", color=color.blue)
plot(upper_band, title="Upper Bollinger Band", color=color.red)
plot(lower_band, title="Lower Bollinger Band", color=color.green)
hline(threshold_high, "Threshold Alto", color=color.red, linestyle=hline.style_dashed)
hline(threshold_low, "Threshold Baixo", color=color.green, linestyle=hline.style_dashed)
plot(z_score, title="Z-Score", color=color.purple)