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 Center および File ExchangeTime Series Events についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by