%% Apply Equality Constraints to Parameters During Estimation
% Fit an AR(2) model to simulated data while holding the model constant fixed during estimation.
%
%% Simulate Data from Known Model
% Suppose the DGP is
% {y_t} = 0.5{y_{t - 1}} - 0.3{y_{t - 2}} + {\varepsilon _t},
% where \varepsilon_{t} is a series of iid Gaussian random variables with mean 0 and variance 0.1.
% Create the AR(2) model representing the DGP.

DGP = arima('AR',{0.5,-0.3},...
    'Constant',0,'Variance',0.1);

% Simulate a random 500 observation path from the model.

rng(5); % For reproducibility
T = 500;
y = simulate(DGP,T);

%
%% Create Model Object Specifying Constraint
% Assume that the mean of y_t is 0, which implies that c is 0.
% Create an AR(2) model for estimation. Set c to 0.

Mdl = arima('ARLags',1:2,'Constant',0)

% Mdl is a partially specified arima model object. Specified parameters include all required parameters and the model constant. NaN-valued properties, including \phi_1, \phi_2, and \sigma^2, are unknown model parameters to be estimated.
%
%% Estimate Model
% Fit the AR(2) model template containing the constraint to y.

EstMdl = estimate(Mdl,y)

% EstMdl is a fully specified, estimated arima model object; its estimates resemble the parameter values of the AR(2) model DGP. The value of c in the estimation summary and object display is 0, and corresponding inferences are trivial or do not apply.
% Copyright 2020 The MathWorks, Inc.