Sort Stocks into Portfolios based on their return
7 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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);
I obtained this code from the following post: http://www.mathworks.com/matlabcentral/answers/3094-sort-stocks-into-portolios-based-on-stock-characteristics
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
0 commentaires
Réponses (2)
dpb
le 29 Juil 2014
Modifié(e) : dpb
le 29 Juil 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":) ...
0 commentaires
Maximilian
le 31 Juil 2014
1 commentaire
dpb
le 31 Juil 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?
Voir également
Catégories
En savoir plus sur Portfolio Optimization and Asset Allocation dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!