Cross-correlation of returns matrix

2 ビュー (過去 30 日間)
Christos Chatzikomnitsas
Christos Chatzikomnitsas 2021 年 1 月 21 日
回答済み: Rik 2021 年 1 月 21 日
Assume a returns table A(200 rows returns,30 cols stock names), trying to create a cross correlation matrix between each of the pairs of stocks.
Am I right trying to use xcorr function? Trying to do that in a for loop and also tried to xcorr with matrix name.
xcorr would take timeseries of A(,1) and create all cross correlations with rest of columns (in pairs), or am I wrong? I would expect the result would be D=cols+(cols-1)+..(cols-N), one cross-correlation for each unique pair. But thats not what I get from the below. Is my understanding wrong or my usage of function?
[r,lags]=xcorr(A)
or
for i=1:30
for j=1:30
D=xcorr(A(:,i),A(:,j))
end
end

回答 (1 件)

Rik
Rik 2021 年 1 月 21 日
I'm not sure the rest of your code is doing what you want, but at the very least you need to index D so you don't overwrite it every iteration.

カテゴリ

Help Center および File ExchangeCorrelation and Convolution についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by