A wave of optimism makes households in Pellas spend more for a while, and its central bank follows a Taylor rule. You will trace what happens, quarter by quarter, in a small model with three equations. Here y_t is the output gap, \pi_t inflation and i_t the bank's policy rate in quarter t; \pi^* is the inflation target and a, b the rule's coefficients.
In quarter t (t = 0, 1, 2, ...) three equations hold, in this order:
- demand (IS): y_t = d_t - \sigma \, (i_{t-1} - \pi_{t-1} - r^*). The output gap y_t (output above normal, as a fraction of normal output) falls when last quarter's real rate i_{t-1} - \pi_{t-1} was above the neutral real rate r^*. The demand shock is d_t = \text{shock} \cdot \rho^t: it hits in quarter 0 and fades by the factor \rho each quarter (\rho^0 = 1, also when \rho = 0).
- Phillips curve: \pi_t = \pi_{t-1} + \kappa \, y_t. Inflation rises while output is above normal.
- policy rule: i_t = r^* + \pi_t + a \, (\pi_t - \pi^*) + b \, y_t, using this quarter's inflation and gap.
Before the shock (quarter -1) the economy is at rest: y_{-1} = 0, \pi_{-1} = \pi^* and i_{-1} = r^* + \pi^*. All rates are yearly rates written as fractions (2 % is 0.02), although the model steps one quarter at a time; sigma >= 0 and kappa >= 0 say how strongly demand reacts to the real rate and inflation to the gap.
The bank is a feedback controller: it measures inflation and the gap, and its rate acts on demand one quarter later.
Write after_the_shock(e, a, b, T) that returns a tuple (gaps, inflation, rates): the lists y_t, \pi_t and i_t for quarters t = 0, 1, ..., T - 1. The rule has no floor in this problem.
The tests build each economy with the helper economy(sigma, kappa, r_star, pi_star, shock, rho), which returns the dict {"sigma": sigma, "kappa": kappa, "r_star": r_star, "pi_star": pi_star, "shock": shock, "rho": rho}; you may use it too.
Press Run with plot(inflation, label="inflation"), plot(rates, label="rate") and plot(gaps, label="gap") to see the impulse response: how the economy rings after one push.
Examples
Input: e = economy(1.0, 0.2, 0.01, 0.02, 0.02, 0.5), a = 0.5, b = 0.5, T = 3
Output: ([0.02, -0.002, 0.0042], [0.024, 0.0236, 0.02444], [0.046, 0.0344, 0.03876]) (rounded here)
Explanation: quarter 0: last quarter's real rate was neutral, so y = 0.02 (the shock);
pi = 0.02 + 0.2 * 0.02 = 0.024; i = 0.01 + 0.024 + 0.5 * 0.004 + 0.5 * 0.02 = 0.046.
Quarter 1: the shock is 0.01, but the real rate 0.046 - 0.024 = 0.022 is 0.012 above
neutral, so y = 0.01 - 0.012 = -0.002.
Input: e = economy(1.0, 0.2, 0.01, 0.02, 0.02, 0.5), a = 0, b = 0, T = 3
Output: ([0.02, 0.01, 0.005], [0.024, 0.026, 0.027], [0.034, 0.036, 0.037]) (rounded here)
Explanation: with a = b = 0 the real rate never moves from neutral, so the gap just
follows the shock and inflation ratchets up and stays up.
Constraints
- answers are compared with a tolerance of
1e-6; do not round
Goals
- Simulate a small economy of demand, inflation and a policy rule quarter by quarter
- Respect the timing: demand reacts to last quarter's rate, the rule to this quarter's data
- Compare a rule that obeys the Taylor principle with one that does not