Impermanent Loss and Stop Loss

Vicyyn
5 min readApr 11, 2021

Impermanent loss is a known term among the crypto communities. Most people don’t really bother understanding but know that staking can cause some minor loss when price fluctuate. In this article we will talk in depth about Impermanent loss, Stop losses and the Math behind it.

Impermanent Loss

There is no better way to understand a concept than taking a look at an example. This example was taken from Binance academy article

Alice deposits 1 ETH and 100 DAI in a liquidity pool. In this particular automated market maker (AMM), the deposited token pair needs to be of equivalent value. This means that the price of ETH is 100 DAI at the time of deposit. This also means that the dollar value of Alice’s deposit is 200 USD at the time of deposit.

In addition, there’s a total of 10 ETH and 1,000 DAI in the pool — funded by other LPs just like Alice. So, Alice has a 10% share of the pool, and the total liquidity is 10,000.

Let’s say that the price of ETH increases to 400 DAI. While this is happening, arbitrage traders will add DAI to the pool and remove ETH from it until the ratio reflects the current price. Remember, AMMs don’t have order books. What determines the price of the assets in the pool is the ratio between them in the pool. While liquidity remains constant in the pool (10,000), the ratio of the assets in it changes.

If ETH is now 400 DAI, the ratio between how much ETH and how much DAI is in the pool has changed. There is now 5 ETH and 2,000 DAI in the pool, thanks to the work of arbitrage traders.

So, Alice decides to withdraw her funds. As we know from earlier, she’s entitled to a 10% share of the pool. As a result, she can withdraw 0.5 ETH and 200 DAI, totaling 400 USD. She made some nice profits since her deposit of tokens worth 200 USD, right? But wait, what would have happened if she simply holds her 1 ETH and 100 DAI? The combined dollar value of these holdings would be 500 USD now.

We can see that Alice would have been better off by HODLing rather than depositing into the liquidity pool. This is what we call impermanent loss. In this case, Alice’s loss wasn’t that substantial as the initial deposit was a relatively small amount. Keep in mind, however, that impermanent loss can lead to big losses (including a significant portion of the initial deposit).

With that said, Alice’s example completely disregards the trading fees she would have earned for providing liquidity. In many cases, the fees earned would negate the losses and make providing liquidity profitable nevertheless. Even so, it’s crucial to understand impermanent loss before providing liquidity to a DeFi protocol.

Here’s a summary of what the graph is telling us about losses compared to HODLing:

  • 1.25x price change = 0.6% loss
  • 1.50x price change = 2.0% loss
  • 1.75x price change = 3.8% loss
  • 2x price change = 5.7% loss
  • 3x price change = 13.4% loss
  • 4x price change = 20.0% loss
  • 5x price change = 25.5% loss

There’s something important you also need to understand. Impermanent loss happens no matter which direction the price changes. The only thing impermanent loss cares about is the price ratio relative to the time of deposit
We can calculate the IL using this formula.

price_ratio = new_price / old_pricedivergence_loss = 2 * sqrt(price_ratio) / (1+price_ratio) — 1

Now we understand what is Impermanent loss but the question is how do we make providing liquidity profitable and is there a way to stop the loss ?

Stop Loss

Similar to what we mentioned before. Impermanent loss can be negated by fees earned when providing liquidity in a pool. the latter have an APR (Annual Percentage Rate) that differs from pool to pool.
Let’s take COPE-USDC fusion pool on Raydium as an example. We are going to suppose that the COPE is worth 5$ and the APR is around 800%
Alice deposits 100 COPE and 500USDC . This means that Alice is making

Alice's daily Profit = 2 * (100 * 8 / 365 ~ 4,4)// we multiple by 2 because we get return based on the total value of liquidity (cope + USDC)

Alice is making 4,4 COPE daily, but she also have to take IL into account. After 3 days of staking, Binance lists COPE and the price doubles, Alice will have a 5,7% Impermanent Loss which is exactly 5,7 COPE. (and some USDC)
Alice staked for 3 days that means she got 13,2 COPE (3 * 4,4) from providing liquidity. But she lost 5,7 COPE from Impermanent Loss. If Alice unstake now she will be up ~7,5COPE (13,2–5,7- some_usdc) . In this case the Impermanent Loss becomes permanent. But if she doesn’t unstake and the price goes back to 5$ again. She will be up 13,2 COPE (13,2–0). This is why it’s called Impermanent Loss, it’s permanent only when you unstake.

Let’s try to calculate the number of days needed in order to diminish the Impermanent Loss.
Alice is making 4,4 COPE daily
Alice has an IL of 25% means Alice lost 0.25 * 100 = 25 COPE
and 500 * 0.25 = 125 USDC

number_of_days * 4,4 = 25 * 2 (USDC and cope Lost)
=> number_of_days = (25 * 2) / 4,4 ~ 11,4 days

We can generalize the formula

daily_return = 2 * (apr / 365) * Liquidity_Provided (100 COPE)
number_of_days * daily_return = 2 * Liquidity_Provided * Loss
number_of_days = (2 * Liquidity * Loss) / daily_return

We simplify

number_of_days = Loss / (apr / 365)

You can test the results here

Closing thoughts

Impermanent loss is one of the fundamental concepts that anyone who wants to provide liquidity to AMMs should understand. In short, if the price of the deposited assets changes since the deposit, the LP may be exposed to impermanent loss. To prevent this loss you have to make more providing liquidity than the IL.

Feel free to ask my anything if you still have some doubts @vicyyn in twitter :)
some other good articles that I found:
https://academy.binance.com/en/articles/impermanent-loss-explained
https://pintail.medium.com/uniswap-a-good-deal-for-liquidity-providers-104c0b6816f2

--

--

Vicyyn

Technology enthusiast and a Blockchain Developer ,Solana. I do machine Learning in my spare time and I love posting about the stuff I do