function results = abc(DeltaL_oos,DeltaL_in,m,qn,dDeltaL_oos,dDeltaL_in,R,e_in);
[P,k]=size(DeltaL_oos);


%s=nw(DeltaL_oos,qn);
%varA=s+(s/P); T=P+R; 
%for t=1:P; 
%    varA=varA-6*(s^2)*((t^2)-t*(R+T)+(R+T)/2+(R^2+T^2)/2);
%end;
%varA;


B=olsbeta(DeltaL_oos,DeltaL_in)*DeltaL_in;  
C=olsres(DeltaL_oos,DeltaL_in);
betahat = olsbeta(DeltaL_oos,DeltaL_in);

%Construct CI
K = [1, mean(dDeltaL_in.*C+DeltaL_in.*(dDeltaL_oos-betahat*dDeltaL_in))]; 
CovLCe=nw([DeltaL_in.*C,e_in],qn); 
V = [nw(DeltaL_in.*C,qn), (sqrt(P/R))*CovLCe(1,2); (sqrt(P/R))*CovLCe(1,2), (P/R)*nw(e_in,qn)]; 
%varbetahat = K*V*K' / (mean(DeltaL_in.^2)^2); 
varbetahat=nw(DeltaL_in.*C,qn)/ (mean(DeltaL_in.^2)^2);
varyhat=(mean(DeltaL_in)^2)*varbetahat; 
rejB=mean(B)-1.96*sqrt(varyhat)/sqrt(P) >0  |  mean(B)+1.96*sqrt(varyhat)/sqrt(P) <0; 

varC=nw(DeltaL_oos,qn)-varyhat; 
%varC=nw(C,qn); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
rejC=mean(C)-1.96*sqrt(varC)/sqrt(P) >0  |  mean(C)+1.96*sqrt(varC)/sqrt(P) <0;  

A=[];  
for tau=m:P; 
    A=[A; sum(DeltaL_oos(tau-m+1:tau))/m]; 
end; 
A = A - mean(DeltaL_oos);
Omega=[nw(DeltaL_oos,qn), mean(dDeltaL_oos.^2)*(sum(e_in.^2)/P)/P; mean(dDeltaL_oos.^2)*(sum(e_in.^2)/P)/P, nw(DeltaL_oos,qn)];
%Omega=[nw(DeltaL_oos,qn), (var(e_in)/R)*mean(dDeltaL_oos.^2)/P; (var(e_in)/R)*mean(dDeltaL_oos.^2)/P, nw(DeltaL_oos,qn)];
%%%Omega=[nw(DeltaL_oos,qn), (((P-m)/m))*(var(e_in)/R)*mean(dDeltaL_oos.^2); (((P-m)/m))*(var(e_in)/R)*mean(dDeltaL_oos.^2), nw(DeltaL_oos,qn)];
%Omega=[nw(DeltaL_oos,qn), (((P-m)/m)^2)*(var(e_in)/R)*mean(dDeltaL_oos.^2)/P; (((P-m)/m)^2)*(var(e_in)/R)*mean(dDeltaL_oos.^2)/P, nw(DeltaL_oos,qn)];
%Omega=[nw(DeltaL_oos,qn), (sqrt(P/m))*(var(e_in)/R)*mean(dDeltaL_oos.^2)/P; (sqrt(P/m))*(var(e_in)/R)*mean(dDeltaL_oos.^2)/P, nw(DeltaL_oos,qn)];
%varA=nw(DeltaL_oos,qn); %A=A-mean(DeltaL_oos); 
Afinal=[]; 
for tau=1:P-m+1;
    Ahere=[1,-1]*(inv(Omega^(1/2)))*[A(tau,1); mean(DeltaL_oos)];
    Afinal=[Afinal; Ahere];
end;  

cv=cvcalcABS(m/P);
[nA,kA]=size(A); 
cvlow=-cv*ones(nA,1); cvup=cv*ones(nA,1); 
varA=nw(DeltaL_oos,qn); 
%varA=[1, -(1/sqrt(R))]*nw([DeltaL_oos,dDeltaL_oos],0)*[1, -(1/sqrt(R))]'; 
rejA=max(sqrt(P)*abs(A)/sqrt(varA)-cvlow <0  |  sqrt(P)*abs(A)/sqrt(varA)-cvup >0); 

%rejA=max(sqrt(P)*abs(A)/sqrt(varA)-cvlow <0  |  sqrt(P)*abs(A)/sqrt(varA)-cvup >0); 
        
stats=[max(sqrt(P)*abs(A)), mean(B)/(sqrt(varyhat)/sqrt(P)),  mean(C)/(sqrt(varC)/sqrt(P))];  
rej=[rejA, rejB, rejC];   
results.A = A;
results.B = B; 
results.C = C; 
results.stats = stats;
results.rej = rej;
results.beta = olsbeta(DeltaL_oos,DeltaL_in);
results.varyhat=varyhat; 