# Forecasting with Xreg arguments

Below is the DF I'm using which contains time series data for 1) operating earnings and 2) Cash flow to equity holders for the quarters spanning Q1'88 to Q4'15:

> dput(dist.frame)
structure(list(QUARTER = c("03/31/1988", "06/30/1988", "09/30/1988",
"12/31/1988", "03/31/1989", "06/30/1989", "09/30/1989", "12/31/1989",
"03/31/1990", "06/30/1990", "09/30/1990", "12/31/1990", "03/31/1991",
"06/30/1991", "09/30/1991", "12/31/1991", "03/31/1992", "06/30/1992",
"09/30/1992", "12/31/1992", "03/31/1993", "06/30/1993", "09/30/1993",
"12/31/1993", "03/31/1994", "06/30/1994", "09/30/1994", "12/31/1994",
"03/31/1995", "06/30/1995", "09/30/1995", "12/31/1995", "03/31/1996",
"06/30/1996", "09/30/1996", "12/31/1996", "03/31/1997", "06/30/1997",
"09/30/1997", "12/31/1997", "03/31/1998", "06/30/1998", "09/30/1998",
"12/31/1998", "03/31/1999", "06/30/1999", "09/30/1999", "12/31/1999",
"03/31/2000", "06/30/2000", "09/30/2000", "12/31/2000", "03/31/2001",
"06/30/2001", "09/30/2001", "12/31/2001", "03/31/2002", "06/30/2002",
"09/30/2002", "12/31/2002", "03/31/2003", "06/30/2003", "09/30/2003",
"12/31/2003", "03/31/2004 ", "06/30/2004", "09/30/2004", "12/31/2004",
"03/31/2005", "06/30/2005", "09/30/2005", "12/31/2005", "03/31/2006",
"06/30/2006", "09/30/2006", "12/31/2006", "03/31/2007", "06/30/2007",
"09/30/2007", "12/31/2007", "03/31/2008", "06/30/2008", "09/30/2008",
"12/31/2008", "03/30/2009", "06/30/2009", "09/30/2009", "12/31/2009",
"03/31/2010", "06/30/2010", "09/30/2010", "12/31/2010", "03/31/2011",
"06/30/2011", "09/30/2011", "12/30/2011", "3/30/2012", "6/29/2012",
"9/28/2012", "12/31/2012", "3/28/2013", "6/28/2013", "9/30/2013",
"12/31/2013", "3/31/2014", "6/30/2014", "9/30/2014", "12/31/2014",
"3/31/2015", "6/30/2015", "9/30/2015", "12/31/2015"), O.E = c(5.48,
6.05, 6.22, 6.37, 6.41, 6.53, 5.54, 5.84, 5.61, 6.06, 5.97, 5.01,
4.77, 4.79, 5.11, 4.63, 4.93, 5.21, 5.12, 5.61, 6.25, 6.57, 6.92,
7.16, 7.17, 7.75, 8.03, 8.8, 8.64, 9.5, 9.78, 9.78, 9.39, 10.31,
9.92, 11.01, 10.56, 11.13, 11.03, 11.29, 10.92, 11.43, 10.45,
11.47, 11.73, 13.21, 12.97, 13.77, 13.97, 14.88, 14.17, 13.11,
10.73, 9.02, 9.16, 9.94, 10.85, 11.64, 11.61, 11.94, 12.48, 12.92,
14.41, 14.88, 15.87, 16.98, 16.88, 17.95, 18, 19.42, 18.84, 20.19,
20.75, 21.95, 23.03, 21.99, 22.39, 24.06, 20.87, 15.22, 16.62,
17.02, 15.96, -0.09, 10.11, 13.81, 15.78, 17.16, 19.38, 20.9,
21.56, 21.93, 22.56, 24.86, 25.29, 23.73, 24.24, 25.43, 24, 23.15,
25.77, 26.36, 26.92, 28.25, 27.32, 29.34, 29.6, 26.76, 25.81,
26.14, 25.44, 23.06), CFE.as...of.O.E = c(0.41, 0.41, 0.4, 0.4,
0.39, 0.44, 0.51, 0.49, 0.49, 0.53, 0.5, 0.62, 0.59, 0.68, 0.61,
0.66, 0.59, 0.62, 0.63, 0.54, 0.48, 0.5, 0.46, 0.43, 0.44, 0.44,
0.41, 0.38, 0.36, 0.38, 0.36, 0.36, 0.37, 0.37, 0.39, 0.34, 0.34,
0.35, 0.37, 0.35, 0.34, 0.37, 0.41, 0.35, 0.34, 0.32, 0.66, 0.56,
0.55, 0.64, 0.68, 0.62, 0.68, 0.82, 0.85, 0.78, 0.67, 0.64, 0.67,
0.63, 0.57, 0.56, 0.56, 0.62, 0.58, 0.55, 0.58, 0.7, 0.79, 0.73,
0.77, 0.87, 0.82, 0.86, 0.79, 0.85, 0.88, 1.01, 1.26, 1.56, 1.21,
1.01, 1.08, -141.33, 0.94, 0.59, 0.59, 0.64, 0.6, 0.68, 0.67,
0.71, 0.71, 0.74, 0.77, 0.71, 0.68, 0.78, 0.81, 0.87, 0.74, 0.83,
0.87, 0.85, 0.99, 0.78, 0.89, 0.95, 1.04, 0.98, 1.1, 1.21)), .Names = c("QUARTER",
"O.E", "CFE.as...of.O.E"), row.names = c(NA, -112L), class = "data.frame")
>


The idea is to incorporate the pre-whitening strategy from the referenced article(https://onlinecourses.science.psu.edu/stat510/node/75) in order to identify a relationship between growth in operating earnings cash flow to equity holders.

oe.series<-ts(dist.frame[2],start = c(1988,1),frequency = 4)

### First diff of LN OE series appears stationary
plot(oe.series)
plot(log(oe.series))
log(oe.series)
OE.LN<-na.kalman(ts(as.vector(log(oe.series)),start=c(1988,1),frequency=4))
plot(OE.LN)
acf2(OE.LN)
summary(ur.df(OE.LN,type = "trend",selectlags = "AIC"))
##Above ADF test failed to reject, move to differencing
oe.ln.diff<-diff(OE.LN)

plot(oe.ln.diff)
acf2(oe.ln.diff)
summary(ur.df(oe.ln.diff,type = "drif",selectlags = "AIC"))

###Auto Arima fit model of 1st diff LN OE in whtX
whtX<-auto.arima(oe.ln.diff)
whtX.res<-residuals(whtX)
summary(whtX)


The above block is to set up what I'm treating as the input series, operating earnings - The economic rationale is that earnings growth in current or previous periods influences the portion of earnings distributed to equity holders to the extent that operating performance conveys information about the future that management will incorporate. The WhtX.res object contains the whitened input series to be used for filtering the output.

###Bring in CFE series, filtering and model fitting applied to Yadj series from TSO to remove outlier effects
cfe.series<-ts(dist.frame$CFE.as...of.O.E,start = c(1988,1),frequency = 4) cfe.series plot(cfe.series) acf2(cfe.series) cfe.tso<-tso(cfe.series,remove.method = "bottom-up",tsmethod = "auto.arima") cfe.tso plot(cfe.tso) cfe.adj<-cfe.tso$yadj

###Auto.Arima indicated that cfe.adj needed differencing for stationarity


Above sets up the CFE series (output) which I ultimately hope to model. This is potentially where I started to get a little in the weeds via the TSO function from TsOutliers package. What makes this a little harder is that both series cover the Q4'08 and Q1'09 crisis periods and the magnitude of these 'outliers' is such that I felt strongly needed to be corrected for. TSO picks up the most significant (to be expected) as 'AO' leading me to proceed with attempting to model and forecast the 'Yadj' series.

Below basically represents two different attempt to filter and model the cross correlation as well as a fitted model with exogenous regressors. The first attempt essentially followed the procedures in the linked paper: Whiten input, filter output accordingly, compare CCF and use this to guide the chosen xreg arguments. Initially this indicated that Lag1 may be a predictor of the differenced CFE series. However, when I tried to fit this the regressor was not significant in the model and no time series structure was found in the errors - not what I had hoped for.

After thinking about this more, I realized that neither series exhibited inter series autocorrelation after transforming for stationarity. This led me to think that maybe the filtering step is not required at all. Moving directly to CCF examination of the stationary series directly, it then appeared that lag4 input may be a viable predictor. After fitting 'Xmodel2' it appears that this might be a better fit (I think?) however auto.arima again finds no time series structure for the errors.

###Examining CCF of series' since ACF plots don't indicate any auto-correlation

###Filter output series from whtX model defined above, examine CCF

oe.train<-window(oe.ln.diff,start=c(1988,2),end=c(2014,4))

whtX$coef whty<-filter(cfe.adj.diff,c(1,-whtX$coef,sides=1))
both<-ts.intersect(whtX.res,whty)
ccf.val<-acf(both,na.action = na.pass)
###After whitening and filtering, CCF indicates input may lead output series by one period

oe.train.lag<-window(lag(oe.train,-1),end=c(2014,4))
oe.train.lag4<-window(lag(oe.train,-4),end=c(2014,4))
Xmodel<-auto.arima(cfe.train,xreg = oe.train.lag)
oe.train.lag4
oe.lag4.test<-window(lag(oe.ln.diff,-4),start=c(2015,1),end=c(2015,4))
xmodel2<-auto.arima(window(cfe.train,start=c(1989,2)),xreg = oe.train.lag4)
summary(xmodel2)
X2fcast<-forecast(xmodel2,xreg = oe.lag4.test,h = 4)
X2fcast