*
* @CorrIntegral(eps=threshold,dim=embedding dimension) series start end
*
* Computes a correlation integral for a series. See, for instance, Campbell, Lo and
* MacKinlay (1997), "The Econometrics of Financial Markets", Princeton University
* Press, pp 476-478.
*
* Parameters:
*  series       series to analyze
*  start  end   range to analyze. By default, the defined range of series
*
* Options:
*  EPS=threshold value for closeness [.1]
*  DIM=embedding dimension [1]
*
*  EPS is Campbell, Lo and MacKinlay's k, and DIM is their n.
*
* Variables Defined:
*  %%CNT is the value of the correlation integral for this value of eps
*  %NOBS is the number of observations
*
* Revision Schedule:
*  05/2008 Stripped from BDSTEST procedure
*
procedure CorrIntegral series start end
type series series
type integer start end
*
option integer dim 1
option real    eps .1
*
local integer startl endl r s j n
local real indics dif
decl  real %%cnt
*
inquire(series=series) startl<<start endl<<end
compute n=endl-startl+1
compute %nobs=n
*
compute indics=0.
do r=startl,endl-dim
   do s=r+1,endl-dim+1
      do j=0,dim-1
         compute dif =abs(series(r+j)-series(s+j))
         if dif>eps
            break
      end do j
      compute indics=indics+(dif<=eps)
   end do s
end do r
*
compute %%cnt=indics/(n*(n-1)/2.)
end

