Enable Parfor or Vectorization
Show older comments
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 Comment
Answers (0)
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!