我正在分析股票的日内交易量概况。我已经构建了一段(粗略的)代码,它可以很好地完成两件事,但速度很慢。一只股票在给定时期内可以进行超过 20 万次交易,我想分析大约 200 只股票。
我的代码查看了超过 3 个月的交易数据,每天将数据分成 10 分钟的存储桶。我这样做是为了确保一只股票每桶至少交易 x 值。然后,我将日内存储桶聚合为时间存储桶,以了解平均交易量分布。
下面的代码示例仅显示了我如何对数据进行 bin 分类,然后按 bin 进行聚合:
% 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
有没有更优雅和(更重要的是)更快的方法来计算这些类型的“蛮力”分析?