Cabbages Planted on Last Year's Price

cobweb model · backward-looking expectations · difference equation · stability · simulation

In the valley of Orlen, cabbage farmers must plant months before they sell. Each spring they plant as if this year's price will be the same as last year's. So the harvest of season t is

Q^s_t = c + d\,P_{t-1}

and once the cabbages are picked they must be sold, whatever they fetch. Buyers want Q^d_t = a - b\,P_t cabbages (in tonnes, prices in coins per tonne, with b > 0 and d > 0). The price P_t of season t is the one at which buyers take exactly the harvest: a - b\,P_t = c + d\,P_{t-1}.

The equilibrium price p^* is the price that, once reached, repeats forever (P_t = P_{t-1} = p^*). A gap P_t - p^* between the price and the equilibrium either shrinks every season ("converges"), keeps exactly the same size while flipping sign ("cycles"), or grows ("explodes"). Which one happens is a property of the market, not of the starting price: give the verdict for a start away from p^*, even if p0 happens to equal p^*.

Write cobweb(a, b, c, d, p0, T) that returns a tuple (p_star, prices, verdict) where prices is [P_0, P_1, \ldots, P_T] (T + 1 numbers, starting with p0). Press Run with plot(prices) to watch the zigzag.

Examples

Input:  a = 100, b = 2, c = 10, d = 1.5, p0 = 20, T = 4
Output: (25.71428571, [20, 30.0, 22.5, 28.125, 23.90625], 'converges')
Explanation: last year's 20 makes farmers plant 10 + 1.5 * 20 = 40 tonnes;
buyers take 40 tonnes at (100 - 40) / 2 = 30. The swings shrink towards 25.71.

Input:  a = 100, b = 2, c = 10, d = 2, p0 = 20, T = 3
Output: (22.5, [20, 25.0, 20.0, 25.0], 'cycles')

Input:  a = 100, b = 2, c = 10, d = 3, p0 = 18, T = 3
Output: (18.0, [18, 18.0, 18.0, 18.0], 'explodes')
Explanation: starting exactly at p* the price never moves, but any other start
would swing further and further away.

Constraints

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

Goals

  • Simulate a market where supply is decided a season ahead, on last season's price
  • Clear the market each season by solving demand = harvest for the price
  • Tell from the slopes whether price swings die out, repeat or grow
Starting Python…