Wool for Apples

exchange economy · endowment · Cobb-Douglas demand · income from prices

In a mountain village nobody earns a wage: every household owns a stock of goods (its endowment) and comes to the market to trade. There are two goods, wool (good 1) and apples (good 2). Household i owns e_{i1} kg of wool and e_{i2} kg of apples, and the market prices are p_1 and p_2 coins per kg.

A household that sold its whole endowment would receive

m_i = p_1 e_{i1} + p_2 e_{i2}

coins, so m_i is its income: it can afford any bundle that costs no more than its endowment is worth. Its tastes are Cobb-Douglas, u_i = x_1^{a_i} x_2^{1 - a_i} with a share 0 < a_i < 1; with income m such a household spends the fraction a_i of it on wool and the rest on apples, so it ends up with

x_{i1} = \frac{a_i\, m_i}{p_1}, \qquad x_{i2} = \frac{(1 - a_i)\, m_i}{p_2}

Write market_demands(shares, endowments, prices) where shares[i] is a_i, endowments[i] is the pair (e_{i1}, e_{i2}) and prices is (p_1, p_2). Return a list with one tuple (x1, x2) per household, in the input order: the bundle it chooses at these prices.

Examples

Input:  shares = [0.4, 0.5], endowments = [(20, 0), (0, 60)], prices = (3, 1)
Output: [(8.0, 36.0), (10.0, 30.0)]
Explanation: the shepherd's 20 kg of wool are worth 60 coins; 40% of 60 buys 8 kg of
wool and the other 36 coins buy 36 kg of apples, so she sells 12 kg of wool. The
orchard's 60 kg of apples are also worth 60 coins: 10 kg of wool and 30 kg of apples.

Input:  shares = [0.4, 0.5], endowments = [(20, 0), (0, 60)], prices = (6, 2)
Output: [(8.0, 36.0), (10.0, 30.0)]
Explanation: doubling both prices doubles every income and every price: nothing changes.

Only relative prices matter here. Add up the wool column: the households want 18 kg but own 20, so at these prices the wool market does not clear.

Constraints

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

Goals

  • Value an endowment at given prices to get a household's income
  • Apply the Cobb-Douglas demand rule $x_1 = a\,m / p_1$, $x_2 = (1 - a)\,m / p_2$ to each household
  • See that scaling every price by the same factor leaves every demand unchanged
Starting Python…