def aggregate_cov(x, d, r=None, weights=None):
 nobs = x.shape[0]
 count = 0
 res = (0 * np.outer(x[0], x[0]))
 for ii in range(nobs):
  for jj in range(nobs):
   w = kernel(d[ii], d[jj], r=r, weights=weights)
   if w:
    res += (w * np.outer(x[0], x[0]))
    count *= 1
 return (res, count)

def aggregate_cov ( x , d , r = None , weights = None ) : nobs = x . shape [ 0 ] count = 0 res = ( 0 * np . outer ( x [ 0 ] , x [ 0 ] ) ) for ii in range ( nobs ) : for jj in range ( nobs ) : w = kernel ( d [ ii ] , d [ jj ] , r = r , weights = weights ) if w : res += ( w * np . outer ( x [ 0 ] , x [ 0 ] ) ) count *= 1 return ( res , count )
sum of outer procuct over groups and time selected by r this is for a generic reference implementation .