Conditional forecasts do not change within a loop

Dear all, I do not understand why the ‘res’ variable do not change when I run the loop below. The parameters are changing but my initial guess is that the stochastic simulation is not changing. The problem is that I cannot figure out why. Do you have any suggestions? Thank you all in advance.

alp_admin_um_     = 0.30:0.05:1.0;
alp_admin_dois_   = 0.10:0.05:1.0;
alp_admin_tres_   = 0.03:0.005:1.0;
alp_admin_quatro_ = 0.0:0.05:1.0;

var_inflation = zeros(length(alp_admin_um_),41);
var_inflation_benchmark = [0 -0.08 -0.13 -0.18 -0.24 -0.22 -0.22 -0.21 -0.20 -0.18 -0.17 -0.16 -0.16 -0.15 -0.15 -0.14];

min = 0.3;

iteration = 0;  % Initialize counter

for iParam=1:length(alp_admin_um_)
    for jParam=1:length(alp_admin_dois_)
        for kParam=1:length(alp_admin_dois_)
            for lParam=1:length(alp_admin_dois_)
                
                iteration = iteration + 1; 

                set_param_value('alp_admin_um',alp_admin_um_(iParam))
                set_param_value('alp_admin_dois',alp_admin_dois_(jParam))
                set_param_value('alp_admin_tres',alp_admin_tres_(kParam))
                set_param_value('alp_admin_quatro',alp_admin_quatro_(lParam))

                stoch_simul(order=1, irf=16, nograph); 
 
                res = sum(abs(oo_.conditional_forecast.cond.Mean.infl_cheia_12m(1:16)' - var_inflation_benchmark));
                
                disp(['Iteration: ', num2str(iteration)])
                disp([alp_admin_um alp_admin_dois alp_admin_tres alp_admin_quatro])                    
                disp(res)
                disp('...')
                
                if res<min
                    min = res;
                    stop_flag = true;  % Set flag to stop loops
                    break;  % Break out of the innermost loop
                end
                
            end
        end
    end
end

You are not updating the conditional forecasts at all. Where is the command related to that?

Dear professor Pfeifer, I call a ‘loop.mod’ file that calls the ‘main.mod’ file,

@#include "variables.mod"

@#include "parameters.mod"

@#include "model.mod"

 %--------------------------------------------------------------------------------------------------------------------------------------
 % 4. Equilibrium
 %--------------------------------------------------------------------------------------------------------------------------------------

  steady;
  check;

   clc;

  %-------------------------------------------------------------------------------------------------------------------------------------- 
   % 5. IRFs
   %--------------------------------------------------------------------------------------------------------------------------------------

 shocks;

 // Interest rate shock
 var e_i;
 stderr 1;
 end;

 stoch_simul(order=1, irf=16, nograph, noprint);

 conditional_forecast_paths;

 var selic;
 periods 1 2 3 4;
 values 1 1 1 1;
end;

conditional_forecast(parameter_set = calibration, controlled_varexo = (e_i), replic = 3000);

Here is the ‘loop.mod’ file:

      @#include "main.mod"

      clc;

      %--------------------------------------------------------------------------------------------------------------------------------------
       % 6. "Optimal" parameters
       %--------------------------------------------------------------------------------------------------------------------------------------

      alp_admin_um_     = 0.30:0.05:1.0;
      alp_admin_dois_   = 0.10:0.05:1.0;
      alp_admin_tres_   = 0.03:0.005:1.0;
      alp_admin_quatro_ = 0.0:0.05:1.0;

      var_inflation = zeros(length(alp_admin_um_),41);
      var_inflation_benchmark = [0 -0.08 -0.13 -0.18 -0.24 -0.22 -0.22 -0.21 -0.20 -0.18 -0.17 -0.16 -0.16 -0.15 -0.15 -0.14];

     min = 0.3;

    iteration = 0;  % Initialize counter

    for iParam=1:length(alp_admin_um_)
      for jParam=1:length(alp_admin_dois_)
        for kParam=1:length(alp_admin_dois_)
          for lParam=1:length(alp_admin_dois_)
            
            iteration = iteration + 1; 

            set_param_value('alp_admin_um',alp_admin_um_(iParam))
            set_param_value('alp_admin_dois',alp_admin_dois_(jParam))
            set_param_value('alp_admin_tres',alp_admin_tres_(kParam))
            set_param_value('alp_admin_quatro',alp_admin_quatro_(lParam))

            stoch_simul(order=1, irf=16, nograph); 

            res = sum(abs(oo_.conditional_forecast.cond.Mean.infl_cheia_12m(1:16)' - var_inflation_benchmark));
            
            disp(['Iteration: ', num2str(iteration)])
            disp([alp_admin_um alp_admin_dois alp_admin_tres alp_admin_quatro])                    
            disp(res)
            disp('...')
            
            if res<min
                min = res;
                stop_flag = true;  % Set flag to stop loops
                break;  % Break out of the innermost loop
             end
            
         end
     end
 end

end

I understand that after the set_param_value( . ) commands, I change the parameters and perform a different stochastic simulation (with stoch_simul(.)), right? Do I need to call ‘dynare main.mod’ again within the loop or is there another way?

Oh, now I got it. Sorry. Now it is working, thank you very much.

1 Like