Study materials · photonresources.comClasses with our teachers · Photon AcademyFor IB Diploma students worldwide

Maths IA · Calculus · topic 32 of 97

Swapping crypto without a market: the constant-product rule · IB Maths IA idea: guide, sample graph and step-by-step plan

one rule sets every price

Some exchanges have no buyers and sellers at all. A pool holds two kinds of token, and one rule sets every price: the amounts multiplied together never change. You will find out what that rule does to the price you get.

Difficulty●●○ Medium
KitA spreadsheet or graphing software, your GDC, the published rules of one exchange pool
TimeAbout 12 to 15 hours
FitsAA SL3 of 3AA HL3 of 3AI SL2 of 3AI HL3 of 3
  • ✓ you like a simple rule whose consequences take real work to see
  • ✓ you want a context for implicit differentiation and optimisation
  • ✓ you want to study how a trading rule behaves, not give investment advice

The big idea

Let a pool hold x of token X and y of token Y, with x·y = k kept constant by every trade. The graph is a hyperbola. The price of X in terms of Y is y/x, which is minus the gradient of the curve. Show that with implicit differentiation, not only by dividing. A trade moves the pool along the curve, so a large trade gets a worse price than the quoted one. You can find the exact amount received and how the shortfall, called slippage, grows with trade size. Then ask what happens to a person who put tokens into the pool when the outside price moves. Their loss compared with just holding has a neat formula in the price ratio r, and its derivative and symmetry are classic calculus. Keep the focus on the mathematics of the rule, not on predicting any price.

Make it yours: pick one twist

Copying a classic won't show your choices. Pick one of these (or invent your own) and your IA becomes yours.

Swipe for more twists →

Price as a gradient

Differentiate x·y = k implicitly to get dy/dx = −y/x and compare it with the slope of the curve y = k/x.

→ Two routes to one result, so you can check one against the other. Explain what the negative sign means for a trader.
Exact amount for a trade

Find the tokens received for a trade of size dx and compare with the quoted price times dx.

→ A rational function of dx. Study its limit as dx grows and say what it means for the largest possible trade.
Slippage against trade size

Define slippage as the fall from the quoted price and find how it depends on dx / x.

→ A function of one ratio, so every pool size gives the same curve. Show why, and use it to compare pools.
Add a fee

Charge 0.3% of the input before the trade and recompute the output and the pool's constant.

→ k now grows with every trade. Find how much and test your formula by running many trades in a spreadsheet.
Impermanent loss

Compare the pool's value with the value of simply holding the tokens when the price ratio becomes r, and find a formula.

→ A function IL(r) with a maximum at r = 1. Differentiate it, prove the symmetry between r and 1/r, and graph it on a log axis.
Fees against loss

Find the trading volume at which fee income cancels impermanent loss for a given price move.

→ Two models meet in one equation. State what you assume about volume and about price paths.

Your Maths IA research question: run the check

which pool? which quantity?

Write your own question first. Then make sure it ticks every box:

  • Names the rule: the invariant, the fee and the sizes of the pool you test.
  • Names what you find: a price, an output, a slippage curve or the loss compared with holding.
  • Says how formulas are tested: a step-by-step spreadsheet of trades or published pool rules.
  • Uses calculus for something you could not do by arithmetic alone, such as a derivative, a limit or an optimum.
  • States what you leave out: other traders, price paths, gas costs and every claim about future prices.
Stuck on your question?Get an RQ Check: each question is scored on 5 points, with what to fix. Your first one is free.
Get an RQ Check

The model

A pool, one trader and one rule. Draw the pool with your own starting amounts and mark which quantity stays fixed in each step.

the poolx of Xy of Ytraderdx indy outx·y = k stays fixed: more X in means less Y outprice = y / xbigger trade,worse priceno order book: just a rule

How your Maths IA could be laid out

The usual order for a topic like this, what each part needs to show, and roughly how much of your 12 to 20 pages it takes. The words are all yours.

Aim and context~1 page
What a constant-product pool is, why it needs no order book, and what you will find. No view on any price.
The invariant and the price~1.5 pages
The curve, the marginal price from implicit differentiation, and a check against y = k/x.
Trading along the curve~2 pages
Exact output for a trade, slippage as a function of trade size, with a worked example and a limit.
Adding a fee~2 pages
The modified rule, the growth of k, and a spreadsheet of repeated trades against your formula.
Impermanent loss~2.5 pages
Derivation of IL(r), its derivative, its symmetry, and a graph on a log axis with sample values.
Conclusion~1 page
Back to your aim: the price rule, slippage, the fee effect and the loss formula, with numbers.
Evaluation~2 pages, the biggest part!
No outside trading, fixed fee, no price path, simplified loss. Say which assumption matters most and what the model cannot say about real pools.
Bibliographynot counted
Where every rule and parameter came from.

What your Maths IA graph could look like

show the slippage gap

Made-up values to show the form of a strong graph, not the answer: the amount of Y a trader receives against the amount of X paid, compared with the quoted price. Yours will use your own pool. example only

0204060801000100020003000400050006000Tokens of X paid in, dxTokens of Y received, dyexact: y·dx/(x + dx)at the quoted price: (y/x)·dxyour spreadsheet trades (made-up)the gap between thecurves is the slippageILLUSTRATIVE · MADE-UP DATA
  • Exact output and the quoted-price line on one set of axes, so the shortfall is visible.
  • Axis labels give units: tokens of each kind, not money.
  • Plot a few of your spreadsheet trades as points: agreement with the curve is your evidence.
  • Say what the exact curve approaches for very large trades.
  • Another graph to consider: slippage as a percentage against dx / x.

The maths in action

worked through, not sketched!

The graph above was a sketch with made-up numbers. This figure works the idea through from the model itself, so you can see what a finished figure looks like. The source line under it says where every number comes from.

Left: a falling hyperbola with two red points close together on it and a dashed tangent line. Right: an upside-down bell shape on a logarithmic horizontal axis, zero at a ratio of one and falling to minus twenty per cent at ratios of one quarter and four.
(a) A pool of 100 X and 10,000 Y: paying 10 X returns 909 Y (about 90.9 per X, against a quoted 100); with a 0.3% fee, 907 Y. (b) Impermanent loss is -5.7% at a price ratio of 2 or 1/2 and -20% at 4 or 1/4.Source: Computed from the constant-product rule (Adams, Zinsmeister and Robinson, 2020); the pool sizes are made up.

How big a trade hurts the price?

Slippage grows with the size of the trade compared with the pool. Calculate it for several sizes and explain why a large pool is less sensitive.

0.1% of the pool0.1%1% of the pool1%5% of the pool4.8%10% of the pool9.1%25% of the pool20%50% of the pool33.3%a trade of half the pool loses a third of the quoted priceSlippage on a trade, %ILLUSTRATIVE · MADE-UP NUMBERS

Your game plan

Tick steps off as you go. We'll remember on this device.

0 of 10 done

  1. Read and predictRead how a constant-product pool works. Before any algebra, guess whether a trade of ten per cent of the pool costs ten per cent in price.
  2. Set up the poolChoose starting amounts and define x, y, k, the quoted price and the trade. Sketch the curve with your numbers.
  3. Price from the derivativeDifferentiate x·y = k implicitly to find dy/dx, and check it against the derivative of y = k/x.
  4. Trial run (1 lesson)Make a spreadsheet of ten trades and compare it with your formula for the output. Fix any mismatch now: the order of the steps, what k includes, rounding.
  5. SlippageFind the exact output and the shortfall from the quoted price. Show that slippage depends only on the ratio of the trade to the pool.
  6. Add the feeApply a fee to the input, rerun your spreadsheet and find how k grows. Compare the growth with your own formula.
  7. Impermanent lossDerive IL(r) for a price ratio r. Differentiate it, prove IL(r) = IL(1/r) and graph it on a log axis.
  8. Go further, with a reasonCompare fee income with the loss, or change the rule to a different invariant. HL: prove one more property yourself.
  9. Reflect as you goAfter every result, write one line on what it means and what it assumes. These lines become your evaluation.
  10. Cut, check, then sendCheck every graph has labelled axes, every symbol is defined once and the conclusion answers your aim. Then send your teacher one draft.

The maths you'll use

  • Rational functions – Write the output as , find its asymptote and compare it with the straight line given by the quoted price.
  • Implicit differentiation – Differentiate to get and interpret the gradient as the price.
  • Derivative of a quotient – Differentiate , find the stationary point at and justify the maximum.
  • Symmetry and logarithmic scales – Show , so is an even function of , and plot it on a logarithmic axis.
  • Iteration in a spreadsheet – Run many trades with a fee, track , and compare the growth with a formula.

Key equations

Syllabus links

  • 2.8Reciprocal and simple rational functions
  • 5.3Differentiating powers of x
  • 5.6Standard derivatives; chain, product and quotient rules
  • 5.7Second derivative and graph behaviour
  • 5.8Maxima, minima, inflexion and optimisation
  • 5.14Implicit differentiation, related rates, optimisationHL

Read up first

Data and sources to start from

A spreadsheet of trades you generate from the rule, plus the published rules of an exchange pool to choose the fee and the formulas.

References to cite

  1. Adams, H., Zinsmeister, N., & Robinson, D. (2020). Uniswap v2 core.
  2. Stewart, J. (2015). Calculus: Early transcendentals (8th ed.). Cengage Learning. (Implicit differentiation.)

Cite what you actually use, in your own format, and say where each number came from.

Traps to avoid in this Maths IA

no price predictions
  • Treating the quoted price y/x as the price you get. It applies only to an infinitely small trade.
  • Forgetting that a fee changes k, and then wondering why the spreadsheet drifts from your formula.
  • Using money amounts for the tokens without saying how you value them. Keep to token units until you define a price.
  • Calling the impermanent loss a real loss of money. It is a comparison with holding, and it only appears when the price ratio changes.
  • Differentiating without saying with respect to what. Say whether the derivative is dy/dx or dIL/dr.
  • Drifting into advice about which tokens or pools to use. The task is the mathematics of the rule.

More Maths IA ideas like this

Make sure it's yours

This guide shows how a topic like this is usually approached. It is not an IA. Your question, choices, data, analysis and words must be your own: change something, tell your teacher where the idea came from, and follow your school's rules on outside help.

Get your RQ checked · first one free