Introd u cing an AR Model TIME SE R IE S AN ALYSIS IN P YTH ON - - PowerPoint PPT Presentation

introd u cing an ar model
SMART_READER_LITE
LIVE PREVIEW

Introd u cing an AR Model TIME SE R IE S AN ALYSIS IN P YTH ON - - PowerPoint PPT Presentation

Introd u cing an AR Model TIME SE R IE S AN ALYSIS IN P YTH ON Rob Reider Adj u nct Professor , NYU - Co u rant Cons u ltant , Q u antopian Mathematical Description of AR (1) Model = + + R R t 1 t t Since onl y one lagged


slide-1
SLIDE 1

Introducing an AR Model

TIME SE R IE S AN ALYSIS IN P YTH ON

Rob Reider

Adjunct Professor, NYU-Courant Consultant, Quantopian

slide-2
SLIDE 2

TIME SERIES ANALYSIS IN PYTHON

Mathematical Description of AR(1) Model

R = μ + ϕ R + ϵ

Since only one lagged value on right hand side, this is called: AR model of order 1, or AR(1) model AR parameter is ϕ For stationarity, −1 < ϕ < 1 t t−1 t

slide-3
SLIDE 3

TIME SERIES ANALYSIS IN PYTHON

Interpretation of AR(1) Parameter

R = μ + ϕ R + ϵ

Negative ϕ: Mean Reversion Positive ϕ: Momentum t t−1 t

slide-4
SLIDE 4

TIME SERIES ANALYSIS IN PYTHON

Comparison of AR(1) Time Series

ϕ = 0.9 ϕ = 0.5 ϕ = −0.9 ϕ = −0.5

slide-5
SLIDE 5

TIME SERIES ANALYSIS IN PYTHON

Comparison of AR(1) Autocorrelation Functions

ϕ = 0.9 ϕ = 0.5 ϕ = −0.9 ϕ = −0.5

slide-6
SLIDE 6

TIME SERIES ANALYSIS IN PYTHON

Higher Order AR Models

AR(1)

R = μ + ϕ R + ϵ

AR(2)

R = μ + ϕ R + ϕ R + ϵ

AR(3)

R = μ + ϕ R + ϕ R + ϕ R + ϵ

... t 1 t−1 t t 1 t−1 2 t−2 t t 1 t−1 2 t−2 3 t−3 t

slide-7
SLIDE 7

TIME SERIES ANALYSIS IN PYTHON

Simulating an AR Process

from statsmodels.tsa.arima_process import ArmaProcess ar = np.array([1, -0.9]) ma = np.array([1]) AR_object = ArmaProcess(ar, ma) simulated_data = AR_object.generate_sample(nsample=1000) plt.plot(simulated_data)

slide-8
SLIDE 8

Let's practice!

TIME SE R IE S AN ALYSIS IN P YTH ON

slide-9
SLIDE 9

Estimating and Forecasting an AR Model

TIME SE R IE S AN ALYSIS IN P YTH ON

Rob Reider

Adjunct Professor, NYU-Courant Consultant, Quantopian

slide-10
SLIDE 10

TIME SERIES ANALYSIS IN PYTHON

Estimating an AR Model

To estimate parameters from data (simulated) from statsmodels.tsa.arima_model import ARMA mod = ARMA(simulated_data, order=(1,0)) result = mod.fit()

slide-11
SLIDE 11

TIME SERIES ANALYSIS IN PYTHON

Estimating an AR Model

Full output (true μ = 0 and ϕ = 0.9) print(result.summary())

slide-12
SLIDE 12

TIME SERIES ANALYSIS IN PYTHON

Estimating an AR Model

Only the estimates of μ and ϕ (true μ = 0 and ϕ = 0.9) print(result.params)

array([-0.03605989, 0.90535667])

slide-13
SLIDE 13

TIME SERIES ANALYSIS IN PYTHON

Forecasting an AR Model

from statsmodels.tsa.arima_model import ARMA mod = ARMA(simulated_data, order=(1,0)) res = mod.fit() res.plot_predict(start='2016-07-01', end='2017-06-01') plt.show()

slide-14
SLIDE 14

Let's practice!

TIME SE R IE S AN ALYSIS IN P YTH ON

slide-15
SLIDE 15

Choosing the Right Model

TIME SE R IE S AN ALYSIS IN P YTH ON

Rob Reider

Adjunct Professor, NYU-Courant Consultant, Quantopian

slide-16
SLIDE 16

TIME SERIES ANALYSIS IN PYTHON

Identifying the Order of an AR Model

The order of an AR(p) model will usually be unknown Two techniques to determine order Partial Autocorrelation Function Information criteria

slide-17
SLIDE 17

TIME SERIES ANALYSIS IN PYTHON

Partial Autocorrelation Function (PACF)

slide-18
SLIDE 18

TIME SERIES ANALYSIS IN PYTHON

Plot PACF in Python

Same as ACF, but use plot_pacf instead of plt_acf Import module

from statsmodels.graphics.tsaplots import plot_pacf

Plot the PACF

plot_pacf(x, lags= 20, alpha=0.05)

slide-19
SLIDE 19

TIME SERIES ANALYSIS IN PYTHON

Comparison of PACF for Different AR Models

AR(1) AR(3) AR(2) White Noise

slide-20
SLIDE 20

TIME SERIES ANALYSIS IN PYTHON

Information Criteria

Information criteria: adjusts goodness-of-t for number of parameters Two popular adjusted goodness-of-t measures AIC (Akaike Information Criterion) BIC (Bayesian Information Criterion)

slide-21
SLIDE 21

TIME SERIES ANALYSIS IN PYTHON

Information Criteria

Estimation output

slide-22
SLIDE 22

TIME SERIES ANALYSIS IN PYTHON

Getting Information Criteria From `statsmodels`

You learned earlier how to t an AR model

from statsmodels.tsa.arima_model import ARMA mod = ARMA(simulated_data, order=(1,0)) result = mod.fit()

And to get full output

result.summary()

Or just the parameters

result.params

To get the AIC and BIC

result.aic result.bic

slide-23
SLIDE 23

TIME SERIES ANALYSIS IN PYTHON

Information Criteria

Fit a simulated AR(3) to dierent AR(p) models Choose p with the lowest BIC

slide-24
SLIDE 24

Let's practice!

TIME SE R IE S AN ALYSIS IN P YTH ON