1. Intro to AR, MA and ARMA models
Now you know how to prepare your data, lets dive straight into AR and MA models and how these are combined into ARMA models.
2. AR models
In an autoregressive model we regress the values of the time series against previous values of this same time series.
The equation for a simple AR model is shown here. The value of the time series at time t, is a-one times the value of the time series at the previous time step. There's also a shock term, epsilon-t. The shock term is white noise, meaning each shock is random and not related to the other shocks in the series. a-one is the autoregressive coefficient at lag one.
Compare this to a simple linear regression where the dependent variable is y-t and the independent variable is y-t-minus-one. The coefficient a-one is just the slope of the line and the shocks are the residuals to the line.
3. AR models
This is a first order AR model. The order of the model is the number of time lags used. An order two AR model has two autoregressive coefficients, and has two independent variables, the series at lag one and the series at lag two.
More generally, we use p to mean the order of the AR model. This means we have p autoregressive coefficients and use p lags.
4. MA models
In a moving average model we regress the values of the time series against the previous shock values of this same time series.
The equation for a simple MA model is shown here. The value of the time series, is m-one times the value of the shock at the previous step; plus a shock term for the current time step.
This is a first order MA model. Again, the order of the model means how many time lags we use. An MA two model would include shocks from one and two steps ago.
More generally, we use q to mean the order of the MA model.
5. ARMA models
An ARMA model is a combination of the AR and MA models.
The time series is regressed on the previous values and the previous shock terms. This is an ARMA-one-one model.
More generally we use ARMA-p-q to define an ARMA model. The p tells us the order of the autoregressive part of the model and the q tells us the order of the moving-average part.
6. Creating ARMA data
Using the statsmodels package, we can fit ARMA models and create ARMA data. Lets take this ARMA-one-one model. Say we want to simulate data with these coefficients.
7. Creating ARMA data
First we import the arma-generate-sample function.
Then we make lists for the AR and MA coefficients. Both coefficient lists start with one. This is for the zero lag term and we always set this to one. We want the lag-one AR coefficient to be 0.5 and the MA coefficient to be 0.2.
We actually need to pass in the negative of the AR coefficients we desire. This is a quirk we will need to remember.
To generate the data, we pass in the coefficients, the number of data points to create, and the standard deviation of the shocks.
8. Creating ARMA data
Our sample may look like this.
9. Fitting and ARMA model
Fitting is covered in the next chapter, but here is a quick peek at how we might fit this data.
First we import the ARIMA model class.
We instantiate the model, feed it the data and define the model order.
Then finally we fit.
10. Let's practice!
You've learned a lot. Now let's practice!