Sort Stocks into Portfolios based on their return
7 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposte (2)
dpb
il 29 Lug 2014
Modificato: dpb
il 29 Lug 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 Commenti
Maximilian
il 31 Lug 2014
1 Commento
dpb
il 31 Lug 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?
Vedere anche
Categorie
Scopri di più su Portfolio Optimization and Asset Allocation in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!