At a wool fair, an auctioneer searches for the price that clears the market by trial. In each round she calls a price P (dollars per bale) and counts:
- bales wanted: D = a - b \cdot P, or
0if that is negative; - bales offered: S = c + d \cdot P, or
0if that is negative.
The excess demand is D - S. If it is positive, buyers are left wanting, so she raises the price; if negative, bales are left over, so she lowers it. Her next call is
where k > 0 is how strongly she reacts (dollars per bale of excess demand). The price never goes below 0.
Write price_path(a, b, c, d, p0, k, rounds) that starts from the call p0, runs rounds rounds, and returns the list of calls: p0 and then the call after each round (rounds + 1 numbers).
A small k creeps towards the price where the two lines cross; a large one overshoots, and can swing for ever. Press Run with plot(price_path(100, 2, -20, 3, 10, 0.1, 30)) and again with k = 0.35 and k = 0.5.
Examples
Input: a = 100, b = 2, c = -20, d = 3, p0 = 10, k = 0.1, rounds = 3
Output: [10, 17.0, 20.5, 22.25]
Explanation: at 10 dollars 80 bales are wanted and 10 offered: the price rises by
0.1 * 70 = 7. At 17: 66 wanted, 31 offered, up by 3.5. The market clears at 24.
Input: a = 100, b = 2, c = -20, d = 3, p0 = 10, k = 0.5, rounds = 4
Output: [10, 45.0, 0, 50.0, 0]
Explanation: at 45 the excess demand is 10 - 115 = -105, and 45 - 52.5 is negative,
so the next call is 0.
Input: a = 100, b = 2, c = -20, d = 3, p0 = 60, k = 0.1, rounds = 2
Output: [60, 44.0, 34.0]
Explanation: at 60 dollars nobody wants wool (not -20 bales), and 160 bales are offered.
Constraints
- answers are compared with a tolerance of
1e-6
Goals
- Simulate a price that moves in the direction of excess demand, round by round
- Apply the floors at zero to quantities and to the price in the stated order
- See that a cautious adjustment converges to the equilibrium and a hasty one overshoots