Continous Zero Lower Bound Implementation

In order to replicate recent NK models which implement the Zero Lower Bound, so an interest rate which is subject to the constrained of being positive,
I have derived a continuous version of the Kronecker Delta function(an IF function) for the monetary policy rule, so it gives Rzlb®=R for R>0 and Rzlb®=0 for R<0.

The function I used is:
Rzlb = k*log(1-exp(-1/k)+exp(r/k));

Which perfectly approximates the “If” function for when k tends to zero.
So I have set k=1/1000 #so some very small value ( a plot can be seen here:*log%281-exp%28-1%2F%281%2F1000%29%29%2Bexp%28x%2F%281%2F1000%29%29%29 )

Also the taylor series approximation follows the “If” function, although it is dependant from which value the approximation is made whether it will give zero everywhere or Rzlb=R everywhere.
I figured for small deviations in R this shouldn’t be a problem, only when crossing between negative and positive values.
however, after I ran some models, and saved the output using the dynasave command, I found when comparing the Rzlb output with its R input, the Rzlb function still gave negative values.

I am using the Stoch simulate command, and the function within the log shouldnt be zero.

Any ideas why it doesn’t work?

y = y(+1) - 1/sigmaC*(r-pi(+1)) + s_b;
pi = betapi(+1) + ((1-theta)(1-betatheta)/theta)(sigmaC+sigmaL)*y + s_p;
% Monetary Policy Rule

% R input where rz is the unbounded r, and r is the interest rate constrained to be positive
rz = rho*r(-1) +  (1-rho)*( phi_pi*pi + phi_y*y ) + phi_dy*(y-y(-1)) + s_r  ;
r = k*log(1-exp(-1/k)+exp(rz/k));[/code]

If I understand you correctly, you are basically using a barrier function approach. That does not get you around the problem that a first order Taylor approximation is going to replace your nonlinear function by a linear one. An linear functions by construction are unbounded.

Thank you for the answer!