This package estimates the cyclical component of a time series by the simple regression-based method proposed in: James D. Hamilton (2018): Why You Should Never Use the Hodrick-Prescott Filter Review of Economics and Statistics, Volume 100 | Issue 5 (December), p.831-843 https://doi.org/10.1162/rest_a_00706 In particular, the variable is regressed on some own lags starting by default 2*pd periods ago (where pd is the periodicity of the data), and the residuals of that (projection) regression are directly taken as the cyclical component. hamilcycle (public function) ============================ Returns: series of the cyclical component Arguments: * series: "series to decompose" * bool: "plot result?" (optional, default TRUE / produce plot) * string: "custom title" (optional, override the automatic plot title, default null / use automatic title) * matrix pointer: "trend placeholder" (optional, a matrix pointer to capture the trend component [see below], default null) * matrix: "custom lags" (optional, override the default set of lags used as regressors, default null) The default setup is to use lags starting from twice the periodicity of the data and including as many terms as the periodicity. This means: - Annual data: Lag 2 only - Quarterly data: Lags 8 through 11 - Monthly data: Lags 24 through 35 You can override this choice with the 5th (final) argument and pass a vector specifying exactly which lags to use. Hamilton's focus seems to be on the cyclical component. Nonetheless, you can extract the implied trend component if you pass a pointer to a (pre-defined) matrix as the 4th (penultimate) argument. The reason why this is not given as a series is that in this context the trend component (or at least the final observations) refers to the future beyond the current sample range. For example, with the information from the final observation T it is possible to construct the predicted value (yhat) for period T+h, where h is the starting lag used in the projection. That value is called g_T in Hamilton, but through the posited relation cyclical_t = y_t - g_{t-h} it is natural that g_T corresponds to period T+h. Therefore, the constructed trend component that can be extracted covers up to the out-of-sample period T+h, which depends on the periodicity of the data (or on the possible user override of the lag structure). --------- Changelog v1.1, June 2021: fix show-stopping bug when the variable has neither a graph name nor a descriptive string in its attributes v1.0, March 2021: first release (based on idea by Jack Lucchetti)