In the threshold autoregressive conditional duration (T-ACD) model, there are seven parameter including threshold value to be estimated. using direct search that the threshold value produces the highest maximized value of the likelihood to estimate the seven parameter.
the code is following , and so the question is how to set the initial value?
proc (2) = directsearch(xi); local ? n=rows(xi); n1=round(0.2*n); n2=round(0.8*n); p_s=unique(xi,1); p=p_s[n1:n2]; c_n=rows(p); ll=zeros(n-1,c_n); //there are six parameters to be estimated pp=zeros(6,c_n) ///is it right or wrong? f=????; // how to set the initial value?? g=????; // how to set the initial value?? cov=????; // how to set the initial value?? retcode=??; // how to set the initial value?? MLE=zeros(n-1,c_n); // how to set the initial value?? ////////////////////////////////////////////////////////////////////////// for i(1,c_n,1); {pp[.,i],f[.,i],g[.,],cov[.,],retcode[i]}=cml(y,0,&T_li_ACD(B,P[i],xi),par); // under given p, solving six parameter MLE[.,i]=T_li_ACD(pp[.,],P[i],xi); endfor; MLE=sumc(ll); d=maxindc(MLE); p_end=p[d]; pp=pp[.,d]; retp(p_end, pp); endp; /***********************************************************************************/ proc T_li_ACD (B,p,Xi) /*************************************************************************************** Likelihood Procedure for threshold ACD Models: ***************************************************************************************/ local omega1,alpha1, beta1,omega2,alpha2, beta2,n; local XI1,XI2,MXI, psi1,psi2,regime1,regime2,likeli1,likeli2,likeli; omega1 = B[1]; alpha1 = B[2]; beta1 = B[3]; omega2 = B[4]; alpha2 = B[5]; beta2 = B[6]; n=rows(xi); XI1=selif(XI[2:n],XI[1:n-1].<=P); XI2=selif(XI[2:n],XI[1:n-1].>P); MXI =xi[1:(n-1)]; psi1 = recserar(omega1 + MXI*alpha1, meanc(XI1)*ones(1,1), beta1); psi2 = recserar(omega2 + MXI*alpha2 , meanc(XI2)*ones(1,1), beta2); regime1=(XI[1:n-1].<=p); regime2=(XI[1:n-1].>p); likeli1 = -(ln(psi1)+(XI[2:n]./psi1)); likeli2 = -(ln(psi2)+(XI[2:n]./psi2)); likeli=likeli1.*regime1+likeli2.*regime2; retp(likeli); endp;
3 Answers
0
pp=zeros(7,c_n);
f=zeros(c_n,1);
g=zeros(7,c_n);
cov= arrayinit(c_n|7|7,0);
retcode=zeros(c_n,1);
MLE=zeros(n-1,c_n); // how to set the initial value??
//////////////////////////////////////////////////////////////////////////
for i(1,c_n,1);
{pp1,f1,g1,cov1,retcode1}=cml(y,0,&T_li_ACD(B,P[i],xi),par);
pp[.,i] = pp1;
f[i] = f1;
g[.,i] = g1;
cov[i,.,.] = c0v1;
retcode[i] = retcode1;
// MLE[.,i]=T_li_ACD(pp[.,],P[i],xi);
MLE1=T_li_ACD(pp[.,],P[i],xi);
MLE[.,i] = MLE1;
endfor;
This part of the code is going to fail:
MLE=sumc(ll);
d=maxindc(MLE);
ll is initialized to zeros, and so MLE which is a matrix of results from the calls to CML is being set here to zeros, and d will be missing values. I think you need to delete that line setting MLE to sumc(ll) outside the loop.
0
thank you very much
I only need the parameter and MLE value, the changed code is in the following . yet it appears the Syntax error, how to modify?
(0) : error G0008 : '(B,p[vfor($1)],xi),par)' : Syntax error
(0) : error G0155 : Nested procedure definition
proc(2)=directsearch(xi);
local n,n1,n2,p_s,p,c_n;
local pp,pp1,f,f1,g,g1,cov,cov1,retcode,retcode1,MLE,MLE1;
n=rows(xi);
n1=round(0.2*n);
n2=round(0.8*n);
p_s=unique(xi,1);
p=p_s[n1:n2];
c_n=rows(p);
pp=zeros(7,c_n);
MLE=zeros(n-1,c_n); // how to set the initial value??
//////////////////////////////////////////////////////////////////////////
for i(1,c_n,1);
{pp1,f1,g1,cov1,retcode1}=cml(xi,0,&T_li_ACD(B,p[i],xi),par);
pp[.,i] = pp1;
MLE1=T_li_ACD(pp[.,],P[i],xi);
MLE[.,i] = MLE1;
endfor;
retp(pp,MLE);
endp;
/*------------------------------------------------------------------------------------*/
proc T_li_ACD (B,p,Xi);
/********************************************************************************************
Likelihood Procedure for threshold ACD Models:
********************************************************************************************/
local omega1,alpha1, beta1,omega2,alpha2, beta2,n;
local XI1,XI2,MXI, psi1,psi2,regime1,regime2,likeli1,likeli2,likeli;
omega1 = B[1];
alpha1 = B[2];
beta1 = B[3];
omega2 = B[4];
alpha2 = B[5];
beta2 = B[6];
n=rows(xi);
XI1=selif(XI[2:n],XI[1:n-1].<=P);
XI2=selif(XI[2:n],XI[1:n-1].>P);
MXI =xi[1:(n-1)];
psi1 = recserar(omega1 + MXI*alpha1,
meanc(XI1)*ones(1,1),
beta1);
psi2 = recserar(omega2 + MXI*alpha2 ,
meanc(XI2)*ones(1,1),
beta2);
regime1=(XI[1:n-1].<=p);
regime2=(XI[1:n-1].>p);
likeli1 = -(ln(psi1)+(XI[2:n]./psi1));
likeli2 = -(ln(psi2)+(XI[2:n]./psi2));
likeli=likeli1.*regime1+likeli2.*regime2;
retp(likeli);
endp;
0
I see a couple of problems in your code, but before I start on that it looks like you either copied and pasted the code in the GAUSS program input/output window or highlighted and hit F4 to "run selected text". I can tell, because the line number of the error is '0'. If you put the code in a file and run that file, you will get exact line numbers of the error which is pretty helpful.
Problem 1
The third input to CML needs to be only a pointer to a procedure. The inputs should not be specified. So the first change we need to make is to change:
{pp1,f1,g1,cov1,retcode1}=cml(xi,0,&T_li_ACD(B,p[i],xi),par);
to:
{ pp1, f1, g1, cov1, retcode1 } = cml(xi,0,&T_li_ACD,par);
Problem 2
The likelihood procedure for CML needs to take two inputs. The first input is a vector of parameter values and the second input will be one or more rows from your data matrix. Pages 54-55 of the CML manual have a pretty good discussion of this.
The third input to your procedure will need to be a global variable that is accessed by your likelihood function. One way to resolve this would be to change:
proc T_li_ACD (B,p,Xi); /******************************************************************************************** Likelihood Procedure for threshold ACD Models: ********************************************************************************************/ local omega1,alpha1, beta1,omega2,alpha2, beta2,n; local XI1,XI2,MXI, psi1,psi2,regime1,regime2,likeli1,likeli2,likeli; omega1 = B[1]; alpha1 = B[2]; beta1 = B[3];
to this:
proc T_li_ACD (B,Xi); /******************************************************************************************** Likelihood Procedure for threshold ACD Models: ********************************************************************************************/ local omega1,alpha1, beta1,omega2,alpha2, beta2,n; local XI1,XI2,MXI, psi1,psi2,regime1,regime2,likeli1,likeli2,likeli, p; p = global_p; omega1 = B[1]; alpha1 = B[2]; beta1 = B[3];
Then as the first line inside the for loop, we could simply add the line:
global_p = p[i];
But for this to work, there has to be a reference to the global_p before this assignment, adding:
//Used to pass 'p' into 'T_li_ACD'
global_p = 0;
at the top of your program will
Problem 3
There are two problems with the line below:
MLE1 = T_li_ACD(pp[.,],P[i],xi);
First the expression pp[.,] is not legal syntax. I am not sure of your intentions on this line, but you might want pp[.,i].
The second problem with this line is that the reference to T_li_ACD will only have two inputs after the change made in the 'Problem 2' section, since we made global_p equal to p[i] above, you can simply remove the second input to T_li_ACD.
Your Answer
3 Answers
pp=zeros(7,c_n);
f=zeros(c_n,1);
g=zeros(7,c_n);
cov= arrayinit(c_n|7|7,0);
retcode=zeros(c_n,1);
MLE=zeros(n-1,c_n); // how to set the initial value??
//////////////////////////////////////////////////////////////////////////
for i(1,c_n,1);
{pp1,f1,g1,cov1,retcode1}=cml(y,0,&T_li_ACD(B,P[i],xi),par);
pp[.,i] = pp1;
f[i] = f1;
g[.,i] = g1;
cov[i,.,.] = c0v1;
retcode[i] = retcode1;
// MLE[.,i]=T_li_ACD(pp[.,],P[i],xi);
MLE1=T_li_ACD(pp[.,],P[i],xi);
MLE[.,i] = MLE1;
endfor;
This part of the code is going to fail:
MLE=sumc(ll);
d=maxindc(MLE);
ll is initialized to zeros, and so MLE which is a matrix of results from the calls to CML is being set here to zeros, and d will be missing values. I think you need to delete that line setting MLE to sumc(ll) outside the loop.
thank you very much
I only need the parameter and MLE value, the changed code is in the following . yet it appears the Syntax error, how to modify?
(0) : error G0008 : '(B,p[vfor($1)],xi),par)' : Syntax error
(0) : error G0155 : Nested procedure definition
proc(2)=directsearch(xi);
local n,n1,n2,p_s,p,c_n;
local pp,pp1,f,f1,g,g1,cov,cov1,retcode,retcode1,MLE,MLE1;
n=rows(xi);
n1=round(0.2*n);
n2=round(0.8*n);
p_s=unique(xi,1);
p=p_s[n1:n2];
c_n=rows(p);
pp=zeros(7,c_n);
MLE=zeros(n-1,c_n); // how to set the initial value??
//////////////////////////////////////////////////////////////////////////
for i(1,c_n,1);
{pp1,f1,g1,cov1,retcode1}=cml(xi,0,&T_li_ACD(B,p[i],xi),par);
pp[.,i] = pp1;
MLE1=T_li_ACD(pp[.,],P[i],xi);
MLE[.,i] = MLE1;
endfor;
retp(pp,MLE);
endp;
/*------------------------------------------------------------------------------------*/
proc T_li_ACD (B,p,Xi);
/********************************************************************************************
Likelihood Procedure for threshold ACD Models:
********************************************************************************************/
local omega1,alpha1, beta1,omega2,alpha2, beta2,n;
local XI1,XI2,MXI, psi1,psi2,regime1,regime2,likeli1,likeli2,likeli;
omega1 = B[1];
alpha1 = B[2];
beta1 = B[3];
omega2 = B[4];
alpha2 = B[5];
beta2 = B[6];
n=rows(xi);
XI1=selif(XI[2:n],XI[1:n-1].<=P);
XI2=selif(XI[2:n],XI[1:n-1].>P);
MXI =xi[1:(n-1)];
psi1 = recserar(omega1 + MXI*alpha1,
meanc(XI1)*ones(1,1),
beta1);
psi2 = recserar(omega2 + MXI*alpha2 ,
meanc(XI2)*ones(1,1),
beta2);
regime1=(XI[1:n-1].<=p);
regime2=(XI[1:n-1].>p);
likeli1 = -(ln(psi1)+(XI[2:n]./psi1));
likeli2 = -(ln(psi2)+(XI[2:n]./psi2));
likeli=likeli1.*regime1+likeli2.*regime2;
retp(likeli);
endp;
I see a couple of problems in your code, but before I start on that it looks like you either copied and pasted the code in the GAUSS program input/output window or highlighted and hit F4 to "run selected text". I can tell, because the line number of the error is '0'. If you put the code in a file and run that file, you will get exact line numbers of the error which is pretty helpful.
Problem 1
The third input to CML needs to be only a pointer to a procedure. The inputs should not be specified. So the first change we need to make is to change:
{pp1,f1,g1,cov1,retcode1}=cml(xi,0,&T_li_ACD(B,p[i],xi),par);
to:
{ pp1, f1, g1, cov1, retcode1 } = cml(xi,0,&T_li_ACD,par);
Problem 2
The likelihood procedure for CML needs to take two inputs. The first input is a vector of parameter values and the second input will be one or more rows from your data matrix. Pages 54-55 of the CML manual have a pretty good discussion of this.
The third input to your procedure will need to be a global variable that is accessed by your likelihood function. One way to resolve this would be to change:
proc T_li_ACD (B,p,Xi); /******************************************************************************************** Likelihood Procedure for threshold ACD Models: ********************************************************************************************/ local omega1,alpha1, beta1,omega2,alpha2, beta2,n; local XI1,XI2,MXI, psi1,psi2,regime1,regime2,likeli1,likeli2,likeli; omega1 = B[1]; alpha1 = B[2]; beta1 = B[3];
to this:
proc T_li_ACD (B,Xi); /******************************************************************************************** Likelihood Procedure for threshold ACD Models: ********************************************************************************************/ local omega1,alpha1, beta1,omega2,alpha2, beta2,n; local XI1,XI2,MXI, psi1,psi2,regime1,regime2,likeli1,likeli2,likeli, p; p = global_p; omega1 = B[1]; alpha1 = B[2]; beta1 = B[3];
Then as the first line inside the for loop, we could simply add the line:
global_p = p[i];
But for this to work, there has to be a reference to the global_p before this assignment, adding:
//Used to pass 'p' into 'T_li_ACD'
global_p = 0;
at the top of your program will
Problem 3
There are two problems with the line below:
MLE1 = T_li_ACD(pp[.,],P[i],xi);
First the expression pp[.,] is not legal syntax. I am not sure of your intentions on this line, but you might want pp[.,i].
The second problem with this line is that the reference to T_li_ACD will only have two inputs after the change made in the 'Problem 2' section, since we made global_p equal to p[i] above, you can simply remove the second input to T_li_ACD.