Khaled Tamim的Avellaneda-Stoikov策略是一种基于Avellaneda-Stoikov模型的量化交易策略。该策略通过计算中间价、买入价和卖出价,同时考虑交易费用,来确定买入和卖出信号。策略的主要思路是在价格低于买入价一定阈值时买入,在价格高于卖出价一定阈值时卖出,以此来获取价差收益。
该策略的核心是Avellaneda-Stoikov模型,通过以下步骤来计算买入价和卖出价: 1. 计算中间价,即当前价格与前一个价格的平均值。 2. 计算买入价,即中间价减去一个包含Gamma、Sigma、T和k的平方根项,再减去交易费用。 3. 计算卖出价,即中间价加上一个包含Gamma、Sigma、T和k的平方根项,再加上交易费用。 4. 当价格低于买入价减去阈值M时,产生买入信号;当价格高于卖出价加上阈值M时,产生卖出信号。
Khaled Tamim的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)