Evaluating the profitability and impermanent loss of Uniswap v3 positions
Uniswap V3 opens up the ability to have much more control over how a liquidity provider (LP) provides its liquidity to the open market. With this comes the ability to build different types of strategies to try and optimize the yield for providing this liquidity during different market conditions.
While researching some optimal rebalancing strategies for some Arrakis Finance vaults, I quickly realized that Impermanent Loss (IL) had a very serious impact on how well any strategy built atop Uniswap V3 would perform.
I recalled an article that Peteris Erins had written on how to determine the IL for a Uniswap V2 pool and wondered if anyone had calculated something similar for Uniswap V3 pools. It turns out that the same author had derived the IL equation for Uniswap V3 as well in this article.
Here P is the initial price of asset X in terms of asset Y, while k is the gain that happens to P over a given timeframe. The values of Pa and Pb are the lower and upper price bounds set by the Uniswap V3 position. ILa,b(k) is the impermanent loss experienced by that range for a given gain k and Uniswap V3 LP position.
While testing various rebalancing strategies on top of Uniswap V3 positions, I thought it would be useful to be able to enter a specific impermanent loss value for a given LP position and have it output the change in P, given by k, that achieves that impermanent loss value. This effectively meant rewriting the above equation to solve for k instead of impermanent loss.
That can be accomplished via the following steps:
Now to make solving this a bit easier we can do the following substitutions:
To give us the following simpler equation:
This is now in the familiar form of a quadratic equation and can be easily solved.
The solution turns out to be:
By replacing the a and b terms in the above equation with their substitutions shown further up, we can input the initial price P, the lower and upper bounds Pa and Pb, and the impermanent loss under consideration to determine the gain in price or loss in price that would cause that specific amount of impermanent loss.
We can also use this equation to solve for k in a Uniswap V2 pool because a Uniswap V2 pool would look like a Uniswap V3 pool where Pa is 0 and Pb is ∞.
When this happens our a and b substitutions become:
So how might solving for k be useful to us?
Let’s consider an example Uniswap V3 position in ETH/USDC. If the current price of ETH is at $3500 and we set our limits to be 0.5X the price on the lower side and 2X the price on the higher side we have a position with Pa = $1750, Pb = $7000, P = $3500.
If we assume that this position is going to earn 25% APR in fees, we might want to know what the actual gain or loss in the price of ETH would be that would wipe out those earned fees via impermanent loss.
So in this case we would set IL to -0.25.
So what this is telling us is that as long as the price stays within our Uniswap V3 LP position lower and upper bounds while we earn the 25% APR, we should be ahead of simply holding outside of the Uniswap V3 position. Or in other words, we should be able to beat impermanent loss if the price stays within our range and we earn the expected amount of fees.
This is because a 25% loss to IL only happens when the price decreases by 0.4539X or increases by 2.2031X and anything in between would have a smaller impermanent loss as seen in the following graph.
Note: This graph is only valid when k varies between 0.5 and 2 for the example Uniswap V3 LP position as the position is out of bounds beyond those limits.
We can confirm that our solutions for k are correct by plugging the k values back into the original ILa,b(k) equation.
Another time when you possibly want to solve for k is when you might want to move your range if impermanent loss hits a specific value. For example, if you wanted to re-center your range when IL hit a loss of 10%. You’d simply plug in the position parameters along with the -0.10 for IL and then calculate the values of k that produce that impermanent loss.
This could help with building a strategy that chooses better times to move and rebalance an LP position instead of updating the position at a point where impermanent loss has already caused too much damage to recover from.
If you are interested in learning more about how to manage liquidity on Uniswap V3 in the most efficient way, then connect with us on the official Arrakis Ecosystem Discord channel!
- Website: https://www.arrakis.finance
- Twitter: https://twitter.com/arrakisfinance
- Telegram: https://t.me/arrakisfinance
- Discord: https://discord.gg/arrakisfinance