Simulating a Moving Average Process

When a moving average process underlies a time series data, we can model the data as a linear combination of the average/mean of the time series, the current error, and past errors. Mathematically, we can represent this process as:

$$ y_t = \mu + \epsilon_t + \theta_1 \epsilon_{t-1} + ... + \theta_q \epsilon_{t-q} $$

This note demonstrates the simulation of the moving average process

import numpy as np
import matplotlib.pyplot as plt
from statsmodels.tsa.arima_process import ArmaProcess

%matplotlib inline
%config InlineBackend.figure_format = 'retina'

Running Simulation

ar = np.array([1])
ma = np.array([1, .53, .31, .01])
ma_process = ArmaProcess( ar=ar, ma=ma ).generate_sample(nsample=150)
fig = plt.figure(figsize=(9,4))
plt.plot(ma_process)
plt.title('Simulation of MA(3) Process')
plt.show()
Time Series Plot for Moving Average Process Simulation

ACF and PACF Plots

With a moving average process, we expect the significant autocorrelation lags to drop more abruptly after some lag q. In this case, right after lag 1

fig, ax = plt.subplots(2, 1,figsize=(12,8))

plot_acf(ma_process, lags=20, auto_ylims=True, ax=ax[0])
plot_pacf(ma_process, lags=20, method='ywm', auto_ylims=True, ax=ax[1])
plt.show()
Time Series Plot for Moving Average Process Simulation