Blogs # A Guide through Impermanent Loss on Uniswap V2 and Uniswap V3

#### Liquidity in Uniswap V2

###### Overview of definitions

###### Defining Impermanent Loss in Uniswap V2

**(1) Impermanent Loss: $ PnL**

#### Liquidity in Uniswap V3

#### Defining Impermanent Loss in Uniswap V3

**(1) Impermanent Loss: $ PnL**

**(2) Impermanent Loss relative to Initial Portfolio**

**(3) Impermanent Loss relative to Hodl**

**About Compass Labs**

#### Learn more?

May 25, 2022

It’s impossible to trade in Decentralised Finance without being familiar with the concept of Impermanent Loss. In the early days of DeFi, with the launch of decentralized exchanges in 2020, crypto investors could earn a passive ‘yield’ on their portfolios of tokens. In return for earning this passive yield, investors take on the risk of adverse selection. This adverse selection became known as ‘Impermanent Loss’.

More precisely ‘Impermanent Loss’ was coined to represent how much the passive investor would have lost out due to this adverse selection, compared instead to simply holding the portfolio of assets, knows as Hodl portfolio. This was the definition originally picked up byBinancein the DeFi summer of 2020.

Over time, the need for different PnL measures has emerged. This came with the creation of more order-book style trading on Uniswap V3, the advent of more sophisticated DeFi quantitative strategies taking over from passive liquidity provisioning, and the creation of derivatives and total-return swaps linked to DeFi payoffs.

The term ‘Impermanent Loss’ (IL) has now come to mean a number of different PnL measures interchangeably. In this post, we discuss what these measures represent and show how they differ from each other quantitatively, and which measures are important for which type of liquidity provider (LP).

Let’s review some of the basic mathematics for Uniswap V2, the original Constant Function Market Maker (CFMM), and review the quantities that Impermanent Loss represents.

Liquidity in Uniswap is distributed uniformly along the *x *· *y = L²* reserves curve, where *x* and *y* are the respective reserves of two assets *X* and *Y* and *L*is the liquidity provided. In Uniswap V2, liquidity is provided across the entire price range (0,∞). After trades are made, the price ratio of the two assets changes, resulting in a change in the proportion of the assets in the pool.

- Liquidity at time
*t*:*x*·*y = L² = k* - Price of asset
*X*in terms of asset*Y*:*P= y/x* - Price of asset Y in terms of asset Y: 1
- Quantity of asset
*X*at time*t = 0*:*x0* - Quantity of asset
*Y*at time*t = 0*:*y0* - Price at time
*t = 0*:*P* - Price at time
*t*:*Pt*

Given this, we can define the quantity of asset *X* and *Y* in terms of *P* as follows:

From the definitions above, we define 3 values:

- (1) V
*0*the value of the initial holdings in the pool in terms of asset*Y*(equation (3)) - (2) V
*t*the value of the holding in the pool where the quantities*x*and*y*move with price (equation (4)) - (3) V
*hodl*the value of the holding if it was kept outside of the pool where the quantities*x*and*y*are constant (equation (5))

The first, most intuitive way, is to define the **return on the position in the pool in $ terms**:

The full payoff is shown in the figure below, where were consider the case of a USDC/ETH 50/50 portfolio with initial ETH price, P = 1500. This PnL measure is relevant for **market neutral funds** or **trading firms**. This group are not denominating their trading in ETH nor are they interested in passive LPing.

**(2) Impermanent Loss relative to Initial Portfolio**

Here we define impermanent loss as t**he opportunity cost return relative to the value of the starting portfolio**:

In Figure 2, we consider our USDC/ETH case again. For an investor denominated entirely or partly in ETH, an investor will have to buy back the same quantity of ETH to return to the same holdings it had before, generating a realized loss.

**(3) Impermanent Loss relative to Hodl**

Here, we define impermanent loss as:

This is Impermanent Loss against Hodl (see figure 2), the original ‘opportunity cost’ definition. It is relevant for an investor who wants to calculate their **portfolio returns against the opportunity cost portfolio**.

This is **not a tradable or hedgable quantity**, and as a result, **derivatives or total return swaps are based on (1) impermanent loss $PnL (equation 6), or (2) impermanent loss relative to the initial portfolio (equation 7).**

Uniswap V3 enables LPs to **concentrate liquidity to smaller price ranges**, where a **position only needs to maintain enough reserves to support trading within its range**.

The position acts like a constant product pool with larger reserves (virtual reserves) within that range. It is called “virtual” because they represent the amount of liquidity available at each price point within the range, rather than the total amount of liquidity held in the pool (figure 3). A position only needs to hold enough of asset *X* to cover price moments to its upper bound, because upwards price movement corresponds to the depletion of the *X*reserves, and vice versa for *Y*.

When the price exits a position’s range, the position’s liquidity is no longer active, and no longer earns fees. When this happens, liquidity is composed entirely of a single asset, because the reserves of the other asset must have been entirely depleted. If the price ever re-enters the range, the liquidity becomes active again.

In an AMM with liquidity *L* and assets *X* and *Y* with respective amounts *x* and *y*, the liquidity is distributed uniformly along the *x *· *y = L² = k* reserves curve. In this case, we define [*pa, pb*] the price interval of the concentrated liquidity position. In the following, both *P* and *Pt* are assumed to be in the price interval. The reserves for the concentrated position are defined by the following curve:

The position acts like a **constant product pool with larger reserves** (virtual reserves) within that range. A position only needs to hold enough of asset *X*to cover price moments to its upper bound, because upwards price movement corresponds to the depletion of the *X *reserves, and vice versa for *Y*. Within the price bounds,* x *and *y* can be defined as follows:

This leads to the following equations for the reserves that are applicable independent of whether P is in the range [*pa,pb*].

Again, we define the 3 values again:

- (1) V
*0*the value of the initial holdings in the pool in terms of asset*Y*(equation 13) - (2) V
*t*the value of the holding in the pool where the quantities*x*and*y*move with price. Again, here we substitute*P*for*Pt*(equation 14) - (3) V
*hodl*the value of the holding if it was kept outside of the pool where the quantities*x*and*y*are constant (equation 15)

Below, we will derive the IL rate for different impermanent loss definitions and illustrate how these terms are affected by plotting the IL curves to ranges symmetrical around the spot price *P*, where *pa = (1/n)P* and *pb = nP, *with* n *ranging from 1% to infinity.

This plot shows that **providing liquidity to AMM pools is similar to taking short gamma positions**, where the way of rewarding is different; short gamma enables investors to earn option premiums, while AMMs compensate with trading fees. When vol is cheap, and options premiums are relatively inexpensive, investors may be better of LPing in AMMs and hedging with IL insurance.

*Compass Labs is a technology startup working at the forefront of machine learning and DeFi, driven by a team of engineers and academics with years of experience in computational simulations, machine learning, statistics, finance, infrastructure and crypto.*

*Compass Labs developed Dojo, an agent-based DeFi simulation software to test, train and optimize DeFi strategies and smart contracts at the smart contract level. Dojo leverages principles from reinforcement learning and agent-based modeling to simulate and optimize a diverse range of scenarios that reflect DeFi dynamics to improve capital efficiency, risk, and rewards.*

- Test & train your DeFi strategy: visit dojo documentation & tutorial
- Reach out for beta testing or protocol integration
- Follow Compass Labs on twitter
- Visit our website and request a demo
- Read our research papers

All Templates