Analysing merging the funding rate of a perpetual contract into x*y = k
Explore the pros and cons of merging the funding rate into the constant product k (of x * y) on a virtual AMM (vAMM).
Outline
0. Intro
1. The implication of x * y = k of a vAMM
2. Merging the funding rate into x * y = k!
3. The pros & cons
4. A slightly different calculation
5. Conclusion
0. Intro
In this article, I assume readers are familiar with perpetual contracts, the funding rate and AMM. Detailed explanations are saved for future ones… perhaps :)
- Perpetual contracts are similar to futures, but with no expiry; instead, a regular settlement schedule called funding rate provides an incentive for traders to come in and balance out the long & short sides.
- Settling the funding payments on exchanges with order books such as FTX, Binance, is quite intuitive: simply adds or removes the payments to or from traders’ balances.
- On an AMM exchange, such as Perpetual Protocol (it is a vAMM, virtual AMM, with no real assets but numbers), however, there is a chance to merge the funding rate into the equation x*y = k, with several pros & cons to be taken into consideration.
Btw, the analysis of this article is merely my personal investigation, and I may be wrong with the conclusion. Feel free to point out my unawareness and leave a comment to discuss it with me, I’d appreciate a lot :)
1. The implication of x * y = k of a vAMM
For those who know Uniswap, this image is more than familiar: the equation x*y = k.
Since x and y stand for the real numbers of two tokens in a pool, modification of the equation x*y = k should only happen when there are indeed changes to the balances of the two tokens, according to this formula(x — Δx) * (y — Δy) = k
vAMM was proposed by Perpetual Protocol: the equation x*y = k is used only for price discovery (how much Δx can get Δy) and no longer stands for the number of real underlying assets.
This leads to the possibility of leverage trading (hence perpetual contracts) on an AMM.
For x
being the (virtual) number of base assets* such as ETH, BTC, and y
being the (virtual) number of quote assets* such as USDC, USDT, by simply multiplying the margin m
a trader pays with the leverage l
a trader wants, we have Δy = l * m
and can know the amount of position/ base asset Δx
we can get with the leveraged margin l * m
.
originally: (x — Δx) * (y — Δy) = kwith leverage trading: l * m = Δynow: (x — Δx) * (y — l * m) = k
In a vAMM approach, it’s okay to play around with the equation x*y = k and modify the three values (x, y, k) to see what changes we can bring to the AMM!
*base asset: the target trading asset
*quote asset: the payment asset
2. Merging the funding rate into x * y = k!
Before we get started, let’s go over the rationale of funding rate again.
There are usually two prices in a perpetual contract market: the trading price & the index price (the average price across various exchanges).
- trading price > index price: positive funding rate/ longs pay shorts
- trading price < index price: negative funding rate/ shorts pay longs
Without further ado, we are ready to get into the fun part: how can we merge the funding rate into the equation x*y = k?
Let’s first look at a case with no funding payment (transaction fee will not be considered throughout the rest of the article):
The original balance of (x, y, k) is (100, 1000, 100000) with the price of x comparing to y being y/x = 1000/100 = 10
. Let’s say x is Bitcoin/BTC and y is USDC (yeah I know that won’t be the price of BTC)
According to (x — Δx) * (y — Δy) = k
, if Alice wants to go long (+) on 10 BTC (Δx = 10), she has to pay 111.111 USDC (Δy). Δy < 0 means payment while Δy > 0 means the balance a trader owes to the AMM.
Later, Bob goes short (-) on 10 BTC (Δx = -10) and he receives 111.111 USDC (Δy) as debt.
As there is no funding payment in the case, if now Bob decides to close his position by returning the 10 BTC (Δx = +10), which is in fact equal to going long, he does not have any profit and loss (PnL). This might sound weird but imagine that in a stock market someone buys a stock and then immediately sells it out: apart from the transaction fee, there is no PnL.
Now, let’s get straight into the solution and I’ll explain it through:
We multiply 1 minus the funding rate r
with the balance of quote asset y
to get y’
and k’
:
originally: x * y = kwith funding rate: (1 - r) * y = y'now: x * y' = (1 - r) * k = k'
There is also another way of achieving this, see 4. A slightly different calculation.
So, what is the impact of the multiplication? Does it really achieve what we wish for: as the funding rate is positive, is the long side really paying to the short side?
We can observe from the above sheet: apart from the change of y
from 1000 to 990 and k
from 100000 to 99000, the only other value changed is the price
of the base asset, from 10 to 9.9, which means the price is lowered.
We all know that the long side earns a profit when the price goes up, and the short side when the price goes down. Now that the price is lowered, the long side pays to the short side! The last two rows of the sheet also show the result: Alice the long side has a loss of -1.11111111 and Bob the short side has a profit of 1.11111111. Voila!
As conventionally a positive funding rate means longs paying shorts, by subtracting 1 by the positive funding rate we can lower the current trading price and thus achieving the effect of funding payments.
However, it’s important to keep in mind that this action is not the realization of PnL but only an adjustment to the price.
Likewise, if there is a negative funding rate, by increasing the price, the short side has to pay to the long side, as the following sheet demonstrates.
3. The pros & cons
So, this is definitely the way to go, right? Let’s first put down the advantages, and then the quite unexpected potential concerns ;)
Pros
- No need to maintain each trader’s PnL caused by funding payments; less gas cost and thus cheaper transaction fee!
- Clean design; sounds convenient and amazing!
Potential Cons
To thoroughly explain the cons, we have to understand how people make $$ with the funding rate. I roughly divide them into two groups: short-term & long-term traders.
- Short-term traders: as the estimated funding rate for the next hour is provided, a trader can get in the market before the funding event and then get out right after it. If the trading price stays still (a strong assumption though) and the transaction fee is low enough, traders can get the funding payment within an extremely short timeframe.
- Long-term traders: Buy a certain amount of spot and then go on the opposite side of the same amount with the perpetual contract: risk-free funding payments! Hear the cha-ching sound hmm?
For those who aren’t familiar with this strategy, let’s look at an example. When there is positive funding rate, by going long on the spot and short on the perpetual contract with the same amount, the price fluctuation is 100% hedged, and we still get the funding payment: since we are on the short side, the long side is paying to us!
Now, what does this have to do with the implementation of the funding rate?
Assume the funding rate is included in the x * y = k as the previous section 2. Merging the funding rate into x * y = k! suggests. For short-term traders, there is barely any difference: they get in, the price changes and they are out with the extra funding payments.
For long-term traders, however, let’s drop the bomb: they may no longer be able to earn risk-free funding payments. Why? As I previous mention: the adjustment to the price is not the realization of PnL.
What does this mean? How does it have to do with the earnings of long-term traders?
Take also the scenario of a positive funding rate as an example. This time, soon after Bob going short and the funding event, Carol comes in to go long.
The result of Carol going long is the rising of the trading price, from 9.9 to 10.308, which is bad news for Bob, as he is going short and the price he’s closing at now is higher.
So, if we extend the above scenario to a longer time span, it’s not hard to imagine that there will always be other traders to come in to trade and move the price
and also the k
. Since the funding event now does not realize the PnL of funding payments immediately, it is not assured that a long-term trader can get his/her expected earnings of funding payments when he/she decides to close the position.
I haven’t yet figured out a more precise way to do this, so let’s settle with the imprecise calculation.
On the spot market, Bob bought 1 BTC on Uniswap (also AMM; there is slippage to be considered on an AMM, thus decreasing the position size). Later as time passes by, the price becomes 17.777 and Bob sells his 1 BTC and ends up with a profit of 7.236706485.
On the perpetual contract market, we first assume the market was heating and thus the effect of funding rate changing the price was negligible.
Bob went short on 1 BTC and ended up with a loss of 7.917007917. To sum up the scenario, Bob has a total loss of 0.680301432.
The above calculation does not quite fit the scenario when the price goes from 10.203 to 17.777, as there should be quite a few positive funding events during a price spike. Let’s say price
changes and k
becomes smaller by 10% (remember the above positive funding rate case?)*. Now, Bob has a larger loss of 0.693481887. Interesting… hmm…
If we make the change of k even larger, the loss is also larger.
To wrap up the section, it seems that merging the funding rate into the x*y=k equation can hurt long-term traders who wish to get some juicy risk-free funding payments.
Though not sure about how many traders of this kind are there in the wild, this is definitely the unwanted loss of trades of, especially when the price of a cryptocurrency has an obvious direction, ex: recent BTC market
*To fix the price
at 17.777 and k
at 90000 (or 80000), we have y/x = 17.777
and x*y = 90000 (or 80000)
. x
and y
can be solved with the two equations.
4. A slightly different calculation
Since the price
is equal to y/x
, instead of multiplying y
with (1 - r)
, with r
being the funding rate, we can also divide x
by (1 — r)
to achieve the same result.
Compared to the previous approach, we can observe from the above sheet that PnLs of the two approaches are different. Which is the right one, then? It depends on the index price, as the funding payment is equal to funding rate * position notional value
.
The notional value of a position is the multiplication of the position size and the price, which should be the index price in the perpetual contract scenario.
We have the funding rate at 1%. If the index price is about 11.11, then the funding payment is 11.1 * 10 * 0.01 = 1.111
; if the index price is about 12.33, then 12.33 * 10 * 0.01 = 1.233
.
However, the result of the previous approach is perhaps more likely, as the price of an efficient secondary market should not differ from the primary market too much. Since the trading price is 10 before the funding event, having a spot price of 11.11 is probably more likely. Probably ;)
What about the scenario of aggregating multiple funding rates during a price spike? Does this approach yield a better result than the previous one?
The answer is: Yes and No. If there are several positive funding events, then according to the above two sheets, the losses are indeed slightly smaller (<1% in the above two sheets). However, if the market is heating and efficient, making funding rates extremely low (≒ 0), then the result is no different from Sheet 1.
5. Conclusion
The AMM model definitely has come a long way in the DeFi space; however, there are still lots of possibilities to be discovered and perhaps many more places to be applied to.
In this article, one method of merging the funding rate into the equation x*y = k is provided and the pros and cons are discussed.
Based on these investigations, I feel quite sceptical about this feature. The reason is that this makes it hard for traders who wish to earn risk-free funding payments to expect their returns and perhaps will potentially reduce the total trading volume.
As usual, if you have any doubt, please leave a comment below and I am willing to start a discussion with you. If this article helps you get to know more about DeFi, stay tuned and there will be more to come!