Pricing uniswap v3 with stochastic process, Part1

zelos
zelos-research
Published in
7 min readDec 25, 2023

Why You Need to Read This

This series tries to use stopping times as a mathematical tool to handle the pricing of V3 positions.

This will be a relatively long series, to provide a reasonable pricing formula for Uniswap V3. In the first post, we will discuss an interesting question. As a liquidity provider for Uniswap V3, how long can you collect fees? This question is very tricky and requires a fair amount of prerequisite knowledge. The entire series requires some understanding of the following concepts:
1. Brownian motion and geometric Brownian motion
2. RN derivatives
3. Laplace transforms
4. Martingales and optimal stopping times

This article also assumes that you have read the Uniswap V3 whitepaper.

Don’t be afraid, after reading the entire post, you will understand why these mathematical tools are needed and the excellent conclusions they lead to.

First Hitting Time and More

The best material for first-hitting time comes from Shreve’s “Stochastic Calculus for Finance II” in section 3.6. For a Brownian motion,W_t the first hitting time can be defined as:

We want to deal with a more interesting stopping time, which has two boundaries (a,b):

For this new stopping time, we want to study some simple properties first. For example, what is the probability that BM stops at a? We will use the following conclusion without proof:

If a process is a martingale, then its stopping time is also a martingale.

For Brownian motion, we have three martingales that can be used:

Using the first martingale, we can obtain:

And because

We can deduce:

Let’s continue with the second martingale:

Now we know how to calculate E[τ]. Before moving on to the more difficult third martingale, let’s see what we can do now.

Simplified model for V3

Suppose I am a V3 liquidity provider and I stop providing liquidity and withdraw my funds as soon as the price reaches any of the two boundaries. I want to know how long I will collect fees.

We need to make a simple assumption about the price movement, with a drift rate of μ=0, price is modeled by:dS=σWt

The ETH price is $2000, and my range for providing liquidity is (1500, 2500), with a volatility of 50% yearly. We first need to convert the liquidity range and price into a Brownian motion:

This way, we transform the problem into a stopping time problem under standard Brownian motion. The expected value of our stopping time is:
E[τ]=−ab=0.25
This means that the expected duration for which I can collect fees is 0.25 years.

Expectation

To simplify calculations and facilitate understanding, we make an unrealistic assumption here: the risk-free interest rate is 0. In subsequent articles in this series, we will modify this assumption and discuss the changes in the model when introducing a risk-free interest rate. This means that our present value (PV) is equal to the future value (FV) without discounting. In addition, we also need to assume that the fee collection ends when the price reaches the market boundary and does not continue to be collected and reinvested. We can now start our first simple pricing model:

E[V]=E[LP]+E[Fee]

LP

For an LP with a value of $1, we have a piecewise function for the value of LP at any time, normalized as follows: H=ph/S0/, L=pl/S0, Pt​=St​​/S0

​​Since our strategy requires us to hold until τ, Pt​ can only take on two values: L and H. We can calculate the value of our LP as:

In our example, we have:

The expected value of LP is calculated as follows:

0.5∗LP(H)+0.5∗LP(L)=0.9334553114807631

This means that LP is expected to incur a loss of 7%. Can the fees compensate for this?

Fee

This part is also very intuitive. fee=τϕ, where ϕ is the fee collection rate. We need to make an additional assumption: liquidity at any price is equivalent to current liquidity, meaning liquidity is the same at any price.

Therefore, it is not difficult to see that fee income is positively correlated with the liquidity we provide. That is,
ϕ(H,L)=daily total fee*liq/generalized_total_liq ∗365

Here, the total fee is the fee collection rate, which can be calculated based on trading volume multiplied by the pool’s fee ratio. The liquidity can be obtained by querying the liquidity on etherscan, for example, at https://etherscan.io/address/0x88e6a0c2ddd26feeb64f039a2c41296fcb3f5640#readContract:

total liq=21997540583974984595total liq=21997540583974984595

For the fee, the relevant detail derivation can be found in the appendix.
The formula is

The expected fee income is:

Substituting the relevant parameters, the expected fee income is 0.04400312313890215.

Considering that our LP is expected to incur a loss of 7%, the fee income is not enough to cover the cost.

Objective Function

Through the above derivation, we conclude that this parameterization of market-making is not feasible. Can we select the optimal market-making range? We just need to rearrange the formula and use some simple calculus.

Simplifying, we have:

Should we maximize E[V]? Not. Earning $1 per hour is better than earning $10 per day. Therefore, our optimization objective function is about the annual return rate:

If

we can substitute it into the formula and differentiate it to select the optimal market-making range. However, this equation is not valid due to Jensen’s inequality, which states that expectations cannot be exchanged in order. Therefore, we need to directly calculate the expectation of the left side of the equation, which only contains the random variable τ. According to the calculation formula for expectations, we have

In the next post, we will use the third martingale to derive the distribution of τ.

Appendix: V3 LP Math

There are many excellent posts available for the derivation of LP V3. In this post, we need to address three additional issues:

  1. To facilitate pricing, we need the initial investment amount to be $1.
  2. We need to convert EVM liquidity into real-world liquidity, which requires us to review the calculations in smart contracts.
  3. P0​x+y=1, where x is the amount of ETH we invest in liquidity and y is the amount of USDC.

Assuming that we provide liquidity in the range PL​<P0​<PH, we can solve for the values of x and y based on the liquidity increase rule and the constraint of total investment. This allows us to determine the value of L.

In the whitepaper, we have the following formula:

In https://atiselsts.github.io/pdfs/uniswap-v3-liquidity-math.pdf, it is further simplified as
x, y, P, pa, pb are related as follows:

By substituting x and y into the total investment of $1, with Pc​=P0​, we obtain

For us, we have the following relationship:

How to convert the current liquidity data from the smart contract back to the generalized world is the question we will discuss next. If we can convert it back, we will be able to calculate the fee collected easily.

Refer to https://uniswapv3book.com/milestone_1/calculating-liquidity.html and the related code. We can derive as follows:

In the EVM world, Lvm​ has some modifications due to the limitations and gas optimization of Solidity. For example, the price format is also different from the real world. However, the formulas are consistent. For example,

For the EVM Liq, we need to make some substitutions. The real-world price has decimals, which need to be converted into unitless prices in the EVM. The decimals for USDC, USDT, and ETH are 6, 18, and 18, respectively.

References

  1. Shreve, S.E. (2004) Stochastic Calculus for Finance II Continuous-Time Models. Springer, Berlin.
  2. Jensen’s inequality: https://en.wikipedia.org/wiki/Jensen's_inequality

--

--