How to efficiently winsorize a big matrix column wise.

3 次查看(过去 30 天)
Hi,
I am looking for an efficient winsorization function / code. Matlab has been running the code below since 24h and it is not yet finished.
Do you know any alternative code / function?
Thank you in advance for your suggestions.
% winsorize factorValues and instrRet
% factor values accross time
% --> nFactors =74 // nAssets=3733 // nDates=261
for f=1:nFactors
for a=1:nAssets
alpha=0.03;
data_min=quantile(factorValues(:,a,f),alpha);
data_max=quantile(factorValues(:,a,f),1-alpha);
factorValues(factorValues<data_min)=data_min;
factorValues(factorValues>data_max)=data_max;
end
end
% accross instrument
for f=1:nFactors
for d=1:nDates
alpha=0.04;
data_min=quantile(factorValues(d,:,f),alpha);
data_max=quantile(factorValues(d,:,f),1-alpha);
factorValues(factorValues<data_min)=data_min;
factorValues(factorValues>data_max)=data_max;
end
end
for i=1:nAssets
alpha=0.03;
data_min=quantile(instrRet(:,f),alpha);
data_max=quantile(instrRet(:,f),1-alpha);
instrRet(instrRet<data_min)=data_min;
instrRet(instrRet>data_max)=data_max;
end

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Special Functions 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by