In this tutorial, the instructor introduces the fundamentals of autoregressive (AR), moving‑average (MA) and combined ARMA time‑series models. An AR model regresses the current value on its past values, with a white‑noise shock term; the order P indicates how many lags are used. A MA model regresses the current value on past shock terms, with order Q indicating the number of lagged shocks. An ARMA(p,q) model combines both approaches, using past values and past shocks. The lesson demonstrates how to simulate ARMA data with the statsmodels function `armageneratesample`, emphasizing the need to pass the negative of the desired AR coefficients and to include a leading 1 in the coefficient arrays. It then briefly shows how to fit an ARMA model using the `ARMA` class: instantiate with data and order, then call `fit()`. The tutorial ends with a prompt to practice the concepts.
Chapters
Now you know how to prepare data, let's dive straight into the models. We will discuss AR and MA models and how these are combined into ARMA models. In an autoaggressive 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 1 times the value of the time series at the previous 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. A1 is the autoregressive coefficient at lag 1. Compare this to a simple linear regression where the dependent variable is is yt and the independent variable is y t minus 1. The coefficient A1 is just the slope of the line and the shocks are the residuals to the line. This is a first order AR model. The order of the model is the number of time lags used. An order 2 AR model has two autoregressive coefficients and has two independent variables, the series at lag 1 and the series at lag 2. More generally, we use P to mean the order of the AR model. This means we have P autoregressive coefficients and use P lags. 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 M1 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 MA2 model would include shocks from one and two steps ago. More generally, we use Q to mean the order of the MA model. 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 1:1 model. More generally, we use Armapq to define an ARMA model. The P tells us the order of the autoregressive part and the Q tells us the order of the moving average part. Using the STATS models package, we can both fit ARMA models and create ARMA data. Let's take this ARMA one one model. Say we want to simulate data with these coefficients. First, we import the armageneratesample function. Then we make lists for the AR and MA coefficients. Note that both coefficient lists start with 1. This is for the 0 lag term and we will always set this to 1. We set the lag 1 ar coefficient as 0.5 and ma coefficient as 0.2. We generate the data, passing in the coefficients, the number of data points to create, and the standard deviation of the shocks. Here we actually pass in the negative of the AR coefficients we desire. This is a quirk we will need to remember. Our sample may look like this fitting is covered in the next chapter, but here's a quick peek at how we might fit this data. First we import the ARMA model class. We instantiate the model, feed it the data, and define the model order. Then, finally, we fit. You've learned a lot. Now let's practice.