library(nowcasting)

This package contains a collection of function to estimate forecasts for the near futures or the recent past, in other words nowcasting. The econometric framework is a model of state spaces with many variables and commom components, the Dynamic Factor Model. In this first version we focus on the problem when the variable of interest is a quarterly time series and the regressor are monthly time series.

Theoretical framework:

The standard model is the Dynamic Factor Model[^1]. This model can be specified in a space state representation:

[^1]:For more details see Stock and Watson (2011).

$$X_t = C F_t + e_t$$ $$ F_{t} = \sum_{j=1}^p (A_{j}L^jF_t) + Bu_t$$ where:

Models and visualization

Little words about each method of estimation

Two Stages

This method is based on Giannone et al (2008) and Bańbura and Rünstler (2011). Brief, the explanatory variables are all in monthly frequencies, the dependent variable is in quarterly frequency, the common factors are estimated by a two stages method based on Principal Component Annalysis and Kalman Filter. The aggregatoion is based on Murasawa and Mariano (2003) approximation.

Quarterly factors

The explanatory variables are aggregated in a quarterly quantity ,and the factor is estimated in this frequency. A bridge equation is estimated to explain and forecast the lower frequency serie.

pib<-BRGDP[,8]
y<-month2qtr(diff(diff(pib,3),12))
x<-Bpanel(BRGDP[,-8],rep(4,dim(BRGDP)[2]),aggregate = T)
q<-1
r<-2
p<-1
now_2sq<-nowcast(y,x,q,r,p,method = '2sq')

The main output is a mts containning the dependent variable, the estimation in-sample and out-sample.

window(now_2sq$main,start=c(2017,1),frequency=4)
nowcast.plot(now_2sq)

The output of bridge equation are available.

summary(now_2sq$reg)

Another output are the factors theyselves:

dfactors<-now_2sq$factors$dynamic_factors
window(dfactors,start=c(2017,1),end=c(2017,12),frequency=12)
nowcast.plot(now_2sq,type='factors')

Monthly factors

The factors are estimared in a monthly frequency, these factors are aggregated in a quarterly quantity, and the bridge equation is estimated.

This method permits to create a monthly measure of a quarterly variable

x<-Bpanel(BRGDP[,-8],rep(4,dim(BRGDP)[2]),aggregate = F)
q<-1
r<-2
p<-1
now_2sm<-nowcast(y,x,q,r,p,method = '2sm')
nowcast.plot(now_2sm,type = 'month_y')

Expected Maximization

No need of bridge equation, series of all frequencies can used to estimate the factor jointly.

x<-Bpanel(BRGDP[,-8],rep(4,dim(BRGDP)[2]),aggregate = F)
q<-1
r<-2
p<-1
now_em<-nowcast(y,x,q,r,p,'EM')

All the three methods return forecasts and nowcasts for the explanatory variables.

datas<-zoo::as.Date(x)
df<-data.frame(x)
row.names(df)<-datas
ind<-which(rownames(df)==as.Date('2017-10-01'))
df1<-df[(ind-6):ind,]
knitr::kable(df1,row.names = T)
df<-now_em$fore_x
row.names(df)<-as.character(datas)
ind<-which(rownames(df)==as.Date('2017-10-01'))
df1<-df[(ind-6):ind,]
knitr::kable(df1,row.names = T)

Data extraction and tranformation

Data base available offline in the package

BRGDP

This is a panel containning a piece of the information for Brazilian economic activity extracted in 03/10/2017. It is available for practice and offline examples. The time series are encoded as in the Brazilian Central Bank Time Series Management System v2.1.

Example of some series:

datas<-zoo::as.Date(BRGDP)
df<-data.frame(BRGDP)
row.names(df)<-datas
knitr::kable(tail(data.frame(df[,5:8]),7),row.names = T)

USGDP

This dataset contain informations for US economy available in replication files of the seminal paper. It is a list with 2 data.frames.

USGDP$Base

It contains the time series with its values. Example of some series:

USGDP<-nowcasting::USGDP
datas<-zoo::as.Date(USGDP$Base)
df<-data.frame(USGDP$Base)
row.names(df)<-datas
knitr::kable(tail(data.frame(df[,1:5]),5),row.names = T)
USGDP$Legenda

It contains the legend with the specifications of the model and the series. Example of some series:

df<-USGDP$Legenda
knitr::kable(tail(data.frame(df[,1:5]),5),row.names = T)

Real Time Data Base

This is a function to create real time data base from series available in Brazilian Central Bank Time Series Management System v2.1. One can use these function to evaluate forecast models in real-time out-of-sample exercises.

A note of warning: We take no responsibility for delays in disclosure of new information or malfunctioning of the central bank platform.

Collecting information now:

br_gdp<-base_extraction(series_code = 22099)
window(br_gdp,start = c(2016,1),frequency = 12)

What information was available yesterday?

We can answer this question for a limited set of time series. To take a look at those use the function RTDB with no argument.

head(RTDB())

Calling the information of a specific vintage.[^2]:

[^2]: Here a vintage is the day when the information was gathered.

serie1<-RTDB(series_code = 1,vintage ='2017-10-30')
window(serie1,start = c(2017,1),frequency = 12)

For which vintages this serie is available:

tail(RTDB(series_code = 1))

Which series were available in a specific vintage:

head(RTDB(vintage ='2017-04-04'))

Pseudo RTDB

This function reacreate a pseudo real-time data base, supposing that there was no revision in the series and that the calendar of releases is fixed in a stylized way provided by the user. One can use this function to evaluate forecast models in pseudo real-time out-of-sample exercises.

suppose all variables are realease instantly after the end of the period, i.e. 0 days of delay, and we are on 2017-03-23.

prtdb<-PRTDB(mts = BRGDP,delay = rep(0,dim(BRGDP)[2]),vintage = '2017-03-23')
window(prtdb,start=c(2017,1),frequency=12)

Now suppose the information is released in a asynchronous fashion, and we are on 2016-12-04.

prtdb<-PRTDB(mts = BRGDP,delay = c(1,3,-50,6,60,15,120,0),vintage = '2016-12-04')
window(prtdb,start=c(2016,1),frequency=12)

Balanced Panel

This function transforms the original monthly time series to its stationary representation following the user specification. The time series with more than 1/3 missings, i.e. NAs are deleted.

The missings and outliers are “corrected” following the same method avaible in the replication files of Giannone et al. 2008. Outliers are defined as observations that lies more than 4 IQR from median. All missings and outliers are replaced by the median. A centered moving average of degree k is calculated, forming a new panel. Then the missings and outliers are replaced by their equivalent observations on this new panel. We've made an important modifications on the outlier_correction function found in the above mentioned files: Here the median of an even-sized sample is calculated by the mean of the two most central values, rather than using the largest of those numbers. Because of this modification the results obtained with the original replication files in (USGDP) are slightly different than those found here.

In the end, the monthly series can be aggregated to quarterly quantities following the Mariano and Murasawsa 2003 approximation.

The transformation is specified by codes, as follows:

$$\frac{X_t - X_{t-1}}{X_{t-1}}$$

$$X_t - X_{t-1}$$

$$\frac{X_t - X_{t-12}}{X_{t-12}} - \frac{X_{t-1} - X_{t-13}}{X_{t-13}}$$

$$(X_t - X_{t-12}) - (X_{t-1} - X_{t-13})$$

bpanel<-Bpanel(BRGDP,rep(4,dim(BRGDP)[2]))
window(bpanel,start=c(2017,1),end=c(2018,1),frequency=12)

month2qtr

This function transforms monthly in quarterly time series only choosing the value of the last month of the quarter to represent it.

Example:

gdp_month<-BRGDP[,'serie22099']
window(gdp_month,c(2016,1),frequency=12)
gdp_qtr<-month2qtr(gdp_month)
window(gdp_qtr,c(2016,1),frequency=4)

qtr2month

This function transforms quarterly in monthly time series doing the opposite process of month2qtr function.

Example:

gdp_month2<-qtr2month(gdp_qtr)
window(gdp_month2,c(2016,1),frequency=12)

Reference:

Bańbura, M., & Rünstler, G. (2011). A look into the factor model black box: publication lags and the role of hard and soft data in forecasting GDP. International Journal of Forecasting, 27(2), 333-346.

Giannone, D., Reichlin, L., & Small, D. (2008). Nowcasting: The real-time informational content of macroeconomic data. Journal of Monetary Economics, 55(4), 665-676.

Mariano, R. S., & Murasawa, Y. (2003). A new coincident index of business cycles based on monthly and quarterly series. Journal of applied Econometrics, 18(4), 427-443.

Stock, J. H., & Watson, M. (2011). Dynamic factor models. Oxford Handbook on Economic Forecasting.



guilbran/nowcasting documentation built on May 17, 2019, 2:09 p.m.