R: Beveridge–Nelson Trend and Cycle Decomposition

This post shows how to extract trend and cyclical components from a univariate time series based on the Beveridge–Nelson (BN) decomposition using tsm R package.


Beveridge–Nelson decomposition



Beveridge and Nelson (1981) provide an way of decomposing a non-stationary time series (\(y_t\)) into a permanent and a temporary (cyclical) component by applying ARIMA methods. \[\begin{align} y_t = \tau_t + c_t \end{align}\] where \(\tau_t\) and \(c_t\) are trend and cyclical components respectively.

The trend is modeled as a random walk with drift, and the cycle is treated as stationary process with zero mean.

Let \(y_t\) be integrated of first order, so that its first difference, \(\Delta y_t\) is stationary and has the following moving average representation \[\begin{align} (1-L)y_t = \Delta y_t = \mu + B(L)\epsilon_t \end{align}\] where \(L\) is the lag operator and \(B(L)\) is a polynomial of order \(q\) in the lag operator. \[\begin{align} L X_t = X_{t-1}, L^2 X_t = X_{t-2}, ... \\ B(L) =1 + B_1 L + B_2 L^2 + ... +B_q L^q \end{align}\]
Consider now the polynomial \(B(L)-B(1)\). Given that \(B(1)\) is just a constant, \(B(L)-B(1)\) will be of order \(q\). As \(1\) is a root of \(B(L)-B(1)\) since \(B(1)-B(1)=0\), the following expression can be obtained. \[\begin{align} B(L)-B(1) = B^*(L)(1-L) \\ \rightarrow B^*(L) = (1-L)^{-1}[B(L)-B(1)] \end{align}\] where \(B^*(L)\) is a polynomial of order \(q-1\) and \(B(1) = \sum_{s=0}^{\infty} B_s\).

Using the above derivations, we can express \(\Delta y_t\) as \[\begin{align} \Delta y_t &= \mu + [B(1) + (1-L)B^*(L)]\epsilon_t \\ &= \mu + B(1)\epsilon_t + (1-L)B^*(L)\epsilon_t \end{align}\] As \(y_t = \tau_t + c_t\), \(\Delta y_t = \Delta \tau_t + \Delta c_t\). Hence, changes in the trend and cycle components of \(y_t\) are respectively, \[\begin{align} \Delta \tau_t &= \mu + B(1)\epsilon_t \\ \Delta c_t &= (1-L)B^*(L)\epsilon_t \end{align}\] As the trend follows a random walk with drift, This expression can be solved to yield. \[\begin{align} \tau_t &= \underbrace{\tau_0 + \mu t}_{\text{deterministic term}} + \underbrace{B(1)\sum_{s=1}^{t} \epsilon_s }_{\text{stochastic term}} \\ c_t &= B^*(L)\epsilon_t = (1-L)^{-1}[B(L)-B(1)]\epsilon_t \end{align}\]

R code


The Beveridge-Nelson decomposition is easily estimated by using tsm R package. You can find the installation instruction and working examples at https://kevinkotze.github.io/ts-5-tut/.

#========================================================#
# Quantitative ALM, Financial Econometrics & Derivatives 
# ML/DL using R, Python, Tensorflow by Sang-Heon Lee 
#
# https://shleeai.blogspot.com
#-----------------------------------------------------------
# Beveridge-Nelson decomposition
#========================================================#
 
graphics.off(); rm(list = ls())
 
#devtools::install_github("KevinKotze/tsm")
library(tsm)
#library(mFilter)
 
#-----------------------------------------------------------
# U.S. Real GDP data from Greene Text book
#-----------------------------------------------------------
 
# read data file
st <- c(19501); fq <- 4
fn <- "http://people.stern.nyu.edu/wgreene/Text/Edition7/TableF5-2.txt"
macro <- read.csv(fn, sep="", header = TRUE)
gdp <- macro$realgdp
 
# logarithm of real gdp multiplied by 100
lngdp <- ts(log(gdp)*100, start = st, frequency = fq)
 
#-----------------------------------------------------------
# Beveridge-Nelson decomposition function arguments
#-----------------------------------------------------------
# bnd(data, nlag)
# data : A vector of first-order 
#        integrated numeric values
# nlag : A numberic scalar for the lag-order 
#        of the autoregressive (cyclical) part
#-----------------------------------------------------------
 
# apply the BN decomposition
bn.decomp <- bnd(lngdp, nlag = 2)
 
# extract the BN trend and cycle
bn.trend <- ts(bn.decomp[, 1], start = st, frequency = fq)
bn.cycle <- ts(bn.decomp[, 2], start = st, frequency = fq)
 
# graph
x11(width = 7, height = 7); 
par(mfrow = c(2,1), mar = c(2.22.211), cex = 1)
plot.ts(lngdp, ylab = "", col = "blue", lwd=2)
lines(bn.trend, col = "red", lwd=2)
legend("topleft", legend = c("log(GDP)""Trend(BN)"), 
       lty = 1, col = c("blue""red"), bty = "n", lwd=3)
plot.ts(bn.cycle, ylab = "", ylim = c(-2.5,2.5), lwd=3, col = 4)
legend("topright", legend = c("Cycle(BN,%)"), 
       lty = 1, col = 4, bty = "n", lwd=3)
 
cs


We can get the following the outputs (trend and cycle) of the BN decomposition.


Reference

Beveridge, S. and C. R. Nelson (1981). A new approach to decomposition of economic time series into permanent and transitory components with particular attention to measurement of the `business cycle', Journal of Monetary Economics 7-2, 151-174. \(\blacksquare\)


No comments:

Post a Comment

Tentative Topics (Keeping Track to Avoid Forgetting)

Segmented Nelson-Siegel model
Shifting Endpoints Nelson-Siegel model
Nadaraya-Watson estimator
Locally weighted scatterplot smoothing (LOWESS)
Time-Varying Parameter Vector Autoregressions (TVP-VAR)
Time-varying or Dynamic Copula
Bayesian VAR
Adrian-Crump-Moench (ACM) term premium model
GARCH-EVT-Copula approach