/***************************************************************************/ /* */ /* Title: CODEPARC.G */ /* includes (1) trans (procedure) */ /* (2) back (procedure) */ /* (3) decodec (procedure) */ /* (4) encodec (procedure) */ /* */ /* Written: John H. Cochrane */ /* by: University of Chicago Graduate School of Business */ /* 1101 E. 58th Street */ /* Chicago, Ill 60637 */ /* ph#: (312) 702-3059 */ /* e-mail: john.cochrane@gsb.uchicago.edu */ /* */ /* Purpose: The below procedures are all used to communicate parameters */ /* to &findjt. Since the argument to optmum (&findjt) can only */ /* only accept the vector of parameters, and must be able to */ /* search from -inf to inf for values, these procs are necessary. */ /* */ /***************************************************************************/ /* ------------------------------------------------------------------------*/ /* TRANS */ /* */ /* Purpose: */ /* Takes alpha, delta, mpk, gam transforms them so that talpha */ /* tdelta tmpk tgam vary from -inf to inf while alpha delta mpk gam */ /* stay in bounds. Currently implementing gam. */ /* Usage: */ /* {talpha,tdelta,tmpk,tgam} = trans(alpha,delta,mpk,gam); */ /* */ /* Inputs: (see above) */ /* Outputs: (see above) */ /* ------------------------------------------------------------------------*/ proc(4) = trans(alpha,delta,mpk,gam); local talpha,tdelta,tmpk,tgam; talpha = alpha; tdelta = delta; tmpk = mpk; tgam = gam; /* tgam[1] = gam[1]; tgam[2] = tan(pi/2*gam[2]/500); /* [-100,100] -> [-inf,inf] */ */ /* talpha = (alpha)^(1/2); /* [0,inf ] -> [-inf,inf] */ tdelta = tan(pi*(delta-1/2)); /* [0,1] -> [-inf,inf]; */ tmpk = tan(pi*(mpk-1/2)); /* [0,1] -> [-inf,inf]; */ */ retp(talpha,tdelta,tmpk,tgam); endp; /* ------------------------------------------------------------------------*/ /* BACK */ /* */ /* Purpose: */ /* Opposite of trans. takes transformed parameters talpha .. and gives */ /* back alpha delta mpk. If you use, make sure trans(back(x)) = x */ /* and vice versa! */ /* */ /* Usage: */ /* {alpha,delta,mpk,gam} = back(talpha,tdelta,tmpk,tgam); */ /* */ /* Inputs: (see above) */ /* Outputs: (see above) */ /* ------------------------------------------------------------------------*/ proc(4) = back(talpha,tdelta,tmpk,tgam); local alpha,delta,mpk,gam; alpha = talpha; delta = tdelta; mpk = tmpk; gam = tgam; /* gam[1] = tgam[1]; gam[2] = 2/pi*500*atan(tgam[2]); */ /* alpha = talpha^2; delta = atan(tdelta)/pi + 1/2; mpk = atan(tmpk)/pi + 1/2; */ retp(alpha,delta,mpk,gam); endp; /* --------------------------------------------------------------------------*/ /* DECODEC */ /* */ /* Purpose: Takes the transformed paramters and the default parameters and */ /* depending on selpar, returns either the 'de'-transform the */ /* tparms or returns the default parameters */ /* */ /* Usage: */ /* {alpha,delta,mpk,gam} = decodec(tparms,selpar,ccode,dalpha,ddelta,dmpk); */ /* */ /* Inputs: */ /* tparms: transformed parameters */ /* selpar: 3x1 vector of 1 or 0, tells you whether to search over the */ /* corresponding parameter. */ /* ccode: 1: consumption is in, 0 consumption is out. */ /* dalpha,ddelta,dmpk: default parameters. If selpar[j] = 0, returns this */ /* value rather than something taken from tpar. */ /* */ /* Outputs: */ /* alpha delta mpk gamma. */ /* */ /* --------------------------------------------------------------------------*/ proc(4) = decodec(tparms,selpar,ccode,dalpha,ddelta,dmpk,dgam); local npar,ni,counter,alpha,delta,mpk,talpha,tdelta,tmpk, dtalpha,dtdelta,dtmpk,dtgam,tgam,gam; /* alpha = dalpha; delta = ddelta; mpk = dmpk; gam = dgam; */ {dtalpha,dtdelta,dtmpk,dtgam} = trans(dalpha,ddelta,dmpk,dgam); if sumc(selpar) > 0; Npar = sumc(selpar); Ni = (rows(tparms)-rows(dgam)*ccode)/Npar; counter = 0; if selpar[1] == 1; talpha = tparms[1:Ni]; counter = counter+1; else; talpha = dtalpha ; endif; if selpar[2] == 1; tdelta = tparms[counter*Ni+1:(counter+1)*Ni]; counter = counter+1; else; tdelta = dtdelta ; endif; if selpar[3] == 1; tmpk = tparms[counter*Ni+1:(counter+1)*Ni]; counter = counter+1; else; tmpk = dtmpk; endif; else; talpha = dtalpha; tdelta = dtdelta; tmpk = dtmpk; endif; if ccode; if rows(tparms) == 1; tgam = tparms; else; tgam = tparms[rows(tparms)-rows(dtgam)+1:rows(tparms)]; endif; else; tgam = dtgam; endif; {alpha,delta,mpk,gam} = back(talpha,tdelta,tmpk,tgam); retp(alpha,delta,mpk,gam); endp; /* ------------------------------------------------------------------------- */ /* ENCODEC */ /* */ /* Purpose: */ /* */ /* Takes alpha delta mpk, constructs tparms, suitable for use by findjt. */ /* If selpar tells you a given parameter is not being searched over, it */ /* does not appear in tparms. */ /* */ /* Usage: */ /* {tparms} = encode(alpha,delta,mpk,gam,selpar,ccode); */ /* */ /* Inputs: (see description in decodec) */ /* */ /* Outputs: (see description in decodec) */ /* --------------------------------------------------------------------------*/ proc(1) = encodec(alpha,delta,mpk,gam,selpar,ccode); local talpha,tdelta,tmpk,tgam,sizepar,npar,tparms,counter; {talpha,tdelta,tmpk,tgam} = trans(alpha,delta,mpk,gam); if sumc(selpar) > 0; sizepar = rows(alpha); tparms = zeros(sizepar*sumc(selpar),1); counter = 0; if selpar[1] == 1; tparms[1:sizepar] = talpha; counter = counter+1; endif; if selpar[2] == 1; tparms[counter*sizepar+1:(counter+1)*sizepar] = tdelta; counter = counter+1; endif; if selpar[3] == 1; tparms[counter*sizepar+1:(counter+1)*sizepar] = tmpk; counter = counter+1; endif; endif; if ccode; if sumc(selpar) == 0; tparms = tgam; else; tparms = tparms|tgam; endif; endif; retp(tparms); endp;