G0043 : Not implemented for complex matrices [maxutil.src, line 2848]

Hi,

I'm wondering after running some procedures, it encountered into a problem

Cross-Product calculation failed

Hessian calculation failed

G0043 : Not implemented for complex matrices [maxutil.src, line 2848]

Please help.

Thanks!

10 Answers



0



I think your likelihood function is returning a complex number at some point where it should not. I would add some code at the bottom of your likelihood function that tests the value you are about to return to see if it is complex. For example, if your likelihood procedure ends like this:

   retp(my_return);
endp;

I would change it to this:

   if iscplx(my_return);
      my_return = my_return;
   endif;
   retp(my_return);
endp;

The line my_return = my_return; is just a placeholder to give you a place to place a breakpoint for the debugger. Click in the margin to the left of the line number on the my_return = my_return; line and then run your program under the debugger.

Under the debugger, you can look at the values of all variables in your function and step through line by line. I would expect that you will find some calculation that ends up passing a negative number to sqrt or something like that.

aptech

1,773


0



I did as you recommended, it pops up an error..

G0008 : Syntax error 'endif'

/** Log-likelihood of the GARCH(1,1) model (volatility component) **/

h = 0;

proc lnl1t(b,y);

local u,z;

u = y;                                                                                  /** Disturbance **/

h = recserar(b[1] + cdfn(b[2])*trimr(0.0|u.^2,0,1),stdc(u)^2,cdfn(b[3])); /** Conditional variance (with restrictions on parameters) **/

z = u./sqrt(h);                                                                /** Standardized disturbance **/
if iscplx( - 0.5*ln(2*pi) - 0.5*ln(h) - 0.5*z.^2 ); 
(- 0.5*ln(2*pi) - 0.5*ln(h) - 0.5*z.^2)=(- 0.5*ln(2*pi) - 0.5*ln(h) - 0.5*z.^2)
endif;
retp( - 0.5*ln(2*pi) - 0.5*ln(h) - 0.5*z.^2 );
endp;

 



0



The code chunk that you sent is missing an ending semi-colon on the end of the line inside the 'if' clause and you cannot assign a statement to a statement in GAUSS. You should take this:

if iscplx( - 0.5*ln(2*pi) - 0.5*ln(h) - 0.5*z.^2 ); 
   (- 0.5*ln(2*pi) - 0.5*ln(h) - 0.5*z.^2)=(- 0.5*ln(2*pi) - 0.5*ln(h) -      0.5*z.^2)
   endif;
   retp( - 0.5*ln(2*pi) - 0.5*ln(h) - 0.5*z.^2 );
endp;

and make it look like this:

//declaring new local variable for return value
local my_ret;
my_ret = - 0.5*ln(2*pi) - 0.5*ln(h) - 0.5*z.^2;
if iscplx( my_ret ); 
   my_ret = my_ret;
endif;
retp(my_ret);
endp;

aptech

1,773


0



That works fine now, no complex matrices pop up unless these two following below:

Cross-Product calculation failed

Hessian calculation failed

I'm running DCC_MGARCH code, from Econometric Modelling with Time Series. Not sure if I have missed anything.

 

/*** Estimate univariate GARCH models for each variable **/
/** Log-likelihood of the GARCH(1,1) model (volatility component) **/

h = 0;

proc lnl1t(b,y);

local u,z;

u = y; /** Disturbance **/

h = recserar(b[1] + cdfn(b[2])*trimr(0.0|u.^2,0,1),stdc(u)^2,cdfn(b[3])); /** Conditional variance (with restrictions on parameters) **/

z = u./sqrt(h); /** Standardized disturbance **/

local my_ret; /** Declaring local variables **/
my_ret = - 0.5*ln(2*pi) - 0.5*ln(h) - 0.5*z.^2;
if iscplx( my_ret );
my_ret = my_ret;
endif;
retp(my_ret);
endp;

__title = "MLE Estimates of the GARCH(1,1) Model (volatility)";

_max_Options = { bhhh hetcon };

b1 = zeros(3,cols(y)); /** Declare volatility pararmeters **/

h1 = zeros(t,cols(y)); /** Declare univariate conditional variances **/
i = 1;

do while i <= cols(y);

bstart = { 0.0 -2 2 };

{ b1[.,i],a,g,omega,retcode } = maxprt(maxlik(y[.,i],0,&lnl1t,bstart));

h1[.,i] = h; /** Save univariate conditional variances to be used in the next stage **/

i = i + 1;

endo;

 

Thank you very much for helping me during these days 🙂



0



Remember from my first answer, the point of adding this bit of code was so that you could put a breakpoint inside the 'if' check and use the debugger to see why you are getting complex numbers returned from your likelihood procedure. I would guess that 'h' is negative for some values of 'b'. Since sqrt is called on 'h', that would produce complex numbers.

aptech

1,773


0



sorry for giving you a bug.

I put a breakpoint for the debugger, there's still

Cross-Product calculation failed

Hessian calculation failed

 

 



0



The GAUSS debugger allows you to pause your program at a certain point and view all the different variables as well as continuing to step line-by-line, etc. Just placing the breakpoint will not make any changes to the program. Take a look on the GAUSS Help Page: Click the "Overview" tab and then expand the nodes "User Guide"->"Starting the Debugger".

aptech

1,773


0



 

You could try putting a floor on the conditional variance:

Substitute sqrt(h) with

sqrt(sqrt(h.*h + .001));



0



I'd like to add that the advantage of the method I proposed to force something to be positive is that it is differentiable.  Other ways of doing this, such as taking the absolute value or using an if statement, are not differentiable and are likely to bring the optimization to a halt.  First and Second order differentiability of the function is a requirement of the optimization methods implemented in GAUSS by Aptech.

There may be ways to make a discontinuously differentiable function to work, but you would need to write gradient and Hessian functions that satisfied certain Lipschitz conditions.



0



Thank you so much.

Your Answer

10 Answers

0

I think your likelihood function is returning a complex number at some point where it should not. I would add some code at the bottom of your likelihood function that tests the value you are about to return to see if it is complex. For example, if your likelihood procedure ends like this:

   retp(my_return);
endp;

I would change it to this:

   if iscplx(my_return);
      my_return = my_return;
   endif;
   retp(my_return);
endp;

The line my_return = my_return; is just a placeholder to give you a place to place a breakpoint for the debugger. Click in the margin to the left of the line number on the my_return = my_return; line and then run your program under the debugger.

Under the debugger, you can look at the values of all variables in your function and step through line by line. I would expect that you will find some calculation that ends up passing a negative number to sqrt or something like that.

0

I did as you recommended, it pops up an error..

G0008 : Syntax error 'endif'

/** Log-likelihood of the GARCH(1,1) model (volatility component) **/

h = 0;

proc lnl1t(b,y);

local u,z;

u = y;                                                                                  /** Disturbance **/

h = recserar(b[1] + cdfn(b[2])*trimr(0.0|u.^2,0,1),stdc(u)^2,cdfn(b[3])); /** Conditional variance (with restrictions on parameters) **/

z = u./sqrt(h);                                                                /** Standardized disturbance **/
if iscplx( - 0.5*ln(2*pi) - 0.5*ln(h) - 0.5*z.^2 ); 
(- 0.5*ln(2*pi) - 0.5*ln(h) - 0.5*z.^2)=(- 0.5*ln(2*pi) - 0.5*ln(h) - 0.5*z.^2)
endif;
retp( - 0.5*ln(2*pi) - 0.5*ln(h) - 0.5*z.^2 );
endp;

 

0

The code chunk that you sent is missing an ending semi-colon on the end of the line inside the 'if' clause and you cannot assign a statement to a statement in GAUSS. You should take this:

if iscplx( - 0.5*ln(2*pi) - 0.5*ln(h) - 0.5*z.^2 ); 
   (- 0.5*ln(2*pi) - 0.5*ln(h) - 0.5*z.^2)=(- 0.5*ln(2*pi) - 0.5*ln(h) -      0.5*z.^2)
   endif;
   retp( - 0.5*ln(2*pi) - 0.5*ln(h) - 0.5*z.^2 );
endp;

and make it look like this:

//declaring new local variable for return value
local my_ret;
my_ret = - 0.5*ln(2*pi) - 0.5*ln(h) - 0.5*z.^2;
if iscplx( my_ret ); 
   my_ret = my_ret;
endif;
retp(my_ret);
endp;
0

That works fine now, no complex matrices pop up unless these two following below:

Cross-Product calculation failed

Hessian calculation failed

I'm running DCC_MGARCH code, from Econometric Modelling with Time Series. Not sure if I have missed anything.

 

/*** Estimate univariate GARCH models for each variable **/
/** Log-likelihood of the GARCH(1,1) model (volatility component) **/

h = 0;

proc lnl1t(b,y);

local u,z;

u = y; /** Disturbance **/

h = recserar(b[1] + cdfn(b[2])*trimr(0.0|u.^2,0,1),stdc(u)^2,cdfn(b[3])); /** Conditional variance (with restrictions on parameters) **/

z = u./sqrt(h); /** Standardized disturbance **/

local my_ret; /** Declaring local variables **/
my_ret = - 0.5*ln(2*pi) - 0.5*ln(h) - 0.5*z.^2;
if iscplx( my_ret );
my_ret = my_ret;
endif;
retp(my_ret);
endp;

__title = "MLE Estimates of the GARCH(1,1) Model (volatility)";

_max_Options = { bhhh hetcon };

b1 = zeros(3,cols(y)); /** Declare volatility pararmeters **/

h1 = zeros(t,cols(y)); /** Declare univariate conditional variances **/
i = 1;

do while i <= cols(y);

bstart = { 0.0 -2 2 };

{ b1[.,i],a,g,omega,retcode } = maxprt(maxlik(y[.,i],0,&lnl1t,bstart));

h1[.,i] = h; /** Save univariate conditional variances to be used in the next stage **/

i = i + 1;

endo;

 

Thank you very much for helping me during these days 🙂

0

Remember from my first answer, the point of adding this bit of code was so that you could put a breakpoint inside the 'if' check and use the debugger to see why you are getting complex numbers returned from your likelihood procedure. I would guess that 'h' is negative for some values of 'b'. Since sqrt is called on 'h', that would produce complex numbers.

0

sorry for giving you a bug.

I put a breakpoint for the debugger, there's still

Cross-Product calculation failed

Hessian calculation failed

 

 

0

The GAUSS debugger allows you to pause your program at a certain point and view all the different variables as well as continuing to step line-by-line, etc. Just placing the breakpoint will not make any changes to the program. Take a look on the GAUSS Help Page: Click the "Overview" tab and then expand the nodes "User Guide"->"Starting the Debugger".

0

 

You could try putting a floor on the conditional variance:

Substitute sqrt(h) with

sqrt(sqrt(h.*h + .001));

0

I'd like to add that the advantage of the method I proposed to force something to be positive is that it is differentiable.  Other ways of doing this, such as taking the absolute value or using an if statement, are not differentiable and are likely to bring the optimization to a halt.  First and Second order differentiability of the function is a requirement of the optimization methods implemented in GAUSS by Aptech.

There may be ways to make a discontinuously differentiable function to work, but you would need to write gradient and Hessian functions that satisfied certain Lipschitz conditions.

0

Thank you so much.


You must login to post answers.

Have a Specific Question?

Get a real answer from a real person

Need Support?

Get help from our friendly experts.