file corr.src, maxutil.src

Hi.

I'm still running DCC_MGARCH, you may find part of the code input before encountered into a problem

/** Reestimate the model without parameter transformations to obtain correct standard errors **/

iflag = 1;

bstart = b[1] | cdfn(b[2 3]) | b[4] | cdfn(b[5 6]) | b[7] | cdfn(b[8 9]) | b[10] | cdfn(b[11 12]) | b[13] | cdfn(b[14 15]) | cdfn(b[16 17]);

{ b,lnl1,g,omega,retcode } = maxprt(maxlik(y,0,&lnlt,bstart));

print "Log-likelihood (unconstrained) = " lnl1;

Not sure how to fix this out. Sorry always giving you a bug.

--------------------------------------------

Currently active call:

File corr.src, line 170, in vcx
end;
Traceback:

File maxutil.src, line 2908, in _max_rdd
a0 = ll(x,z);
File maxutil.src, line 2093, in _max_stepl
rs = _max_rdd(lfct,0,x0+d,0,0,0,LLoutput,Lmaxlag,dataset,vindx,
File maxutil.src, line 738, in _max
{ s,bksteps } = _max_stepl(g,vof,x0,d,lfct,Lmaxlnsch,Lmaxusrsch,
File maxlik.src, line 515, in maxlik
{ x,f,g,h,retcode,Lmlfhess,Lmlitdta,Lmlcpvcp,Lmlhsvcp,_max_dat,

10 Answers



0



You should have an error printed out before you see "Currently active call". Can you post that error, or maybe lines 168-172 of your GAUSSHOME/corr.src file?

aptech

1,338


0



165-177 in corr.src

proc vcx(x);
/* check for complex input */
if iscplx(x);
if hasimag(x);
errorlog "ERROR: Not implemented for complex matrices.";
end;
else;
x = real(x);
endif;
endif;

retp( moment( x-meanc(x)',0) / ( rows(x) - 1 ) );
endp;

And here's the output before encountered into an error.

============================================================
MLE Estimates of the DCC MGARCH Model (full)
============================================================
MAXLIK Version 4.0.26 2/24/2015 3:02 pm
============================================================

return code = 0
normal convergence

Mean log-likelihood -8.28624
Number of cases 99

Covariance matrix of the parameters computed by the following method:
Not computed or failed to invert

The covariance matrix of the parameters failed to invert

Parameters Estimates Gradient
----------------------------------------------
P01 4.141936 0.000955
P02 -1.129334 0.000086
P03 0.564088 -0.000139
P04 42.164065 -0.000115
P05 -3.231880 -0.000166
P06 -27.146524 0.000000
P07 0.113691 0.000415
P08 -7.059574 0.000000
P09 4.253920 -0.000062
P10 0.118952 -0.001108
P11 -3.382566 0.000164
P12 3.748638 -0.000359
P13 0.427416 0.000557
P14 -3.576744 -0.001309
P15 2.422706 0.001113
P16 -4.672540 0.000007
P17 2.207918 0.000020

Number of iterations 230
Minutes to convergence 3.68293

Hope you can help.

Thank you



0



So it looks like the error you received was "Not implemented for complex matrices". If that is correct and this error came up during the run of the line:

{ b,lnl1,g,omega,retcode } = maxprt(maxlik(y,0,&lnlt,bstart));

then most likely your likelihood procedure is returning complex numbers when it should not. Usually this is because the function takes the square root of negative numbers or the log of a negative number.

aptech

1,338


0



I guess your assumption is correct. So do you know how can I solve this?

 



0



You need to either use the debugger to find the location where your likelihood function or put some print statements in to see the output. You could add something like this: (I am using out as the return value from your likelihood function, you will need to change it to the name of the return value from your function)

//Check to see if the value is complex
if iscplx(out);
   print out;

//End the program when we find a complex output   
   end;
endif;

Once you figure out what is happening (probably taking the log or sqrt of a negative number, you can look to a solution).

aptech

1,338


0



I see. 

Well, is it possible that my src files are too old, so it's not compatible with the code I have got?



0



Well, is it possible that my src files are too old, so it's not compatible with the code I have got? since some of my src files are about year 1997 but the code I have implemented is based on gauss 10.0



0



I don't think that is likely to be your problem. Can you post your likelihood function?

aptech

1,338


0



After I have entered the following:

icheck = 0; /** Needed to choose the correct starting qbar to check the program **/

bstart = vec(b1) | -5 | -5;

_max_Active = ones(3*cols(y),1) | 0 | 0;

__title = "MLE Estimates of the DCC MGARCH Model (test)";

_max_Options = { bhhh hetcon screen };

{ b,a,g,omega,retcode } = maxprt(maxlik(y,0,&lnlt,bstart));

 

The error occured:

G0058 : Index out of range [maxutil.src, line 2902]

Currently active call:

File maxutil.src, line 2902, in lnlt
a0 = ll(dd*x+LmaxActive,z);
Traceback:

File maxutil.src, line 2902, in _max_rdd
a0 = ll(dd*x+LmaxActive,z);
File maxutil.src, line 405, in _max
vof = _max_rdd(lfct,0,x0,0,0,0,LLoutput,Lmaxlag,dataset,vindx,row,
File maxlik.src, line 515, in maxlik
{ x,f,g,h,retcode,Lmlfhess,Lmlitdta,Lmlcpvcp,Lmlhsvcp,_max_dat,

 

Is there anything to do with maxutil.src?

by the way, I'm doing DCC MGARCH.



0



Please find the code below, I ran until the red paragraph and it popped up the same.

Currently active call:

File corr.src, line 170, in vcx
end;
Traceback:

File maxutil.src, line 2908, in _max_rdd
a0 = ll(x,z);
File maxutil.src, line 2093, in _max_stepl
rs = _max_rdd(lfct,0,x0+d,0,0,0,LLoutput,Lmaxlag,dataset,vindx,
File maxutil.src, line 738, in _max
{ s,bksteps } = _max_stepl(g,vof,x0,d,lfct,Lmaxlnsch,Lmaxusrsch,
File maxlik.src, line 515, in maxlik
{ x,f,g,h,retcode,Lmlfhess,Lmlitdta,Lmlcpvcp,Lmlhsvcp,_max_dat,

Sorry giving you a bug, but please help 🙂

/*****
*** Program to estimate the Dynamic Conditional Correlation (DCC) MGARCH model of US yields.
*****/

library maxlik,pgraph;

graphset;
gausset;
maxset;

cls;

format /rd 10,3;

/**Read the data: US daily yields starting Jan 3 2000 and ending August 21 2006 **/
vls = reshape(error(0),9,1);

load yields_data[100,30]=C:\gausslt14\liq\Chapter\dailyfinance1f.txt; /** Yields: 1yr, 2yr ... to 30yr (30 series) **/
load forwards_data[100,30]=C:\gausslt14\liq\Chapter\dailyfinance2f.txt; /** Forwards: 1yr, 2yr, 3yr .... 30yr (15 series) **/
/** Note that a 1 year forward matrures in year 2 **/
yields = yields_data[.,1 5 10 15 20]; /** Choose the variables **/
output file=C:\gausslt14\liq\Chapter\output1.txt reset;
y = 100*(trimr(yields,1,0) - trimr(yields,0,1)); /** Transform the variables **/
y = y - meanc(y)'; /** Demean the variables **/
t = rows(y); /** Sample size **/

/*** 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;

/** Log-likelihood of the dcc MGARCH(1,1) model (correlation component) **/

proc lnl2t(b,y);
local lnl,h,z,q,qbar,r,s,m,u,i,n,z_data;
n = cols(y); /** Number of equations **/
lnl = zeros(t,1); /** Declare log likelihood **/
u = y; /** Residuals **/
z = u./sqrt(h1); /** Standardised residuals **/
qbar = vcx(z);
q = qbar; /** Initialise q **/
i = 1;
do while i <= t;
s = diagrv(eye(n),sqrt(h1[i,.])'); /** Diagonal matrix of conditional standard deviations **/
r = inv( diagrv( eye(n),sqrt(diag(q)) ) )*q*inv( diagrv( eye(n),sqrt(diag(q)) ) ); /** Conditional correlation matrix **/
h = s*r*s; /** Update conditional variance-covariance matrix **/
lnl[i] = - 0.5*ln(det(r)) - 0.5*z[i,.]*inv(r)*z[i,.]' + 0.5*z[i,.]*z[i,.]'; /** Log of the likelihood at observation i **/
q = abs(1 - cdfn(b[1]) - cdfn(b[2]))*qbar + cdfn(b[1])*z[i,.]'*z[i,.] + cdfn(b[2])*q;
i = i + 1;
endo;
local my_ret;
my_ret=lnl;
if iscplx(my_ret);
my_ret=my_ret;
endif;
retp(my_ret);
endp;
bstart = { -2, 2 };
__title = "MLE Estimates of the DCC MGARCH Model (correlation)";

_max_Options = { bfgs hetcon screen };
_max_GradTol = 0.001;

{ b2,a,g,omega,retcode } = maxprt(maxlik(y,0,&lnl2t,bstart));
icheck = 0; /** Used to check the code **/
iflag = 0; /** Transformed parameters **/

/** Log-likelihood of the dcc MGARCH(1,1) model (full model) **/

proc lnlt(b,y);
local lnl,h,h_ii,z,q,qbar,r,s,m,u,i,n,z_data;
n = cols(y); /** Number of equations **/
lnl = zeros(t,1); /** Declare log likelihood **/
u = y; /** Residuals **/
h_ii = zeros(t,n); /** Contains the conditional variances **/

if iflag == 0;

h_ii[.,1] = recserar(b[1] + cdfn(b[2])*trimr(0.0|u[.,1].^2,0,1),stdc(u[.,1])^2,cdfn(b[3])); /** Conditional variance of variable 1 **/
h_ii[.,2] = recserar(b[4] + cdfn(b[5])*trimr(0.0|u[.,2].^2,0,1),stdc(u[.,2])^2,cdfn(b[6])); /** Conditional variance of variable 2 **/
h_ii[.,3] = recserar(b[7] + cdfn(b[8])*trimr(0.0|u[.,3].^2,0,1),stdc(u[.,3])^2,cdfn(b[9])); /** Conditional variance of variable 3 **/
h_ii[.,4] = recserar(b[10] + cdfn(b[11])*trimr(0.0|u[.,4].^2,0,1),stdc(u[.,4])^2,cdfn(b[12])); /** Conditional variance of variable 4 **/
h_ii[.,5] = recserar(b[13] + cdfn(b[14])*trimr(0.0|u[.,5].^2,0,1),stdc(u[.,5])^2,cdfn(b[15])); /** Conditional variance of variable 5 **/

else;

h_ii[.,1] = recserar(b[1] + b[2]*trimr(0.0|u[.,1].^2,0,1),stdc(u[.,1])^2,b[3]); /** Conditional variance of variable 1 **/
h_ii[.,2] = recserar(b[4] + b[5]*trimr(0.0|u[.,2].^2,0,1),stdc(u[.,2])^2,b[6]); /** Conditional variance of variable 2 **/
h_ii[.,3] = recserar(b[7] + b[8]*trimr(0.0|u[.,3].^2,0,1),stdc(u[.,3])^2,b[9]); /** Conditional variance of variable 3 **/
h_ii[.,4] = recserar(b[10] + b[11]*trimr(0.0|u[.,4].^2,0,1),stdc(u[.,4])^2,b[12]); /** Conditional variance of variable 4 **/
h_ii[.,5] = recserar(b[13] + b[14]*trimr(0.0|u[.,5].^2,0,1),stdc(u[.,5])^2,b[15]); /** Conditional variance of variable 5 **/

endif;
z = u./sqrt(h_ii); /** Standardised residuals **/

if icheck == 0;

qbar=diagrv(eye(n),stdc(z).^2); /** Unconditional covariance matrix of the standardised residuals (covariances set to zero to begin) **/

else;

qbar = vcx(z);

endif;

q = qbar; /** Initialse q **/

i = 1;

do while i <= t;

s = diagrv(eye(n),sqrt(h_ii[i,.])'); /** Diagonal matrix of conditional standard deviations **/

r = inv( diagrv( eye(n),sqrt(diag(q)) ) )*q*inv( diagrv( eye(n),sqrt(diag(q)) ) ); /** Conditional correlation matrix **/

h = s*r*s; /** Update conditional variance-covariance matrix **/

lnl[i] = - 0.5*n*ln(2*pi) - 0.5*ln(det(h)) - 0.5*u[i,.]*inv(h)*u[i,.]'; /** Log of the likelihood at observation i **/

if iflag == 0;

q = abs(1-cdfn(b[16])-cdfn(b[17]))*qbar + cdfn(b[16])*z[i,.]'*z[i,.] + cdfn(b[17])*q; /** Update Q **/

else;

q = abs(1-b[16]-b[17])*qbar + b[16]*z[i,.]'*z[i,.] + b[17]*q; /** Update Q **/

endif;

i = i + 1;

endo;

local my_ret;
my_ret=lnl;
if iscplx(my_ret);
my_ret=my_ret;
endif;
retp(my_ret);
endp;

/** This parameterisation provides a test of the full likelihood code as the program will converge in one step as the covariance parameters are set to zero **/

icheck = 0; /** Needed to choose the correct starting qbar to check the program **/

bstart = vec(b1) | -5 | -5;

_max_Active = ones(3*cols(y),1) | 0 | 0;

__title = "MLE Estimates of the DCC MGARCH Model (test)";

_max_Options = { bhhh hetcon screen };

{ b,a,g,omega,retcode } = maxprt(maxlik(y,0,&lnlt,bstart));

/** Estimate the full model **/

icheck = 1; /** Needed to choose the correct starting qbar as not checking the program **/

bstart = vec(b1) | b2;

_max_Active = ones(3*cols(y),1) | 1 | 1;

__title = "MLE Estimates of the DCC MGARCH Model (full)";

_max_Options = { bfgs hetcon screen };

{ b,a,g,omega,retcode } = maxprt(maxlik(y,0,&lnlt,bstart));

/** Reestimate the model without parameter transformations to obtain correct standard errors **/

iflag = 1;

bstart = b[1] | cdfn(b[2 3]) | b[4] | cdfn(b[5 6]) | b[7] | cdfn(b[8 9]) | b[10] | cdfn(b[11 12]) | b[13] | cdfn(b[14 15]) | cdfn(b[16 17]);

{ b,lnl1,g,omega,retcode } = maxprt(maxlik(y,0,&lnlt,bstart));

print "Log-likelihood (unconstrained) = " lnl1;
/** Estimate the constant covariance DCC model and perform a likelihood ratio test **/

bstart = b;

__title = "MLE Estimates of the Constant Covariance DCC MGARCH Model";

_max_Options = { bhhh hetcon screen };

_max_Active = ones(3*cols(y),1) | 0 | 0;

bstart[16] = 0.0; bstart[17] = 0.0; /** Set the correlation parameters to zero **/
{ b,lnl0,g,omega,retcode } = maxprt(maxlik(y,0,&lnlt,bstart));
print "Log-likelihood (constrained) = " lnl0;
lr = -2*t*(lnl0 - lnl1);
dof = 2;
pv = cdfchic(lr,dof);

print "";
print "Likelihood ratio test";
print " Value = " lr;
print " Degrees of freedom = " dof;
print " P-value = " pv;
output off;

 

 

Your Answer


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.

Try GAUSS for 30 days for FREE

See what GAUSS can do for your data

© Aptech Systems, Inc. All rights reserved.

Privacy Policy