Technical Deep Dive into the Avellaneda & Stoikov Strategy¶
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):
Optimal spread around reservation price:
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)
- \(\gamma\) [1/quote asset] = inventory risk aversion parameter
- \(\sigma\) [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)
- \(\delta^{a}, \delta^{b}\) [quote asset]= Bid/Ask spread (they are symmetrical to reservation price → \(\delta^{a}=\delta^{b}\))
- \(\kappa\) [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:
- Hummingbot allows traders to specify the order amount, so we introduce
order_amount_shape_factor
(\(\eta\)), as described in the 2018 Optimal High-Frequency Market Making paper. - Given the rapid volatility changes in crypto, we suggest a volatility threshold that triggers a recalculation of strategy parameters
vol_to_spread_multiplier
. - Recalculation as mentioned in point 2.
- 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 \(\gamma\), \(\kappa\) and \(\eta\)¶
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, \(\gamma\) 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 \(\gamma\)¶
Assuming users have set min_spread
and max_spread
, we calculate the maximum possible risk factor (\(\gamma\)) based on these spreads:
Case where q>0 (inventory ratio should be decreased)¶
To comply with user-defined spreads:
From this, we derive:
Combining these inequalities:
Case where q<0 (inventory ratio should be increased)¶
For q<0:
Both cases lead to the inequality:
Setting inventory_risk_aversion
(IRA) as a coefficient between 0 and 1, we define \(\gamma\) as:
Calculation of \(\kappa\)¶
We select order_book_depth_factor
(\(\kappa\)) 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:
Final equation for \(\kappa\):
Calculation of \(\eta\)¶
order_amount_shape_factor
(\(\eta\)) modifies order size based on the distance from the target inventory q. Using inventory_risk_aversion
(IRA), we determine:
\(IRA \to 0 \implies \gamma \to 0\)¶
When \(IRA \to 0\) (equivalent to \(\gamma \to 0\)), the reservation price becomes symmetrical to the mid-price, with final spread values determined by:
Thus, if \(\gamma \to 0\), the spread around r = mid_price will be fixed:
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)