Hummingbot’s Avellaneda Strategy on Beaxy

June 16, 2021 | 

Hummingbot’s Avellaneda Strategy on Beaxy

Beaxy Exchange is integrated with Hummingbot, the open-source platform for automated trading. Hummingbot is free to download and gives you access to customizable algorithmic trading strategies that focus on market-making.

In this article, we take a look at Hummingbot’s new strategy that is based on the classic 2008 academic paper authored by Marco Avellaneda and Sasha Stoikov.

Introduction to Hummingbot’s Avellaneda Market Making Strategy

In the introduction of their academic paper, Avellaneda and Stoikov address the two primary factors that will determine your success as a market maker:

  • Assessing inventory risk
  • Determining the optima bid-ask spread for your trading bot

The idea is that optimizing for these two decision points will lead to greater success with algorithmic trading. Avellaneda and Stokoive provided the following formulas that allow market makers to calculate their inventory risk and determine how wide their spreads ought to be.

Reservation price formula:

Hummingbot’s Avellaneda Strategy on Beaxy

Optimal bid-ask spread formula:

Hummingbot’s Avellaneda Strategy on Beaxy


Hummingbot’s Avellaneda Strategy on Beaxy

Don’t worry if you don’t understand these terms yet. We will cover the mechanics of these formulas in the remainder of the article.

Understanding Reservation Price

A general strategy for market makers suggests that bid and ask orders should be placed symmetrically around the current mid-price in the market. Meaning that both bid and ask orders should be placed with an equal distance between them and the mid-price.

But, the primary drawback to placing symmetrical orders is the risk of getting offsides with your inventory. For example, assume that the BTC-USDT market is entering a downward trend. With the symmetrical approach, only the bid orders will be hit as the BTC price continues to drop. This would eventually result in the market maker only having BTC in their inventory. By holding 100% of BTC (which lost value against USDT) and 0% USDT, the market maker is left with less total value relative to USD and also now has no inventory to place on the bid side of the order book.

Avellaneda and Stoikov’s formula introduces the reservation price in place of the mid-price to solve this issue. The reservation price is based on three factors:

Hummingbot’s Avellaneda Strategy on Beaxy

Distance Between the Trader’s Current Inventory Position and the Target Position

In this formula, the distance between the trader’s current inventory and target inventory is expressed as ‘q’.

For instance, assume the trader desires to have a 50-50 inventory between BTC and USDT. The value of q changes every time an order is executed and the inventory shifts.

When the value of q is zero, this means that your inventory already matches your desired inventory. In this case, the reservation price matches the current mid-price.

When q is less than zero, the trader now has less of the base asset, BTC. Here, the reservation price will be moved above the mid-price. This increases the likelihood of a buy versus a sell. Now that you are more likely to buy the base asset, your inventory can move back towards an even 50-50 split between BTC and UDST.

When q is greater than zero, the trader is long on the base asset and needs to move their preference to sell in order for inventory to get back to 50-50. To achieve this, the reservation price will now be lower than the mid-price.

How Much Inventory Risk Will the Trader Take?

In the formula for calculating the reservation price, the symbol “γ” denotes the amount of inventory risk that you, as the trader, are willing to take on. If the value of “γ” is close to zero, the reservation price will be closer to the current mid-price. A near-zero value would be entered if you are willing to take on inventory risk similar to that of a more symmetrical strategy. Conversely, a higher “γ” value will move your reservation price further away from the mid-price.

Time Until the End of the Trading Session

The final segment of the formula that calculates reservation price determines the time until the end of your trading session. This is expressed as (T – 1) in the formula.

To put this simply, the reservation price that we are calculating will converge toward the current mid-price as your predetermined trading session gets closer to completion. On Hummingbot, you can enter this value as a number of days or a fraction of a day.

Understanding the Optimal Spread

The second formula provided by Avellaneda and Stoikov is used to determine the optimal spread for the particular asset that you are trading.

Hummingbot’s Avellaneda Strategy on Beaxy

Order Book Density

The first segment of this formula that we will cover is the order book density. This is also referred to as order liquidity and is expressed as “κ” in the formula for optimal spreads. Order book density or liquidity refers to the amount and size of the orders that are currently placed on an order book. An order book with more orders of larger size has a greater density or more liquidity. On the other hand, an order book with only a few orders of smaller volumes would be less dense.

It’s important to note that using a high “κ” value assumes that the order book is denser or more liquid. In this case, the optimal spread will have to be smaller or tighter due to the increased competition for executions on the order book.

Using a smaller “κ” value will assume that the order book is lacking in liquidity. In this case, your orders can still be executed with a wider spread.

Combining the Reservation Price and Optimal Spread

Now that we’ve examined each formula independently, we can combine to discover just how powerful the Avellaneda strategy from Hummingbot can be.

The steps to combine these formulas are as follows:

  1. Calculate the reservation price based on your target inventory amounts.
  2. Determine the optimal bid and ask spread.
  3. Start sending orders based on the reservation price.Bid orders = reservation price – optimal spread / 2Ask orders = reservation price + optimal spread / 2

You can see this dynamic on the graphic below:

Hummingbot’s Avellaneda Strategy on Beaxy

By viewing the reservation price (green line) and the mid-price (blue line) on the graph shown above, we can see how these two price points converge and diverge as the market conditions change.

You’ll notice that the green reservation price is below the mid-price on the left half of the graph. By considering the formulas offered for reservation price, we can determine that this market marker was holding

too much of the asset it was trading and needed to focus on selling to get back to the desired inventory amount.

We can also see that the ask orders (top orange line) are placed closer to the mid-price as the optimal spread is derived from the reservation price.

The opposite situation is presented on the right side of the graph. Here, the inventory position has shifted and the market maker has less of the asset they are trading needs to move orders up toward mid-price.

Getting Started with Hummingbot

Automated and algorithmic trading has never been easier. Visit Hummingbot to download the free open-source software and follow this guide to have it set up and running on Beaxy in minutes!

To get started on Beaxy, click below and complete the setup for your new trading account. Beaxy’s traders get verified in 5 minutes or less on average.


While you were away, new posts appeared on our blog.