Instead of loop in loop, multiply e (residuals, NxT) with ej where ej is e with jth element to front, i.e. ej = (ej, ej+1,...,eN,e1,...,ej-1). loop over ej and multiply with e. gives N cross correlations, i.e. one row for rho matrix.
advantage: only one loop necessary. faster?
disadvantage: if large T and large N, speed might be slower.
solutions: do test runs and assign threshold when multiplication gets slower.
Instead of loop in loop, multiply e (residuals, NxT) with ej where ej is e with jth element to front, i.e. ej = (ej, ej+1,...,eN,e1,...,ej-1). loop over ej and multiply with e. gives N cross correlations, i.e. one row for rho matrix.
advantage: only one loop necessary. faster? disadvantage: if large T and large N, speed might be slower. solutions: do test runs and assign threshold when multiplication gets slower.