How to efficiently winsorize a big matrix column wise.

3 views (last 30 days)
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

Answers (0)

Categories

Find more on Special Functions in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!