matlabmoving-averageautoregressive-models

How to generate Moving Average model


In order to generate Autoregressive model, we have the aryule() command and we can also use filtersEstimating AR model. But how do I generate MA model? For instance, can somebody please show how to generate MA(20) model? I could not find any appropriate technique to do so. The noise is generated from a nonlinear map

epsilon(1) = 0.01;

for i =1 : N 
        epsilon(i+1) = 4*epsilon(i)*(1-epsilon(i));
    end

So, the MA model will regress over epsilon terms.

Q1: Shall be extremely helpful if the code and functional form of an MA model is shown preferably MA(20) using the above noise model.

Q2: This is how I generated an AR(20) using random noise but don't know how to use the above equation as the noise instead of using rand for both MA and AR

 %Generate sine wave = A*sin(2*pi*f*t + phi)
t = linspace(0,1,1000);
A = 5;
f = 2;
phi = pi/8;
sinewave = A*sin(2*pi*f*t + phi);
noisy_sine=sinewave+0.5*randn(size(t));
subplot(1,2,1);
plot(t, sinewave)
hold on;
subplot(1,2,2);
plot(t,noisy_sine);

%Generate AR model(20)
order =20;
ARCoeff = aryule(noisy_sine,order);

Solution

  • I had a same problem. The following links can help :

    https://www.mathworks.com/examples/econometrics/mw/econ-ex18477389-simulate-an-ma-process


    Simulate an MA Process

    This example shows how to simulate sample paths from a stationary MA(12) process without specifying presample observations.

    Contents

    1. Specify a model.
    2. Generate sample paths.
    3. Plot the simulation variance.

    Step 1. Specify a model.

    Specify the MA(12) model

    {y_t} = 0.5 + {\varepsilon _t} + 0.8{\varepsilon _{t - 1}} + 0.2{\varepsilon _{t - 12}}

    where the innovation distribution is Gaussian with variance 0.2.

    model = arima('Constant',0.5,'MA',{0.8,0.2},...
                  'MALags',[1,12],'Variance',0.2);
    

    Step 2. Generate sample paths. Generate 200 sample paths, each with 60 observations.

    rng('default')
    Y = simulate(model,60,'NumPaths',200);
    

    Step 3. Plot the simulation variance.

    figure
    plot(Y,'Color',[.85,.85,.85])
    hold on
    h = plot(mean(Y,2),'k','LineWidth',2)
    legend(h,'Simulation Mean','Location','NorthWest')
    title('MA(12) Process')
    hold off