High frequency large time-series matrix: Split in months
1 view (last 30 days)
Show older comments
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!
0 Comments
Accepted Answer
Azzi Abdelmalek
on 13 Sep 2012
Edited: Azzi Abdelmalek
on 13 Sep 2012
clear
data=num2cell(rand(365*2,2))
%d1: first day
%m1: first month
%y1: first year
% If the first sample was taken on 2008/08/15
y1=2008;m1=8;d1=15;
my=datevec(datestr(datenum(y1,m1,(d1:365*2+d1-1)),'yyyy/mm/dd'))
idx=find(diff(my(:,2))~=0)
idx1=1;
for k=1:numel(idx)
M{k}=data(idx1:idx(k),:)
idx1=idx(k)+1
end
5 Comments
Azzi Abdelmalek
on 14 Sep 2012
X={ 0.847 0
0.409 0
0.192 0.039
0.482 0 }
idx=find(any(cellfun(@(x) x==0,X))==1)
X(:,idx)={0}
More Answers (1)
Andrei Bobrov
on 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});
0 Comments
See Also
Categories
Find more on Dates and Time 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!