Second order approximation and the IRF explosive

Prof. Jpfeifer,

Thanks for your kind reply. When I have a stoch_simul-command in the mod-file, which is put right before the maximization code, the results are a little different. The first is that the running time is much less when I have the stoch_simul-command. In your tested code, Dynare runs about 10 minutes in my computer. However, if I have stoch_simul-command right before the maximization code in the mod-file, Dynare just runs about several seconds. Why is the running time so different?

Another difference is that the welfare values which is stored in “fhat”, is exactly the same with or without the stoch-simul command. But the optimal parameter values are very different. In your tested code, the two parameter values which is stored in “x_opt_hat”, are 1.1583 and 7.6269, but 1.3077 and 86.8614 if having the stoch-simul command in the mod-file. Which result should I trust and why?

Besides, could you please show me how to write a loop to do the grid search? Is the code just inside the mod-file, or I have to write a separate m-file about the loop?

Sorry about that I have asked so many questions. I understand that it must spend you much time in answering my questions. Thank you very much. I am looking forward to your reply.

  1. There should be no difference, except for different random numbers being used for the optimizer. Have you compared the value of the objective function for the two cases? Which one is lower?
  2. Yes, that code for the grid search needs to encase the current call to the optimizer.
    For example:
rho_grid_values=0.01:0.01:1;
n_grid_points=length(rho_grid_values);
fvalues=NaN(n_grid_points,1);
for ii=1:n_grid_points
   set_param_value('rho',rho_grid_values(ii));
   [fhat,x_opt_hat] = csminwel(@welfare_objective,x_start,H0,[],crit,nit,x_opt_name);
   fvalues(ii)=fval;
   x_optvalues(:,ii)=x_opt_hat;
end

Hi Prof. Jpfeifer,

Thanks for your reply. I have checked the value of the objective function for the two cases, one is that I put the maximization codes after the stoch_simul command, the other one is that I put the maximization codes right before the stoch_simul command. The “fhat” is the same across the two cases, which is -5.4732. But the optimal parameter values are different. Could you please help me see whether there exists some mistakes?

Here attached the code files for your checkhousing.mod (7.2 KB)
welfare_objective.m (713 Bytes)

When I put
options_.irf=0;
in the mod-file, I don’t get a difference with or without stoch_simul. Your model seems to feature local maxima that are found by the stochastic optimizer when you generate IRFs using random numbers. You should:

  1. Try using a global optimizer
  2. Potentially restrict the parameter space. Big values like 80 are often unreasonable.

Dear Prof. Jpfeifer,

Thanks for your reply. Could you please show me how to use a global optimizer in the mod-file? Besides, I have set irf=o after the stoch_simul command. What’s the difference using options_.irf=0?

  1. See Optimal policy parameters in a non-linear model
  2. If you do not use the stoch_simul(irf=0)-command then options_.irf=0 needs to be manually set. Otherwise, it is redundant

Prof. Jpfeifer,

Thanks for your kindly help. Based on your posted code, I write a loop within the mod-file, in order to do the grid search. Could you please help me check whether it is correct?

Here attached the code. Thank you very much! housing.mod (7.6 KB)
welfare_objective.m (713 Bytes)

You obviously cannot use a grid to specify two parameter values and then for these given parameters find the optimal value for those parameters. What then is the point of having the outer loop?

Prof. Jpfeifer,

Thanks for your reply. You previous post showed me about the grid search code with only one parameter. I thought it can also work for two parameters. However, could you please show me how to do grid search with multiple parameters in Dynare?

You still do not clearly specify

  1. what is the grid of parameters to be kept fixed and conditional on which the optimal parameters for the policy rule are to computed
  2. what those parameters in policy rule are
    Note that the parameters in 1 and 2 cannot be identical.

Prof. Jpfeifer,

The parameters which I want to optimize over is rho_pi and rho_y, which are the coefficients of the Taylor rule. To be more specific, I want to search over a two dimensional grid, with the ranges for the three parameters being [1, 3] for rho_pi. [0, 3] for rho_y. And the grid step for each parameter is 0.1. The Taylor is standard as r=(1/beta_s)pi_c^rho_pi(y/steady_state(y))^rho_y. I want to find the optimized parameters values which can generate the highest welfare. The welfare is defined as the utility of the household, which is v in my code.

Could you please show me how to write the code for the grid search? Thank you very much!

I still don’t get it. Why do a grid search if you can directly compute the optimal values for the two?

Prof. Jpfeifer,

Please find the attached paper. What I want to do is exactly the same as that in the paper. At the first paragraph of page 1512, it is stated that “We search over a four-dimensional grid over the parameters ranges…”, and also the footnote 25 of page 1512. Leaning against boom bust cycles in credit and housing prices.pdf (742.4 KB)

Could you please show me about how to do the grid search in Dynare? Thank you very much!

Again, there is no point in doing a grid search. You can simply find the optimal parameter combinations using a numerical optimizer as in the code I wrote above. Why do you want to find the maximum over a coarse grid instead?

Prof. Jpfeifer,

Thanks for your explanation. However, when I run my mod-file using the optimizer code you posted, I find a problem: no matter how I change the parameters which are needed to be optimized, the maximized welfare always remain the same without any changes. The “fhat” is always the same in many different cases. I have tried the optimizer with only one parameter - rho_pi, two parameters - rho_pi and rho_y, three parameters- rho_r, rho_pi and rho_y, and other scenarios. The “fhat” always keeps fixed. Could you please help me check what the problem is and how to fix it? Here attached the code.

Moreover, I know that “fhat” stores the maximized welfare value in my case. It is conditional or unconditional welfare?

Thank you very much! welfare_objective.m (713 Bytes)
housing.mod (8.6 KB)

I am not sure I understand. Running your code, I get an fhat of -5.567347243835366. Commenting out the optimization over rho_y, leaving only three parameters, I get -5.567345262735201, which is similar, but not identical.

You are computing unconditional welfare as you are reading out the unconditional mean of welfare.

Prof. Jpfeiefer,

Thanks for your reply. Could you please show me how to compute conditional welfare in Dynare?

You posted that I should “Use theoretical moments for welfare evaluation”. My understanding is that I should compare the mean of “approximated theoretical moments” shown in Matlab. If I am right, is the “approximated theoretical moments” conditional or unconditional welfare for welfare comparison between different policy rules?

You currently do use the unconditional theoretical moments. What you need to do is replace the code in the welfare_objective.m, which follows unconditional welfare codes at https://github.com/JohannesPfeifer/DSGE_mod/tree/master/Born_Pfeifer_2018/Welfare, with the conditional ones you can also find there

Prof. Jpfeifer,

Thanks for your reply. I have one more question: Since I need to use the theoretical moments for welfare evaluation which is shown as the mean of “approximated theoretical moments” shown in Matlab window, is it just the value in “fhat”?

In your old welfare_function.m, you return

outvalue=-oo_.mean(strmatch('v',var_list_,'exact')); %extract Welfare

which is minus the mean of your defined welfare function.