How to efficiently winsorize a big matrix column wise.

조회 수: 3 (최근 30일)
BdS
BdS 2020년 2월 4일
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