칼레드 타미
이 전략의 핵심은 다음과 같은 단계를 통해 제안 및 요청 가격을 계산하는 Avellaneda-Stoikov 모델입니다.
칼레드 타미
/*backtest start: 2024-03-01 00:00:00 end: 2024-03-31 23:59:59 period: 4h basePeriod: 15m exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}] */ //@version=5 strategy("Khaled Tamim's Avellaneda-Stoikov Strategy", overlay=true) // Avellaneda-Stoikov model logic avellanedaStoikov(src, gamma, sigma, T, k, M) => midPrice = (src + src[1]) / 2 sqrtTerm = gamma * sigma * sigma * T // Add 0.1% fee to bid and ask quotes fee = 0 // 0.1% fee bidQuote = midPrice - k * sqrtTerm - (midPrice * fee) askQuote = midPrice + k * sqrtTerm + (midPrice * fee) longCondition = src < bidQuote - M shortCondition = src > askQuote + M [bidQuote, askQuote] // Define strategy parameters gamma = input.float(2, title="Gamma") sigma = input.float(8, title="Sigma") T = input.float(0.0833, title="T") k = input.float(5, title="k") M = input.float(0.5, title="M") // Calculate signals [bidQuote, askQuote] = avellanedaStoikov(close, gamma, sigma, T, k, M) longCondition = close < bidQuote - M shortCondition = close > askQuote + M // Plot signals plotshape(series=longCondition ? low : na, title="Buy Signal", location=location.belowbar, color=color.green, style=shape.labelup, text="BUY") plotshape(series=shortCondition ? high : na, title="Sell Signal", location=location.abovebar, color=color.red, style=shape.labeldown, text="SELL") // Plot bid and ask prices plot(bidQuote, title="Bid Price", color=color.blue, linewidth=1) plot(askQuote, title="Ask Price", color=color.red, linewidth=1) // Plot inventory level as bars in a separate graph plot(strategy.netprofit, title="Inventory", color=color.new(color.purple, 80), style=plot.style_columns) // Strategy logic if (longCondition) strategy.entry("Buy", strategy.long) if (shortCondition) strategy.entry("Sell", strategy.short)