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
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Special Functions에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!