A comprehensive guide to Avellaneda & Stoikov’s market-making strategy

hummingbot
Hummingbot Blog
Published in
5 min readApr 26, 2021

This blog was originally posted on the Hummingbot blog on April 13, 2021.

A brand new strategy arrived with the latest Hummingbot release (0.38). It is fascinating for us because it is the first Hummingbot configuration based on classic academic papers that model optimal market-making strategies.

A brief explanation about the model proposal

In their introduction, Avellaneda & Stoikov talked about a market maker’s two main concerns:

  • Dealing with inventory risk
  • Finding the optimal bid and ask spreads.

After going through some mathematical modeling, they arrive at two formulas that help market makers solve these problems.

Reservation price

Optimal bid & ask spread

Where,

  • s = current market mid price
  • q = quantity of assets in inventory of base asset (could be positive/negative for long/short positions)
  • σ = market volatility
  • T = closing time, when the measurement period ends (conveniently normalized to 1)
  • t = current time (T is normalized = 1, so t is a time fraction)
  • δa, δb = bid/ask spread, symmetrical → δa=δb
  • γ = inventory risk aversion parameter
  • κ = order book liquidity parameter

If you don’t know what any of this means, don’t worry. This article will simplify what each of these formulas and values means.

But if you are looking for more information about how everything works backstage, stay tuned because we will also publish another article with more technical details.

What is the reservation price?

The basic strategy for market making is to create symmetrical bid and ask orders around the market mid-price.

But this kind of approach, depending on the market situation, might lead to the market maker inventory skewing in one direction, putting the trader in a wrong position as the asset value moves against him.

Avellaneda & Stoikov approach the inventory risk problem by calculating a new reference price where the buy and sell orders will be created around, based on three main factors:

Reservation price

I. How distant is the trader’s current inventory position is from the target position? (q)

The value of q on the formula measures how many units the market maker inventory is from the desired target.

On Hummingbot, the value of q is calculated based on the target inventory percentage you are aiming for.

II. How much inventory risk does the trader want to take? (γ)

This parameter is a value that must be defined by the market maker, considering how much inventory risk he is willing to be exposed.

On Hummingbot, you can set the value of γ by yourself or let the bot calculate in an automated way.

III. Time until the trading session ends (T-t)

The model was created before Satoshi Nakamoto mined the first Bitcoin block, before the creation of trading markets that are open 24/7.

That way, Avellaneda & Stoikov added the trading session terminal time (T). To put it simply, as the trading session is nearing the end, the reservation price will approach the market mid-price, reducing the risk of holding the inventory too far from the desired target.

On Hummingbot, you can define (in days or fraction of a day) how long the “trading sessions” will take.

Note: Avellaneda & Stoikov also considers a model where the trading session has an infinite horizon. We agree that this infinite horizon model would make more sense for cryptocurrency markets, and we plan to add it to a future release.

You might have noticed that I haven’t added volatility(σ) on the main factor list, even though it is part of the formula. That is because volatility value depends on the market price movement, and it isn’t a factor defined by the market maker. If the market volatility increases, the distance between reservation price and market mid-price will also increase.

What is the optimal spread?

The second part of the model is about finding the optimal position the market maker orders should be on the order book to increase profitability.

Optimal Spread

As you can see on the second formula, two of the factors incorporated on the reservation price formula (γ and (T-t)) also appears in the calculation of the best total spread (δa + δb), and a new factor is incorporated:

What is the order book liquidity/density (κ)

There is a lot of mathematical detail on the paper explaining how they arrive at this factor by assuming exponential arrival rates. There are many different models around with varying methodologies on how to calculate the value.

But for now, it is essential to know that using a significant κ value, you are assuming that the order book is denser, and your optimal spread will have to be smaller since there is more competition on the market.

On the other hand, using a smaller κ, you are assuming the order book has low liquidity, and you can use a more extensive spread.

Combining reservation price and optimal spread

Here is where the magic happens. The execution logic of the model is pretty simple:

  1. Calculate the reservation price based on what is the target inventory
  2. Calculate the optimal bid and ask spread
  3. Create market orders using the reservation price as reference:
  • Bid offer price = reservation price — optimal spread / 2
  • Ask offer price = reservation price + optimal spread / 2

Calculating the parameters input

Going back a bit on this article, you will remember that we mentioned that there are three main factors the Avellaneda-Stoikov model uses to calculate the reservation price and the optimal spread:

  1. Inventory position (q)
  2. Time until the trading session ends (T-t)
  3. Risk factor (γ)
  4. Order book depth (κ)

For each input above, list the associated parameter name in the Avellaneda strategy. 1 and 2 are pretty straight forward while 3 and 4 are a bit… complicated.

After setting up the strategy, here are a few other new configurations you can change on the bot:

closing_time - Here, you set (in days) how long each “trading session” will take. This affects the (T-t) parameter we mentioned earlier.

volatility_buffer_size - This indicates to hummingbot how many seconds will be used to populate the data to calculate market volatility. It is important to note that before the bot starts to create orders, it will take this many seconds to store the price data needed for the calculation.

To know more detailed information about the Avellaneda-Stoikov strategy and how to set it up, you can read the full blog here.

Learn More

--

--

hummingbot
Hummingbot Blog

hummingbot, an #opensource #crypto #marketmakingbot. Decentralize #marketmaking: hummingbot.io