Effacer les filtres
Effacer les filtres

Intersection of multiple time-series

4 vues (au cours des 30 derniers jours)
Léon
Léon le 26 Sep 2011
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;

Réponses (2)

Fangjun Jiang
Fangjun Jiang le 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,:);

Léon
Léon le 26 Sep 2011
Sorry, I don't get it. :-(
I understand your example, but I have stored the data in cell arrays and call each matrix of this array in the loop, so I don't know how to adapt your code. As you can see in my code I already tried this but it results in an error.
  1 commentaire
Fangjun Jiang
Fangjun Jiang le 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.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Time Series 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!

Translated by