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