n=size(prices,2);
M_coint=zeros(n,n);
for i=1:n;
j=1:n;
M_coint(i,j)=cadf(prices(:,i),prices(:,j),0,1);
M_coint(i,j)=M_coint.adf;
end
message error: The following error occurred converting from struct to double: Error using double Conversion to double from struct is not possible.

댓글 수: 1

fede
fede 2015년 9월 22일
cadf give the following results: ans =
alpha: -0.0199
adf: -3.0082
crit: [6x1 double]
nlag: 1
nvar: 1
meth: 'cadf'
I want to pull out the result of adf

댓글을 달려면 로그인하십시오.

 채택된 답변

Stephen23
Stephen23 2015년 9월 22일
편집: Stephen23 2015년 9월 22일

0 개 추천

cadf does not seem to be an inbuilt MATLAB function, and you give no information about how it is defined or the output that it returns. And you also don't give us the complete error message (which tell us the line), so we have to also guess where this error is occurring in your code.
I like guessing games, so lets try.
First you define
M_coint=zeros(n,n);
which means M_coint is a matrix of class double. Then if we assume that cadf returns a structure, then the line
M_coint(i,j)=cadf(...)
will try to allocate that structure to M_coint.
Ouch! Allocating a structure to a double is an error! It does not work.

댓글 수: 4

fede
fede 2015년 9월 22일
cadf give the following results: ans =
alpha: -0.0199
adf: -3.0082
crit: [6x1 double]
nlag: 1
nvar: 1
meth: 'cadf'
I want to pull out the result of adf
Stephen23
Stephen23 2015년 9월 22일
편집: Stephen23 2015년 9월 22일
Perhaps you meant to do something like this:
tmp = cadf(prices(:,i),prices(:,j),0,1);
M_coint(i,j) = tmp.adf;
Or alternatively you could save the complete output in a non-scalar structure, which means that you will have all of the data that cadf returns:
N = size(prices,2);
for n = N:-1:1;
S_coint(n) = cadf(prices(:,n),prices,0,1);
end
This also makes accessing the data easy, try:
[S_coint.adf]
{S_coint.method}
horzcat(S_coint.crit)
fede
fede 2015년 9월 22일
mmmm ok the error message disappear, but I have not that I want. I have a matrix, in which in the each columns I have the single stocks, and in the row the time serie price. For example
IBM JPM C p11 p12 p13 p21 p22 p23 .................... pn1 pn2 pn3
I want obtain a output as a var-cov matrix, but in place of the covariance the score of cointegration test, as the following table.
ibm jpm c
ibm - -3.2 -4.2
jpm -1.2 - -2.1
c -2.3 -4.3 -
I can not generate a code suitable to my needs
Stephen23
Stephen23 2015년 9월 23일
This is a different topic to your original question. Please search for solutions to this new topic in the documentation, on the internet, or in this forum.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 App Building에 대해 자세히 알아보기

질문:

2015년 9월 22일

댓글:

2015년 9월 23일

Community Treasure Hunt

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

Start Hunting!

Translated by