Original link:http://tecdat.cn/?p=5399

Original source:Extension end number according to the tribal public number

introduce

An analysis of the business cycle requires the extraction of the periodic component of a time series, which is often also influenced by other factors such as underlying trends or noise. This article describes some of the methods used in recent literature to extract business cycles from a given sequence. It is based on the chapter on business cycles in the “Handbook of Macroeconomics” by Stock and Watson (1999). I also introduce relatively new methods such as wavelet filters or empirical mode decomposition. Since the focus of this article is on implementing certain filtering techniques in R, I won’t get into the math. Instead, I will refer to the respective literature. For these examples, I used quarterly data on real GDP.

Names (GDP) < - c (" Time ", "GDP") # rename GDP \ [, "GDP" \] < - log \ [, \] "GDP" (GDP) # logarithmic

To get a sense of what it means to extract the periodic component of a time series, look at the development of logarithmic real GDP over time in the figure below.

ggplot(gdp,aes(x=Time,y=GDP)) + geom\_line(size=.5) + theme\_classic()

The data has a clear trend of increasing, gradually decreasing. Moreover, the sequence fluctuates around this trend in a more or less conventional way. The sequence’s deviation from the trend is very small, and occurs frequently, but there are also significant deviations that can persist over several periods. The latter is the volatility associated with business cycle analysis.

Time tends to fade

The first way to remove a trend from a sequence is to regress the variables of interest over time and obtain residuals. These are plotted in the figure below, where the linear trend is removed.

Gplot (dat,aes(x=Time,y= linEarly.Detrended)) + geom\_hline+ geom\_line

This approach is relatively controversial because it assumes a constant linear time trend. As we have seen above, this is unlikely to happen given the steady decline in trend growth rates over time. However, it is still possible to assume different functional forms of the time trend, such as adding quadratic terms to get rid of the trend. Another drawback of this approach is that it can only rule out trends, but not noise, which is very small fluctuations in a sequence.

The differential

The next approach is to use first-order difference, as it is usually taught to obtain a stationary time series. This assumes that the data are unstable. The result of obtaining a first-order difference is shown in the figure below, where it is also compared with the time trend series. Difference data fluctuates more around the zero line, but it also contains a lot of noise.

Plot axis. Line =element_line(size=.3,colour="black"), Plot. Cycles (d=g)

Hodrick Prescott Filter

Hodrick and Prescott (1981) developed a filter that divides time series into trend, period, and noise components. Time series and smoothing parameters are required. The figure below shows the periodic component values of real GDP obtained by the Hodrick-Prescott filter and compares them with the values of a linear detrending sequence. The behavior of the two sequences looks very similar, except that the HP sequence fluctuates around zero, while the linear detrending sequence still contains an element of trend. In addition, the cyclic HP sequence also includes some noise-like components.

# drawing g < - melt (dat \ [, c (1, 3) \], id, vars = "Time", na. The rm = TRUE) plot (g)

BaxterThe filter

Baxter and King (1994,1999) proposed a filter that could produce results similar to those of the HP filter, but it could eliminate many of the noise-like behaviors shown above. It requires a sequence, a lower and upper limit on the number of cycles, a presumed cycle occurrence (PL and PU), and a smoothing factor NFIX. The literature (see NBER, Stock, and Watson (1999)) shows that business cycles last from 6 to 32 months. These values are used to specify the lower and upper limits for the cycle period. The results of the BK filter are shown in the figure below. A relative sequence disadvantage of this method is that the smoothing factor results in loss of samples at the beginning and end of the sequence. This could be a small sample problem.

# drawing dat < - cbind (dat, the data frame (bk) g < - melt (dat \ [, c (1,5,4) \], and na. The rm = TRUE) plot (g)

Wavelet filter

Yogo (2008) proposed to use wavelet filters to extract business cycles from time series data. The advantage of this method is that the function can not only extract the trend, period and noise of the sequence, but also more specifically describe the period in which the period occurs. However, since this method can only capture the periodicity of powers of 2, i.e., 2,4,8,16,32, etc., there is no complete degree of freedom.

The method implementation in R is also neat, but requires some additional data conversion before it can be used. It requires different versions of the time series and depth of decomposition.

This function gives multiple sequences that must be cumulated to turn them back into data that reflects a periodic pattern. In addition, some sequences can be combined with rowSums. This is useful when cycles lasting 8 to 16 and 16 to 32 cycles should be analyzed together, as shown in the figure below. The wavelet filter produces a result similar to that of the BK filter, since the upper limit of the cycle period is equal in both and the lower limit differs by only 2.

# drawing g < - melt (dat \ [, c (1,6,5) \], id, vars = "Time", na. The rm = TRUE) levels (g \ [2 \]) < - c (" Wavelet ", "Baxter King") plot.cycles(g,"Wavelet vs. Baxter King")

Empirical Mode Decomposition (EMD)

Based on Huang et al. (1998) Kozic and Sever (2014) proposed empirical pattern decomposition as another method of business cycle extraction. It requires different time series, boundary conditions, and rules that specify the point at which the iteration process is satisfied and can be stopped. The results of this filter method are different from those of HP, BK and wavelet filters.

emd <- as.data.frame(emd(xt=diff(gdp\[,2\]),boundary="wave",stoprule="type2")$imf) g <- Melt (dat\[,c(1,7,4)\],id.vars="Time",na.rm=TRUE) plot.cycles(g,"EMD vs. Hodrick Prescott")


The most popular insight

1. Use LSTM and PyTorch in Python for time series prediction

2. LSTM, a long and short term memory model, is used in Python for time series prediction analysis

3. Use R language to conduct ARIMA (exponential smoothing) analysis

4. R language multivariate Copula-GARCH-model time series prediction

5. R language copulas and financial time series cases

6. R language random fluctuation model SV is used to deal with random fluctuations in time series

7. TAR threshold autoregressive model for R language time series

8. K-shape time series clustering method of R language is used to cluster the time series of stock prices

9. Python 3 uses ARIMA model for time series prediction