필터 지우기
필터 지우기

Enable Parfor or Vectorization

조회 수: 3 (최근 30일)
Brian
Brian 2012년 6월 27일
I'm looking for a faster way to calculate these loops. I've read some about vectorization on Loren's page but I'm not sure that would apply here. I also have the parallel computing toolbox, but because of how I'm writing to my preallocated data arrays, I get the message "Valid Indices are restricted in parfor loops." Can someone take a look at my code and make a suggestion how to get parfor to work and/or use vectorization? Essentially I'm calculating a 21 day return for every security, for every day (past 21 days) in my dataset.
Thanks a lot, Brian
parfor i = 1:SecCnt
tickidx = strcmp(UnqSec(i,1),Cusips);
for d = 21:DatesCnt
RollRtns(i*(d-21)+1,1) = prod(Rtns(Rtns(:,2)>d-21 & Rtns(:,2)<=d & tickidx));
RollCusips(i*(d-21)+1,1) = UnqSec(i,1);
RollDates(i*(d-21)+1,1) = UnqDates(d,1);
end
end
  댓글 수: 1
Brian
Brian 2012년 7월 2일
편집: Brian 2012년 7월 2일
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

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Parallel for-Loops (parfor)에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by