from Weak form market efficiency tests by Anis Ben Hassen
market efficiency tests

res=averday(x)
function res=averday(x)
% -----------------------------------------------------------------
% Elaborated by : BEN HASSEN Anis 
% "Institut Suprieur de Gestion de Tunis" (ISG Tunis)
% University of Tunis
% 41, rue de la Libert - Cit Bouchoucha - C.P. : 2000 Le Bardo
% Tunisia
% University e-mail: http://www.isg.rnu.tn/
% Personal e-mail: benhassenanis@yahoo.com
% _________________________________________________________________
% January 14, 2004.
% auxiliary function
l=length(x);
i=1;
while i<=l & x(i)~=1 
   i=i+1;
end
debut=i;
i=l;
while i>=1 & x(i)~=1 
   i=i-1;
end
fin=i;
if debut<fin
    for i=debut:fin-1,
        if x(i)==0 && x(i+1)==1
        debut=[debut i+1];
        elseif x(i)==1 && x(i+1)==0
        fin=[fin i];
        end
    end
    fin=[fin(2:length(fin)) fin(1)];
    res=fin-debut+1;
else res=0;
end

Contact us at files@mathworks.com