Understand LP risks: use Effective Gain/Loss, not Impermanent Loss

Gui Lamacie
17 min readFeb 15, 2022

--

TL;DR

When providing liquidity to AMMs (“LPing”) we have exposure to the underlying tokens we deposit into the pools. Impermanent Loss does not fully describe those risks. When LPing, we should focus on the effective gain or loss (EGL) we are exposed to, when token prices vary. The main result is that, assuming a token price is multiplied by a factor f, the value of our LP position is multiplied by the square-root of f . The main formulas are summarized in this table:

Introduction

If you are going to yield farm by being a Liquidity Provider (LP) in a decentralized exchange, you should understand your risks.

I see many retail traders getting confused about a concept called “Impermanent Loss”, trying to use it somehow (”check that table!”, “subtract it from APY!”, etc), and end up doing it in the wrong way.

To make it clear and practical, you should always focus on Effective Gain or Loss (EGL), not Impermanent Loss (IL). In this article, we’ll explain each one, their differences and similarities, and how to calculate what really matters to you.

We analyze different cases like pairs with one volatile token, pairs with two volatile tokens, and when we borrow one of the assets.

Note 1: The proofs of all the equations are kept in the Appendix, called “Doing the Math”, for those who are interested.

Note 2: To explain the concepts, we focus on the most popular type of AMM model (the one used by PancakeSwap, SushiSwap, Uniswap V2, and many others). The formulas will be different for concentrated liquidity AMMs, like Uniswap V3, and for stablecoin swaps like Curve, although the concepts remain the same.

Intuitive Understanding

When we LP, we typically provide liquidity into an automated market maker (AMM), built in the DeX. We earn fees (that’s the main reason for LPing), but we also have exposure to the underlying assets. To take care of this second part, we use Effective Gain or Loss (EGL), which is the final result from the total market risk exposure of our position. So, our final PnL (profit and loss) will be PnL = EGL + “fees & rewards”

Let’s analyze LPing to the most common type of automated market makers (AMMs).

First of all, we need to define which one is our reserve currency (or quote currency). This is the currency in which we want to measure our wealth. USD is a common choice. But, since we’re talking about crypto, let’s take a USD Stablecoin, for the sake of simplicity. For example, USDC.

Now, suppose we choose to provide liquidity to a pool comprised of token ABC and USDC (in a later section, we also analyze pools of two volatile tokens).

We start with a certain amount of USDC, say 1000 USDC. In most cases, part of this USDC will have to be exchanged (or swapped) for ABC, so that we can provide liquidity to both sides of the pool. Sometimes the DeX/Dapp does this automatically for us; sometimes we have to do it explicitly. Suppose the exchange rate is 10 USDC per ABC, so we convert 500 USDC into 50 ABC (we ignore possible slippage here, for simplicity). We now have 500 USDC and 50 ABC. Importantly, note that, after this step, because we have ABC tokens, we are exposed to their variation (market risk!)

👉 Risk : we just got some ABC, so we are exposed to its value against USDC (i.e. the exchange rate ABC/USDC).

Now, consider two scenarios: either ABC goes up in value against USDC (Scenario “ABC 25% UP”), or it goes down (Scenario “ABC 25% DOWN”).

Because of the dynamics of AMMs, after each scenario, the amounts of the two tokens in the pool will be different.

In Scenario ABC 25% UP, there will be less ABC tokens in the pool than in the beginning, while the amount of USDC will increase. Why? Because the price will typically increase via “buy ABC” swaps, which give USDC to the pool, and take ABC away, decreasing the amount of ABCs in the pool.

Conversely, in Scenario ABC 25% DOWN, the quantity of ABC tokens will increase, while the quantity of USDC will decrease.

Effective Gain/Loss

Now, let’s think about our profits or losses that may come from our exposure to the ABC token (in the end, we need to check if these risks are compensated by the expected fees that we earn as LPs).

In Scenario ABC 25% UP, the exchange rate goes from 10 to 12.5 USDC per ABC. So, we profit, because we have ABC and its price goes up. This result (what matters!) is called Effective Gain/Loss (EGL). Theoretically, EGL can be viewed as a cost of opportunity, which simply makes a comparison between our Final Value (Position 2) and what would be our final value if we did nothing and just held Position 0 until the end.

In Scenario ABC 25% DOWN, the price of ABC goes from 10 to 7.5 USDC per ABC. Thus, we lose.

We define EGL in money terms as the financial EGL, or EGL$. And we also call the EGL relative to the initial worth by percent EGL, or EGL%.

The calculations above were simple because we already knew the final quantities of ABC and USDC (Position 2). Anyway, in AMMs, those quantities are also linked to the price variation of USDC/ABC. So, we can derive a formula to calculate EGL only as a function of price variation.

Let’s define a price factor f as the factor by which the initial price was multiplied. For example, in our first scenario, ABC price goes up 25%, so f=1.25

If price is multiplied by f, how much is our worth (the value of our position) multiplied by? For the most popular kind of AMMs, this factor can be beautifully described just as the square-root of f :

Thus, our EGL% becomes:

For example, in our first scenario where ABC price goes up 25%, f=1.25. Then, our worth is multiplied by the square-root of 1.25, which is 1.118. And our gain, EGL%, is simply ”1.118–1", or 11.8%.

In our second scenario, ABC price goes down 25%, so f=0.75. Our worth is multiplied by square-root of 0.75, or 0.866. Our loss, EGL%, is then ”0.866–1" or -13.4%.

Equations (1) and (2) are proved in the appendix “Doing the Math”.

The following plot exhibits our relative Effective Gain or Loss, given each f :

Some of the values are shown in the table for ease of reading:

Effective Gain/Loss (EGL) vs Impermanent Loss (IL)

Note that we analyzed our gains and losses and we didn’t even mention impermanent loss (IL). We focused on EGL, and the simple “square-root rule” took care of everything. So, where’s the IL in all this? What’s the relation between EGL and IL?

As a principle, we should always focus on our Effective Gain/Loss (EGL), i.e. the result of our entire portfolio, so that we don’t miss the big picture, and don’t forget important risks. But let’s explore the relation between the two concepts.

As we’ve seen, in scenario ABC 25% UP, we profit because we are exposed to ABC. But note that, due to the LP activity, our quantity of ABC decreases right when its price is going up! So, we don’t profit as much as if we had kept the 50 ABCs that we had in “Position 1”. The difference between those two (profit) situations is called Impermanent Loss (IL).

Impermanent Loss measures a cost of opportunity: **Position 2 vs Position 1, evaluated in the end. But, for our purposes, why to compare our final worth (Position 2) against our Position 1 instead of comparing it directly against our initial position (Position 0)? If we hadn’t decided to LP, we wouldn’t even have bought those 50 ABCs in the first place. We bought them only after we chose to LP in the ABC-USDC pool, probably because we saw a table of APYs, TVLs and other numbers, and then opted for that pair. In other words, our process did not start at Position 1, but actually at Position 0! So, the most natural cost of opportunity to use in this case is to compare Position 2 vs Position 0, evaluated in the end, which is simply our EGL. That’s why we don’t necessarily have to focus on impermanent loss when LPing.

In the Appendix, we also prove a formula for IL, but it’s not quite relevant for us here.

Anyway, IL became hyped and is frequently mentioned, sometimes correctly, sometimes in a wrong or misleading way. Therefore, we should be able to distinguish between those cases, and make sure we understand the relation between IL and EGL.

The following diagram shows how that relation plays out in our example:

Indeed, our EGL is equivalent to holding a Long Position of 50 ABCs (half of our initial portfolio) and also incurring impermanent loss. In financial terms, EGL$ will be the sum of the two parts:

where PnL_position1 is the hypothetical financial result (profit or loss) of Position 1 after the price variation. When dealing with percentages, we should use them by compounding (1+EGL%)=(1+R_position1)(1+IL%), where R_position1 is the return of Position 1 when the price of ABC moves. However, the latter relation can only be applied for examples like this, and does not hold in general when Position 1 consists of more complex portfolios, like those in section “A General Framework for EGL”.

Then, why IL?

A simple use of IL is to assess the marginal risk we incur in LPing after the risks of our portfolio (Position 1) have already been taken into account. In our example, suppose we already had a portfolio with exactly 50 ABCs and 500 USDCs, and we were just deciding whether or not to LP that portfolio (the only two options are: we either hold the portfolio or deposit it into the pool). In this case, we could use IL to measure our marginal risk if we LP. This is not an usual case because in the end what matters is our whole exposure, but this is still a valid justification for IL.

When we Borrow to LP

A more relevant application is when PnL_position1 is always null for every price variation (in Equation (3) above). In this case, we have EGL$ = IL$. An example is if we short ABCs, including that position in our portfolio (Position1), to cancel out with our long ABC position. One way to do it is simply by borrowing 50 ABCs (a short exposure), then depositing them into the pool (a long exposure), along with 500 USDCs. This is actually an approach sometimes used by market makers: to borrow the asset for which they provide liquidity. And that’s why this example is probably the most important one to support the concept of IL. Of course, for the final PnL we still have to discount the borrowing fees. Moreover, in order to borrow the 50 ABCs, we need an amount of collateral (let’s say 1000 USDCs) which is more than what we borrow. The three stages of the process are:

Checking the Net position, it’s easy to see that Position 1 is always the same as Position 0 (independent of price variation), making EGL$ = IL$

However, the overcollateralization decreases our result in percentage terms (the denominator, our whole position, becomes larger). So, beware of using IL% formula or percentages directly because they don’t take into account this collateral (IL% refers only to the amount that you post as LP).

How to calculate EGL in this case?

We know that EGL$ = Value(pos2) - Value(pos2). The value of Position 2 is the value of X ABC plus Y USDC (which together are the result of a regular LP position of initial size 1000 USDC), minus 50 ABC (short position, which is initially valued at 500 USDC), plus 1000 USDC. From the square-root rule (Equations (1) and (2)) we know that the final value of the LP position is 1000.square-root(f). So the final EGL$ in this example can be expressed as:

More generally, consider that the total capital used is K and c is the collateral ratio. In our example, collateral ratio was c=2, meaning that collateral (1000 USDC) was as double as the borrowed amount (50 ABC, equivalent to 500 USDC). For examples like this, EGL$ would be:

and to get EGL% we just divide that by the total initial capital (K):

As usual, the Appendix presents the proof. As a side note about this example, I’ve seen people in the communities referring to this type of trading as delta-neutral. Unfortunately, this is not a suitable term, since we have a clear exposure to ABC price variation (represented by f) in our result. The position only “begins” as delta-neutral, but as soon as the ABC-USDC quantities start varying inside the pool, it‘s not delta-neutral anymore.

Pools of two Volatile Assets

So far we analyzed EGL assuming that the pool is comprised of a reserve currency (e.g. a stablecoin) and a volatile token. What if both assets in the pool are volatile assets?

Suppose we LP into a pool comprised of assets ABC and XYZ, and that our reserve currency is USD. Inspired by our previous examples, we start with some USD (Position 0), trade them into ABC and XYZ (Position 1), deposit them into the pool, and after a while we have Position 2, which will depend on the price variations of each asset.

Let’s say the prices of assets ABC and XYZ at Position 2 are their initial price multiplied by fa and fx, respectively (these prices are relative to the reserve currency USD). In the Appendix, we prove that the final value of Position 2, will be equivalent to Position 0 multiplied by square-root(fa.fx):

So that EGL% is simply:

These formulas are a simple generalization of formulas (1) and (2) (the factor f of a stablecoin should be 1).

General Framework for EGL

In more general LPing processes, we could define Position 0 as the initial capital in the reserve currency; Position 1 as the portfolio right before any LPing, and Position 2 as the portfolio after price variations. So, a general framework to calculate EGL would be to separately apply the square-root rule for every piece of our portfolio that is submitted to LP, and a suitable variation for the rest of the portfolio. Check the example below, where we start with USDCs, and do diverse things, like buying some tokens, borrowing, and submit LPs. From the lessons above, it’s straightforward to calculate Position 2 final value, and then EGL.

The financial EGL would then be:

And percent EGL:

A final PnL would have to compare EGL with the expected fees and rewards (including borrowing fees):

The “fees and rewards” part is out of the scope of this article, but some comments are worth the while. When yield farming, we see estimated APYs from LP positions. Those usually include the fees we earn from LPing (for example, a 0.30% fee on each swap anybody does with the pool) and sometimes rewards, commonly granted as native tokens. It is important to differentiate between them (platforms can usually show them separately). The LP fees are proportional to the ratio between the traded volume in the pool and its size (TVL). For example, if a pool has a fixed 0.30% fee and, within a certain period, its TVL was USD 20 million and it had a trading volume of USD 5 million, the collected fees during this period were (0.30%).volume/TVL = (0.30%).5/20 = 0.075% of the value we deposited. So, we would have to project the future volume (and TVL) in the period we are considering to have an estimate of this rate. Also, note that the fees are usually paid out in the pool tokens, so they actually increase our exposure to the tokens at those same percentage rates (one can also reduce this exposure by regularly selling the accrued tokens). Regarding the rewards, note that some platforms give so many native tokens that their inflation substantially depreciates them. So we should be careful with how much (or whether) we count them in. That’s why it’s important to see the LP fees separately from the rewards. Finally, remember that, for the final PnL, we must discount any costs and paid fees, like borrowing fees.

How to apply these equations?

The equations we’ve seen describe our results as a function of the price fluctuations of the tokens in the pool. They can be used to:

  • understand the relations between price moves (market risk) and EGL, and have an intuitive approximation of the risks and opportunities
  • simulate different price movements and check how our projected EGL changes (scenario analysis), and possibly optimize LP positions (and portfolio positions) based on distribution of price movements
  • simulate extreme price movements and check our stress risks
  • backtest LP positions
  • hedge LP positions
  • compare any simulation with estimates from fees and rewards, balancing them out to decide whether or not to LP

If this article was helpful to you, give a thumbs up! And stay tuned for more explanations on different concepts related to trading, crypto and quant finance!

If you want to share comments, suggestions, editions, or discuss any related subjects, feel free to get in touch at gui.lamacie@gmail.com

Appendix: Doing the Math

The most common constant product AMMs follow these well-known equations:

which imply:

where x and y are the quantities of each asset in the pool (in our example, x in the quantity of ABC tokens, and y is the quantity of USDC), L is constant (for our purposes) and P is the price of x relative to y (in our example, the exchange rate ABC/USDC). Note above that P=y/x actually comes from writing y as a function of x (i.e. y=L²/x) and then:

Our relative quantities of the two assets follow the quantities in the pool, since what we have is just a share of the pool. We have an initial exchange rate P_init and a final one P_final, which define the price factor f = P_final/P_init

Let’s evaluate how much Position 0, 1 and 2 would be worth in the end of the process (i.e. with the new price P_final):

We see that our final value V_pos2 is just our initial position V_pos0 multiplied by the square-root of f, what proves Equation (1)

It easily follows that the EGL (relative to initial worth) is:

and this proves Equation (2).

To derive a formula for IL%:

To prove Equation (3), just note that EGL$=V_pos2 - V_pos0 and that IL$=V_pos2 - V_pos1 , so that EGL$ - IL$=V_pos1 - V_pos0 which is equivalent to the PnL of Position 1 after price variation. Related to this, to see the compounding effect if we used relative (percent) values, note that our Position 1 consists of a portfolio of which half is the reserve currency and the other half is the risk token. So, if price is multiplied by f, the return of the portfolio will be R_position1 = 1/2 . (f-1)+1/2 . (0) and the value of this portfolio is multiplied by (1+R_position1) = 1/2 + f/2. This is equivalent to:

To prove Equation (4), suppose the capital needed in the process is K, and the collateral ratio is c (in the example, we had c=2). When we LP into a pair, we input each asset as half of the total value. Let’s call this “half-value” as a. Note that K=c.a+a, since c.a will be used to borrow an amount of token ABC equivalent to a (one half of the deposit) and the other a will come directly as USDC (the other half of the deposit). We have an a LP position with initial value 2a, a short (borrowed ABC) position equivalent to a, and a collateral value of ca. So, in the end of the process, if ABC price is multiplied by f, our LP position will be worth 2a.sqrt(f), our short position -af and our collateral will still be ca, so that:

Since EGL%= EGL$ / V_pos0 and V_pos0=K, we have

Let’s prove the case for pools with two volatile assets (Equations (5) and (6)). To make notation easier, say the two assets are X and Y, and that we start our process with 2z units of the reserve currency (Position 0). We convert half of it (z) into x units of asset X and the other half into y units of asset Y. The prices of conversion are then Px=z/x and Py=z/y. Under arbitrage-free hypothesis, the price in the pool, corresponding to exchanging X for Y, is P=y/x=Px/Py, where y=L.sqrt(P) and x=L/sqrt(P) as usual (let L here correspond to our fraction of the pool’s liquidity, a trick to simplify notation).

Suppose the initial prices Px and Py are then multiplied by fx and fy, respectively, so that the new price between X and Y is:

Define x’and y’ and the final quantities of the assets after price variation. The final values of Position 0, 1 and 2 will then be:

Now it’s easy to see that V_pos2 / V_pos0=sqrt(fx.fy) , and thus:

Regarding impermanent loss,

References

[1] Guillermo Angeris et al. An analysis of Uniswap markets. 2019

[2] Adams H, Zeinsmeister N, Robinson D, Uniswap V2 Core, https://uniswap.org/whitepaper.pdf

[3] Adams H, Zeinsmeister N, Salem M, Keefer R, Robinson D, Uniswap V3 Core, https://uniswap.org/whitepaper-v3.pdf

[4] Peteris Erins, How to Calculate Impermanent Loss: Full Derivation, 2021, https://medium.com/auditless/how-to-calculate-impermanent-loss-full-derivation-803e8b2497b7

--

--