The brief
A central bank has published its projected path for the policy rate, quarter by quarter for three years. It starts at today's 5.25% and falls towards 3%, the bank's estimate of the neutral rate. A rates desk models the policy rate with the mean-reversion equation
where is the policy rate, the neutral rate and the speed, per year. The desk wants the speed that fits the projection, how fast the gap closes, and the yield curve the path implies.
Your task
- Write
rate_path(t, r0, theta, k): the solution with , at a time in years or an array of times. RaiseValueErrorfor a negative . - Write
fit_speed(times, rates, theta): the whose path fromrates[0]makes the sum of squared differences fromratessmallest. RaiseValueErrorif the lists differ in length or hold fewer than two points. Raise it too if the times do not start at 0 and increase, or if the path starts attheta. - Write
half_life(k), the time for the gap to halve, andtime_to_within(gap, r0, theta, k). The second is the first time at whichgap, and 0 if that already holds. Both raiseValueErrorif is not positive, andtime_to_withinifgapis not positive. - Write
zero_yield(T, r0, theta, k): the continuous zero-coupon yield to maturity when the short rate follows the path. At it is . RaiseValueErrorfor a negative or .
The data
TIMES holds the 13 quarterly dates in years from today, and PROJECTION the bank's projected rates as decimals, published to 0.05 percentage points. NEUTRAL is the bank's neutral rate. The projection is synthetic.
Hint: Where to start
Lesson 6.1.1 solves by separating the variables: . Lesson 6.1.2 reaches the same answer with an integrating factor.
Hint: Fitting the speed
With and fixed, the path depends on alone, so the fit is a search in one variable. Case study 4.4.5 fits a curve by least squares, and warns that minimize stops early when rates are typed as decimals.
Hint: Yields from the path
Case study 6.1.4 prices a zero-coupon bond under a known short rate, and finds that the yield is the average rate, . The integral of has a closed form.