//////////////////////////////////////////////////////////
//

  lines(0);
  
	lbls = ["BG  ";"BP  ";"BA  ";"BAY ";"BATS"; ...
		"BT  ";"CBRY";"CPG ";"DGE ";"GKN "; ...	
		"GSK ";"III ";"ISYS";"ITV ";"LAD "; ...
		"LAND";"LLOY";"LOG ";"EMG ";"MKS "; ...
		"NG  ";"PRU ";"RTR ";"RSA ";"RBS "; ...
		"TATE";"TSCO";"VOD ";"WOS ";"WPP "]  ;

	dtlbl	= ", Aug 27th 1998 to Jan 17th 2008";


function[chisq,Count] = Contingency1(x)  // x is a vector of +/- 1 s
  nx = size(x,1)-1;
  Jp = x(1:$-1)== 1;
  Jm = x(1:$-1)==-1;
  Kp = x(2:$)  == 1;
  Km = x(2:$)  == -1;
  n11 = sum(bool2s(Jp&Kp));
  n12 = sum(bool2s(Jp&Km));
  n21 = sum(bool2s(Jm&Kp));
  n22 = sum(bool2s(Jm&Km));
  Count  = [n11,n12; n21,n22] ;
  chisq = Pearson(Count);
endfunction

function[chisq] = Pearson(X)  // contingency table
   N = sum(X);
   v = size(X); df = (v(1)-1)*(v(2)-1) ;
   Xr = sum(X,'r');
   Xc = sum(X,'c');
   E  = Xc*Xr/N;
   z  = (X-E).^2;
   z  = z./E;
   z   = sum(z);
   [chisq,Q] = cdfchi("PQ",z,1) ;
endfunction

function[chisq,Count] = Contingency2(x,y); // x, y is vector of +/- 1  s
   x = (1+x)/2;
   y = (1+y)/2;
   V = x + 2*y; // codes the 4 possibilities to {0,1,2,3}
                //      0 = --, 1 = +-, 2 = -+, 3 = ++
   V0 = V(1:$-1);  V1 = V(2:$);
   V0 = round(V0); V1 = round(V1);
   Count = zeros(4,4);
   for ii = 1:length(V0),
      I = 1+V0(ii);  J = 1+V1(ii);
      Count(I,J) = Count(I,J)+1;      
   end;
   chisq = Pearson(Count);
endfunction
