time series analysis: autocorrelation instructor: g...

16
Time Series - Autocorrelation APS 425 - Advanced Managerial Data Analysis (c) Prof. G. William Schwert, 2001-2015 1 APS 425 Fall 2015 Time Series Analysis: Autocorrelation Instructor: G. William Schwert 585-275-2470 [email protected] Topics Causes of autocorrelation Diagnosing autocorrelation Modeling autocorrelation

Upload: vonhan

Post on 31-Jan-2018

225 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Time Series Analysis: Autocorrelation Instructor: G ...schwert.ssb.rochester.edu/a425/a425_auto.pdf · Time Series - Autocorrelation APS 425 - Advanced Managerial Data Analysis (c)

Time Series - Autocorrelation APS 425 - Advanced Managerial Data Analysis

(c) Prof. G. William Schwert, 2001-2015 1

APS 425Fall 2015

Time Series Analysis:Autocorrelation

Instructor: G. William Schwert585-275-2470

[email protected]

Topics

• Causes of autocorrelation

• Diagnosing autocorrelation

• Modeling autocorrelation

Page 2: Time Series Analysis: Autocorrelation Instructor: G ...schwert.ssb.rochester.edu/a425/a425_auto.pdf · Time Series - Autocorrelation APS 425 - Advanced Managerial Data Analysis (c)

Time Series - Autocorrelation APS 425 - Advanced Managerial Data Analysis

(c) Prof. G. William Schwert, 2001-2015 2

Autocorrelation

• When the data used in regression model measure the same thing at different points in time, such as the price of Xerox stock, XRXt, it is not unusual for adjacent observations to be correlated with each other [APS_XRX.WF1]

• Corr(XRXt, XRXt-1) > 0, means that when the stock price in period t-1 is above the sample average, it is likely that the stock price in period t will also be above the sample average

• A graph of positively autocorrelated data shows smooth cycles, infrequently crossing the average

Diagnosing Autocorrelation in Eviews

• Calculate autocorrelations from “View” menu

• Graph data from “View” menu

Page 3: Time Series Analysis: Autocorrelation Instructor: G ...schwert.ssb.rochester.edu/a425/a425_auto.pdf · Time Series - Autocorrelation APS 425 - Advanced Managerial Data Analysis (c)

Time Series - Autocorrelation APS 425 - Advanced Managerial Data Analysis

(c) Prof. G. William Schwert, 2001-2015 3

Autocorrelation:Xerox Stock Price, 1961-2015

Note: autocorrelations start at .97 and decay slowly to .75•graph shows slowly moving, persistent pattern

Autocorrelation:Why?

• Autocorrelation happens for many reasons

– Information changes slowly through time, so the factors influencing a variable are likely to be similar in adjacent periods

Page 4: Time Series Analysis: Autocorrelation Instructor: G ...schwert.ssb.rochester.edu/a425/a425_auto.pdf · Time Series - Autocorrelation APS 425 - Advanced Managerial Data Analysis (c)

Time Series - Autocorrelation APS 425 - Advanced Managerial Data Analysis

(c) Prof. G. William Schwert, 2001-2015 4

Example: Random Walk Model for Stock Prices

• If returns to stocks, rt, are random through time (unpredictable), perhaps because the market processes information efficiently and incorporates it into prices immediately,

• Prices (or the logs of prices) will follow a random walk, since this period’s (log) price, log(Pt), equals last period’s (log) price, log(Pt-1), plus this period’s random (continuously compounded) return:

rt = log(Pt) - log(Pt-1) = log(Pt / Pt-1) = log(1 + (Pt - Pt-1)/ Pt-1))

• While the changes in (log) prices are random and unpredictable, the (log) prices in consecutive months contain much of the same information

– The (log) price at time t is just the (log) price at time 0 plus the sum of all returns between 0 and t

log(Pt) = rt + rt-1 + . . . + r1 + log(P0)

– So log(Pt) and log(Pt-1) share t-1 past returns, which means they will be highly correlated

Example: Random Walk Model for Stock Prices

Page 5: Time Series Analysis: Autocorrelation Instructor: G ...schwert.ssb.rochester.edu/a425/a425_auto.pdf · Time Series - Autocorrelation APS 425 - Advanced Managerial Data Analysis (c)

Time Series - Autocorrelation APS 425 - Advanced Managerial Data Analysis

(c) Prof. G. William Schwert, 2001-2015 5

Autocorrelation:Xerox Stock Returns, 1961-2015

Note: autocorrelations for returns are much smaller and returns vary randomly around the mean

Autocorrelation:Xerox Stock Returns by Decade

Puzzling negative spike at lag 6 raises the question of whether it is pervasive (implying a trading opportunity?) or not, so I look at autocorrelations by decade. Spike at lag 6 shows up from 1961-79, and 2000-2009. Not in other decades.

Page 6: Time Series Analysis: Autocorrelation Instructor: G ...schwert.ssb.rochester.edu/a425/a425_auto.pdf · Time Series - Autocorrelation APS 425 - Advanced Managerial Data Analysis (c)

Time Series - Autocorrelation APS 425 - Advanced Managerial Data Analysis

(c) Prof. G. William Schwert, 2001-2015 6

Correcting for Autocorrelation:ARIMA Models

•A simple class of models called autoregressive (AR), integrated (I), moving average (MA) models are often used to represent autocorrelated series

•AR(1) model uses the last observation on the series to predict the current one:

Yt = a + b1 Yt-1 + et

•AR(P) model uses the last P observations on the series to predict the current one:

Yt = a + b1 Yt-1 + . . . + bP Yt-P + et

AR(P) Models in Eviews

•AR(1) model for log of Xerox stock price by using the lagged dependent variable, log(XRXP(-1)), as the independent variable

•Note that the AR(1) coefficient is close to 1

Page 7: Time Series Analysis: Autocorrelation Instructor: G ...schwert.ssb.rochester.edu/a425/a425_auto.pdf · Time Series - Autocorrelation APS 425 - Advanced Managerial Data Analysis (c)

Time Series - Autocorrelation APS 425 - Advanced Managerial Data Analysis

(c) Prof. G. William Schwert, 2001-2015 7

•AR(1) model for log of Xerox stock price by using the AR(1) specification for the errors

•Note the only difference is the constant, which equals the sample mean of XRXP in this case and [sample mean × (1 - .9745) ] when the lagged dependent variable is used

AR(P) Models in Eviews

Residual Autocorrelations from AR(1) Model for Xerox Stock

•Residuals are not autocorrelated, so we fixed the problem

Page 8: Time Series Analysis: Autocorrelation Instructor: G ...schwert.ssb.rochester.edu/a425/a425_auto.pdf · Time Series - Autocorrelation APS 425 - Advanced Managerial Data Analysis (c)

Time Series - Autocorrelation APS 425 - Advanced Managerial Data Analysis

(c) Prof. G. William Schwert, 2001-2015 8

Correcting for Autocorrelation:Differencing

•A series is called “integrated” (the I in ARIMA) when the levels of the series seem to wander around with no tendency to return to any particular point (e.g., the mean), but the differences, Yt = (Yt - Yt-1), seem to be “stationary”

•When the AR(1) coefficient is essentially 1.0 (as in the stock price example), this says you should be analyzing the changes in prices (or returns), not the levels

•Take first differences of the data, then estimate an ARMA model for the changes

Example: Consumer Price Index

•Workfile A425_CPI.WF1 contains the Consumer Price Index for All Urban Consumers both seasonally adjusted (CPISA) and not seasonally adjusted (CPINSA) from the Bureau of Labor Statistics monthly from 1947 through September 2015

•Seasonal adjustment is a complicated filter that is intended to remove “seasonal” patterns from data (we’ll look at whether it is successful here later)•Looks like exponential growth => use log transformation

Page 9: Time Series Analysis: Autocorrelation Instructor: G ...schwert.ssb.rochester.edu/a425/a425_auto.pdf · Time Series - Autocorrelation APS 425 - Advanced Managerial Data Analysis (c)

Time Series - Autocorrelation APS 425 - Advanced Managerial Data Analysis

(c) Prof. G. William Schwert, 2001-2015 9

Logs of Consumer Price Index

•You can also plot data using a log scale for the y-axis

•This plot looks more linear, so log transformation works pretty well•But there is still a pronounced upward trend•Try a regression against a time trend, “time = @trend”

Trend Model for Log of Consumer Price Index

•Model looks great???•R2 = 97%•Coefficient of time = 0.0034

.34% inflation per month, about 4.1% per year•But, lots of serial correlation in the residuals

•Durbin-Watson should be close to 2.0, not 0.0

Page 10: Time Series Analysis: Autocorrelation Instructor: G ...schwert.ssb.rochester.edu/a425/a425_auto.pdf · Time Series - Autocorrelation APS 425 - Advanced Managerial Data Analysis (c)

Time Series - Autocorrelation APS 425 - Advanced Managerial Data Analysis

(c) Prof. G. William Schwert, 2001-2015 10

•Durbin-Watson if approximately 2 [ 1 – auto(1)] where auto(1) is the first autocorrelation of the residuals

•So DW is between 0 and 4, with 2 being a “good” value

•Just as easy to look at the residual autocorrelations at all lags (allows you to see patterns beyond lag 1)

•Usually a good idea to look at multiples of the seasonal period

•In this case, with monthly data, we use 24 lags•Note that the residual autocorrelations are large out to lag 24

Trend Model for Log of Consumer Price Index

Inflation = Differences of Log of Consumer Price Index

•Another way to eliminate trends is to look at changes of the variable

•In this case, the first difference of the logs of the CPI is the inflation rate

Page 11: Time Series Analysis: Autocorrelation Instructor: G ...schwert.ssb.rochester.edu/a425/a425_auto.pdf · Time Series - Autocorrelation APS 425 - Advanced Managerial Data Analysis (c)

Time Series - Autocorrelation APS 425 - Advanced Managerial Data Analysis

(c) Prof. G. William Schwert, 2001-2015 11

Autocorrelations of Inflation

•Autocorrelations are much smaller, but still decay very slowly

•Note that differencing the time trend model

[LOG(CPINSAt)= a + b1 TIMEt + et ]

INFLNSAt = a + b1 TIMEt + et - a - b1 TIMEt-1 - et-1

= b1 + et - et-1

•since TIMEt - TIMEt-1 = 1

•Therefore, the constant in the first differences equation (the average inflation rate) is the same as the slope coefficient in the time trend model for the log of the CPI

Autocorrelations of Inflation:Try an AR(1) Model for Inflation

•AR coefficient, 0.57, is pretty big (t-stat=11.65)•Note R2 is much smaller than for time trend model

•it is in fact the square of the autoregressive coefficient, .572

•This is NOT a problem, since the dependent variable is different •logs of CPI for trend model and differences here

•The SE of regression is comparable, and smaller here (0.002859)

Page 12: Time Series Analysis: Autocorrelation Instructor: G ...schwert.ssb.rochester.edu/a425/a425_auto.pdf · Time Series - Autocorrelation APS 425 - Advanced Managerial Data Analysis (c)

Time Series - Autocorrelation APS 425 - Advanced Managerial Data Analysis

(c) Prof. G. William Schwert, 2001-2015 12

Diagnostics for AR(1) Model for Inflation

•While the residual autocorrelations are much better than for the trend model, they still suggest that the AR(1) is not enough

•We will try an AR(4) model, just to see what happens

AR(4) Model for Inflation

Page 13: Time Series Analysis: Autocorrelation Instructor: G ...schwert.ssb.rochester.edu/a425/a425_auto.pdf · Time Series - Autocorrelation APS 425 - Advanced Managerial Data Analysis (c)

Time Series - Autocorrelation APS 425 - Advanced Managerial Data Analysis

(c) Prof. G. William Schwert, 2001-2015 13

AR(4) Model for Inflation:Interpretation

•AR coefficients are all small and positive and seem to be decaying slowly•This suggests a “moving average (MA)” part to the model•MA models are like AR models, except that we used lagged errors instead of lagged values of the variable

•e.g., MA(1) model uses the last error to predict the current observation:

Yt = a + et + c1 et-1

•MA(Q) model uses the last Q errors to predict the current observation :

Yt = a + et + c1 et-1 + . . . + cQ et-Q

Try an MA(4) Model for Inflation

•MA coefficients are all small and positive and seem to be decaying slowly •This suggests that maybe we need both an AR and an MA part to the model=> try ARMA(1,1) for inflation

Page 14: Time Series Analysis: Autocorrelation Instructor: G ...schwert.ssb.rochester.edu/a425/a425_auto.pdf · Time Series - Autocorrelation APS 425 - Advanced Managerial Data Analysis (c)

Time Series - Autocorrelation APS 425 - Advanced Managerial Data Analysis

(c) Prof. G. William Schwert, 2001-2015 14

Try an ARMA(1,1) Model for Inflation

•This is the best yet

•AR coefficient is close to one, so we will also try differencing the inflation rate and then estimating an MA(1) model

ARMA(1,1) Model for Inflation:Diagnostics

•Residual autocorrelations are pretty small now

•A little bit of negative autocorrelation at the seasonal lag (commonly happens with “seasonally adjusted data” – more on this later)

Page 15: Time Series Analysis: Autocorrelation Instructor: G ...schwert.ssb.rochester.edu/a425/a425_auto.pdf · Time Series - Autocorrelation APS 425 - Advanced Managerial Data Analysis (c)

Time Series - Autocorrelation APS 425 - Advanced Managerial Data Analysis

(c) Prof. G. William Schwert, 2001-2015 15

ARIMA(0,1,1) Model for Inflation

•This simple model is virtually the same as the ARMA(1,1) model earlier, because we are constraining the AR coefficient to equal 1 (and it was .90)

Estimating ARIMA Models in Eviews

The function dlog(cpisa,2) specifies second differencing

You may also specify the difference and log options at seasonal frequencies as described for the simple d operator, dlog(x,n,s), which represents the nth seasonal difference with a seasonal period of s.

If you specify the model using the difference operator expression for the dependent variable, dlog(cpisa), the forecasting procedure will provide you with the option of forecasting the level of the “raw” variable, in this case CPISA.

Page 16: Time Series Analysis: Autocorrelation Instructor: G ...schwert.ssb.rochester.edu/a425/a425_auto.pdf · Time Series - Autocorrelation APS 425 - Advanced Managerial Data Analysis (c)

Time Series - Autocorrelation APS 425 - Advanced Managerial Data Analysis

(c) Prof. G. William Schwert, 2001-2015 16

The difference operator may also be used in specifying independent variables and can be used in equations without ARMA terms. Simply include them in the list of regressors in addition to the endogenous variables. For example,

d(cs,2) c d(gdp,2) d(gdp(-1),2) d(gdp(-2),2) time

is a valid specification that employs the difference operator on both the left-hand and right-hand sides of the equation.

Estimating ARIMA Models in Eviews

Links

Xerox Stock Price dataset:http://schwert.ssb.rochester.edu/A425/A425_xrx.wf1

CPI dataset:http://schwert.ssb.rochester.edu/A425/A425_cpi.wf1

Return to APS 425 Home Page:http://schwert.ssb.rochester.edu/A425/A425main.htm