Code run using Parfor function and error correction
Show older comments
I am using the below code. However, it takes a lot of time to run this especially when it has to search the data. I get the following error when i run this code-
Error using signatureplottry (line 30)
Error: The variable startDate is perhaps intended as a reduction variable, but is actually an
uninitialized temporary.
See Parallel for Loops in MATLAB, "Temporary Variables Intended as Reduction Variables".
Adding just first 50 elements of the dataset. The original file has about 17 million rows. I also tried analyzing using the Profiler and observed that the maximum time is consumed in the search functions -
test12 = ALLDataVector.data(ALLDataVector.test >= temp1(2,:) & ALLDataVector.test < temp2(2,:)); %Consumes 206 seconds
tempreturn = ALLDataVector.data(ALLDataVector.test <= temp1(2,:)); %Consumes 104 seconds
% matlabpool open 2
startingTime = tic
%Code to convert time into strings and create a matrix
t1 = datetime(2014,12,1); %Iniliaze start time for an array calender time
t2 = datetime(2014,12,2);
t = t1:t2;
startDate = datetime("01-Dec-2014 00:00:00");
%CREATE LOOP FOR DIFFERENT INTERVALS
interval = 3;
n=1;
%2:2:18; %Number of minutes for the sampling frequency
%Total number of days between 1Dec 2014 to 7th Jan 2019 is equal to 1498 days
slotu = (n*(24*(60/interval)))-1;
returnsForDay = zeros(size(final_data)-1);
previousReturn = 0;
rv =[]; %Matrix to store values of realised variance per day
counter = 0; %Initilised the value of counter as 0
while startDate <= datetime("1-Dec-2014 23:59:59") %Define a condition where the last date is defined
parfor i = 0:slotu %The loop is defined from 0 until the slot for one day only
startDate = startDate + minutes(00:interval:interval); %The value of startDate is incremented everytime by the interval time, (Say 5 min or 7 min as per the sampling frequency)
endDate = startDate + minutes(00:01:01); %The value of endDate is incremented everytime by just one min after being incremented by the sampling frequency for the exclusion of that time
temp1 = datestr(startDate,'dd-mmm-yyyy HH:MM:SS'); %Converts start datetime array into input array
temp2 = datestr(endDate,'dd-mmm-yyyy HH:MM:SS'); %Converts end datetime array into input array
test12 = ALLDataVector.data(ALLDataVector.test >= temp1(2,:) & ALLDataVector.test < temp2(2,:));
%ALLDataVector.data - Lookup for a price in the ALLDataVector table
if(isempty(test12)) %Checks if test12 is empty or not
tempreturn = ALLDataVector.data(ALLDataVector.test <= temp1(2,:));
if(isempty(tempreturn)) %Checks if tempreturn1 is empty or not
previousValue = 300;
else
previousValue = tempreturn(end);
end
currentValue = previousValue;
else
currentValue = test12(1,:);
end
newcol = length(returnsForDay);
returnsForDay(newcol + 1) = currentValue - previousReturn;
previousReturn = currentValue;
end %for loop is closed
[RV]=realzvariation(returnsForDay); %Function call
rv(counter + 1) = RV; %all new elements move from RV and gets stored in rv
counter = counter + 1; %counter is increased by 1 (like i = i+1)
end %While loop is closed
fprintf('Done with %d iterations in %f seconds\n', slotu, toc(startingTime));
% matlabpool close
Accepted Answer
More Answers (0)
Categories
Find more on Distributed Arrays 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!