Prices for Every Stall at Once

general equilibrium · linear system · Walras' law · Gaussian elimination · Cobb-Douglas

A harbour market has n households and m goods. Household i owns e_{ik} units of good k, so at prices p its income is \sum_k p_k e_{ik}. Its tastes are Cobb-Douglas with positive weights w_{ij}: it spends the share s_{ij} = w_{ij} / \sum_k w_{ik} of its income on good j. A competitive equilibrium is a price vector at which every market clears: for every good j, the households together demand exactly the total E_j = \sum_i e_{ij} that exists.

Good 1 (index 0) is the numeraire, with price 1. Because every weight is positive and every good exists, there is exactly one such price vector, and all its prices are positive.

Write equilibrium_prices(weights, endowments) that returns the list of the m equilibrium prices, starting with 1.0. Any method that gets within the tolerance is allowed; an exact method is the aim here (an iterative price adjustment can need many thousands of rounds when some weights are tiny). Plain Python only: no numpy.

Examples

Input:  weights = [[1, 1, 2], [2, 1, 1]], endowments = [[10, 0, 0], [0, 8, 4]]
Output: [1.0, 0.78125, 2.1875]
Explanation: at these prices the fisher's 10 fish are worth 10 and the salt trader's
goods 8 * 0.78125 + 4 * 2.1875 = 15.0. They demand 2.5 + 7.5 = 10 fish,
3.2 + 4.8 = 8 salt and 2.2857 + 1.7143 = 4 rope: every market clears.

Input:  weights = [[2, 3], [1, 1]], endowments = [[20, 0], [0, 60]]
Output: [1.0, 0.4]

Constraints

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

Goals

  • Turn market clearing with Cobb-Douglas households into a linear system in the prices
  • Use Walras' law to drop one redundant equation and the numeraire to fix one price
  • Solve the remaining system by Gaussian elimination written by hand
Starting Python…