1 Introduction

Hodrick and Prescott (1997) filter is a popular trend filtering method for univariate macroeconomic time series such as real gross domestic product (GDP). For example, it has been used for calculating the composite leading indicators of the Organisation for Economic Co-operation and Development since December 2008 (OECD 2012 ). Recent studies of the filter include de Jong and Sakarya (2016), Cornea-Madeira (2017), Hamilton (2018), Sakarya and de Jong (2020), Phillips and Jin (2021), Phillips and Shi (2021), Yamada (2015, 2018a, b, 2020, 2022), and Yamada and Jahra (2019). It is defined by

$$\begin{aligned} \min _{x_{1},\ldots ,x_{T}\in \mathbb {R}}\, f_{\mathrm {HP}}(x_{1},\ldots ,x_{T})=\sum _{t=1}^{T}(y_{t}-x_{t})^{2}+\psi \sum _{t=3}^{T}(\Delta ^{2} x_{t})^{2}, \end{aligned}$$
(1)

where \(y_{1},\ldots ,y_{T}\) denote T observations of an economic time series, \(\psi \) is a positive smoothing parameter that controls fidelity and smoothness, and \(\Delta \) denotes a difference operator such that \(\Delta x_{t}=x_{t}-x_{t-1}\) and accordingly \(\Delta ^{2} x_{t}=\Delta x_{t}-\Delta x_{t-1}=x_{t}-2x_{t-1}+x_{t-2}\).

Quantile regression was developed by Koenker and Bassett (1978). It is the regression defined by

$$\begin{aligned} \min _{\varvec{\beta }\in \mathbb {R}^{p}}\,\sum _{t=1}^{T}\rho _{\tau }\left( y_{t}-\varvec{x}_{t}'\varvec{\beta }\right) , \end{aligned}$$
(2)

where \(\rho _{\tau }(u)\) denotes the check function defined by

$$\begin{aligned} \rho _{\tau }(u) = {\left\{ \begin{array}{ll} \tau |u| &{} \text {if}~{ u\ge 0},\\ (1-\tau )|u| &{} \text {if}~{u<0}, \end{array}\right. } \end{aligned}$$
(3)

where \(\tau \in (0,1)\). See Fig. 1, which depicts \(\rho _{\tau }(u)\) for \(\tau =0.1,0.5,0.9\). Thus, it includes least absolute deviations as its special case. One of the essential properties of the \(\tau \) quantile regression above is that if the regression includes intercept, the ratio of negative residuals, denoted by N/T, is less than or equal to \(\tau \) and is greater than or equal to \(\tau \) minus the ratio of zero residuals, denoted by Z/T:

$$\begin{aligned} \tau -\frac{Z}{T}\le \frac{N}{T}\le \tau . \end{aligned}$$
(4)

See Theorem 3.4 of Koenker and Bassett (1978) and Theorem 2.2 of Koenker (2005). From (4), for example, if \(\tau =0.1\), then the ratio of negative residuals is at most 10%.

Fig. 1
figure 1

Check functions

In this paper, we consider the quantile regression version of HP filter. It is the filtering method that is defined by replacing quadratic loss function of HP filter with quantile regression loss function. More precisely, it is:

$$\begin{aligned} \min _{x_{1},\ldots ,x_{T}\in \mathbb {R}}\,f(x_{1},\ldots ,x_{T}) =\sum _{t=1}^{T}\rho _{\tau }(y_{t}-x_{t}) +\lambda \sum _{t=3}^{T}(\Delta ^{2} x_{t})^{2}, \end{aligned}$$
(5)

where \(\lambda \) is a positive smoothing parameter. In the paper, we refer to (5) as quantile Hodrick–Prescott (qHP) filter.

Does the suggested qHP filter also have the property given by (4)? It is not a trivial question and is essential for applying the filter. In this paper, we answer this question. For this purpose, we apply the reparameterization used by Paige and Trindade (2010). Other than the main result, we present an empirical example.

This paper is organized as follows. In Sect. 2, we present some preliminary results. In Sect. 3, we present the main results of the paper. In Sect. 4, we present an empirical example. Section 5 concludes the paper. In the Appendix, we provide MATLAB and R user-defined functions for solving the minimization problem (5).

2 Preliminaries

In this section, after fixing notations, we provide some preliminary results.

2.1 Notations

Let \(\varvec{x}=[x_{1},\ldots ,x_{T}]'\), \(\varvec{\iota }=[1,\ldots ,1]'\in \mathbb {R}^{T}\), \(\varvec{z}=[1,\ldots ,T]'\), \(\varvec{I}_{r}\) denote the \(r\times r\) identity matrix, \(\varvec{J}=[\varvec{0},\varvec{I}_{T-2}]\in \mathbb {R}^{(T-2)\times T}\), and \(\varvec{D}\in \mathbb {R}^{(T-2)\times T}\) be the second-order difference matrix such that \(\varvec{D}\varvec{x}=[\Delta ^{2}x_{3},\ldots ,\Delta ^{2}x_{T}]'\), which is explicitly shown in (11). In addition, let

(6)

and accordingly \(\varvec{\Gamma }\) is a \(T\times (T-2)\) matrix. Finally, for a vector \(\varvec{u}=[u_{1},\ldots ,u_{T}]'\), we denote the \(\ell _{p}\)-norm of \(\varvec{u}\) by \(\Vert \varvec{u}\Vert _{p}\), i.e., \(\Vert \varvec{u}\Vert _{p}=(|u_{1}|^{p}+\cdots +|u_{T}|^{p})^{1/p}\).

2.2 Matrix representations of HP and qHP filters

In matrix notation, (1) can be represented as

$$\begin{aligned} \min _{\varvec{x}\in \mathbb {R}^{T}}\,f_{\mathrm {HP}}(\varvec{x})=\Vert \varvec{y}-\varvec{x}\Vert _{2}^{2}+\psi \Vert \varvec{D}\varvec{x}\Vert _{2}^{2}. \end{aligned}$$
(7)

Likewise, given that \(\rho _{\tau }(u)\) in (3) can be represented as \(0.5|u|+(\tau -0.5)u\), we have

$$\begin{aligned} \sum _{t=1}^{T}\rho _{\tau }(y_{t}-x_{t})&=0.5\sum _{t=1}^{T}|y_{t}-x_{t}|+(\tau -0.5)\sum _{t=1}^{T}(y_{t}-x_{t})\nonumber \\&=0.5\Vert \varvec{y}-\varvec{x}\Vert _{1}+(\tau -0.5)\varvec{\iota }'(\varvec{y}-\varvec{x}), \end{aligned}$$
(8)

from which (5) can be represented as follows:

$$\begin{aligned} \min _{\varvec{x}\in \mathbb {R}^{T}}\,f(\varvec{x})=0.5\Vert \varvec{y}-\varvec{x}\Vert _{1}+(\tau -0.5)\varvec{\iota }'(\varvec{y}-\varvec{x}) +\lambda \Vert \varvec{D}\varvec{x}\Vert _{2}^{2}. \end{aligned}$$
(9)

Note that when \(\tau =0.5\), (9) reduces to

$$\begin{aligned} \min _{\varvec{x}\in \mathbb {R}^{T}}\,f(\varvec{x})=0.5\Vert \varvec{y}-\varvec{x}\Vert _{1}+\lambda \Vert \varvec{D}\varvec{x}\Vert _{2}^{2}, \end{aligned}$$
(10)

which is the filtering method that is defined by replacing quadratic loss function of HP filter with absolute loss function and thus it is more robust to outliers than the HP filter.

2.3 Matrices \(\varvec{A}\) and \(\varvec{D}\)

\(\varvec{A}\) in (6) was used by Paige and Trindade (2010) to derive a ridge regression representation of the HP filter. Given that \(|\varvec{A}|=1\), \(\varvec{A}\) is nonsingular. Moreover, from Paige and Trindade (2010), it follows that

(11)

Thus, given that \(\varvec{J}\in \mathbb {R}^{(T-2)\times T}\) is a selection matrix, we have \(\varvec{J}\varvec{A}^{-1}=\varvec{D}\), and it immediately follows that

$$\begin{aligned} \varvec{D}\varvec{A}=\varvec{J}. \end{aligned}$$
(12)

Note that \(\varvec{D}\varvec{\Gamma }=\varvec{I}_{T-2}\), i.e., \(\varvec{\Gamma }\) is a right-inverse matrix of \(\varvec{D}\).

2.4 Solution set of qHP filter

Concerning \(f(\varvec{x})\), we have the following results:

Proposition 2.1

(i) There exists \(\widehat{\varvec{x}}\) such that \(f(\widehat{\varvec{x}})\le f(\varvec{x})\) for any \(\varvec{x}\in \mathbb {R}^{T}\) and (ii) the corresponding solution set is convex.

Proof

See the Appendix. \(\square \)

Remark 2.2

(i) Proposition 2.1(i) indicates that \(\widehat{\varvec{x}}\) is a global minimizer of qHP filter. (ii) MATLAB and R user-defined functions for obtaining \(\widehat{\varvec{x}}\) are given in the Appendix.

2.5 Reparameterization of qHP filter

Let \(\varvec{\theta }=[\theta _{1},\ldots ,\theta _{T}]'\) and \(\widehat{\varvec{\theta }}=[{\widehat{\theta }}_{1},\ldots ,{\widehat{\theta }}_{T}]'\) be T-dimensional column vectors such that \(\varvec{x}=\varvec{A}\varvec{\theta }\) and \(\widehat{\varvec{x}}=\varvec{A}\widehat{\varvec{\theta }}\), respectively. Recall that \(\varvec{A}\) is nonsingular and its first (second) column is \(\varvec{\iota }\) (\(\varvec{z}\)). From (12), we have \(\varvec{D}\varvec{x}=\varvec{D}\varvec{A}\varvec{\theta }=\varvec{J}\varvec{\theta }=[\theta _{3},\ldots ,\theta _{T}]'\in \mathbb {R}^{T-2}\), which leads to

$$\begin{aligned} \Vert \varvec{D}\varvec{x}\Vert _{2}^{2}=\Vert \varvec{J}\varvec{\theta }\Vert _{2}^{2}. \end{aligned}$$
(13)

Accordingly, the objective function of qHP filter can be represented with \(\varvec{\theta }\) as follows:

$$\begin{aligned} f(\varvec{x}) =0.5\Vert \varvec{y}-\varvec{A}\varvec{\theta }\Vert _{1}+(\tau -0.5)\varvec{\iota }'(\varvec{y}-\varvec{A}\varvec{\theta }) +\lambda \Vert \varvec{J}\varvec{\theta }\Vert _{2}^{2}. \end{aligned}$$

Likewise, we obtain \(f(\widehat{\varvec{x}}) =0.5\Vert \varvec{y}-\varvec{A}\widehat{\varvec{\theta }}\Vert _{1}+(\tau -0.5)\varvec{\iota }'(\varvec{y}-\varvec{A}\widehat{\varvec{\theta }}) +\lambda \Vert \varvec{J}\widehat{\varvec{\theta }}\Vert _{2}^{2}\). Given that \(\widehat{\varvec{x}}\) is a global minimizer, combining the above equations yields the inequality such as

$$\begin{aligned}&0.5\Vert \varvec{y}-\varvec{A}\varvec{\theta }\Vert _{1}+(\tau -0.5)\varvec{\iota }'(\varvec{y}-\varvec{A}\varvec{\theta })+\lambda \Vert \varvec{J}\varvec{\theta }\Vert _{2}^{2} =f(\varvec{x})\nonumber \\&\qquad \ge f(\widehat{\varvec{x}}) =0.5\Vert \varvec{y}-\varvec{A}\widehat{\varvec{\theta }}\Vert _{1}+(\tau -0.5)\varvec{\iota }'(\varvec{y}-\varvec{A}\widehat{\varvec{\theta }}) +\lambda \Vert \varvec{J}\widehat{\varvec{\theta }}\Vert _{2}^{2}, \end{aligned}$$
(14)

which shows that \(\widehat{\varvec{\theta }}=\varvec{A}^{-1}\widehat{\varvec{x}}\) is a solution of the penalized quantile regression defined by

$$\begin{aligned} \min _{\varvec{\theta }\in \mathbb {R}^{T}}\,g(\varvec{\theta })=0.5\Vert \varvec{y}-\varvec{A}\varvec{\theta }\Vert _{1}+(\tau -0.5)\varvec{\iota }'(\varvec{y}-\varvec{A}\varvec{\theta }) +\lambda \Vert \varvec{J}\varvec{\theta }\Vert _{2}^{2}. \end{aligned}$$
(15)

This is an alternative representation of qHP filter.

3 The main results

The following result answers the question posed in Sect. 1.

Theorem 3.1

Let N and Z denote the proportion of negative and zero entries of the residual vector \(\varvec{y}-\widehat{\varvec{x}}\,(=\varvec{y}-\varvec{A}\widehat{\varvec{\theta }})\). Then, it follows that

$$\begin{aligned} \tau -\frac{Z}{T}\le \frac{N}{T}\le \tau . \end{aligned}$$
(16)

Proof

Given that \(\widehat{\varvec{\theta }}\) is a global minimizer of a convex function \(g(\varvec{\theta })\) in (15), \(\varvec{0}\) must belong to the subdifferential of \(g(\varvec{\theta })\) at \(\widehat{\varvec{\theta }}\), that is, there must exist the following \(\widehat{\varvec{v}}=[{\widehat{v}}_{1},\ldots ,{\widehat{v}}_{T}]'\) such that

$$\begin{aligned} -0.5\varvec{A}'\widehat{\varvec{v}}-(\tau -0.5)\varvec{A}'\varvec{\iota }+2\lambda \varvec{J}'\varvec{J}\widehat{\varvec{\theta }}=\varvec{0}, \end{aligned}$$
(17)

where

$$\begin{aligned} {\widehat{v}}_{t}\in {\left\{ \begin{array}{ll} \{1\} &{} \text {if }(y_{t}-{\widehat{x}}_{t})>0,\\ {[}-1,1] &{} \text {if }(y_{t}-{\widehat{x}}_{t})=0,\\ \{-1\} &{} \text {if }(y_{t}-{\widehat{x}}_{t})<0, \end{array}\right. } \end{aligned}$$
(18)

for \(t=1,\ldots ,T\). Then, given that the first column of \(\varvec{A}\) is \(\varvec{\iota }\) and \(\varvec{J}'\varvec{J}=\mathsf {diag}(0,0,1,\ldots ,1)\in \mathbb {R}^{T\times T}\), the first row of (17) is \(-0.5\varvec{\iota }'\widehat{\varvec{v}}-(\tau -0.5)\varvec{\iota }'\varvec{\iota }=0\), from which we have

$$\begin{aligned} \varvec{\iota }'\widehat{\varvec{v}}=T-2T\tau . \end{aligned}$$
(19)

In addition, by definition of \(\widehat{\varvec{v}}\) in (18), it follows that \(P-N-Z\le \varvec{\iota }'\widehat{\varvec{v}}\le P-N+Z\), where \(P=T-N-Z\). By eliminating P from these inequalities, we obtain

$$\begin{aligned} T-2(N+Z)\le \varvec{\iota }'\widehat{\varvec{v}}\le T-2N. \end{aligned}$$
(20)

Substituting (19) into (20) yields \(N\le T\tau \le N+Z\). By dividing the inequalities by \(T>0\) and rearranging them, we finally obtain (16). \(\square \)

Remark 3.2

It is notable that the property derives from \(\theta _{1}\) being not penalized in (15). Recall that \(\varvec{J}\varvec{\theta }=[\theta _{3},\ldots ,\theta _{T}]'\).

Next, we provide another property of qHP filter.

Proposition 3.3

Denote the convex solution set of qHP filter by S. If \(\varvec{y}\notin S\), then it follows that

$$\begin{aligned} \Vert \varvec{D}\varvec{y}\Vert _{2}^{2}>\Vert \varvec{D}\widehat{\varvec{x}}\Vert _{2}^{2}. \end{aligned}$$
(21)

Proof

From Proposition 2.1, \(\widehat{\varvec{x}}\) is a global minimizer of \(f(\varvec{x})\) and it thus follows that \(f(\varvec{y})>f(\widehat{\varvec{x}})\) if \(\varvec{y}\notin S\). In addition, given (9), we have \(f(\varvec{y})=\lambda \Vert \varvec{D}\varvec{y}\Vert _{2}^{2}\). Moreover, given that \(\rho _{\tau }(y_{t}-{\widehat{x}}_{t})\ge 0\) for \(t=1,\ldots ,T\), we have \(f(\widehat{\varvec{x}})\ge \lambda \Vert \varvec{D}\widehat{\varvec{x}}\Vert _{2}^{2}\). By combining these results, we obtain

$$\begin{aligned} \lambda \Vert \varvec{D}\varvec{y}\Vert _{2}^{2}=f(\varvec{y})>f(\widehat{\varvec{x}})\ge \lambda \Vert \varvec{D}\widehat{\varvec{x}}\Vert _{2}^{2}, \end{aligned}$$

if \(\varvec{y}\notin S\). Finally, dividing the above inequalities by \(\lambda >0\) leads to (21). \(\square \)

Remark 3.4

(21) corresponds to the property of HP filter presented in Weinert (2007, p. 961) and indicates that \(\widehat{\varvec{x}}\) is smoother than \(\varvec{y}\).

4 An empirical illustration

As an empirical illustration of qHP filter, we estimate several qHP trends of the growth rates of US real GDP and real consumption, which were used in the empirical analysis of Müller and Watson (2018).Footnote 1 To apply qHP filter, we must specify its smoothing parameter \(\lambda \) in (5)/(9). We selected them so that \(\widehat{\varvec{x}}\) may satisfy

$$\begin{aligned} \Vert \varvec{D}\widehat{\varvec{x}}\Vert _{2}^{2}=\Vert \varvec{D}\widehat{\varvec{x}}_{\mathrm {HP}}\Vert _{2}^{2}. \end{aligned}$$
(22)

For obtaining \(\widehat{\varvec{x}}_{\mathrm {HP}}\) in (22), we must specify \(\psi \) in (1)/(7). We used the following three values of \(\psi \):

$$\begin{aligned} \psi =26307.9,133107.9,420602.7. \end{aligned}$$
(23)

They are obtained from

$$\begin{aligned} \psi =\left\{ 2\sin \left( \frac{\pi }{p}\right) \right\} ^{-4},\quad p=80,120,160. \end{aligned}$$
(24)

Note that, given the data frequency is quarterly, \(p=80\), for example, corresponds to 20 years. For details about (24), see Yamada (2022, Sec. 4).Footnote 2 The values of \(\lambda \) corresponding to the values of \(\psi \) in (23) are tabulated in Table 1.

Table 1 The values of \(\lambda \) in (5)/(9) for Figs. 25
Fig. 2
figure 2

Empirical cumulative distribution function plots of residuals, \(\varvec{y}-\widehat{\varvec{x}}\), where \(\varvec{y}\) denotes the growth rates of US real GDP used in the empirical analysis of Müller and Watson (2018) and \(\widehat{\varvec{x}}\) denotes the trends estimated by qHP filter

Fig. 3
figure 3

Empirical cumulative distribution function plots of residuals, \(\varvec{y}-\widehat{\varvec{x}}\), where \(\varvec{y}\) denotes the growth rates of US real consumption used in the empirical analysis of Müller and Watson (2018) and \(\widehat{\varvec{x}}\) denotes the trends estimated by qHP filter

Fig. 4
figure 4

The dashed lines labeled by GDP denote the growth rates of US real GDP used in the empirical analysis of Müller and Watson (2018). The solid lines represent the trends estimated by qHP filter

Fig. 5
figure 5

The dashed lines labeled by CON denote the growth rates of US real consumption used in the empirical analysis of Müller and Watson (2018). The solid lines represent the trends estimated by qHP filter

Figures 234, and 5 show the results. Figure 2 (resp. 3) shows empirical cumulative distribution function plots of residuals, \(\varvec{y}-\widehat{\varvec{x}}\), cumulative distributions of residuals, \(\varvec{y}-\widehat{\varvec{x}}\), where \(\varvec{y}\) denotes the growth rates of US real GDP (resp. consumption) and \(\widehat{\varvec{x}}\) denotes the trends estimated by qHP filter. From the figures, we can observe that in all cases the ratio of negative residuals almost equals the corresponding value of \(\tau \) and these results are consistent with Theorem 3.1. For example, from the top left panel of Fig. 2, we observe that the ratio of negative residuals corresponding to \(\tau =0.9,0.5,0.1\) are nearly equal to 90%, 50%, 10%, respectively. See three bullets in the panel. Figures 4 and 5 show the trends estimated by qHP filter. From these figures, we may observe the estimated 90% (resp. 10%) qHP trends are roughly decreasing (resp. increasing) over the sample period. As a result, the bands of these quantile trends become narrower. We note that these results are consistent with a stylized fact called the Great Moderation in the US economy, which is defined as the decline in macroeconomic volatility starting in the mid-1980s. Here, we would like to stress that such results are never obtainable from applying HP filter.

5 Conclusion

Theorem 3.1 is the main result of the paper. It states that even though qHP filter is a penalized quantile regression, it satisfies one of the essential properties of quantile regression given by (4). The key point is that \(\theta _{1}\) in (15) is not penalized. The empirical results illustrate Theorem 3.1. As a result, it is shown that qHP filter could be a useful macroeconometric tool.