function [ L ] = logl_MA( b0 )
% Loglikelihood for MA(1) and MA(2).

global x T MA

omega = zeros(T,T);                                                         % Placeholder for Variance-Covariance Matrix.
mean = b0(1);                                                               % Mean.
stddev = b0(2);                                                             % Standard deviation.
theta1 = b0(3);                                                             % MA coefficient.
mu = ones(T,1)*mean;                                                        % Mean Vector.

    if MA == 1                                                              % For MA(1) process.
        
        omega = omega + eye(T).*(stddev^2).*(1+theta1^2);                   % Fill in the variances.
        
        omega(2,1) = (stddev^2)*theta1;                                     % Fill in the first order covariances.
        omega(T-1,T) = omega(2,1);
        
        for i = 2:T-1
            omega(i-1,i) = (stddev^2)*theta1;
            omega(i+1,i) = omega(i-1,i);
        end
        
    elseif MA == 2                                                          % For MA(2) process.
  
        ADD CODE HERE
    end
    
    
L = -0.5*T*log(2*pi) - 0.5*log(abs(det(omega))) ...                         % Loglikelihood function.
                                        - 0.5*(x-mu)'*inv(omega)*(x-mu);

L = -L;                                                                     % Negative of loglikelihood function (for minimization).

end

