Sort Stocks into Portfolios based on their return

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

Answers (2)

dpb
dpb on 29 Jul 2014
Edited: dpb on 29 Jul 2014
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 on 31 Jul 2014
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 Comment
dpb
dpb on 31 Jul 2014
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?

Sign in to comment.

Categories

Find more on Elementary Math 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!