Algorithm Search⌘K

Algorithmcore

Tatonnement

Also called Walrasian tatonnement, Walrasian auctioneer.

Raises the prices of goods in excess demand and lowers the others. In continuous time it converges under gross substitutes; discrete versions also need small enough steps.

Time
O(T n m) worst
Space
O(m) extra
Where
T = the number of rounds; m = the number of goods; n = the number of buyers
Properties
deterministiciterative
Origin
Leon Walras, Kenneth Arrow, Leonid Hurwicz, H. D. Block, Herbert Scarf, 1874

Tatonnement, French for groping, is the oldest algorithm for finding market prices. An imaginary auctioneer calls out prices, asks every agent what she would buy, and then raises the price of each good that is wanted more than it is supplied and lowers the price of each good that is left over. No trade happens until the prices balance. Walras (1874) used the process to argue that markets find their competitive equilibrium, and it is the model behind most later price-adjustment algorithms. Its rest points are exactly the equilibria, but it does not always reach them. Arrow, Block and Hurwicz (1959) proved that the continuous-time process converges when goods are gross substitutes, and Scarf (1960) built a market in which it cycles forever. Discrete versions, the ones a computer runs, also need step sizes small enough for the market at hand.

In plain words

The auctioneer starts with some prices. Each person says how much of each good she wants at these prices. If people want more of a good than there is, its price goes up a bit. If some of it is left over, its price goes down a bit. Then everyone answers again. When every good is used up exactly, the prices are right and trade starts. This works well when goods can replace each other, like tea and coffee: when tea becomes expensive, people buy more coffee. It can fail when goods are used together, like left and right shoes. Then the prices can go round in circles. Steps that are too large can also make prices jump past the right value again and again.

The problem

There are mm divisible goods with supplies sj>0s_j > 0. The market is given by its excess demand z(p)∈Rmz(p) \in \mathbb{R}^m: at positive prices pp, zj(p)z_j(p) is the total demand for good jj minus sjs_j. The algorithm uses zz as a black box, one call per round. The usual assumptions are those of a market with locally nonsatiated agents and well-defined demand:

  • zz is continuous on positive prices and zj(p)≥−sjz_j(p) \ge -s_j (demand is never negative);
  • z(λp)=z(p)z(\lambda p) = z(p) for λ>0\lambda > 0 (only relative prices matter);
  • Walras' law: p⋅z(p)=0p \cdot z(p) = 0 (every agent spends all her money).

The task is to find p>0p > 0 with z(p)=0z(p) = 0, or an approximate equilibrium with ∣zj(p)∣≤εsj|z_j(p)| \le \varepsilon s_j for every jj. In a Fisher market with nn buyers, the demand of each buyer is computed from her budget and utility at pp, so a round costs O(nm)O(nm) time for the usual utility classes.

The demand is gross substitutes (for divisible goods) if raising the price of one good never lowers the demand for any other good; strict gross substitutes asks that it strictly raises it. CES utilities (∑jaijxjρ)1/ρ(\sum_j a_{ij} x_j^\rho)^{1/\rho} with 0<ρ<10 < \rho < 1 give gross substitutes, and Cobb-Douglas utilities (ρ→0\rho \to 0) are the borderline case. The gross substitutes page treats the version of this condition for indivisible items.

The algorithm

  1. TATONNEMENT(excess demand z, supplies s, start p0 > 0, step λ ∈ (0, 1), rounds T, tolerance ε)
  2. 1p ← p0
  3. 2for t = 0, 1, ..., T - 1 do
  4. 3z ← z(p)
  5. 4if |z_j| / s_j ≤ ε for every good j then return (p, t, converged)
  6. 5p_j ← p_j · (1 + λ · min(z_j / s_j, 1)) for every good j
  7. 6return (p, T, whether |z_j(p)| / s_j ≤ ε for every j)

Line L5 is a multiplicative rule of the kind studied by Cole and Fleischer (2008). The relative excess demand is capped at 11, so one round at most multiplies a price by 1+λ1 + \lambda. Since zj/sj≥−1z_j / s_j \ge -1, the factor is at least 1−λ>01 - \lambda > 0, so prices stay positive. The classical additive rule p←p+λz(p)p \leftarrow p + \lambda z(p) is the Euler method for the differential equation p˙=z(p)\dot{p} = z(p), the continuous tatonnement of Arrow and Hurwicz. The implementation has both rules, in floating point, and excess demand functions for Cobb-Douglas, CES and linear Fisher markets and for Scarf's economy.

Example

Take the Fisher check value: budgets 11 and 11, one unit of each of two goods, linear utilities u1=(2,1)u_1 = (2, 1) and u2=(1,2)u_2 = (1, 2). The equilibrium prices are (1,1)(1, 1). As long as p2/p1p_2 / p_1 lies strictly between 1/21/2 and 22, buyer 1 spends her budget on good 1 and buyer 2 on good 2, so zj=1/pj−1z_j = 1/p_j - 1. With λ=1/2\lambda = 1/2 and pj≥1/2p_j \ge 1/2, line L5 gives pj←pj+(1−pj)/2p_j \leftarrow p_j + (1 - p_j)/2, which halves the distance to 11. From p0=(0.8,1.4)p^0 = (0.8, 1.4), pt=(1−0.2/2t,  1+0.4/2t)p^t = (1 - 0.2 / 2^t, \; 1 + 0.4 / 2^t).

tt pp zz
0 (0.8,1.4)(0.8, 1.4) (0.25,−0.2857)(0.25, -0.2857)
1 (0.9,1.2)(0.9, 1.2) (0.1111,−0.1667)(0.1111, -0.1667)
2 (0.95,1.1)(0.95, 1.1) (0.0526,−0.0909)(0.0526, -0.0909)
3 (0.975,1.05)(0.975, 1.05) (0.0256,−0.0476)(0.0256, -0.0476)

With ε=10−9\varepsilon = 10^{-9}, line L4 stops after 29 updates. Note that the linear demand is not a function where a buyer is indifferent, for example at p=(2,1)p = (2, 1); the implementation raises an error there, and tatonnement as defined here needs a demand function.

Scarf's economy. Three agents and three goods; agent jj owns one unit of good jj and wants goods jj and j+1j + 1 (indices mod 3) in equal amounts, a Leontief utility. The equilibrium prices are the multiples of (1,1,1)(1, 1, 1). Along the continuous process both ∑jpj2\sum_j p_j^2 and ∏jpj\prod_j p_j stay constant, so from (1.2,1.0,0.8)(1.2, 1.0, 0.8) the prices circle the equilibrium forever. The additive rule with λ=0.1\lambda = 0.1 is worse: ∑jpj2\sum_j p_j^2 grows from 3.083.08 to about 3.0973.097 after 100 rounds and 3.5283.528 after 1000, and prices turn negative after about 10410^4 rounds.

Correctness

The proof is in proofs/correctness.md. It shows:

  1. With 0<λ<10 < \lambda < 1, prices stay positive, and a price vector is a rest point of line L5 if and only if it is an equilibrium. When line L4 returns, pp is an ε\varepsilon-approximate equilibrium.
  2. In a Fisher market with Cobb-Douglas utilities, zj=cj/pj−1z_j = c_j / p_j - 1 with cjc_j the money spent on good jj, and once pj≥cj/2p_j \ge c_j / 2 line L5 shrinks pj−cjp_j - c_j by the factor 1−λ1 - \lambda each round. The prices converge to the equilibrium cc at a geometric rate.
  3. The continuous process p˙=z(p)\dot{p} = z(p) converges to the equilibrium ray under strict gross substitutes (Arrow, Block and Hurwicz 1959). The proof uses the Lyapunov function max⁡jpj/pj∗\max_j p_j / p^*_j: the goods with the highest ratio to the equilibrium prices have negative excess demand, so their prices fall.
  4. In Scarf's economy, Walras' law gives ddt∑jpj2=2p⋅z=0\frac{d}{dt} \sum_j p_j^2 = 2 p \cdot z = 0, and ∑jzj/pj=0\sum_j z_j / p_j = 0 gives ddt∑jlog⁡pj=0\frac{d}{dt} \sum_j \log p_j = 0. The orbit from a point off the equilibrium ray never reaches it, and the additive rule increases ∑jpj2\sum_j p_j^2 by λ2∥z∥2\lambda^2 \|z\|^2 in every round.
Proof: Rest points of tatonnement are equilibria, and when it convergesfull

Fix mm goods with supplies sj>0s_j > 0 and an excess demand function zz on positive price vectors with zj(p)≥−sjz_j(p) \ge -s_j. Line L5 of the algorithm maps pp to F(p)F(p) with Fj(p)=pj(1+λmin⁡(zj(p)/sj,1))F_j(p) = p_j (1 + \lambda \min(z_j(p)/s_j, 1)) and 0<λ<10 < \lambda < 1.

Claim 1 (positive prices). If p>0p > 0 then F(p)>0F(p) > 0. Proof. zj/sj≥−1z_j / s_j \ge -1, so the factor 1+λmin⁡(zj/sj,1)1 + \lambda \min(z_j/s_j, 1) is at least 1−λ>01 - \lambda > 0. □\square

Claim 2 (rest points). For p>0p > 0, F(p)=pF(p) = p if and only if z(p)=0z(p) = 0. Proof. Fj(p)=pjF_j(p) = p_j with pj>0p_j > 0 holds exactly when min⁡(zj/sj,1)=0\min(z_j/s_j, 1) = 0, that is, when zj=0z_j = 0. □\square

Claim 3 (output). If line L4 returns at round tt, then ∣zj(p)∣≤εsj|z_j(p)| \le \varepsilon s_j for every jj, so pp is an ε\varepsilon-approximate equilibrium. If line L6 reports convergence, the same holds for the returned pp. Proof. Both lines test exactly this condition on the returned vector. ■\blacksquare

The algorithm runs at most TT rounds, so it always stops. Whether it converges depends on the market, as the next claims show.

Claim 4 (Cobb-Douglas Fisher markets). Let buyer ii have budget ei>0e_i > 0 and spend the fixed share aij≥0a_{ij} \ge 0 of it on good jj, with ∑jaij=1\sum_j a_{ij} = 1, and let each good have supply 11 and cj=∑iaijei>0c_j = \sum_i a_{ij} e_i > 0. Then zj(p)=cj/pj−1z_j(p) = c_j / p_j - 1, the unique equilibrium is p=cp = c, and from any p0>0p^0 > 0 the iterates of line L5 converge to cc. Once pj≥cj/2p_j \ge c_j / 2, Fj(p)−cj=(1−λ)(pj−cj)F_j(p) - c_j = (1 - \lambda)(p_j - c_j).

Proof. Buyer ii buys aijei/pja_{ij} e_i / p_j units of good jj, so the demand for good jj is cj/pjc_j / p_j and zj=cj/pj−1z_j = c_j / p_j - 1, which is 00 exactly when pj=cjp_j = c_j. Each coordinate of FF depends only on its own price, so fix jj.

If pj≥cj/2p_j \ge c_j / 2, then zj≤1z_j \le 1 and Fj(p)=pj+λpj(cj/pj−1)=pj+λ(cj−pj)F_j(p) = p_j + \lambda p_j (c_j/p_j - 1) = p_j + \lambda (c_j - p_j), so Fj(p)−cj=(1−λ)(pj−cj)F_j(p) - c_j = (1 - \lambda)(p_j - c_j). The new price lies between pjp_j and cjc_j, so it is again at least cj/2c_j / 2.

If pj<cj/2p_j < c_j / 2, then zj>1z_j > 1 and Fj(p)=(1+λ)pjF_j(p) = (1 + \lambda) p_j. After at most ⌈log⁡1+λ(cj/(2pj))⌉\lceil \log_{1 + \lambda}(c_j / (2 p_j)) \rceil such rounds the price is at least cj/2c_j / 2, and it is then below (1+λ)cj/2<cj(1 + \lambda) c_j / 2 < c_j.

After that, ∣pj−cj∣|p_j - c_j| shrinks by the factor 1−λ1 - \lambda in every round, so it is at most εcj\varepsilon c_j after O(log⁡(1/ε)/λ)O(\log(1/\varepsilon) / \lambda) more rounds. □\square

Claim 5 (the check value). In the Fisher market with budgets (1,1)(1, 1), unit supplies and linear utilities u1=(2,1)u_1 = (2, 1), u2=(1,2)u_2 = (1, 2), with λ=1/2\lambda = 1/2 and p0=(0.8,1.4)p^0 = (0.8, 1.4), the iterates are pt=(1−0.2/2t,  1+0.4/2t)p^t = (1 - 0.2/2^t, \; 1 + 0.4/2^t). Proof. While 1/2<p2/p1<21/2 < p_2 / p_1 < 2, buyer 1 has bang per buck 2/p1>1/p22/p_1 > 1/p_2 on good 1 and buyer 2 has 2/p2>1/p12/p_2 > 1/p_1 on good 2, so each buyer spends her budget 11 on her own good, and zj=1/pj−1z_j = 1/p_j - 1. This is the case c=(1,1)c = (1, 1) of Claim 4, so pjt+1−1=(pjt−1)/2p^{t+1}_j - 1 = (p^t_j - 1)/2 as long as pjt≥1/2p^t_j \ge 1/2. The formula holds at t=0t = 0, and by induction for every tt: the iterates have p1∈[0.8,1)p_1 \in [0.8, 1) and p2∈(1,1.4]p_2 \in (1, 1.4], so p2/p1∈(1,1.75]p_2 / p_1 \in (1, 1.75] stays inside (1/2,2)(1/2, 2) and both prices stay above 1/21/2. □\square

Claim 6 (Arrow, Block and Hurwicz). Let zz be continuously differentiable on R>0m\mathbb{R}^m_{> 0}, homogeneous of degree 00, satisfy Walras' law p⋅z(p)=0p \cdot z(p) = 0, and have strict gross substitutes: ∂zj/∂pk>0\partial z_j / \partial p_k > 0 for all k≠jk \ne j. Let p∗>0p^* > 0 be an equilibrium. Then the equilibrium prices are exactly the multiples of p∗p^*, and every solution of p˙=z(p)\dot{p} = z(p) with p(0)>0p(0) > 0 converges to cp∗c p^* with c=∥p(0)∥/∥p∗∥c = \|p(0)\| / \|p^*\|.

Proof. Step 1. Let p>0p > 0 not be a multiple of p∗p^*. Let r=max⁡jpj/pj∗r = \max_j p_j / p^*_j and JJ the set of goods that attain it. Then zj(p)<0z_j(p) < 0 for every j∈Jj \in J. Indeed, let q=rp∗q = r p^*, so z(q)=z(p∗)=0z(q) = z(p^*) = 0 by homogeneity, qj=pjq_j = p_j for j∈Jj \in J, and qk>pkq_k > p_k for k∉Jk \notin J, a nonempty set. On the segment q+σ(p−q)q + \sigma (p - q), σ∈[0,1]\sigma \in [0, 1], the derivative of zjz_j for j∈Jj \in J is ∑k∉J(∂zj/∂pk)(pk−qk)<0\sum_{k \notin J} (\partial z_j / \partial p_k)(p_k - q_k) < 0, since every term has a positive derivative and a negative difference. So zj(p)<zj(q)=0z_j(p) < z_j(q) = 0. In the same way, the goods with the smallest ratio pj/pj∗p_j / p^*_j have zj(p)>0z_j(p) > 0. In particular pp is not an equilibrium, which proves the first statement.

Step 2. Let V(p)=max⁡jpj/pj∗V(p) = \max_j p_j / p^*_j and W(p)=min⁡jpj/pj∗W(p) = \min_j p_j / p^*_j. Along a solution, V(p(t))V(p(t)) has the right derivative max⁡j∈Jzj(p(t))/pj∗\max_{j \in J} z_j(p(t)) / p^*_j, the largest derivative among the coordinates that attain the maximum, and by Step 1 this is negative whenever p(t)p(t) is not a multiple of p∗p^*. So VV does not increase, and in the same way WW does not decrease. Also ddt∥p∥2=2p⋅z(p)=0\frac{d}{dt} \|p\|^2 = 2 p \cdot z(p) = 0. Hence the solution stays in the compact set K={p:W(p(0))p∗≤p≤V(p(0))p∗,  ∥p∥=∥p(0)∥}K = \{p : W(p(0)) p^* \le p \le V(p(0)) p^*, \; \|p\| = \|p(0)\|\} of positive vectors, on which zz is C1C^1, so the solution exists for all t≥0t \ge 0.

Step 3. V(p(t))V(p(t)) is nonincreasing and bounded below, so it has a limit V∞V_\infty. Let pˉ\bar{p} be a limit point of p(tk)p(t_k) for some tk→∞t_k \to \infty; it exists because KK is compact, and V(pˉ)=V∞V(\bar{p}) = V_\infty by continuity. Suppose pˉ\bar{p} is not a multiple of p∗p^*. By Step 2, the solution φ\varphi that starts at pˉ\bar{p} has V(φ(τ))<V(pˉ)=V∞V(\varphi(\tau)) < V(\bar{p}) = V_\infty for some τ>0\tau > 0. Solutions depend continuously on the initial point, so p(tk+τ)→φ(τ)p(t_k + \tau) \to \varphi(\tau) and V(p(tk+τ))→V(φ(τ))<V∞V(p(t_k + \tau)) \to V(\varphi(\tau)) < V_\infty, against V(p(t))≥V∞V(p(t)) \ge V_\infty for all tt. So every limit point is a multiple of p∗p^* with norm ∥p(0)∥\|p(0)\|, and the only such point is cp∗c p^*. A path in a compact set whose only limit point is cp∗c p^* converges to it. □\square

Discrete rules with a fixed step need more: a step that is too large can overshoot even under gross substitutes. Codenotti, McCune and Varadarajan (2005) and Cole and Fleischer (2008) prove convergence of discrete rules with suitable steps; the implementation only tests convergence on CES markets with a small step.

Claim 7 (Scarf's economy cycles). Let agent jj (indices mod 3) own one unit of good jj and have the Leontief utility min⁡(xj,xj+1)\min(x_j, x_{j+1}). Then

zj(p)=pj−1pj−1+pj−pj+1pj+pj+1,z_j(p) = \frac{p_{j-1}}{p_{j-1} + p_j} - \frac{p_{j+1}}{p_j + p_{j+1}},

the equilibria are the multiples of (1,1,1)(1, 1, 1), both ∥p∥2\|p\|^2 and p1p2p3p_1 p_2 p_3 are constant along p˙=z(p)\dot{p} = z(p), and the additive rule p←p+λz(p)p \leftarrow p + \lambda z(p) satisfies ∥p+λz∥2=∥p∥2+λ2∥z∥2\|p + \lambda z\|^2 = \|p\|^2 + \lambda^2 \|z\|^2.

Proof. Agent jj has income pjp_j and buys pj/(pj+pj+1)p_j / (p_j + p_{j+1}) units of goods jj and j+1j + 1. Good jj is bought by agents jj and j−1j - 1, so its excess demand is pj/(pj+pj+1)+pj−1/(pj−1+pj)−1p_j / (p_j + p_{j+1}) + p_{j-1} / (p_{j-1} + p_j) - 1, which is the formula above. For p>0p > 0, zj(p)=0z_j(p) = 0 means pj−1(pj+pj+1)=pj+1(pj−1+pj)p_{j-1}(p_j + p_{j+1}) = p_{j+1}(p_{j-1} + p_j), that is pj−1pj=pj+1pjp_{j-1} p_j = p_{j+1} p_j, that is pj−1=pj+1p_{j-1} = p_{j+1}. With three goods, these three equations say that all prices are equal. So the equilibria are exactly the multiples of (1,1,1)(1, 1, 1).

Walras' law: p⋅z=∑jpjpj−1/(pj−1+pj)−∑jpjpj+1/(pj+pj+1)=0p \cdot z = \sum_j p_j p_{j-1} / (p_{j-1} + p_j) - \sum_j p_j p_{j+1} / (p_j + p_{j+1}) = 0, because the two sums are the same sum over the three pairs of neighbors. Then ddt∥p∥2=2p⋅z=0\frac{d}{dt} \|p\|^2 = 2 p \cdot z = 0, and ∥p+λz∥2=∥p∥2+2λp⋅z+λ2∥z∥2=∥p∥2+λ2∥z∥2\|p + \lambda z\|^2 = \|p\|^2 + 2 \lambda p \cdot z + \lambda^2 \|z\|^2 = \|p\|^2 + \lambda^2 \|z\|^2.

For the product, ∑jzj/pj=∑jpj−12−pj2pj−1pj(pj−1+pj)\sum_j z_j / p_j = \sum_j \frac{p_{j-1}^2 - p_j^2}{p_{j-1} p_j (p_{j-1} + p_j)} after shifting the index of the second sum by one, and each term is pj−1−pjpj−1pj=1pj−1pj−1\frac{p_{j-1} - p_j}{p_{j-1} p_j} = \frac{1}{p_j} - \frac{1}{p_{j-1}}, which sums to 00 around the cycle. So ddt∑jlog⁡pj=∑jzj/pj=0\frac{d}{dt} \sum_j \log p_j = \sum_j z_j / p_j = 0.

On the sphere ∥p∥=R\|p\| = R of positive vectors, the product p1p2p3p_1 p_2 p_3 has its unique maximum at the equilibrium (R/3)(1,1,1)(R/\sqrt{3})(1, 1, 1), by the inequality of arithmetic and geometric means applied to pj2p_j^2. A solution that starts at a positive point off the equilibrium ray keeps its norm and its smaller product, so it stays at a positive distance from every equilibrium and never converges. The additive rule increases ∥p∥2\|p\|^2 by λ2∥z∥2>0\lambda^2 \|z\|^2 > 0 in every round in which pp is not an equilibrium. □\square

Complexity

A round costs one evaluation of zz plus O(m)O(m) time; in a Fisher market with linear, CES or Cobb-Douglas utilities an evaluation takes O(nm)O(nm), so TT rounds take O(Tnm)O(Tnm) time and O(m)O(m) extra space. The number of rounds is the hard part. In the Cobb-Douglas case it is O(log⁡(1/ε)/λ)O(\log(1/\varepsilon) / \lambda) once prices are within a factor 2 of equilibrium. Codenotti, McCune and Varadarajan (2005) proved that a discrete tatonnement reaches an approximate equilibrium in polynomial time for markets with weak gross substitutes, and Cole and Fleischer (2008) bounded the rate of convergence of multiplicative updates for several classes of markets. Without gross substitutes there is no bound in general: the process may cycle.

Properties

  • Local information. Each price moves only according to the excess demand of its own good. No agent reports her utility; the auctioneer only asks for demands.
  • Rest points are equilibria. With positive prices, pp is fixed by line L5 exactly when z(p)=0z(p) = 0.
  • Scale invariant. Since zz is homogeneous of degree 00, multiplying p0p^0 by a constant multiplies every iterate by it.
  • Not monotone. Unlike the DGS auction, prices can go up and down.
  • Float arithmetic. The output is approximate. To get an exact equilibrium of a linear market, use a combinatorial method such as the DPSV algorithm.

Variants and improvements

  • Continuous time. p˙j=zj(p)\dot{p}_j = z_j(p), or p˙j=hj(zj(p))\dot{p}_j = h_j(z_j(p)) for sign-preserving functions hjh_j. Arrow and Hurwicz (1958) and Arrow, Block and Hurwicz (1959) proved global stability under gross substitutes.
  • Gradient view. For Fisher markets, Cheung, Cole and Devanur (2020) showed that a multiplicative tatonnement is a generalized gradient descent on a convex function of the prices. This gives convergence for some markets beyond gross substitutes. Proportional response dynamics is a related method that updates bids instead of prices, as mirror descent on a convex program.
  • Ascending auctions. With indivisible items and money, the Kelso-Crawford process and the DGS auction only raise prices, in discrete steps, and stop at an exact Walrasian equilibrium.
  • Global methods. For markets without gross substitutes, the Scarf algorithm finds approximate equilibria by simplicial path following, at the cost of an exponential worst case.

When to use it

Use it as a model of how prices react in a decentralized market, and as an algorithm when the demand has gross substitutes and only demand queries are available, for example in a simulation where agents are black boxes. For exact equilibria of linear Fisher markets use the Eisenberg-Gale program or a combinatorial algorithm. For markets with complements, use a method with a convergence guarantee for that class, or expect cycles.

Pitfalls

  • A step λ\lambda that is too large in line L5 makes prices overshoot. In the tests, CES Fisher markets with ρ=3/4\rho = 3/4 converge with λ=0.2\lambda = 0.2, but one of them fails to converge in 5000 rounds with λ=1/2\lambda = 1/2. Gross substitutes alone does not make every discrete step size work.
  • Without the cap min⁡(zj/sj,1)\min(z_j / s_j, 1) in line L5, a good with huge excess demand at a tiny price gets a huge jump, and the next round may overshoot by a large factor.
  • The additive rule p←p+λzp \leftarrow p + \lambda z can make prices negative. In Scarf's economy it does so after enough rounds, and even before that it spirals outward.
  • The stopping test in line L4 must be relative to the supplies sjs_j. An absolute test on zjz_j means different things for goods with supplies of very different size.
  • Line L3 needs a demand function. With linear utilities the demand is a set at prices where a buyer is indifferent, and these are exactly the equilibrium prices of many markets; the excess demand there must be chosen, and a naive choice can make the prices jump around the equilibrium.

Implementations

Each implementation follows the pseudocode above. A comment @line links a line of code to a line of the pseudocode. Point at a line of the pseudocode to see the matching code. The build runs the native tests of each language.

tatonnement.pyI0RawGitHub
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/tatonnement/. The authors are listed in prov/ZA6PKF.jsonl.
"""Discrete tatonnement: move each price in the direction of its excess demand.

A market is given by an excess demand function z(p) -> list of floats, one per good, and the
supply s_j of each good. The multiplicative rule p_j <- p_j (1 + step * min(z_j / s_j, 1)) keeps
prices positive for 0 < step < 1. The additive rule p <- p + step * z is the Euler scheme of the
continuous process dp/dt = z(p) of Arrow, Block and Hurwicz. All arithmetic is floating point;
convergence means max_j |z_j| / s_j <= tol.
"""


def tatonnement(excess, p0, step, rounds, tol, supply=None):
    """Run the multiplicative rule. Return (p, t, converged), where t is the number of updates."""
    m = len(p0)
    s = supply or [1.0] * m
    p = [float(q) for q in p0]  # @line L1
    for t in range(rounds):  # @line L2
        z = excess(p)  # @line L3
        if max(abs(z[j]) / s[j] for j in range(m)) <= tol:  # @line L4
            return p, t, True
        p = [p[j] * (1 + step * min(z[j] / s[j], 1.0)) for j in range(m)]  # @line L5
    z = excess(p)
    return p, rounds, max(abs(z[j]) / s[j] for j in range(m)) <= tol  # @line L6


def tatonnement_additive(excess, p0, step, rounds):
    """Run the additive rule p <- p + step * z(p) and return the list of all price vectors."""
    path = [[float(q) for q in p0]]
    for _ in range(rounds):
        p = path[-1]
        z = excess(p)
        path.append([p[j] + step * z[j] for j in range(len(p))])
    return path


# Excess demand functions of some markets with one unit of each good.

def fisher_cobb_douglas(a, budgets):
    """Fisher market, buyer i spends the share a[i][j] of her budget on good j."""
    def z(p):
        return [sum(a[i][j] * budgets[i] for i in range(len(a))) / p[j] - 1 for j in range(len(p))]
    return z


def fisher_ces(a, budgets, rho):
    """Fisher market with CES utilities (sum_j a_ij x_ij^rho)^(1 / rho), 0 != rho < 1.
    For 0 < rho < 1 the goods are gross substitutes."""
    sigma = 1 / (1 - rho)

    def z(p):
        out = [-1.0] * len(p)
        for i, row in enumerate(a):
            denom = sum(row[k] ** sigma * p[k] ** (1 - sigma) for k in range(len(p)) if row[k] > 0)
            for j in range(len(p)):
                if row[j] > 0:
                    out[j] += budgets[i] * row[j] ** sigma * p[j] ** (-sigma) / denom
        return out
    return z


def fisher_linear(u, budgets):
    """Fisher market with linear utilities, where each buyer has a single best good. The demand is
    not a function at prices where a buyer is indifferent, so those prices raise an error."""
    def z(p):
        out = [-1.0] * len(p)
        for i, row in enumerate(u):
            bang = [row[j] / p[j] for j in range(len(p))]
            best = max(bang)
            top = [j for j in range(len(p)) if bang[j] == best]
            if len(top) > 1:
                raise ValueError("buyer %d has several best goods" % i)
            out[top[0]] += budgets[i] / p[top[0]]
        return out
    return z


def scarf(p):
    """Scarf's exchange economy: consumer j owns one unit of good j and wants goods j and j + 1 in
    equal amounts (indices mod 3). The equilibrium prices are the multiples of (1, 1, 1)."""
    m = len(p)
    return [p[j - 1] / (p[j - 1] + p[j]) - p[(j + 1) % m] / (p[j] + p[(j + 1) % m]) for j in range(m)]
test_tatonnement.py 105 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/tatonnement/. The authors are listed in prov/ZA6PKF.jsonl.

import random
import unittest

from tatonnement import (fisher_cobb_douglas, fisher_ces, fisher_linear, scarf, tatonnement,
                         tatonnement_additive)


class TestTatonnement(unittest.TestCase):
    def test_check_value(self):
        # Linear Fisher market of the page: while p_1 / p_2 stays in (1/2, 2), z_j = 1 / p_j - 1
        # and the step with factor 1/2 halves the distance to (1, 1).
        z = fisher_linear([[2, 1], [1, 2]], [1, 1])
        p = [0.8, 1.4]
        for t in range(1, 8):
            p, _, _ = tatonnement(z, p, 0.5, 1, 0.0)
            self.assertAlmostEqual(p[0], 1 - 0.2 / 2 ** t, delta=1e-12)
            self.assertAlmostEqual(p[1], 1 + 0.4 / 2 ** t, delta=1e-12)
        p, t, ok = tatonnement(z, [0.8, 1.4], 0.5, 200, 1e-9)
        self.assertTrue(ok)
        self.assertAlmostEqual(p[0], 1.0, delta=1e-8)
        self.assertAlmostEqual(p[1], 1.0, delta=1e-8)

    def test_linear_tie_has_no_demand_function(self):
        z = fisher_linear([[2, 1], [1, 2]], [1, 1])
        with self.assertRaises(ValueError):
            z([2.0, 1.0])

    def test_cobb_douglas_contracts(self):
        rng = random.Random(1)
        for _ in range(20):
            n, m = rng.randint(1, 4), rng.randint(1, 4)
            a = []
            for _ in range(n):
                w = [rng.random() for _ in range(m)]
                a.append([v / sum(w) for v in w])
            budgets = [rng.uniform(0.5, 3) for _ in range(n)]
            c = [sum(a[i][j] * budgets[i] for i in range(n)) for j in range(m)]
            z = fisher_cobb_douglas(a, budgets)
            step = rng.uniform(0.1, 0.9)
            p = [cj * rng.uniform(0.5, 3) for cj in c]
            for _ in range(10):
                q, _, _ = tatonnement(z, p, step, 1, 0.0)
                for j in range(m):
                    self.assertAlmostEqual(q[j] - c[j], (1 - step) * (p[j] - c[j]), delta=1e-9)
                p = q
            p, _, ok = tatonnement(z, p, step, 10000, 1e-10)
            self.assertTrue(ok)
            for j in range(m):
                self.assertAlmostEqual(p[j], c[j], delta=1e-8)

    def test_ces_markets_converge(self):
        rng = random.Random(2)
        for rho in [0.75, 0.5, 0.25, -1.0]:
            for _ in range(5):
                a = [[rng.uniform(0.1, 1) for _ in range(3)] for _ in range(3)]
                budgets = [rng.uniform(0.5, 2) for _ in range(3)]
                z = fisher_ces(a, budgets, rho)
                p, _, ok = tatonnement(z, [1.0, 1.0, 1.0], 0.2, 5000, 1e-9)
                self.assertTrue(ok)
                self.assertAlmostEqual(sum(p), sum(budgets), delta=1e-7)

    def test_large_step_can_fail(self):
        # With rho = 3/4 demand is elastic, and the step 1/2 overshoots on one of these markets.
        rng = random.Random(2)
        results = []
        for _ in range(5):
            a = [[rng.uniform(0.1, 1) for _ in range(3)] for _ in range(3)]
            budgets = [rng.uniform(0.5, 2) for _ in range(3)]
            z = fisher_ces(a, budgets, 0.75)
            results.append(tatonnement(z, [1.0, 1.0, 1.0], 0.5, 5000, 1e-9)[2])
        self.assertIn(False, results)

    def test_scarf_identities(self):
        rng = random.Random(3)
        for _ in range(100):
            p = [rng.uniform(0.1, 5) for _ in range(3)]
            z = scarf(p)
            self.assertAlmostEqual(sum(p[j] * z[j] for j in range(3)), 0.0, delta=1e-12)
            self.assertAlmostEqual(sum(z[j] / p[j] for j in range(3)), 0.0, delta=1e-9)
            z2 = scarf([7 * q for q in p])
            for j in range(3):
                self.assertAlmostEqual(z[j], z2[j], delta=1e-12)
        self.assertEqual(scarf([1.0, 1.0, 1.0]), [0.0, 0.0, 0.0])

    def test_scarf_does_not_converge(self):
        step = 0.1
        path = tatonnement_additive(scarf, [1.2, 1.0, 0.8], step, 1000)
        for t in range(1000):
            p, q = path[t], path[t + 1]
            z = scarf(p)
            norm_p = sum(v * v for v in p)
            norm_q = sum(v * v for v in q)
            # Walras' law makes the additive step move away from the origin.
            self.assertAlmostEqual(norm_q, norm_p + step * step * sum(v * v for v in z), delta=1e-9)
            self.assertGreater(norm_q, norm_p)
            self.assertGreater(max(abs(v) for v in z), 0.05)
        _, _, ok = tatonnement(scarf, [1.2, 1.0, 0.8], 0.1, 3000, 1e-3)
        self.assertFalse(ok)


if __name__ == "__main__":
    unittest.main()

History

Walras (1874) described the groping of prices by which a market finds its equilibrium, with no trade before prices balance. Arrow and Hurwicz (1958) and Arrow, Block and Hurwicz (1959) studied the process as a differential equation and proved that it is globally stable when goods are gross substitutes. Scarf (1960) showed with an economy with complementary goods that the process can cycle forever, so no general stability theorem holds. Computer science returned to tatonnement as a distributed algorithm: Codenotti, McCune and Varadarajan (2005) proved polynomial-time convergence to approximate equilibria for weak gross substitutes, Cole and Fleischer (2008) studied fast multiplicative updates and ongoing markets, and Cheung, Cole and Devanur (2020) explained tatonnement in Fisher markets as gradient descent.

References

  1. Leon Walras, Elements d'economie politique pure, Corbaz, Lausanne, 1874, the theory of exchange (the groping, or tatonnement, by which prices of goods in excess demand rise and the others fall)
  2. Kenneth J. Arrow and Leonid Hurwicz, On the stability of the competitive equilibrium, I, Econometrica 26(4), 522-552 (1958), the whole paper (local and global stability of the continuous process, gross substitutes)
  3. Kenneth J. Arrow, H. D. Block and Leonid Hurwicz, On the stability of the competitive equilibrium, II, Econometrica 27(1), 82-109 (1959), the whole paper (global stability of continuous tatonnement for any number of goods under gross substitutes)
  4. Herbert Scarf, Some examples of global instability of the competitive equilibrium, International Economic Review 1(3), 157-172 (1960), the whole paper (exchange economies with complementary goods in which the continuous process cycles)
  5. Bruno Codenotti, Benton McCune and Kasturi Varadarajan, Market equilibrium via the excess demand function, Proceedings of the 37th ACM Symposium on Theory of Computing (STOC 2005), 74-83, the whole paper (a discrete tatonnement that reaches an approximate equilibrium in polynomial time under weak gross substitutes)
  6. Richard Cole and Lisa Fleischer, Fast-converging tatonnement algorithms for one-time and ongoing market problems, Proceedings of the 40th ACM Symposium on Theory of Computing (STOC 2008), the whole paper (multiplicative price updates and their rate of convergence)
  7. Yun Kuen Cheung, Richard Cole and Nikhil R. Devanur, Tatonnement beyond gross substitutes? Gradient descent to the rescue, Games and Economic Behavior 123 (2020), the whole paper (tatonnement in Fisher markets as gradient descent on a convex function)

About this page

The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.

LadderLevelWhat the next level needs
Human proofH1 sketch
  • a full proof of time.worst
  • a full proof of space.extra
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
Code (python)I0 not checked yet
  • the tests did not run in this build
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW2 basic
  • a scene preset for the example