Let's Forecast Interest Rates
You will now use the forecasting techniques you learned in the last exercise and apply it to real data rather than simulated data. You will revisit a dataset from the first chapter: the annual data of 10-year interest rates going back 56 years, which is in a Series called interest_rate_data. Being able to forecast interest rates is of enormous importance, not only for bond investors but also for individuals like new homeowners who must decide between fixed and floating rate mortgages.
You saw in the first chapter that there is some mean reversion in interest rates over long horizons. In other words, when interest rates are high, they tend to drop and when they are low, they tend to rise over time. Currently they are below long-term rates, so they are expected to rise, but an AR model attempts to quantify how much they are expected to rise.
The class ARIMA and the function plot_predict have already been imported.
Deze oefening maakt deel uit van de cursus
Time Series Analysis in Python
Oefeninstructies
- Create an instance of the
ARIMAclass calledmodusing the annual interest rate data and choosing theorderfor an AR(1) model. - Fit the model
modusing the method.fit()and save it in a results object calledres. - Plot the data and the in-sample and out-of-sample forecasts of the data using the
.plot_predict()function.- The first argument of
plot_predict()should be the fitted model. - Pass the arguments
start=0to start the in-sample forecast from the beginning, and chooseendto be '2027' to forecast several years in the future. - Note that the
endargument 2027 must be in quotes here since it represents a date and not an integer position.
- The first argument of
Praktische interactieve oefening
Probeer deze oefening eens door deze voorbeeldcode in te vullen.
# Forecast interst rates using an AR(1) model
mod = ARIMA(interest_rate_data, order=___)
res = mod.fit()
# Plot the data and the forecast
fig, ax = plt.subplots()
interest_rate_data.plot(ax=ax)
plot_predict(___, start=___, end=___, alpha=None, ax=ax)
plt.show()