Dalle2 vision of liquidation pools

01.1 My Journey to the ATH: Liquidity pools and impermanent loss Part I


 

Welcome to the first instalment of my blog My Journey to the ATH!  Like I explained in my introduction post, the plan is to do a monthly dive into some interesting aspect of the crypto market, with emphasis on the theoretical aspects and risk assessment. To get a hands on example I will invest a small amount (20$) using the topic of the month and go through the process and what I learned.

Notice that of course nothing I write should be taken as a financial advice as I am equally well equipped to predict the markets as you or your dog. This is simply for the sake of learning and for the fun.

 

This month the topic is Liquidity pools.  My intention was to publish this last Friday but the concept is rather interesting and my post become a bit longer than I expected. Thus I decided to delay the publishing by few days and split it into two parts. The first part (the one you are currently reading) will focus on the theory behind automated market makers and liquidity pools. In the second part I will go into my own investment on pancake swap and consider two very simplistic models for assess the risk of the investment.

So what on earth are liquidity pools and how do they work?

 

Liquidity pools are tools on decentralized exchanges that provides liquidity of a pair of assets, that secures quick transfers and thus minimize slippage. The liquidity is provided by the users of the exchange that stake their own coins into the pool.  As a reward they get a fraction of the exchange fee when someone uses the exchange to swap between the two coins. The fraction earned by the user is proportional to the relative size of their stake in the pool. The expected rewards vary a lot between pairs, e.g. if the pool is very large one gets a smaller fraction of the fee, but it could be made up if the pool is very active. This goes the other way around also. Usually you would enter a pool with equal amount of both coins, and receive an LP token, that represents a proportion of the pool when you entered it.  Then when you exit the pool you trade back your LP coin for a proportion (relative to the new size of the pool) of the pool.  Sounds good, right? But there are of course always risks when you invest no matter what! 

Let’s try to understand in more depth how the pools work and identify the possible risks.

The risks

There are two main risks investing in a liquidity pool I could find:

  • Price fluctuations: The first and perhaps most obvious risk is that one is investing in currencies that could drop considerably in price relative e.g. a USD. This risk can be minimized by providing liquidity to a stable coin pair, although stable coins are not guaranteed to be stable. 
  • The second source of risk is called impermanent loss and is more subtle and interesting.

If you think I am overlooking some obvious risk please let me know in the comments.

Automated market makers and Impermanent loss

 

Let’s start by imagine a Liquidity pool for coins A and B, at a given time there are N_A and N_B amount of each coin respectively in the pool. As already stated, this liquidity pool liquidity pool will provide liquidity for trades with the two coins, but unlike classical financial markets the price on the exchange is not controlled with an order book but it uses the very simple concept that the multiple of the two amounts N_A and N_A should be equal before and after a trade

cb32968b9e7831c7cf7914a5814921fcc8c395fc9ebbb4329948f97634c43090.png

 

where the Delta_A and Delta_B are the changes amount of coins A and B in the pool respectively. From Form this we can easily derive the price p_A,B of A in terms of coin B, by setting Delta_A = -1 and Delta_B = P_A,B, i.e. we take one A out and give p_A,B Bs back to the pool.

4cedea2a63513b28ebf6f8a26d3fa07cd00e06779e7eb06dd532b955531f1460.png

So we see that for large enough pools the price of A is given in terms of the ratio between amounts of each coin in the total pool. The equations are of course symmetric in A and B.

Those formulas together with the liquidity pools define a so called automated market maker (AMM). An interesting feature about the AMM is that because the prices are completely governed locally by trades with the coins in the pool, it is blind to global changes on the market. This leads to arbitrage opportunities for outside investors to gain from discrepancy of the price between the pool and other markets. This can lead to a loss for the owners of the pool, that is often called impermanent loss. Impermanent loss is one of those things that sound very confusing when you hear about it for the first time, but really are not that completed to understand. It is confusing because it is relative to position of not investing in the pool but rather hold the same amount of coins. We can easily derive the percentage of impermanent loss as a function of the ratio of the initial and final prices, r.

First it is convenient to set the multiple equal to some arbitrary constant, c.

4d591535c296a430bfe13cd21db612effe7d1e68fcb062f1d734085ef30e4f9f.png

Then using the above it is easy to find the size of the pools as a function of the price, p_A,B:

a6be0b4dbf9afbda70e1b8e9627130dc7cc563b3dec6f99caf251e01af0f2db5.png

Then the Impermanent loss is:

b708d292e5e7aeeff7e1146538ea29d09b3f63c0811b563d5297657a657629ae.png

 

where in the third equality we used the equation for p_A,B^fin and in the last two equality we used the equations for N_A and N_B and a little bit of algebra together with the definition r = p_A,B^fin/p_A,B^init.

 

75400d09902a6c16a929e2a89be2638b3e258dc4d9c5d44fd1c24768fc4e1f50.png

Interestingly this is never positive, i.e. the best we could hope for is zero loss. This sounds like the investment is totally not worth it, the best thing we can hope is break even from the holding position… but of course we have forgotten about the rewards from the exchange fee payed to us. If the rewards are higher than the impermanent loss the pool is profitable! So before we invest we should think how likely it is that the two coins diverge enough for the impermanent loss to nullify the gains from the rewards. If we assess it so that it likely happens we know that the investment is likely not worth it.

From the graph we see that for example if one of the coins 2.5x in price relative to the other we experience a 10% loss relative to the holding potion. This means that is we would get 10% rewards the investment is profitable as long as the relative price of the coins changes less the 2.5 times.

Here the word relative is pretty important if our reference is some other third currency, e.g. dollars we could have made a considerable gains even though we have a high impermanent loss. In this case the question about impermanent loss starts to feel a bit arbitrary, as it builds up on the idea that would we have held on to those specific coins, which in many cases is unlikely. And isn’t there always a better position we could have made, anyway?

In any case it is very important to understand how the prices coins affect the return get from investing in the pool. Best case scenario is that both coins gain value relative to our preferred reference, and further that are highly correlated and don’t diverge so the impermanent loss is minimized.

Let’s define our coin prices in terms of the reference coin at the starting position and exit position c711392294fd02aed3f8f8ac9fa79342be648fb583a38f821780db5312bed764.png then we have

fff26fad04c1554b0ef7fac2abedd308055d6161e1ed2d6fe8fecd2df78289b4.png

The final worth of the investment in terms of the reference currency (still ignoring the rewards) is thus

d84bdfc042dbb57b7a47427826d7ea8f8d48e35a73f58e895e43fb823b933d15.png

Let’s visualize this by considering two coins A,B that initially are worth 1 unit of our reference currency but the final value take value on the range from 0 to 5 

dd866b0f5281eb431ea0122247549454e32d760f8353ba7ab22e93e6eef9a108.png

The thick blue line shows the boundary between losing and gaining from the investment. We see as we expected that our outcome space is symmetric around the A=B line. From the figure it might look like it is much more likely to gain than lose as the area above the boundary is much larger. This is of course not necessarily the case since we don’t know how the prices will change. We will need to assign some probability distributions to the price rages and use them to compute the expected gain or lose. We will do this explicitly in part 2.

 

 

Coupling to staking

 

Interestingly there is sometimes an extra layer of complications to the liquidity pools as one is often allowed to stake the LP coin for rewards, those could be in terms of one of the coins, or a third coin all together. When it is a third coin we simply need a new dimension to our outcome space i.e. the price of the third coin. But perhaps more interestingly when it is one of the original coins it will break the A/B symmetry of the outcome space.   To see this let R_s be the yearly rewards percentage from staking and it is payed in a coin C, then the final worth of our investment after one year is   737e430d8c29c28906482da6a1b1229365ff5027a84b07814e50e23d6140f4c7.png

  Setting C=B, then yields

4e4165d35b910e71692439dd61599b4f6a8d96e81a5ad505c276b8949796c9c5.png

Let’s stick to our example from above and further assume R_s=0.2 and it is payed in B. Then our outcome space looks as follows 5fa8e79f46c1ceb63008db6e23eda78246d990e430a21839a4fea7ea279f8f60.png

We see that the symmetry is broken and the values are positively skewed towards the B axis, i.e. we are happy if the B coin gains value faster than the A coin.  

Summary

Let’s now finally consider the rewards, by defining R_r as the yearly rewards percentage, the rewards percentage is relative to the starting investment so our most general formula for the worth of a liqudity pool investment in a year is 19ed405dddfac970a276afe4a6816d723b72464cea8225a5bfeb2a6540dcc661.png

Now if there is no extra staking we simply set Rs=0 and if the staking is payed terms of B we set (C=B).

This will be the starting point for my next post when we look at a real example, and will try to construct some very simple models to assess the the risk of it.

 

Thanks a lot for reading and I hope it is interesting and fun for somebody. I would appreciate a tip on the site you liked this and in case you liked it very much feel free to send me some BAT, Matic or BNB tip to 

0x18f2f4543dc948ebA68515C25720e349c61c47Dc

I will use all tips for future experiments.

 

See you in my next post!

 

p.s. Latex is not currently supported  on this editor so I needed to screenshot my equations. I will start up a GitHub site very soon where it will be much easier to read.

How do you rate this article?

19



My Journey to the ATH
My Journey to the ATH

I am a mathematician and my latest obsession are crypto currencies. I want to learn more and the best way for me to learn is to pretend I am explaning it to someone else. Every last Friday of each month I will invest 20$ in some crypto and try out different currencies and earn options. I will try my best to assess the risk of the trade and explain the theory behind it. The first Friday of every month I will then post a detailed summary of the journey so far.

Send a $0.01 microtip in crypto to the author, and earn yourself as you read!

20% to author / 80% to me.
We pay the tips from our rewards pool.