To (greatly) simplify the code, we wrote a function which computes the "penalty function" for responses based upon the sign constraints.
- Code: Select all
*
* UhligPenalty(q,first,last,constrained) returns the penalty function
* for the weight vector <<q>> (applied to the impulse responses in the
* global VECT[SERIES] impulses). <<first>> and <<last>> are the range of
* responses constrained (1 = impact response). <<constrained>> is a
* VECT[INTEGER] with the variable positions being constrained. Use +slot
* for a positivity constraint and -slot for a negativity constraint.
* That is, if you want the first 4 responses to be positive on the 2nd
* variable and negative on the third, you would use the function
*
* UhligPenalty(q,1,4,||2,-3||)
*
function UhligPenalty q first last constrained
type real UhligPenalty
type vector q
type integer first last
type vect[int] constrained
*
local integer i k
local real func
local vector ik
*
compute func=0.0
do k=first,last
compute ik=(%xt(impulses,k)*q)./scales
do i=1,%rows(constrained)
if constrained(i)<0
compute value= ik(-constrained(i))
else
compute value=-ik(constrained(i))
compute func=func+%if(value<0.0,value,100*value)
end do i
end do k
compute UhligPenalty=func
end
This also uses a different method for handling the minimization of the penalty function than was done in the program for the Uhlig JME 2005 paper. Instead of doing each optimization twice, then rejecting draws where the modes don't match up, it does a slower broad scan with the genetic algorithm as the preliminary method, which seems in practice to find the global optimum with very high reliability. With this (fairly large) model, it's able to do 250 draws in about five minutes, which is much faster than the Gauss code provided by the authors.
