from Exact Negative Log-likelihood of ARMA models via Kalman Filtering by Statovic
Computation of the exact negative log-likelihood of ARMA models using the Kalman Filter

kalman_example.m
n = 1000;
A = [0.8,0.2]';
C = [-0.7,0.3]';

% Generate 2000 samples from the specific ARMA model with unit variance
y = filter([1,A'], [1,C'], normrnd(0,1,1,n));

% Find the negative log-likelihood of the samples under the true model directly 
Gamma = toeplitz(arma_ACV(A,C,1,n));

fprintf('Calculating negative log-likelihood of n=%d datapoints directly ...\n', n);

t = cputime;
detlogGamma = sum(log(eig(Gamma)));
L = (n/2)*log(2*pi) + (1/2)*detlogGamma + y*inv(Gamma)*y'/2;
t = cputime-t;

fprintf(' Negative Log-likelihood = %f, log(Det(Gamma))  = %f, (time taken %f secs)\n', L, detlogGamma, t);

% Find the negative log-likelihood of the samples under the true model using the Kalman filtering approach
G = toeplitz(arma_ACV(A,C,1,n));

fprintf('Calculating negative log-likelihood of n=%d datapoints directly ...\n', n);

t = cputime;
[L, v_est, v_var, yp] = arma_KalmanLikelihood(A, C, 1, y);
t = cputime-t;

fprintf(' Negative Log-likelihood = %f, log(prod(v_var)) = %f, (time taken %f secs)\n', L, sum(log(v_var)), t);

Contact us at files@mathworks.com