How can i speed up this code
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hello fellows,
I need some help to speed up my code.
Its basically a backtesting system, my array have 32M elements, and in my calculation the script will take 17 days to end the processing.
The code look for some patterns in matrix padroes, read each line and find the pattern in other array called direcao
in this code i look for 10 pips in 10 minutes and a maximum stop loss of 5 pips.
here is the code
if true
barra = waitbar(0,'Iniciando Backtests');
nAcertos=0;
incremento = 0.1/10000;
for t =size(padroes,1):-1:1
perc = (t / size(padroes,1));
waitbar(perc,barra,sprintf(' %f%%concluidos',perc))
posicoes = findPattern2(direcao,padroes(t,:));
if ( length(posicoes) >=30)
nAcertos=0;
for j=1:length(posicoes)
% Here i calculate what is the minutes thats ends the array
% for example i want to close the trade in 10 minutes and
% the minutes found in the array is 40 so i ll look for the
% next occurrency o of (40+11) 51, 10 minutes of trade
if ( minutos(posicoes(j)+15) + 11 <60 )
quantosMinutos = minutos(posicoes(j)+15) + 11;
else
quantosMinutos = (minutos(posicoes (j) +15 )) +11 - 60 ;
end
if ( posicoes(j) +2000> length(direcao))
break;
end
r= find( minutos(posicoes(j)+15: posicoes(j) +2000)>quantosMinutos,1,'first');
if (~isempty(r) && ( horas( r +(posicoes(j)+15 )) - horas(posicoes(j)+15) ) <2 )
posicaoFinalVetor = r + posicoes(j)+15 ;
end %
r=[];
resultado = bid(posicoes(j)+16)+ (10/10000) ; % here i calculate what is my price for profit.. and the look its index in the array
r = find(bid(posicoes(j)+15:posicaoFinalVetor)>resultado,1,'first');
if ( ~isempty(r))
posicaoGain = r+ posicoes(j)+15;
% sprintf('Operação de compra')
% sprintf('Preço de entrada %f',bid(posicoes(j)+15))
r=[];
resultado = bid(posicoes(j)+15)- 0.0005;here i calculate what is my price for stop.. and the look its index in the array
r = find(bid(posicoes(j)+15:posicaoFinalVetor)<resultado,1,'first');
% [~,ia,~] = unique(c,'first');
%resultado = resultado - incremento ;
if ( ~isempty(r) )
posicaoStop = r + posicoes(j)+15;
% sprintf('Stopado em %d',bid(r))
else
posicaoStop = posicaoGain +1 ;
% sprintf('Gain Atingido %d',bid(posicaoGain))
end
% if posicaogain< posicaostop i assume that this is a winning
% trade otherwise a losing trade
if ( posicaoGain < posicaoStop)
nAcertos = nAcertos+1;
end
if ( (nAcertos + (length(posicoes) -j) /length(posicoes) < 0.6))
break;
end
end
end
achou=0;
% nAcertos
% length(posicoes);
%((nAcertos / length(posicoes)))*100
if ((nAcertos / length(posicoes) >=0.60)&& nAcertos ~= 0)
padraoaux = padroes(t,:);
nAcertos =0;
dlmwrite(sprintf('c:/users/leonardo/documents/MATLAB/padroes/Alta/Filtrados/Final/EURUSDfinal.txt'),padraoaux, '-append', 'delimiter' , '','newline','pc');
end
nAcertos =0;
stopou =0;
end
end
close(barra) end
I appreciate the help in advance, thank you!
0 Kommentare
Antworten (0)
Siehe auch
Kategorien
Mehr zu Characters and Strings finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!