What a Kilo of Apples Fetches

competitive equilibrium · numeraire · relative price · market clearing

The village trades wool (good 1) and apples (good 2). Household i owns (e_{i1}, e_{i2}) kg and has Cobb-Douglas tastes with wool share a_i: at prices (p_1, p_2) its income is m_i = p_1 e_{i1} + p_2 e_{i2} and it demands x_{i1} = a_i m_i / p_1 kg of wool and x_{i2} = (1 - a_i) m_i / p_2 kg of apples.

Doubling both prices changes nobody's choices, so only the relative price is pinned down. Take wool as the numeraire: its price is fixed at p_1 = 1, and p_2 is then the number of kilos of wool that one kilo of apples trades for.

A competitive equilibrium is a price p_2 > 0 at which both markets clear: the households together want exactly the wool and exactly the apples they own between them. (With two goods it is enough to clear one market: by Walras' law, the value of the excess demands is zero, so the other then clears too.)

Write clearing_price(shares, endowments) that returns a tuple (p2, allocation): the equilibrium price of apples with p_1 = 1, and the list of bundles (x1, x2) the households choose at that price, in the input order.

Examples

Input:  shares = [0.4, 0.5], endowments = [(20, 0), (0, 60)]
Output: (0.4, [(8.0, 30.0), (12.0, 30.0)])
Explanation: at p2 = 0.4 the shepherd's wool is worth 20 and the orchard's apples 24.
They want 8 + 12 = 20 kg of wool and 30 + 30 = 60 kg of apples: exactly what exists.

Input:  shares = [0.25, 0.75], endowments = [(6, 3), (2, 9)]
Output: (0.66666667, [(2.0, 9.0), (6.0, 3.0)])
Explanation: both incomes are 8 kg of wool's worth; the first household trades 4 kg of
wool for 6 kg of apples, the second does the opposite.

Constraints

  • answers are compared with a relative tolerance of 1e-6; do not round

Goals

  • Fix one good as the numeraire and look for the relative price of the other
  • Find the price at which the market for a good clears, by algebra or by bisection
  • Report the equilibrium allocation and check that it uses up exactly the goods that exist
Starting Python…