Trading Dev AcademyFree quant education

Free lesson · DeFi models

LP inventory after price changes

Open interactive lessonPractice calculationsExplore labs

Start with the idea

A constant-product pool sells the rising asset and accumulates the falling asset as arbitrage aligns its reserve ratio with an external price.

Symbols, units & horizon
  • x: base reserve
  • y: quote reserve
  • p: external quote/base price
  • k: constant reserve product in base×quote units
  • arbitrage-aligned no-fee state at one checkpoint

When and why to use this

Explain how liquidity provision changes token exposure as market prices move.

A constant-product pool sells the rising asset and accumulates the falling asset as arbitrage aligns its reserve ratio with an external price.

For a no-fee pool with invariant k, external price p in quote per base implies y/x=p. Solve this together with xy=k to determine inventory.

A provider’s claim is a share of the resulting reserves, not a fixed number of the original tokens. Fees and deposits change invariant or ownership share; hold them fixed in this first model.

x(p)=kp,y(p)=kp
Model assumptions, derivation and arithmetic

LP inventory after price changes

  1. From price alignment write y=px.
  2. Substitute into xy=k to get px²=k and solve the positive root for x.
  3. Multiply x by p to get y; verify both reserve product and price ratio.
Work it by hand

k=1,000,000 base×quote, p=400 quote/base: x=sqrt(2500)=50 base and y=sqrt(400000000)=20,000 quote.

Apply it in a strategy

  • Explain how liquidity provision changes token exposure as market prices move.
  • Record the input timestamp, executable quantity, currency and horizon. Reconcile the result with a cash-flow or state table.
  • Stress this failure condition: An oracle or arbitrage delay means the pool may not actually be aligned with the external price at the observation time.

Research deliverable

Build and explain a lp inventory after price changes worksheet. Explain how liquidity provision changes token exposure as market prices move.

Evidence boundary: Synthetic arithmetic and scenarios illustrate mechanics. They are not historical returns, a paper replication, or evidence of an executable edge. Research sources and their access limitations are recorded at the end of this module.

Python implementation

Self-contained teaching example. Python 3.10+; dependencies and input conventions are shown in the code and notation. Run in your own Python environment.

# Python 3.10+; standard library unless NumPy is imported below.
# Inputs and outputs use the units defined in this lesson. Synthetic teaching example.
from math import sqrt
def pool_inventory(invariant,price):
    if invariant<=0 or price<=0: raise ValueError("Positive invariant and price required")
    return sqrt(invariant/price),sqrt(invariant*price)

print(pool_inventory(1_000_000,400))

Continue learning

DeFi: AMMs, Liquidity Provision and Lending — all lessons
  1. Constant-product swaps with an input fee
  2. LP inventory after price changes
  3. LP value versus holding the original tokens
  4. Concentrated liquidity and range boundaries
  5. LVR and the price of stale inventory
  6. Lending utilization and rate response
  7. Collateral health factor and correlated shocks
  8. Liquidation incentives after execution costs

Quantitative finance and development glossary · Python resources and libraries · Research sources and limitations