1 / 23
Todays Plan
Todays plan
2 / 23
External Toolboxes
External toolboxes
Kevin Sheppard toolbox
We will use the Kevin Sheppard Toolbox for time series models.
Available from http://www.kevinsheppard.com/MFE_Toolbox.
See notes from Matlab Session 4 to see how to add the path to this
toolbox to Matlab directory.
Functions from the toolbox will be marked with a KS next to them.
3 / 23
To plot time series, you need to know the date and time of observations.
Matlab can treat date and time in two formats: string and number.
datestr(numDate,formatOut)
I
datenum(strDate,formatIn)
I
I
Example
datestr(736285,mm/dd/yyyy)
datenum(17-Nov-2015,dd-mmm-yyyy)
Daria Kalyaeva (SFI)
gives 11/17/2015.
gives 736285.
November 13, 2015
4 / 23
You need to be able to manipulate dates and times in Matlab to plot time
series.
datetick(axis,dateFormat)
Converts dates in numerical form on the specified axis (x or y)
to dates in specified format (1 dd-mmm-yyyy, see Matlab Help
for the full list of formats).
Example
Get date ticks on the x-axis in the format mmm-yy (e.g. Jan-15 for January
2015):
plot(dateAsNum,Y)
datetick(x,mmm-yy)
5 / 23
ACF/PACF plots are the starting point for ARMA model selection:
we can see whether the series are autocorrelated and if so, what the
autocorrelation pattern is.
6 / 23
[AC,ACstErr] = sacf(X,k,robust)
(KS)
I do not use the standard errors from this function in the examples, so I
set this to 0 to avoid plotting graphs automatically.
(KS)
7 / 23
ACF and PACF plots allow us to determine what ARMA model to use.
Exponential decline pattern in ACF/PACF can be present in
slightly different forms but overall it is the same thing:
I
I
8 / 23
ACF
F
F
PACF
F
F
Typical patterns:
I
I
I
9 / 23
Confidence bands: 2 T .
The choice of the number of lags: we want enough lags to see a pattern
but not so many that AC estimates become unreliable.
10 / 23
ARMA(1,0) PACF
0.4
PAC
AC
0.4
0.2
0.2
0
0
0
10
15
20
ARMA(0,1) ACF
15
20
0.4
PAC
0.4
AC
10
ARMA(0,1) PACF
0.2
0.2
0
0
0
10
15
20
0.6
0.4
0.2
0
0
10
15
10
15
20
ARMA(1,1) PACF
PAC
AC
ARMA(1,1) ACF
20
0.6
0.4
0.2
0
-0.2
0
10
15
20
11 / 23
AC
ARMA(1,0) ACF
0.08
0.06
0.04
0.02
0
-0.02
0
10
15
0.08
0.06
0.04
0.02
0
-0.02
20
ARMA(0,1) ACF
15
20
PAC
0.1
0.05
0
0
10
15
20
ARMA(1,1) ACF
10
15
20
ARMA(1,1) PACF
0.2
0.2
PAC
AC
0.1
0.05
AC
10
ARMA(0,1) PACF
0.1
0.1
0
0
0
10
15
20
10
15
20
12 / 23
Then the only thing left should be the unpredictable error terms!
I
13 / 23
Plot
series
Mean
stationary
?
yes
Select
model using
ACF/PACF
plots
Estimate
parameters
Uncorrelated
residuals
?
yes
Significant
coefficients
?
no
no
no
Remove
trend,
seasonality
Add
parameters
Remove
parameters
yes
Forecast
Modify
model
14 / 23
(KS)
Example
AR(p) model with constant
MA(q) model with constant
armaxfilter(y,1,(1:p))
armaxfilter(y,1,[],(1:q))
15 / 23
16 / 23
17 / 23
I
I
18 / 23
Parameter interpretation:
I
AR parameters:
F
F
PAC;
for returns/growth: the coefficient estimate is the percentage change in
current value due to a 1% change in past value.
MA parameters:
F
F
19 / 23
Testing
Testing
What to keep in mind?
F
F
H0 : k = 0 k {1, ..., K };
H1 : k 6= 0 for some k {1, ..., K }.
P
2k
Test statistic: Q = T (T + 2) Kk=1 T k
.
Under H0 , Q 2K . Reject H0 if Q > 2K ,1 .
NOTE: Do not use the Ljung-Box test function from the Kevin
Sheppard toolbox; it performs a different test.
Daria Kalyaeva (SFI)
20 / 23
Testing
Testing
Ljung-Box test
(D)
LBresult = LjungBoxTest(X,K,alpha)
21 / 23
Testing
Testing
Joint coefficient hypothesis testing
Use the LRtest(.) function for the likelihood ratio test (presented in
Session 4 slides).
22 / 23
Forecasting
Forecasting
What to keep in mind?
Example
We have T observations of stock price, p.
Estimated AR(1) model for stock returns, rt = log(pt+1 ) log(pt ):
rt = + 1 rt1 .
Forecast for price in period T + 1:
1
rT = + 1 rT 1 ;
2
pT +1 = e rT +log(pT ) = pT e rT .
Daria Kalyaeva (SFI)
23 / 23