The board of the central bank of Pellas wants to pick the coefficients a and b of its Taylor rule. It scores each candidate rule by simulating the same demand shock in a small model of the economy. Here y_t is the output gap, \pi_t inflation and i_t the policy rate in quarter t; \pi^* is the inflation target.
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.
A rule's loss over quarters t = 0, 1, ..., T - 1 adds the squared miss of the inflation target and, with weight lam >= 0, the squared output gap, both measured in percentage points (so a miss of 0.004 counts as 0.4):
The rule has no floor in this problem. This is how a control engineer tunes a controller: simulate, score, compare.
Write tune_rule(e, a_values, b_values, lam, T) that tries every pair (a, b) with a from a_values and b from b_values, and returns a tuple (a, b, loss) for the pair with the lowest loss. If several pairs share the lowest loss exactly, return the one that comes first when the pairs are listed with a in the order of a_values and, for each a, b in the order of b_values.
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.
Examples
Input: e = economy(1.0, 0.2, 0.01, 0.02, 0.02, 0.5), a_values = [0, 0.5, 1.5],
b_values = [0, 0.5, 1.0], lam = 0.5, T = 20
Output: (1.5, 0.5, 3.0799314) (rounded here)
Explanation: the passive rule a = b = 0 leaves inflation 0.8 points above target for
good and scores 11.73 + 0.5 * 5.33 = 14.40. The pair (1.5, 1.0) reacts so hard that the
economy swings back and forth and scores 1291.24. The pair (1.5, 0.5) scores 3.08.
Input: e = economy(0.0, 0.2, 0.01, 0.02, 0.02, 0.5), a_values = [0.5, 1.5],
b_values = [0.5, 0.25], lam = 1, T = 10
Output: (0.5, 0.5, 10.6679114) (rounded here)
Explanation: with sigma = 0 the rate does not affect demand, so every rule scores the
same, and the first pair wins.
Constraints
- answers are compared with a tolerance of
1e-6; do not round
Goals
- Score a policy rule by simulating the economy and adding up squared misses
- Search a grid of rule coefficients for the lowest loss, with a stated tie rule
- See how the weight on output changes which rule is best