Khaled Tamim’s Avellaneda-Stoikov Strategy is a quantitative trading strategy based on the Avellaneda-Stoikov model. The strategy determines buy and sell signals by calculating the mid-price, bid price, and ask price while considering transaction costs. The main idea of the strategy is to buy when the price is below the bid price by a certain threshold and sell when the price is above the ask price by a certain threshold, thereby capturing the spread profit.
The core of this strategy is the Avellaneda-Stoikov model, which calculates the bid and ask prices through the following steps:
Khaled Tamim’s Avellaneda-Stoikov Strategy is a quantitative trading strategy based on the classic market-making model. It generates trading signals by calculating bid and ask prices while considering transaction costs. The strategy’s advantages lie in its solid theoretical foundation, clear logic, and consideration of transaction costs. However, the strategy’s performance depends on parameter selection and requires high execution efficiency. In the future, the strategy can be further optimized by introducing machine learning algorithms, optimizing trade execution, introducing risk management, and other methods.
/*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)