1 Introduction

Many economic time series like GDP increase steadily over time. A simple way to describe such upward trends is to consider a linear model of the data \(y_t\) on a deterministic time trend plus a noise component (Enders 1995; Greene 2003; Hamilton 1994):

$$\begin{aligned} y_t = \alpha + \delta t + \varepsilon _t. \end{aligned}$$
(1)

Processes with such representation are typically described as trend stationary, in the sense that if one subtracts the trend \(\alpha + \delta t\) from (1), the result is a stationary process, that is, whose mean and autocovariances do not depend on the date t. However, this regression technique may not be appropriate to detrend series whose growth component is time varying, depends on other endogenous or exogenous conditions, or is stochastic. In fact, macroeconomic time series are frequently represented by the random walk plus drift model, a special case of unit root processes:

$$\begin{aligned} y_t = y_{t-1} + \delta + \varepsilon _t. \end{aligned}$$
(2)

Given the initial condition \(y_0\), the general solution for this difference equation is (Enders 1995):

$$\begin{aligned} y_t = y_{0} + \delta t + \sum _{i=1}^{t} \varepsilon _t. \end{aligned}$$
(3)

Thus, detrending a process such (2) is not sufficient to eliminate the stochastic trend \(\sum \varepsilon _t\) where each shock \(\varepsilon _i\) with \(i \le t\) has a permanent effect on the mean of \(y_t\). Nevertheless, its representation in first-differences:

$$\begin{aligned} \Delta y_t \equiv (1 - L) y_t = y_t - y_{t-1} = \delta + \varepsilon _t, \end{aligned}$$
(4)

where L is the lag operator, is stationary. Thus, the random walk with drift is an example of a difference stationary model that can be transformed into a stationary process by differencing (Enders 1995).

Detrending and differencing are popular practices in macroeconometrics because the autoregressive moving average (ARMA) framework is applicable only to stationary time series. However, both practices have several drawbacks. On one hand, the linear model (1) assumes that trend is unchanging over time with a secular growth rate \(\delta\) that could not accommodate technological, demographic or other fundamental shocks that might occur overtime. On the other hand, the first-difference filter (4) removes the zero (long-run) frequency and accentuates the high-frequencies in the data \(y_t\), producing a noisier stationary component \(\varepsilon _t\) (Cooley and Prescott 1995; Hamilton 1994).

In practice, detrending and differencing may not be adequate to describe the business cycle, that is, the more or less regular pattern of expansion and contraction in economic activity around the path of trend growth that is observed in most macroeconomic series. In fact, business cycles can vary widely across methods that extract different types of information from data (Canova 1998). Ideally, the business cycles should depict the deviations from a long-term trend using, namely, a stylised circular clock (Lourenço and Rua 2022). Given a seasonally adjusted time series \(y_t\), the business cyclical component \(c_t\) can be defined as

$$\begin{aligned} c_t \equiv y_t - x_t - \epsilon _{t}, t = 1, \dots , N \end{aligned}$$
(5)

where \(x_t\) and \(\epsilon _t\) are the trend (low-frequency) and irregular (high-frequency) components of \(y_t\), respectively. Thus, the cycle \(c_t\) should capture the medium-frequencies with periods lasting no fewer than six and no more than thirty-two quarters as defined by the National Bureau of Economic Research (NBER) researchers (St-Amant and van Norden 1997).

The trend is generally seen as a slow movement over time that could be extracted with appropriate filtering techniques. Ideally, they should capture not only the deterministic but also the stochastic dimension of the growth as described. In several cases, filtering consists in applying a smooth operator M to a moving-centred window of the data with length \(l = 2k + 1\) in order to estimate the trend component

$$\begin{aligned} x_{t} = \text {M} \left[ y_{t-k}, \dots , y_t, \dots , y_{t+k} \right] , t = 1, \dots , N. \end{aligned}$$
(6)

Linear and nonlinear techniques can be mobilised to perform this task. Moving Average (MA), that is, using the arithmetic mean as smooth operator in equation (6) is a simple way to do it:

$$\begin{aligned} \tilde{x}_{t} = \frac{1}{2k + 1}\sum _{i=-k}^{k} y_{t+i}, t = 1, \dots , N. \end{aligned}$$
(7)

This is an example of a Linear Time-Invariant (LTI) low-pass filter which does not affect low frequencies, rejects high-frequencies and avoid phase shifts through its symmetry (Smith 2011). Setting \(k = 15\), the MA filter can be used to block business cycles with length up to \(l=31\) quarters in coherence with the NBER definition. And it can be applied once again to the residual \(\tilde{\varepsilon }_t = y_t - \tilde{x}_t\) to separate the pure cycle component \(c_t\) from the high-frequencies \(\epsilon _{t}\) by fixing \(k=2\) (window length of 5 quarters) as in the decomposition (5), even when the trend \(x_t\) was estimated with other techniques including the linear time trend regression (1).

A special case of moving average and linear filtering is the widely used Hodrick and Prescott (1997) filter (HP). In this method, the trend sequence \(\{x_t\}\) is chosen to minimise either the sum of the squares of deviations from data series \(\{y_t\}\) plus the weighted sum of the squares of the trend’s second difference, a possible measure of its smoothness.

In a recent critique, Hamilton (2017) stressed that the HP filter produces extremely predictable cyclical components whose rich dynamics are purely artefacts created by the filter rather than reflecting any true dynamics of the data-generating process itself, following an argument similar to Harvey and Jaeger (1993) that found that the HP filter may create spurious cycles and cross-correlations between different variables. In fact, when applied to persistent data, the HP filter can generate business cycle dynamics even if none are present in the original data (Cogley and Nason 1995; Cogley 2001). This is a common feature of linear filters including the symmetric Baxter and King (1999) and asymmetric Christiano and Fitzgerald (1999) band-pass filters which tend to eliminate large fluctuations either in expansions or contractions (Wen and Zeng 1999). Thus, linear filters produce smooth trends that might not capture fundamental sharp changes in the growth component of the time series under study. This problem is particularly acute with the HP method because it produces a trend with a very regular, predictable, pattern and passes everything else to the cyclical component, including high-frequencies.

As suggested by Wen and Zeng (1999), nonlinear filters could perform better than linear filters in capturing occasional, discrete shifts in the growth dynamics of economic series. In particular, the Median (MED) filter provides a simple noise attenuation with robustness against impulsive-type noise and it has proved to be effective in signalling recessions. However, it produces a very noisy trend that might fail the test of either smoothness or persistence. The alternative metric for the HP minimisation problem proposed by Mosheiov and Raveh (MR) (1997) could deal with this problem, producing a suggestive piecewise trend. A similar result can be obtained by applying the \(\ell_1\) trend filter proposed by Kim et al. (2009).

We start by describing those different filtering techniques (MED, HP and MR). Then, we compare the different insights in describing the business cycles of the Portuguese economy since 1977. One conclusion of our analysis is that the trend and the cyclical components are both informative about economic conditions. As framework, we dated the Portuguese contractions (recessions) and expansions (recoveries) by applying the Bry and Boschan (1971) algorithm to GDP, private consumption, investment and employment (see Appendix 2).

In this paper, we do not distinguish between trend GDP growth and potential GDP growth, nor between cyclical component and output gap.Footnote 1

2 Alternative filtering techniques

2.1 The Median (MED) filter

Linear filters implicitly assign all sharp changes in time series to shifts in non-fundamentals, assuming away the possibility that the growth trend can also experience sudden shifts or jumps. In fact, linear filters can only suppress undesired parts of the signal and retain the desired information about business cycles if and only if the noise and the signal occupy different frequency bands. In reality, however, signals reflecting sudden but fundamental changes could share the same frequency band with noise.

To deal with these limitation of linear filters, Wen and Zeng (1999) introduced a class of nonlinear filters, called the median filters, that has been proven useful and powerful for removing time trend and noise in several contexts. To compute the output of the Median (MED) filter, an odd number of sample values are sorted, and the middle or median value is used as the trend component \(x_t\). In practice, the MED filter adopted the median X as smooth operator M in equation (6):

$$\begin{aligned} \hat{x}_t = \text {X} \left[ y_{t-k}, \dots , y_t, \dots , y_{t+k} \right] \end{aligned}$$
(8)

for \(t = 1, \dots , N\) and \(k = 15\) with quarterly data. To be able to filter also the outermost observations, where the filter window partially fall outside the input signal, those authors replicated the \(y_1\) and \(y_N\) values as many times as needed, the so-called “first and last values carry-on appending strategy” (Wen and Zeng 1999).

The MED output has good deterministic and statistical properties. Namely, it is optimal in the mean absolute error sense because the median of \(y_1, \dots , y_N\) can be defined as the value \(\beta\) minimising the following expression when \(\gamma = 1\)

$$\begin{aligned} \sum _{t=1}^{N}{\vert y_{t} - \beta \vert ^{\gamma }}. \end{aligned}$$
(9)

In fact, the sample median is the maximum likelihood estimate for the location parameter of the Laplace probability distribution (Wen and Zeng 1999).

Wen and Zeng (1999) compared the MED with the HP, BK and MA filters and concluded that the MED cycle \(\hat{c}_t \equiv y_t - \hat{x}_t\) for GDP coincides almost exactly with the NBER dated recessions for the United States of America, while the linear filters are too noisy outside contraction periods. This result indicates that linear filters are not efficient in retaining the growth component of GDP in terms of effectively capturing sharp changes in growth trend. Those authors also stressed that the HP and MA filters generate very similar trend paths which could be explained by the moving average representation of the HP filter, as described below.

2.2 The Hodrick-Prescott (HP) filter

Let denote \(y=(y_1,y_2,\dots ,y_N)\) as the \((N \times 1)\) vector of the seasonally adjusted time series \(y_t\). The Hodrick-Prescott (HP) trend \(x^* = (x_1,x_2,\dots ,x_N)\) is chosen to minimise the sum of the square residuals \(\varepsilon _t=y_t-x_t\) plus the weighted smoothness of the trend component

$$\begin{aligned} \min _{\{g_t\}} \left[ \sum _{t=1}^{N} \varepsilon _t^2 + \lambda \sum _{t=3}^{N} \left( g_t - g_{t-1} \right) ^2 \right] \end{aligned}$$
(10)

where \(\lambda > 0\) is a penalty for the square of the difference of the trend growth \(g_t \equiv x_t - x_{t-1}\), which is the second difference (acceleration) of the trend component \(x_t\). Thus, the larger the value of \(\lambda\), the smoother will be the HP trend. In particular, as \(\lambda\) approaches infinity, the limit of solutions to program (10) is the least squares fit of the linear time trend model (1). If the residual \(\varepsilon _t\) and the difference \(g_t - g_{t-1}\) are uncorrelated white noise processes with means zero and variances \(\sigma _{\varepsilon }^2\) and \(\sigma _g^2\), then the conditional expectation of \(x_t\) on data \(y_t\) would be the solution to program (10) when \(\lambda = \sigma _{\varepsilon }^2 / \sigma _g^2\) (Dermoune et al. 2009; Hamilton 2017; Hodrick and Prescott 1997). The view of Hodrick and Prescott (Hodrick and Prescott 1997) is that a 5 percent cyclical component is moderately large, as is a one-eighth of 1 percent change in the growth rate in a quarter. This assumption led them to select \(\sqrt{\lambda } = 5/(1/8) = 40\) or \(\lambda = 1600\) as the value for the filter’s smoothing parameter in order to extract business cycles from quarterly data.

It is convenient to express the problem (10) in matrix form

$$\begin{aligned} \min _{x} \left[ (y-x)^T (y-x) + \lambda x^T D^T D x \right] \end{aligned}$$
(11)

where \(D \in \mathbb {R}^{(N-2) \times N}\) is an upper triangular Toeplitz matrix with first row \([1 \, -2 \, 1 \, 0 \, \cdots \, 0]\). As noted by Kim et al. (2009), this objective function is strictly convex in x, thus has a unique minimiser

$$\begin{aligned} x^* = \left( I + \lambda D^T D \right) ^{-1}y. \end{aligned}$$
(12)

From the optimality condition \(y - x^* = \lambda D^T D x^*\), we could obtain the optimal fitting error, that is, the cyclical component of the HP filter

$$\begin{aligned} c^* \equiv y - x^* = \lambda D^T D \left( I + \lambda D^T D \right) ^{-1}y. \end{aligned}$$
(13)

From the first order condition (12), the HP trend estimate is simply a moving average of the original unfiltered data y whose weights change as we move from the mid-sample to the end (or the begin) of the sample, as stressed by St-Amant and van Norden (1997).

The HP filter is an example of an heuristic two-part decomposition of time series that could be represented by a high-pass transfer function. As found by King and Rebelo (1993), the transfer function of the cycle component (13) is given by

$$\begin{aligned} H(\omega;\,\lambda ) = \frac{4 \lambda (1 - \cos {(\omega )})^2}{1+4 \lambda (1 - \cos {(\omega )})^2} \end{aligned}$$
(14)

where the frequency \(\omega\) measures the number of cycles completed during \(2\pi\) periods which is unity for the cosine function. The HP transfer function is also the gain of the filter because it assumes only real (non imaginary) values. This result is a direct consequence of the symmetry of the HP filter and from Euler equations (see also Hamilton 1994). Thus, the HP filter is similar to a high-pass filter where choosing different values for \(\lambda\) is comparable to fix different values for the cut-off point of the filter (Ravn and Uhlig 2002).

Solving in \(\lambda\) the equation (14) for a gain of 0.5 as suggested by Mohr (2005), we found that the critical frequency of \(\pi /20 = 2\pi /40 = 0.157\), which corresponds to a period of 40 quarters (10 years), requires a value of \(\lambda \approx 1600\) as proposed by Hodrick and Prescott (1997) to filter quarterly data. Moreover, for a gain of 0.7, the critical frequency associated with \(\lambda = 1600\) is approximately \(\pi /16\), the cut-off frequency of a filter that passes oscillations lasting 32 quarters (8 years) or less. Thus, the HP filter with \(\lambda = 1600\) high-passes business cycle frequencies with no more than thirty-two quarters as defined by NBER (St-Amant and van Norden 1997) for a reasonable gain of the filter. Nevertheless, the HP cyclical component may have residual seasonality and other high frequencies with period less than 6 quarters mixed with business cycle frequencies because the HP is not a band-pass filter. Applying the MA filter (7) with \(k=2\) (\(l=5\)) to the HP cycle (13) can mitigate this problem.

2.3 The Mosheiov-Raveh (MR) filter

As suggested above, the median filter output minimises the sum of the absolute values of the fitting residual \(\varepsilon _t = y_t - x_t\). Thus, the MED trend \(\hat{x_t}\) is well-fitted to the original time series \(y_t\) and it is always one of the input observations from (8). The fidelity or closeness to data is an important property of the trend but the smoothness should also be considered. So, we could imagine a generalised median filter which results from the following problem (Mosheiov and Raveh 1997):

$$\begin{aligned} \min _{\{x_t\}} \left[ \alpha \sum _{t=1}^{N} \vert y_t - x_t \vert + (1 - \alpha ) \sum _{t=1}^{N-2} \vert (x_{t+2} - x_{t+1}) - (x_{t+1} - x_{t}) \vert \right] \end{aligned}$$
(15)

where \(\alpha\) and \(1 - \alpha\) are the weights assigned by the user to fidelity and smoothness, respectively, with \(0 \le \alpha \le 1\). The choice of the parameter \(\alpha\) is somewhat arbitrary, but has a significant effect on the final trend estimate. From visual inspection, Mosheiov and Raveh (1997) chose only small values of \(\alpha\), namely, \(\alpha = 0.1\) in the sense that their natural preference for smoothness was more significant than fidelity.

Nevertheless, the trade-off between fidelity and smoothness can be fixed to assure the same fitting error is provided either by the HP or the MR filters, following the practice of Kim et al. (2009) in the scope of \(\ell _1\) trend filtering. To apply this criterion, it is convenient to rewrite the previous problem as

$$\begin{aligned} \min _{\{x_t\}} \left[ \sum _{t=1}^{N} \vert y_t - x_t \vert + \theta \sum _{t=1}^{N-2} \vert (x_{t+2} - x_{t+1}) - (x_{t+1} - x_{t}) \vert \right] \end{aligned}$$
(16)

where \(\theta = (1 - \alpha ) / \alpha\) indicates how much the degree of smoothness is more important than fidelity. Then, we fix \(\theta\) such that the resulting MR trend \(x_t(\theta )\) provides a mean squared fitting error similar to the one provided by the HP trend \(x_t(\lambda )\), that is

$$\begin{aligned} \theta : \frac{1}{N} \sum _{t=1}^{N} \left[ y_t - x_t(\theta ) \right] ^2 \approx \frac{1}{N} \sum _{t=1}^{N} \left[ y_t - x_t(\lambda ) \right] ^2. \end{aligned}$$
(17)

The objective function (16) is a variation of the HP objective function (10) which substitutes the sum of squares, that is, the squared \(\ell _2\) Euclidean norm, for the sum of absolute values, the \(\ell _1\) norm, to measure either the fidelity or the smoothness of the trend \(x_t\).Footnote 2 Thus, the smoothing parameter \(\theta\) can be interpreted in a similar manner than the \(\lambda\) parameter, noting that, in the MR filter, the errors are measured in absolute terms while, in the HP filter, they are quadratic errors. Therefore, it would be expected that, for the same data set, the value of \(\theta\) should be close to the square root of \(\lambda\). The concept of business cycles in a developed economy is a mechanism that usually is considered to last between 6 and 10 years. In the context of the HP filter, \(\lambda = 1600\) is appropriate for quarterly data to separate the trend and cycle components in that time horizon, as said. Similarly, the MR filter with a \(\theta\) between 30 and 50 should obtain similar cycles.

The problem (16) can be solved through a linear programming framework. We propose an improvement to that method to allow non-positive trend growth, see Appendix 1 for details. Other methods are available, namely the interior point approach that uses a logarithmic barrier potential-function, widely applied to solve the least absolute deviation and quantile regression problems (Portnoy and Koenker 1997).

2.4 Filter properties

The reason for the popularity of the HP filter among practitioners rests on a few properties. First, it smooths the data. This property is common to all filters, except the linear filter that smooths the data too much. Second, it allows for an estimate of the trend growth. Once again, this is a common property to all statistical filters. Third, it provides an estimate of the cyclical position of an economy in every period. This property is also common to all filters, even though the linear filter accepts too large cyclical components, and the HP and the other filters may underestimate the cyclical component. This is one important advantage of nonlinear filters, providing a potentially better measure of the cyclical position, that is, the slack or overheating of the economy. Fourth, the key distinctive feature of the HP filter is that it allows trend growth to be different throughout the time line. In this perspective, the HP filter is the simplest statistical method that assumes time-varying growth. Moreover, it allows this growth to follow the data, even though in much smoother form than actual observed growth.

The MR filter shares this fitting property, in contrast with other statistical techniques that either force a constant trend growth, or model this growth as a function of other covariates, or even allowing it to vary according to predefined periods. Of course, some of the limitations of the HP filter are well known, especially its bias near the end of the sample period, which can severely affect the estimates of trend growth and cyclical component. This bias can be serious and therefore most researchers treat with great care the estimates of GDP trend growth and cyclical position near the end, usually the present, of the available data.

The most interesting feature of the MR filter when compared with the HP filter is that it provides a more robust estimate of the trend growth, only changing this estimate if the signal coming from the data is sufficiently strong. Thus, the MR filter could delay the recognition of a change in regime, but it would be robust in signalling a new trend once sufficient evidence is present in the data.

3 Findings

The above described statistical methods were applied to the quarterly real (chain linked) national accounts of GDP, private consumption, gross fixed capital formation (GFCF) and employment level provided by the Portuguese National Statistics Office (INE) since the first quarter of 1995 till the second quarter of 2023. This seasonally adjusted data was complemented with long-term series from Banco de Portugal (BdP) to produce a set of 186 observations since the first quarter of 1977. Moreover, a procedure described in Appendix 2 was used to date the Portuguese recessions by tracking the peaks and troughs in the various series.

The smoothing parameter \(\theta\) of the MR filter was fixed to assure that the fitting error is approximately equal to the one provided by the HP filter with \(\lambda = 1600\). For GDP, the main series of interest, this criterion provides a value of \(\theta\) of 42, quite close to 40, which is the square root of 1600 (see Table 1). We fix \(\theta = 42\) for all series, noting that the parameter \(\lambda = 1600\) of the HP filter was adopted in all cases too.

Table 1 Mean squared fitting error of the Portuguese quarterly real GDP, private consumption, investment (GFCF) and employment computed with the Hodrick-Prescott (HP) filter and the Mosheiov-Raveh (MR) filter for different values of its smoothing parameter \(\theta\)

In Figs. 1 and 2, we show the trend component of GDP according to the five methods. The linear time model provides substantially different results from the other four. Notice how recessions, denoted by the shaded regions in the graphs, tend to slow down growth in all other four methods. Moreover, notice how the four methods, bar linear trend, show a declining trend GDP between 2008 and 2013.

Fig. 1
figure 1

Trend component of 100 times the log of GDP computed with the linear time model, Moving Average and Median (smoothed with a centered moving average of 5 quarters) filters (Portugal, 1977Q1-2023Q2)

Fig. 2
figure 2

Trend component of 100 times the log of GDP computed with the linear time model, Hodrick-Prescott and Mosheiov-Raveh filters (Portugal, 1977Q1-2023Q2)

In Figs. 3 and 4, we plot the trend GDP growth, which brings more or less cyclical patterns accordingly with the model. What is most striking, however, is that after 2000 the estimate of GDP growth never returned to the highest values observed around the previous peaks, even at the recovery after 2013. Moreover, trend GDP growth was smaller than the constant (0.47%) estimated by the linear model in almost all quarters, except for the HP filter at the end of sample. The private consumption, investment and employment follow similar patterns. It is striking that the general shape of alternation between trend growth levels is quite similar across statistical methods, except the constant linear model.

Fig. 3
figure 3

First difference of the trend component of 100 times the log of GDP computed with the linear time model, Moving Average and Median filters (Portugal, 1977Q1-2023Q2)

Fig. 4
figure 4

First difference of the trend component of 100 times the log of GDP computed with the linear time model, Hodrick-Prescott and Mosheiov-Raveh filters (Portugal, 1977Q1-2023Q2)

The behaviour of investment (GFCF) is worth an additional note. According to most models, investment trend growth was negative between 2001 and early 2014. Moreover, Fig. 5 shows how far is the fixed investment from the levels observed in 2001. This is a good measure for the severity of slowdown in investment observed for about 20 years (from 2002 to the present), a much extended period indeed.

Fig. 5
figure 5

Trend component of 100 times the log of GFCF computed with the linear time model, Hodrick-Prescott and Mosheiov-Raveh filters (Portugal, 1977Q1-2023Q2)

Fig. 6
figure 6

First difference of the trend component of 100 times the log of GFCF computed with the linear time model, Hodrick-Prescott and Mosheiov-Raveh filters (Portugal, 1977Q1-2023Q2)

An immediate approach is to interpret the different trend growth rates as different natural periods of the Portuguese economy. We do it in Table 2, which proved to be a complement of the recessions dated in the Appendix 2. While all filtering techniques (moving average, median filter, HP and MR) provide similar estimates for GDP trend growth that highlight different periods, the MR filter provides this dating in a very natural fashion. In fact, the MR filter appears to capture a broad pattern of strong growth periods followed by weak periods that can be interpreted as the change in pace during expansions and contractions. Thus, we identify eight distinctive periods for the evolution of the Portuguese economy since 1977.

Table 2 Portuguese economic periods as determined by the MR filter (end quarter)

The first period, ending in late 1980, represents a strong expansionary period (average growth of 1.1% per quarter, see Fig. 4). It was followed by a period of low growth (average growth of 0.3%) which ends in late 1985 and includes a short recession. The third period is again strongly expansionary (average quarterly growth of 1.2%) until late 1990. The fourth period, which includes a small recession at the beginning, has a low growth around 0.4%.

However, the remaining four periods show a very different switch of trend growth. The apparent strong growth in period 5 (1.0% per quarter) is moderate by historical standards, but is still the strongest of the following three periods. The sixth period (average growth of 0.2%) is unusually long (seven years), but it was not followed by a period of strong growth. In effect, trend GDP growth becomes negative in period 7 (\(-\)0.3% per quarter) and includes two recessions. So it can be classified as a period with a double dip recession. This is the period with the weakest growth of the Portuguese economic history after 1977.

The current period 8 started in late 2013 (average trend growth of 0.5%) which can be considered as a regular expansionary period, close to the secular average estimated by the linear model, but much weaker than the recoveries from the 1980s and 1990s. This period includes the recession generated by the COVID-19 pandemic and implemented lockdown policies in 2020Q1-Q2. The stability of the MR filter is evident, contrary to the HP filter that slowly changes the trend growth between contractions and expansions. From its ability to attenuate the impact of outliers and noise, the MR filter is particularly useful to deal with such volatility in the data.

These eight periods are visible on series other than GDP. For some series, two periods may be represented as a single period (e.g. the first and second periods for consumption and investment, see Table 2). Moreover, the exact beginning of the strong and the weak spots are not necessarily estimated to begin and end on the same quarter by all time series analysed. In particular, investment suggests that the period 8 might have ended at 2019, right before the COVID crisis. However, they tell the same story from a qualitative point of view.

This description of the results shows the power of the MR approach to identify natural periods of differential growth on the data series. These periods show up quite naturally, and the weak periods usually include one or two recessions. So, the MR filter can be used for that purpose. This type of classification is useful for policy since weak periods of growth should recommend fiscal stimulus and strong periods of growth should counsel additional debt repayments and savings.

One can argue that HP filter provides a similar story. However, the beginning and ending of the periods is less obvious (associated with the inflexion points in Figs. 4 and 6), and the HP trend growth must be averaged to characterise each period directly signalled by the MR filter.

The five methods might provide very different estimates of the trend GDP growth. Using the last quarter of the data, the range of this growth is between 0.19% for the MA filter and 0.66% for the HP filter. The MR filter is quite conservative due to its robust estimation properties: changes of its estimated trend growth require stronger signals from data than temporary discrete shocks or cyclical recovery. In fact, it signals a trend GDP growth of 0.50% since the third quarter of 2014, despite the COVID-19 crisis and its developments.

Note that the linear model generates an extremely different pattern for the cyclical component, because it assumes a constant trend growth of 0.47% (see Fig. 7). The other filters generate fairly similar cycles except near the begin and end points of the sample (Figs. 8 and 9).

Fig. 7
figure 7

Cyclical component of 100 times the log of GDP computed with the linear time model (Portugal, 1977Q1-2023Q2)

Fig. 8
figure 8

Cyclical component of 100 times the log of GDP computed with the Moving Average and Median filters (Portugal, 1977Q1-2023Q2)

Fig. 9
figure 9

Cyclical component of 100 times the log of GDP computed with the Hodrick-Prescott and Mosheiov-Raveh filters (Portugal, 1977Q1-2023Q2)

A remarkable feature of the nonlinear filtering techniques is that they produce cycle components less volatile than the difference between the original data and the HP trend, a suggested by the Table 3. This result is particularly evident for the median filter and it is a direct consequence of the ability of nonlinear filters to capture sharp swifts in the trend growth. Thus, the cyclical components associated with nonlinear filters (including MR) are less contaminated with noise and changes other than pure cyclical effects. As illustrated by Fig. 8 for GDP, the cyclical components of the MED filter coincides almost exactly with the recessions dated in the Appendix 2 with the Bry and Boschan (1971) algorithm which is a direct consequence of that characteristic of nonlinear filtering in general. Nevertheless, the MR filter realises a cycle component that is more comparable with the HP cycle (Fig. 9) than MED cycle.

Table 3 Standard deviation of the cyclical component of the Portuguese quarterly real GDP, private consumption, investment (GFCF) and employment computed with the linear time model, Moving Average (MA), Median (MED), Hodrick-Prescott (HP) and Mosheiov-Raveh (MR) filters

4 Conclusion

Assessing economic conditions overtime requires separating trend, cyclical and noise components from time series. This task is often model dependent. Simple detrending models assume a secular trend that is fixed over time, thus all shocks are described as cyclical or temporary within that kind of framework. However, technology, demography and other fundamentals will likely change trend growth overtime. So, the trend of an economy can be better described as a slow changing movement over time rather than a fixed drift. The Hodrick and Prescott (1997) filter is very popular in part because it can estimate that kind of non-constant but smooth trend growth, producing insightful business cycles.

However, the HP and other linear filtering techniques generate trends with regular and predictable patterns that pass everything else to the stationary component, including high-frequencies and shocks other than pure cyclical effects. In practice, they produce ‘artificial’ trend-cycle decompositions that might not reflect the underlying economic processes.

Robust nonlinear filters could perform better than linear filters in capturing discrete shifts in the trend growth of economic series. For example, the median filter provides noise-attenuation and it has been effective in signalling recessions. Nevertheless, its trend is noisy even when averaged across adjacent time periods. We found that the filter proposed by Mosheiov and Raveh (1997) keeps the robust statistical properties of the median filter, while generating stable trend growth estimates that lend themselves to insightful interpretations of the different time periods of an economy.

The distinctive feature of the MR filter is the piecewise nature of its trend growth. This unique characteristic might be useful to estimate the trend growth of the economy and to highlight natural periods of differential growth on the data series. Moreover, it allows for economic shocks to have direct and discrete impacts on the cyclical position as well as in the potential growth. In fact, the MR filter is conceptually similar to HP filter but uses robust statistics anchored on the median and absolutes deviations of the data. Thus, the MR filter provides a more robust estimate of trend growth, only changing this estimate if the signal coming from the data is sufficiently strong. Additionally, it may provide a better measure of the output gap and as such a measure of the slack or overheating of the economy.

We propose a criterion to fix the smoothing parameter of the MR filter based on the error estimated with the HP filter. We found that it should be close to 40, which is the square root of the HP smoothing parameter for quarterly data (1600). In addition, we propose a new method to estimate the MR filter using least absolute deviations (LAD), see Appendix 1 for details.

With the help of the MR filter, we found eight distinctive periods for the Portuguese economy between 1977 and 2023 that show up quite naturally. In general, strong and weak periods of growth are estimated directly from data. The weak periods might include one or two recessions for some variables such investment or employment. In particular, the sixth period (2000Q4-2008Q2) was unusually long, has a moderate average trend GDP growth of only 0.2% per quarter, and it was not followed by a period of strong growth yet. Despite the COVID-19 pandemic, we found that the potential growth of the Portuguese economy is still positive and close to 0.5% per quarter or 2.0% annualised.