-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogl_MA2.m
35 lines (25 loc) · 1.18 KB
/
logl_MA2.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
function L = logl_MA2( b )
% The following constructs the loglikelihood function for an MA(2).
global x2 T
omega = zeros(T,T); % Placeholder for Variance-Covariance Matrix.
b0 = b(1); % Mean.
b1 = b(2);
b2 = b(3);
s = b(4); % Standard deviation.
omega = omega + eye(T).*(s^2).*(1+b1^2+b2^2); % Fill in the variances.
omega(2,1) = (s^2)*(b1+b1*b2); % Fill in the first order covariances.
omega(T-1,T) = omega(2,1);
omega(3,1) = (s^2)*b2;
omega(T-2,T) = omega(3,1);
for i = 2:T-1
omega(i-1,i) = (s^2)*(b1+b1*b2);
omega(i+1,i) = omega(i-1,i);
end
for i = 3:T-2
omega(i-2,i) = (s^2)*b2;
omega(i+2,i) = omega(i-2,i);
end
L = - 0.5*log(abs(det(omega)))- 0.5*(x2-b0)'*inv(omega)*(x2-b0);
L = L - 0.5*T*log(2*pi);
L = -L; % Negative of loglikelihood function (for minimization).
end