Sort Stocks into Portfolios based on their return

Hallo everybody,
I have a question regarding a code i am currently working on.
I have a matrix containing stock returns for a universe of stocks for different days. Now, i would like to sort the stocks depending on their return on the first day into ten different portfolios.
Currently i am using those functions:
announcement_returns_quantiles = quantile(announcement_returns_vol_sig_adj, 0.1:0.1:0.9, 2);
[~,idx] = histc(announcement_returns_vol_sig_adj(a, :).',[-inf ... announcement_returns_quantiles(a,:) inf]);
nonNaN = idx ~= 0;
return_ew(r,:) = accumarray(idx(nonNaN), stock_returns(r, nonNaN), [], @nanmean);
However, as i have several stocks with a return of zero on this day, the result of the quantile-function sometimes looks like this with more than one boarder equal to zero. (-0.045 -0.034 -0.03 -0.01 0 0 0.01 0.023 0.03).
If I now use the histc command the resulting portfolios are unbalanced as one portfolio contains all the stocks with a return equal to zero and the other portfolio which also has 0 as its quantile boarder does not contain any stocks at all.
Does anyone know a solution to this problem ?
Thanks in advance, Maximilain

답변 (2개)

dpb
dpb 2014년 7월 29일
편집: dpb 2014년 7월 29일
Before histc fixup the EDGES vector...
>> v= [-0.045 -0.034 -0.03 -0.01 0 0 0.01 0.023 0.03];
>> v(diff(v)~=0)
ans =
-0.0450 -0.0340 -0.0300 -0.0100 0 0.0100 0.0230
>>
ADDENDUM
I didn't look at the code link but probably the best way would be to make the fix/cleanup in the routine that returns the quantiles (and a bug report/fix to the author, maybe in order). BTW, this "boarder" isn't a paying lodging resident but a "border":) ...
Maximilian
Maximilian 2014년 7월 31일

0 개 추천

Hi, first of all thank you for your help.
But that wont fix my problem.
The problem is that i have a large proportion of variables equal to zero hence to "borders" are equal to zero in the quantile function.
histc then only assigns those variables with an value equal to zero to only one of the bins and completely ignores the other bin which should also contain variables with an value equal to zero.
Kind regards, Maximilian

댓글 수: 1

dpb
dpb 2014년 7월 31일
Then you don't want a histogram at all, then. As far as it goes, "zero is zero". Why is that binning any different than classifying some number of nonzero values in a given bin according to their value?
That aside, if indeed there needs must be multiple zero-valued bins, what's wrong with then shifting some arbitrary number from the one to however many there are approximating the mean of N(0)/n0 where N is the total number and n is the number of zero bins?

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기

질문:

2014년 7월 29일

댓글:

dpb
2014년 7월 31일

Community Treasure Hunt

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

Start Hunting!

Translated by