다항기 회귀를 이용한 양적 트렌드 거래 전략

저자:차오장, 날짜: 2023-09-11 09:04:37
태그:거래양적기술 분석다항식 회귀추세추진력시스템위험 관리최적화견고함

이 양적 거래 시스템은 입시 신호에 대한 잠재적 인 트렌드 반전을 식별하기 위해 다항기 회귀 분석을 사용합니다. 체계적이고 규칙 기반의 방식으로 모멘텀을 활용하는 것을 목표로합니다.

어떻게 작동 합니까?

이 전략은 최근 높은 가격과 낮은 가격에 복소항 회귀선을 맞추고 최근 높은 가격이나 낮은 가격의 회귀 예측을 얼마나 초과하는지 추적합니다.

만약 높은 점 또는 낮은 점의 한계점을 넘어서면, 상승 추세를 나타내는 구매 또는 판매 신호가 생성됩니다. 입력 비율에 따라 정지 및 목표가 설정됩니다.

변동성 각도가 최소를 초과할 때 입장이 입력됩니다. 불안정한 시장을 피하기 위해. 거래는 정의된 위험 매개 변수에 따라 관리됩니다.

장점 과 단점

수학적 분석에 기반한 트렌드 신호를 자동화함으로써 전략은 재량 거래에 객관적인 접근을 제공합니다. 최적화는 성능을 향상시킬 수 있습니다.

그러나 곡선 조정은 과도한 최적화로 이어질 수 있습니다. 모든 기술적 시스템과 마찬가지로 성능은 시장 조건에 크게 달려 있습니다. 신중한 위험 관리를 대체하는 전략은 없습니다.

각기 다른 기간, 자산 클래스 및 시장 환경에서 신중한 테스트는 견고성을 평가하는 데 중요합니다. 어떤 전략도 무분별하지 않으므로 위험을 관리하는 것이 중요합니다.

전체적으로, 양적 전략은 잠재적인 거래를 식별하는 규칙 기반의 방법론을 제공합니다. 수학적 기술과 기술 기술을 혼합하면 타이밍과 위험 캘리브레이션을 향상시킬 수 있습니다.


/*backtest
start: 2023-01-01 00:00:00
end: 2023-09-10 00:00:00
period: 4h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=4
//
// ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ //
//Ultima version underground09

// strategy(title = " underground09",
//          shorttitle = "Under09",
//          overlay = true,
//          precision = 8,
//          calc_on_order_fills = true,
//          calc_on_every_tick = true,
//          backtest_fill_limits_assumption = 0,
//          default_qty_type = strategy.fixed,
//          default_qty_value = 2,
//          initial_capital = 10000,
//          pyramiding=5,
//          currency = currency.USD,
//          linktoseries = true)

//
// ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ //
var sl = 0.0
var tp = 0.0
var acumaldor_vxp = 0.0
var acomuldor_vol = 0.0

//stop_loss = input(defval=0.2, title="Porcentaje Stop Loss", type=input.float, step=0.2)
stop_loss = input(defval=1.4, title="Porcentaje Stop Loss", type=input.float, step=0.2)
//take_profit = input(defval=4.4, title="Porcentaje Take Profit", type=input.float, step=0.2)
take_profit = input(defval=5.6, title="Porcentaje Take Profit", type=input.float, step=0.2)
//pintar_trade = input(defval=false, title="Pintar trade TP SL")
angulo_permitido = input(defval=26.8, title="Angulo permitido", type=input.float, step=0.2)

backTestSectionFrom = input(title = "═══════════════ From ═══════════════", defval = true, type = input.bool)

FromMonth         = input(defval = 1, title = "Month", minval = 1)
FromDay           = input(defval = 1, title = "Day", minval = 1)
FromYear          = input(defval = 2019, title = "Year", minval = 2014)

backTestSectionTo = input(title = "════════════════ To ════════════════", defval = true, type = input.bool)
ToMonth           = input(defval = 31, title = "Month", minval = 1)
ToDay             = input(defval = 12, title = "Day", minval = 1)
ToYear            = input(defval = 9999, title = "Year", minval = 2014)

Config            = input(title = "══════════════ Config ══════════════", defval = true, type = input.bool)
//p = input(6)
p = input(4)
//length = input(30)
length = input(26)
//
backTestPeriod() => (time > timestamp(FromYear, FromMonth, FromDay, 00, 00)) and (time < timestamp(ToYear, ToMonth, ToDay, 23, 59))
//
//
// ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ //

x1 = bar_index
x2 = sqrt(x1)
y = high
//
S11 = sum(x2,length) - sqrt(sum(x1,length)) / length  
S12 = sum(x1*x2,length) - (sum(x1,length) * sum(x2,length)) / length  
S22 = sum(sqrt(x2),length) - sqrt(sum(x2,length)) / length            
Sy1 = sum (y*x1,length) - (sum(y,length) * sum(x1,length)) / length   
Sy2 = sum (y*x2,length) - (sum(y,length) * sum(x2,length)) / length   
//
max1 = sma(x1,length) 
max2 = sma(x2,length)
may = sma(y,length)
b2 = ((Sy1 * S22) - (Sy2*S12))/(S22*S11 - sqrt(S12))
b3 = ((Sy2 * S11) - (Sy1 * S12))/(S22 * S11 - sqrt(S12))
b1 = may - b2*max1 - b3*max2
qr = b1 + b2*x1 + b3*x2
//
yl = low
//
Sy1l = sum(yl*x1,length) - (sum(yl,length) * sum(x1,length)) / length  
Sy2l = sum(yl*x2,length) - (sum(yl,length) * sum(x2,length)) / length  
//
mayl = sma(yl,length)
b2l = ((Sy1l * S22) - (Sy2l*S12))/(S22*S11 - sqrt(S12))
b3l = ((Sy2l * S11) - (Sy1l * S12))/(S22 * S11 - sqrt(S12))
b1l = mayl - b2l*max1 - b3l*max2
qrl = b1l + b2l*x1 + b3l*x2
//
period = round(p/2)+1
hh = qr[period]
ll = qrl[period]
countH = 0
countL = 0
buy=0
sell=0
//
for i = 1 to period-1
    if qr[i]<hh
        countH:=countH+1
    if qrl[i]>ll
        countL:=countL+1

for i = period+1 to p+1
    if qr[i]<hh
        countH:=countH+1
    if qrl[i]>ll
        countL:=countL+1

if countH==p
    pivotH = high[period]
    buy := 1
    
if countL==p
    pivotL = low[period]
    sell := 1
//
Angulo(_serie) =>
    atan( _serie - _serie[1] ) * 180 / acos(-1)
    
//calcular elvwap
vxp = volume*hlc3
//:= signo de acumulador
acumaldor_vxp := acumaldor_vxp + vxp
acomuldor_vol := acomuldor_vol + volume
vwap2 = acumaldor_vxp / acomuldor_vol

pendiente = Angulo(vwap2)

//  

plotshape(buy == 1 , text='⬆️', style=shape.arrowup, location=location.belowbar, color=#32CD32, textcolor=color.white, offset=0, transp=0,size=size.auto)
if buy == 1
    alert("Posible long",alert.freq_all )
    
plotshape(sell == 1 , text='⬇️', style=shape.arrowdown, location=location.abovebar, color=#FF0000, textcolor=color.white, offset=0, transp=0,size=size.auto)
if sell == 1
    alert("Posible short",alert.freq_all )
//

//if (backTestPeriod())
    //strategy.entry("long", true, 1, when = buy == 1)
    //    strategy.entry("short", false, 1, when = sell == 1) 

if buy == 1 and pendiente > angulo_permitido
//if buy == 1    
    cantidad = round(strategy.equity / close ) 
    strategy.entry("long", true, cantidad, comment = "Compra")
    sl := close * ( 1 - (stop_loss/100))
    tp := close * ( 1 + (take_profit/100))

if sell == 1 and pendiente > angulo_permitido
//if sell == 1 
    cantidad = round(strategy.equity / close ) 
    strategy.entry("short", false, cantidad, comment = "Venta")
    sl := close * ( 1 + (stop_loss/100))
    tp := close * ( 1 - (take_profit/100))
    
//Validaciones
comprado = strategy.position_size > 0 //true si es positivo
vendido = strategy.position_size < 0 //true si es negativo

if  comprado
    //Salir sl
    if  close >= tp
        //plotshape(close >= tp, style=shape.xcross)
        strategy.close("long", comment="TP")
        
    //Salir tp
    if  close <= sl
        strategy.close("long", comment="SL")
        
if  vendido
    //Salir sl
    if  close <= tp
        strategy.close("short", comment="TP")
    //Salir tp
    if  close >= sl
        strategy.close("short", comment="SL")

    
//sl tp
plot( sl , color =color.red, style=plot.style_cross)
plot( tp , color= color.green , style=plot.style_circles)

    
//color
//bgcolor (comprado ? color.green: na)
//bgcolor (vendido ? color.red: na)

//if pintar_trade 
    //bgcolor (close >= tp ? color.green : na, transp=80) 
    //bgcolor (close >= sl ? color.red : na, transp=80) 



관련

더 많은