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 v al u e on right hand side , this is called : AR model of order 1, or AR (1) model AR parameter is ϕ For stationarit y, −1 < ϕ < 1 TIME SERIES ANALYSIS IN PYTHON
Interpretation of AR (1) Parameter = + + R μ ϕ R ϵ t −1 t t Negati v e ϕ : Mean Re v ersion Positi v e ϕ : Moment u m TIME SERIES ANALYSIS IN PYTHON
Comparison of AR (1) Time Series ϕ = 0.9 ϕ = −0.9 ϕ = 0.5 ϕ = −0.5 TIME SERIES ANALYSIS IN PYTHON
Comparison of AR (1) A u tocorrelation F u nctions ϕ = 0.9 ϕ = −0.9 ϕ = −0.5 ϕ = 0.5 TIME SERIES ANALYSIS IN PYTHON
Higher Order AR Models AR (1) R = μ + ϕ R + ϵ 1 t −1 t t AR (2) R = μ + ϕ R + ϕ R + ϵ 1 t −1 2 t −2 t t AR (3) R = μ + ϕ R + ϕ R + ϕ R + ϵ 1 t −1 2 t −2 3 t −3 t t ... TIME SERIES ANALYSIS IN PYTHON
Sim u lating 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) TIME SERIES ANALYSIS IN PYTHON
Let ' s practice ! TIME SE R IE S AN ALYSIS IN P YTH ON
Estimating and Forecasting 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
Estimating an AR Model To estimate parameters from data ( sim u lated ) from statsmodels.tsa.arima_model import ARMA mod = ARMA(simulated_data, order=(1,0)) result = mod.fit() TIME SERIES ANALYSIS IN PYTHON
Estimating an AR Model F u ll o u tp u t ( tr u e μ = 0 and ϕ = 0.9 ) print(result.summary()) TIME SERIES ANALYSIS IN PYTHON
Estimating an AR Model Onl y the estimates of μ and ϕ ( tr u e μ = 0 and ϕ = 0.9 ) print(result.params) array([-0.03605989, 0.90535667]) 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() TIME SERIES ANALYSIS IN PYTHON
Let ' s practice ! TIME SE R IE S AN ALYSIS IN P YTH ON
Choosing the Right 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
Identif y ing the Order of an AR Model The order of an AR ( p ) model w ill u s u all y be u nkno w n T w o techniq u es to determine order Partial A u tocorrelation F u nction Information criteria TIME SERIES ANALYSIS IN PYTHON
Partial A u tocorrelation F u nction ( PACF ) TIME SERIES ANALYSIS IN PYTHON
Plot PACF in P y thon Same as ACF , b u t u se plot_pacf instead of plt_acf Import mod u le from statsmodels.graphics.tsaplots import plot_pacf Plot the PACF plot_pacf(x, lags= 20, alpha=0.05) TIME SERIES ANALYSIS IN PYTHON
Comparison of PACF for Different AR Models AR (1) AR (2) AR (3) White Noise TIME SERIES ANALYSIS IN PYTHON
Information Criteria Information criteria : adj u sts goodness - of -� t for n u mber of parameters T w o pop u lar adj u sted goodness - of -� t meas u res AIC ( Akaike Information Criterion ) BIC ( Ba y esian Information Criterion ) TIME SERIES ANALYSIS IN PYTHON
Information Criteria Estimation o u tp u t TIME SERIES ANALYSIS IN PYTHON
Getting Information Criteria From ` statsmodels ` Yo u learned earlier ho w 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 f u ll o u tp u t result.summary() Or j u st the parameters result.params To get the AIC and BIC result.aic result.bic TIME SERIES ANALYSIS IN PYTHON
Information Criteria Fit a sim u lated AR (3) to di � erent AR ( p ) models Choose p w ith the lo w est BIC TIME SERIES ANALYSIS IN PYTHON
Let ' s practice ! TIME SE R IE S AN ALYSIS IN P YTH ON
Recommend
More recommend