Fixed Shares of the Pay Packet

Cobb-Douglas utility · demand function · budget shares · dictionaries

A household's tastes over several goods are described by Cobb-Douglas utility. Each good i has a positive weight w_i; dividing by the total weight W = \sum_i w_i gives exponents a_i = w_i / W that add up to 1, and the utility of buying quantities x_i is

U = \prod_i x_i^{a_i}

Maximising this utility with income m and prices p_i gives a famous result (the lesson derives it): the household spends the fixed share a_i of its income on good i, so it buys

x_i = \frac{a_i \, m}{p_i}

Write fixed_shares(weights, prices, income) that returns a tuple (demand, utility): a dict with the quantity x_i of every good, and the utility U of that bundle. weights and prices are dicts with the same names.

Try changing one price or the income with Run: doubling a good's price halves the amount bought of it and leaves the others alone, and doubling the income doubles every quantity (and the utility).

Examples

Input:  weights = {"books": 0.3, "food": 0.7}, prices = {"books": 12, "food": 4}, income = 240
Output: ({'books': 6.0, 'food': 42.0}, 23.42717266)
Explanation: 30% of 240 is 72, which buys 72 / 12 = 6 books; 70% is 168, which buys
168 / 4 = 42 units of food. U = 6 ** 0.3 * 42 ** 0.7.

Input:  weights = {"books": 3, "food": 7}, prices = {"books": 12, "food": 8}, income = 240
Output: ({'books': 6.0, 'food': 21.0}, 14.42111637)
Explanation: weights 3 and 7 give the same exponents 0.3 and 0.7. Food now costs twice as
much, so the household buys half as much of it; the spending on books does not change.

Constraints

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

Goals

  • Apply the Cobb-Douglas demand rule $x_i = a_i m / p_i$ to several goods
  • Normalise weights into exponents that add up to 1
  • See that demand for a good falls in proportion to its own price and rises in proportion to income
Starting Python…