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.
LP inventory after price changes
- From price alignment write y=px.
- Substitute into xy=k to get px²=k and solve the positive root for x.
- Multiply x by p to get y; verify both reserve product and price ratio.
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- Constant-product swaps with an input fee
- LP inventory after price changes
- LP value versus holding the original tokens
- Concentrated liquidity and range boundaries
- LVR and the price of stale inventory
- Lending utilization and rate response
- Collateral health factor and correlated shocks
- Liquidation incentives after execution costs
Quantitative finance and development glossary · Python resources and libraries · Research sources and limitations