ChadFulton / tsa-notebooks

Jupyter notebooks on time series econometrics topics.
273 stars 173 forks source link

GDP (Quarterly) Prediction in Mixed Frequency DFM #37

Closed SebKrantz closed 1 year ago

SebKrantz commented 1 year ago

Dear Chad, thanks a lot for the excellent work of implementing these codes in Python. Regarding your example given in this notebook, you compute the quarterly forecast / nowcast from its unobserved monthly counterpart using

# Resample to quarterly frequency by taking the value in the last
# month of each quarter
point_forecasts_q = point_forecasts_m.resample('Q').last()

However, this does not correspond to the internal modelling a la Mariano and Murwasa (2003) or Banbura and Modugno (2014), where the quarterly series growth rate is a weighted average of the unobserved monthly series. I summarized this in this note here:

Screenshot at Mar 01 13-22-52

So, if you follow Banbura and Modugno (2014) as I presume, should not the quarterly forecast be obtained as:

def wma_BM(x):
    return x + 2*x.shift(1) + 3*x.shift(2) + 2*x.shift(3) + x.shift(4)

wma_BM(gdp_forecast)

Final comment on the notebook: the FRED databases are no longer on amazon AWS, the base URL should be changed to:

base_url = 'https://files.stlouisfed.org/files/htdocs/fred-md'
ChadFulton commented 1 year ago

Thanks Sebastian, glad to hear these have been helpful for you!

As long as you specify the quarterly variables using the endog_quarterly argument, then the temporal aggregation structure that you're referring to is built-in to the state space model (accounting for this feature is why the endog_quarterly value exists).

For monthly variables, the observation equation has the form:

$$y_{it}^M = \lambda_i ft + \varepsilon{it}$$

while for quarterly variables, it has the form:

$$y_{it}^Q = (\lambda_i ft + \varepsilon{it}) + 2 (\lambdai f{t-1} + \varepsilon_{it-1}) + 3 (\lambdai f{t-2} + \varepsilon_{it-2}) + 2 (\lambdai f{t-3} + \varepsilon_{it-3}) + (\lambdai f{t-4} + \varepsilon_{it-4})$$

You can confirm this by examining the "design" matrix $Z_t$ of the observation equation:

$$y_t = Z \alpha_t + \varepsilon_t$$

which you can find as results.model['design'].

Final comment on the notebook: the FRED databases are no longer on amazon AWS, the base URL should be changed to:

Thanks for letting me know.

SebKrantz commented 1 year ago

Thanks a lot for the swift response and clarification! My confusion was because the prediction of GDP is a monthly prediction, which made me think you are just returning $\tilde{y}_{it}^m = \lambda_i ft+\epsilon{it}$. I get now from your response that it is a monthly prediction of quarterly growth rates that is being returned. Since this is not very intuitive, it would be good to state this in the documentation for the DynamicFactorMQ class.

ChadFulton commented 1 year ago

Thanks, that is a good idea to note this in the documentation.