Intersection of multiple time-series

2 次查看(过去 30 天)
Léon
Léon 2011-9-26
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;

回答(2 个)

Fangjun Jiang
Fangjun Jiang 2011-9-26
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 2011-9-26
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 个评论
Fangjun Jiang
Fangjun Jiang 2011-9-26
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Time Series Events 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by