-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
A simple constant product market making method #118
Comments
As the collateral of this Market Protocol contract is in imBTC, let‘s assume that the market maker’s funding pool is also in imBTC. If the initial capital of the market maker is in US dollars, conversion and hedging can be done so that the problem is equivalently reduced to the same market-making problem in imBTC. Define some symbols as follows: PRICE: The price of the contract denominated in imBTC The above definition shows that buyers holding long tokens can receive imBTC at the index price when the contract is settled. So, if the buyer had purchased the tokens at some price lower than the settlement index price, his profit would be: Settlement Index - PRICE. The market maker's goal is to place bid/ask orders around some "market" PRICE, thus providing liquidity while minimizing its risk and exposure to the underlying asset, i.e. the index.
Let INIT FUND be the initial funds of the market marker, e.g 2-5imBTC( about $20k-50k). X = INIT FUND / ( 2 * LONG TOKEN PRICE) = INIT FUND / ( 2 * INIT PRICE)
Let Δx be the ask order size, then (X-Δx)(Y+Δx)=X Y, Let Δx be the bid order size, then (X+Δx)(Y-Δx)=X Y,
When the ask order gets filled, update X' = X - Δx,Y'=Y+Δy Optimization We could artificially enlarge the initial X and initial Y to reduce the slippage. The disadvantage is that the market making depth will become limited. Thus, Let X = p X and Y = p Y. p is a parameter. For example, let p = 10. We could add an additional fixed discount/premium rate to the bid/ask order to increase the make maker's profit and reduce risk: Roll to new contract We can continue to use the X and Y values of the old contract in the new contract. This is because the value of the contract has not changed much in two consecutive days. |
@Jie85 thanks for the write up! I think it makes sense on the high-level, need to clarify some details:
|
I see. Because we use USDT for trading and IMBTC for contract settlement. I have edited the post to change to USDT. I think it has answered questions 1 and 3. My answer to question 2: My answer to question 4: |
(work-in-progress) Choice of bonding curve reserves Real reserves
Operations and their effect on real reserves:
MM daily goals wrt to real reserves:
Virtual Reserves
Daily operations
Throughout the day:
BTC price hedging |
Current Strategy
Note that all the inputs are the latest values at the time of order creation.
Recalculate initX and initY each time when an order is about to be placed with the latest inputs (using uniswap formula only for price shifts from the theoretical price). Formulae Final Outputs where r1 and r2 are preset params for even more offset, r1 and r2 are real numbers. |
Data entries worth keep track of if possible
** a.k.a volume weighted avg price calculation procedure.
Operation Details
|
Although the collateral of this Market Protocol contract is imBTC, the market maker’s funds are all USDT.
Define some symbols as follows:
PRICE
: The price of the contractdenominated in USD
LONG TOKEN PRICE
: The price of the long position token in USD. It should also be equal to the USD value of the IMBTC got by the long position token holder when the contract is settled. Besides, because the Market Protocol contract's price floor is set to 0, PRICE = LONG TOKEN PRICEThe market maker's goal is to place bid/ask orders around some market
PRICE
.First, we calculate the
INIT PRICE
using some model, for example, a model based on FTX hash rate contract. How to calculate theINIT PRICE
is beyond this issue.Second, we calculate the initial
X
(long position reserve) andY
(collateral token reserve) in the constant product formula.Let
INIT FUND
be the initial funds of the market marker, eg $20k-50k.X
=INIT FUND
/ ( 2 *INIT PRICE
)Y
=INIT FUND
/ 2Third, we apply the constant product formula:
X Y= k
, to get the bid/ask order price.Let
Δx
be the ask order size, then(X-Δx)(Y+Δy)=X Y
,ASK PRICE
= Δy/Δx = Y/(x-Δx)Thus the market maker should put an ask order in the order book with order size is Δx and the order price is
ASK PRICE
Let
Δx
be the bid order size, then(X+Δx)(Y-Δy)=X Y
,BID PRICE
= Δy/Δx = Y/(x+Δx)Thus the market maker should put a bid order in the order book with order size is Δx and order price is
BID PRICE
Third, update the X and Y:
Whenever the market maker has both long position tokens and short position tokens, he should redeem the tokens by Market Protocol.
Hedge
When the market maker is the seller, the buyer pays USDT to the market maker and the market maker uses IMBTC to mint Long and Short token. Thus, the market maker needs to convert some USDT to imBTC before minting and the imBTC locked in the Market Protocol is a risk exposure. We could hedge the imBTC risk exposure in a Perpetual or Futures market if needed.
Optimization
We could artificially enlarge the initial X and initial Y to reduce the slippage. The disadvantage is that the market making depth will become limited. Thus, Let
X = p X
andY = p Y
.p
is a parameter. For example, let p = 10.We could add an additional fixed discount/premium
rate
to the bid/ask order to increase the make maker's profit and reduce risk:ASK PRICE
= Δy/Δx = Y/(x-Δx) * (1 +rate
)BID PRICE
= Δy/Δx = Y/(x+Δx) * (1 -rate
)Roll to new contract
We can continue to use the X and Y values of the old contract in the new contract. This is because the value of the contract has not changed much in two consecutive days.
We can also use the Y/X of the previous day to get the
INIT PRICE
of the new day. And recalculate the initialX
andY
based on the remaining available funds of market maker.The text was updated successfully, but these errors were encountered: