function results = testsofidentical(pdens,mom,date)
% runs the Andrews QLR test for the pits
% INPUTS: pdens - PITs
%         mom - powers of the pits
%         date - vector of dates corresponding to the time-series
% OUTPUTS: h - indicator whether the null has been rejected or not
%          pvalue - pvalue of the test
%          stat - test statistics
%          cvalue - critical value of the test statistic
% The default level of signifiance is 5%
% the output is in a vector form reporting the results for the time series
% of the PITs from all the considered models
truncdate = [];
for i = 1:size(pdens,1)
    pit = cleanNaN(pdens(i,:));
    
    iter = 1;
    for j = 1:length(pit);
        k = 0;
        while k == 0
            if pit(1,j) == pdens(i,iter)
                truncdate = [truncdate; date(iter,1)];
                k = 1;
            end
            iter = iter+1;
        end
    end
    qlr(i,:) = QLR_hac(pit'.^mom,ones(length(pit),1),0,ones(length(pit),1),1,0); 
    brdate(i,:) = truncdate(qlr(i,3),1);
    %[h(i,1) pValue(i,1) stat(i,1) cValue(i,1)] = lbqtest((pit-mean(pit)).^mom,lag);
end

results.stat = qlr(:,1);
results.pValue = qlr(:,2);
results.brdate = brdate;