# Avellaneda & Stoikov’s market-making strategy AS模型的通俗理解篇（一）

AS是经典的做市模型，最主要就是为了控制库存风险。一般来说在震荡行情中，很适合做市，特别是波动率不高情况下，我们通过AS的经典论文得到2个最关键公式，下面来解读一下这个公式的含义，如何在hummingbot 策略中如何设置这些参数。

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

A brief explanation about the model proposal
In their introduction, Avellaneda & Stoikov talk about a market maker’s two main concerns:
Dealing with inventory risk
After going through some mathematical modeling, they arrive at two formulas that help market makers solve these problems.

1、库存风险 （也就是单边的行情，你持有很多仓位，下场比较惨兮兮）
2、找到最优的买入价格、卖出价格。

Reservation price:（预定价格）

Where,
s = current market mid price （中间价，也就是【最佳卖价+最佳买价】/2）
q = quantity of assets in inventory of base asset (也就是买入多少价值的股票数量)
σ = market volatility （市场波动率，可以用std标准差来表示）
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)
t是当前时间，T是结束时间，如果是操盘连续合约，那么T可以设置为无穷大。

γ = inventory risk aversion parameter 这个翻译过来就是 规避库存风险的参数，当他取值很大的时候，我们按照公式一计算的预定价格就和中间价差距就远。
κ = order book liquidity parameter 这个是一个评估订单本，订单密度参数。也就是K值越大，参与买卖的人比较多，出价也比较均衡，订单量也比较大。

What is the reservation price?
The basic strategy for market making is to create symmetrical bid and ask orders around the market mid-price. 一般策略就是围绕中间价进行报价，比如卖价 midprice +σ;买入价 midprice -σ

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.

For example, if the BTC-USDT market price enters a downtrend and the trader uses the symmetrical approach, his buy orders will be filled more often than the sell orders. At the end of the day, the market maker will be loaded with BTC, and his total inventory will have a smaller value.看看下面的btc震荡下跌图，如果你采用类似固定值网格操盘法，你就收到一堆btc存货，而且btc价格不断走低，你也亏了不少。

AS通过3个fator来规避这种存货风险：

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

When q<0, the trader is short on the asset, and the reservation price will be higher than market mid-price, increasing the chance of a buy order is filled; 也就是q小于目标值了，就要提高预定值，这样买单执行概率增大。

When q > 0, the trader is long on the asset, and the reservation price will be lower than market mid-price, increasing the chance of a sell order is filled;也就是q大于目标值了，就要降低预定值，这样卖单执行概率增大。

How much inventory risk does the trader wants to take? (γ)这一段比较简单，你设置γ越大，公式一后面部分成绩就大，然后和midprice偏离就大。如果设置很小就很靠近midprice.
This parameter is a value that must be defined by the market maker, considering how γ inventory risk he is willing to be exposed.

If γ value is close to zero, the reservation price will be very close to the market mid-price. Therefore, the trader will have the same risk as if he was using the symmetrical price strategy.设置为0，就是固定网格值的网格策略，虽然盈利概率99.5%，但最后一次就是让你送命。

Time until the trading session ends (T-t)，也就是交易持续的时间

The agent’s objective is to maximize the expected exponential utility of his P&L proﬁle at a terminal time T.

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.

THE END