Skip to content

Technical Deep Dive into the Avellaneda & Stoikov Strategy

cover

In our previous blog post, we introduced the new avellaneda_market_making strategy. This time, we delve deeper into the mathematical aspects of this strategy. We aim to explain how we adapted the original Avellaneda-Stoikov model for the cryptocurrency market and simplified the calculation of key parameters, known as greeks.

This article mathematically substantiates the assumptions and calculations that made the authors' model more suitable for Hummingbot traders.

Original Model and Our Proposed Extensions

Let's start by revisiting the core equations from the Avellaneda-Stoikov paper:

Original Model

Reservation price (market price, adjusted toward your target inventory level):

r(s,q,t,σ)=sqγσ2(Tt)
kerf={gG:f(g)=eH}.

Optimal spread around reservation price:

δa+δb=γσ2(Tt)+2γln(1+γκ)

Where:

  • s [quote asset] = current mid price
  • q [no unit] = quantity of stocks in inventory of base asset (could be positive/negative for long/short positions)
  • γ [1/quote asset] = inventory risk aversion parameter
  • σ [quote asset] = volatility
  • T [no unit] = closing time (conveniently normalized to 1)
  • t [no unit] = current time (T is normalized = 1, so t is a time fraction)
  • δa,δb [quote asset]= Bid/Ask spread (they are symmetrical to reservation price → δa=δb)
  • κ [1/quote asset]= Order book liquidity parameter

Proposed Extensions

The paper's model is predicated on assumptions that may not align well with the needs of a crypto trader. To address this, we propose several modifications:

  1. Hummingbot allows traders to specify the order amount, so we introduce order_amount_shape_factor (η), as described in the 2018 Optimal High-Frequency Market Making paper.
  2. Given the rapid volatility changes in crypto, we suggest a volatility threshold that triggers a recalculation of strategy parameters vol_to_spread_multiplier.
  3. Recalculation as mentioned in point 2.
  4. Considering that bots may run indefinitely, we propose a finite closing_time (T) with a recurring time fraction t, alongside parameter recalibration every time t=T.

Calculation of γ, κ and η

Introduction

The original Avellaneda equations offer multiple variables. To establish constraints, we focus on the bid/ask spread to mid-price as a primary value for our bots. Additionally, γ serves as a risk aversion parameter to inventory risk, so we seek a knob parameter to manage this factor while adhering to user-defined spread parameters.

Calculation of γ

Assuming users have set min_spread and max_spread, we calculate the maximum possible risk factor (γ) based on these spreads:

Case where q>0 (inventory ratio should be decreased)

To comply with user-defined spreads:

Spread optimal_askt=0Min Spread
Spread optimal_bidt=0Max Spread

From this, we derive:

(12q)γσ2+12ln(1+γκ)Min Spread
(12+q)γσ2+12ln(1+γκ)Max Spread

Combining these inequalities:

2qγσ2Max SpreadMin Spread

Case where q<0 (inventory ratio should be increased)

For q<0:

2qγσ2Max SpreadMin Spread

Both cases lead to the inequality:

γMax SpreadMin Spread2qσ2=γmax

Setting inventory_risk_aversion (IRA) as a coefficient between 0 and 1, we define γ as:

γ=γmaxIRA=Max SpreadMin Spread2qσ2IRA

Calculation of κ

We select order_book_depth_factor (κ) to start with the maximum possible spread at t=0. This decision is to traverse a broader range of spreads for maximum profitability. The calculation is:

spreadt=0=δa+δb2±Δ
(δa+δb)max=(2IRA)Max Spread+IRAMin Spread

Final equation for κ:

κ((δa+δb)t=0)=γexp{(δa+δb)t=0γσ2γ22}1

Calculation of η

order_amount_shape_factor (η) modifies order size based on the distance from the target inventory q. Using inventory_risk_aversion (IRA), we determine:

qdecay=Totalinventoryinbase_assetIRAη=1qdecay

IRA0γ0

When IRA0 (equivalent to γ0), the reservation price becomes symmetrical to the mid-price, with final spread values determined by:

IRA0γ0t=0(Tt)=1limγ0r(s,q,t=0,σ)=slimγ0δa+δb(q,t=0,σ)=2κ

Thus, if γ0, the spread around r = mid_price will be fixed:

r=sIf γ0IRA0 (δa+δb)=2Max Spread

In this scenario, pure market making strategy is a special case of the Avellaneda market making strategy.

References

High-frequency trading in a limit order book (Avellaneda and Stoikov, 2006)

Optimal High-Frequency Market Making (Fushimi, Gonzalez Rojas and Herman, 2018)

Was this page helpful?