I have edited this code so that it now works in parallel but is still rather slow. I've read about vectorization and I'm wondering if it's possible for this code. This takes about 30 seconds to in serial and 10 seconds to run in parallel because of the large data overhead. I'm just trying to speed this up a bit.
parfor i = 1:SecCnt
NestLoop = NaN(1,DatesCnt-21);
tickidx = strcmp(UnqSec(i,1),Cusips);
for d = 21:DatesCnt
NestLoop(d-20) = prod(Rtns(Rtns(:,2)>d-21 & Rtns(:,2)<=d & tickidx));
end
RollRtns(i,:) = NestLoop;
end