Cointegration test (in a loop function)

Hi,
I have a n x m dimensional matrix consisting of "n" stock price observations and "m" stocks. I call this matrix "StockPrices" in the example.
I want to run a number of cointegrating regressions on each of the possible pairs of stocks and store the test statistics in a matrix.
That is, I want to first use stock 1 as the dependent variable and regress it on all other stocks, i.e. stock 2, 3, 4 etc, one at a time.
Next, I want to use stock 2 as the dependent variable, and regress it on stock 1, 3, 4., etc. I am using the "cadf" function. How to a write a loop that prevents me from regressing stock 1 on stock 1, and stock 2 on stock 2, etc.?
My initial thought (without adressing the above problem):
for i=1:m;for j=1:m;
y=StockPrices(:,i);
x=StockPrices(:,j);
results=cadf(y, x, 0, 1);
Test statistics(i,j)=results.adf;
end;
end;
Thanks!

回答(0 个)

类别

提问:

2013-9-16

Community Treasure Hunt

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

Start Hunting!

Translated by