% Matlab program file to accompany
% Christoffersen and Diebold (1997),
% "Cointegration and Long-Horizon Forecasting"
% Conditional MLE of MA(1) for dy2;

function f=ml(x);

global dy2 uhat2 Te;

uhat2=zeros(Te,1);

for t=2:Te;
    uhat2(t)=dy2(t)-x(1)*uhat2(t-1); 
end;

ml= - (Te-1)/2*log(2*pi) - (Te-1)/2*log(x(2)^2) - sum(uhat2.^2)/2/x(2)^2;
   
if x(1)>.99;  ml=-1000000; end;
if x(1)<-.99; ml=-1000000; end;

f=-ml;