我正在分析股票的日內交易量情況。我已經構建了一個(粗糙的)代碼,可以很好地完成兩件事,但速度很慢。一隻股票可以在一段時間內超過20萬股交易,我想分析大約200只股票。循環速度升級
我的代碼看起來超過了3個月的交易數據,將數據裝入每天10分鐘的桶中。我這樣做是爲了確保股票每桶至少交易x值。然後,我將日內桶集合到時間桶中,以獲得平均容量分佈的感覺。下面只是
的代碼示例演示如何斌我的數據,然後通過總倉:
% Totals by time bucket
for i = 1:size(VALUE,1)
MyDay = day(datenum(sprintf('%d',VALUE(i,1)),'yyyymmdd'));
MyMonth = month(datenum(sprintf('%d',VALUE(i,1)),'yyyymmdd'));
MyYear = year(datenum(sprintf('%d',VALUE(i,1)),'yyyymmdd'));
StartHour = hour(VALUE(i,2));
StartMinute = minute(VALUE(i,2));
EndHour = hour(VALUE(i,3));
EndMinute = minute(VALUE(i,3));
if StartMinute ~= 50
t = (day(MyTrades(:,1)) == MyDay & month(MyTrades(:,1)) == MyMonth & year(MyTrades(:,1)) == MyYear & hour(MyTrades(:,1)) == StartHour & minute(MyTrades(:,1)) >= StartMinute & minute(MyTrades(:,1)) <= EndMinute);
else
t = (day(MyTrades(:,1)) == MyDay & month(MyTrades(:,1)) == MyMonth & year(MyTrades(:,1)) == MyYear & hour(MyTrades(:,1)) == StartHour & hour(MyTrades(:,1)) < EndHour & minute(MyTrades(:,1)) >= StartMinute);
end
tt = MyTrades(t,:);
MyVALUE(i,1) = sum(tt(:,5));
end
% Aggregate totals
for ii = 1:50
VWAP(ii,1) = datenum(0,0,0,9,0,0)+datenum(0,0,0,0,10,0)*ii-datenum(0,0,0,0,10,0) ;
VWAP(ii,2) = datenum(0,0,0,9,0,0)+datenum(0,0,0,0,10,0)*ii;
StartTime = VWAP(ii,1);
temp = (VALUE(:,2) == StartTime);
temp2 = VALUE(temp,:);
VWAP(ii,3) = sum(temp2(:,4))/100;
end
有沒有計算這些類型的「蠻力」分析的更優雅和(更重要的)更快的方式?
@lesto是正確的一切字符串比較和創作正在極大地減慢你的速度。但真正的解決方案是用C或C++編寫。 –