Intersection of multiple time-series
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I managed to get the intersection of all time-series, but now I want to reduce all matrices based upon this intersection stored in 'AnB':
So the problem is how to extract all rows for that I have data points. As of now the last line is incorrect.
May somebody help me? Thank you very much!
%%1. Get data
conn = yahoo('http://download.finance.yahoo.com');
stocks = {'^GDAXI';'DB1.DE';'ADS'}
Beginn = {'Jan 01 2009'}
Ende = {'Dec 31 2011'}
N = length(stocks)
data = cell(N,1);
for n = 1:N,
data{n} = fetch(conn, stocks(n,1),{'Close', 'Adj Close'},Beginn, Ende, 'd');
end;
%%2. Sync time series
for n = 1:N,
% Get the dates where I have data in all series (intersection)
AnB = intersect(data{n,1}(:,1),data{n,1}(:,1));
end;
for n = 1:N,
% Now delete all rows in every time-series that are not part of the intersection
[c, a, b] = intersect(AnB(:,1),data{n,1}(:,1));
data{n,1} = data{n,1}(a,:); % --> this gives an error
end;
0 Kommentare
Antworten (2)
Fangjun Jiang
am 26 Sep. 2011
Use this example, the key is to check the extra return arguments of intersect().
A={'a',1;'b',2;'c',3;'d',4};
B={'a',10;'c',30;'e',40;'f',50};
[AnB,IA,IB]=intersect(A(:,1),B(:,1));
NewA=A(IA,:);
NewB=B(IB,:);
0 Kommentare
Léon
am 26 Sep. 2011
1 Kommentar
Fangjun Jiang
am 26 Sep. 2011
Please give a short snip of data to make your point. Others won't go fetch the stock from Yahoo to test your code. You also need to double check your code. AnB = intersect(data{n,1}(:,1),data{n,1}(:,1)) has two exact same input arguments.
Siehe auch
Kategorien
Mehr zu Time Series Events finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!