High frequency large time-series matrix: Split in months
Afficher commentaires plus anciens
Hi! I have a dataset of about 3000 samples with each having about 2 years of daily return data. Now I want to calculate monthly Sharpe Ratios, i.e. as far as I understood I need 24 matrices with monthly data.
Now: How can I have the matrix split in months considering that every month has a different amount of days (i.e. each new small matrix will have different size)?
Additionally: Would it be somehow possible to filter the small matrices even further, i.e. include only specific datasets out of the total amount of samples? I am thinking somehow using another matrix "samples"x"months" indicating 1 or 0 for being included or not.
THank you for every hint on either the first or the second or both of my questions!
Réponse acceptée
Plus de réponses (1)
Andrei Bobrov
le 14 Sep 2012
data = randi(456,800,15); % 15 samples and 800 daily data for example.
datainitial = '2009-07-13';
[y,m,d] = datevec(datainitial);
[y2,m2] = datevec(datenum(y,m,(d:d+size(data,1)-1)'));
[c,c,c] = unique([y2,m2],'rows');
[i1,i2] = ndgrid(c,1:size(data,2));
out = accumarray([i1(:),i2(:)],data(:),[],@(x){x});
Catégories
En savoir plus sur Time Series dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!