Amaru's tastes are Cobb-Douglas with spending shares a_i that add up to 1: with income m and prices p_i he buys x_i = a_i m / p_i of every good, and the utility of a bundle is U = \prod_i x_i^{a_i}.
This year prices moved from old_prices to new_prices, and his income from old_income to new_income. Each year he buys his best bundle at that year's prices and income. Write raise_kept_up(shares, old_prices, new_prices, old_income, new_income) that returns a tuple (verdict, needed, old_basket):
verdict:"better","worse"or"same", comparing this year's utility with last year's. Count them as the same whenabs(new_utility / old_utility - 1) <= 1e-9.needed: the income that would give him exactly last year's utility at the new prices.old_basket: what last year's bundle would cost at the new prices.
Examples
Input: shares = {"rent": 0.4, "food": 0.6}, old_prices = {"rent": 10, "food": 2},
new_prices = {"rent": 10, "food": 3}, old_income = 1000, new_income = 1150
Output: ('worse', 1275.42450063, 1300.0)
Explanation: last year he bought 40 units of rent and 300 of food. That basket now costs
400 + 900 = 1300, but by moving some spending from food to rent he could match last year's utility with
1275.42. A 15% raise to 1150 falls short of both.
Input: the same, with new_income = 1300
Output: ('better', 1275.42450063, 1300.0)
Explanation: he could buy last year's basket again, and by switching away from the
dearer food he does even better.
Input: shares = {"bus": 0.5, "lunch": 0.5}, old_prices = {"bus": 1, "lunch": 1},
new_prices = {"bus": 4, "lunch": 1}, old_income = 100, new_income = 200
Output: ('same', 200.0, 250.0)
Constraints
neededandold_basketare compared with a relative tolerance of1e-6
Goals
- Judge whether a consumer is better or worse off by comparing maximised utilities
- Find the income that restores the old utility at the new prices
- See why the cost of the old basket overstates that income: consumers substitute