This vignette works through the modified HP filter of Choudhary, Hanif and Iqbal (2014): the smoothing parameter chosen series by series by the generalised cross-validation of McDermott (1997). It applies the filter to the US quarterly series of the package, sets the results beside those of the paper, and shows how the criterion behaves. The data differ from the paper’s (FRED 1959Q1 to 2009Q3 here; IFS 1957Q1 to 2010Q1 there), so the values are compared, not reproduced.
2 The idea
The HP filter fixes \(\lambda\) by the frequency of the data: 100 for annual, 1600 for quarterly and 129600 for monthly series. Choudhary et al. (2014) argue that one value cannot suit every series and every economy, and choose \(\lambda\) for each series as the minimiser of \[
\mathrm{GCV}(\lambda) = \frac{1}{T}\left(1 + \frac{2T}{\lambda}\right)\sum_{t=1}^{T}\left(x_t - \hat{g}_t(\lambda)\right)^2
\] over \(\lambda = 1, 2, \dots\) (their eq. 6). The vignette “Theory” derives this criterion and its exact form.
Modified HP Filter Result
==============================
Observations: 203
Optimal lambda: 683
GCV: 2.82e-04
Filtered on the log scale; cycle = series - trend in levels
Cycle Statistics:
Mean: 1.044
SD: 91.54
AR1: 0.8554
Range: 561.9
Sources: Hodrick and Prescott (1997); McDermott (1997); Coe and McDermott
(1997); Choudhary et al. (2014); Choudhary et al. (2014, MATLAB code). Full
references: mhp_cite(x).
The criterion against \(\lambda\) has a single interior minimum:
ggplot2::autoplot(object = fit , which ="gcv" )
and the trend and cycle:
ggplot2::autoplot(object = fit , which ="decomposition" )
4 Three US series
mhp_batch() filters the columns of a matrix, each with its own \(\lambda\).
X <-log(as.matrix(us_macro[, c("gdp", "consumption", "investment")]))b <-mhp_batch(X = X , max_lambda =100000 )lam <-attr(x = b, which ="lambdas")lam[, paper :=c(941, 841, 488)]lam
series lambda gcv paper
<char> <int> <num> <num>
1: gdp 683 0.0002819926 941
2: consumption 534 0.0001753795 841
3: investment 1009 0.0063778004 488
The column paper holds the values of Table 2 of Choudhary et al. (2014) for the United States. Ours are of the same order, below the 1600 of the HP filter, but differ series by series: the samples and the vintages of the data are not the same, and the criterion is flat near its minimum, so small changes in the data move \(\lambda\) a long way. Investment has the largest \(\lambda\) here and the smallest in the paper.
plot_batch(x = b , show ="cycle" , facet =TRUE , highlight =NULL )
5 Against the HP filter
mhp_compare() sets the cycle of the HP filter with the conventional \(\lambda\) beside the cycle of the modified filter.
mhp_compare(x =log(us_macro$gdp) , frequency ="quarterly" , max_lambda =100000 )
Choudhary et al. (2014) compare the filters on 30 simulated designs: a random-walk trend with drift and an AR(2) cycle, with six pairs of AR coefficients and five ratios of the standard deviations of the two shocks. mhp_designs(paper = "2014") lists them and mhp_simulate() draws a series from one of them; the vignette “Simulation” runs the comparison.
Choudhary, M. A., Hanif, M. N. and Iqbal, J. (2014). On smoothing macroeconomic time series using the modified HP filter. Applied Economics, 46(19), 2205–2214.
Hodrick, R. J. and Prescott, E. C. (1997). Postwar U.S. business cycles: an empirical investigation. Journal of Money, Credit and Banking, 29(1), 1–16.
McDermott, C. J. (1997). An automatic method for choosing the smoothing parameter in the HP filter. Unpublished manuscript, International Monetary Fund.