Attached is a mod file. I am getting some weird residual values. Can someone figure out what is missing here.

mutualfunds.mod (3.3 KB)

Attached is a mod file. I am getting some weird residual values. Can someone figure out what is missing here.

mutualfunds.mod (3.3 KB)

Try computing the steady state analytically.

I have computed steady state analytically

Then

applies

Unable to understand why I am suddenly getting Nan. Steady state has been calculated analytically and appears and initial values. Its a simple model which is behaving weird. Can someone help figure out.mutualfunds_v2.mod (3.6 KB)

You are setting

```
o_f = of_bar;
```

but did not set `of_bar`

. So both will be 0, resulting in a division by 0.

1 Like

I am trying to minimise a loss function subject to am optimal simple rule. But I find that although dynare is throwing estimates of the parameters, the value of the objective function is not changing. Can someone figure out what is the reason for this? I have tried with different initial values also, but objective function does not change from where it started. here are the results I am getting

OSR: Initial value of the objective function: 0.0336506

n=5: (4,8)-CMA-ES(w=[53 29 14 4]%, mu_eff=2.6) on function osr_obj

Iterat, #Fevals: Function Value (median,worst) |Axis Ratio|idx:Min SD idx:Max SD

1 , 9 : 3.3650636293349e-02 +(3e-12,6e-12) | 1.99e+01 | 2:9.4e-03 1:1.9e-01

2 , 17 : 3.3650636294518e-02 +(1e-12,3e-12) | 2.00e+01 | 2:9.1e-03 1:1.8e-01

3 , 25 : 3.3650636295258e-02 +(2e-12,7e-12) | 2.00e+01 | 2:9.4e-03 1:1.8e-01

#Fevals: f(returned x) | bestever.f | stopflag (saved to variablescmaes.mat)

26: 3.36506362953e-02 | 3.36506362933e-02 | tolfun

mean solution: +4.7e-01 +4.9e-01 +5.2e-01 +5.1e-01 +5.2e-01

std deviation: 1.8e-01 9.4e-03 1.0e-02 1.1e-02 1.1e-02

use plotcmaesdat.m for plotting the output at any time (option LogModulo must not be zero)

OPTIMAL VALUE OF THE PARAMETERS:

```
gamma 0.49405
g1 0.498351
g2 0.506277
g3 0.510933
g4 0.511093
```

Objective function : 0.0336506mutualfunds_v3WithLabor.mod (4.5 KB)

What does the objective function value indicate? Is this the value of the loss function?

Yes, this value is a loss function. Have tried whether the respective variances are sensitive to the parameters you are optimizing over?

@jpfeifer. Thanks for looking at the problem. I used your code

% make loop silent

options_.nofunctions=1;

options_.nocorr=1;

options_.noprint=1;

options_.irf=0;

options_.silent_optimizer=1;

options_.osr.opt_algo=9;

% find position of variables in variable_weights

y_pos=strmatch(‘y_hat’,M_.endo_names,‘exact’);

pi_pos=strmatch(‘pi_hat’,M_.endo_names,‘exact’);

% find position of variables in var_list_

y_pos_var_list_=strmatch(‘y_hat’,var_list_,‘exact’);

pi_pos_var_list_=strmatch(‘pi_hat’,var_list_,‘exact’);

weight_grid=0:0.01:1;

n_grid_points=length(weight_grid);

var_y=NaN(n_grid_points,1);

var_pi=NaN(n_grid_points,1);

for grid_iter=1:n_grid_points

M_.osr.variable_weights(pi_pos,pi_pos) = weight_grid(grid_iter);

M_.osr.variable_weights(y_pos,y_pos) = (1-weight_grid(grid_iter));

oo_.osr = osr(var_list_,M_.osr.param_names,M_.osr.variable_indices,M_.osr.variable_weights);

if oo_.osr.error_indicator==0

var_y(grid_iter)=oo_.var(y_pos_var_list_,y_pos_var_list_);

var_pi(grid_iter)=oo_.var(pi_pos_var_list_,pi_pos_var_list_);

end

end

figure

plot(var_y,var_pi)

after my standard code

I am getting this error

ERROR: mf_frontier.mod: line 257, cols 8-10: syntax error, unexpected NAME, expecting EQUAL or ‘.’

I am attaching the mod file. Can you please let me know where the problem lies. Should this code be used in the mod file or elsewhere.

mf_frontier.mod (5.7 KB)

Use

```
% find position of variables in variable_weights
y_pos=strmatch('y',M_.endo_names,'exact');
pi_pos=strmatch('pi',M_.endo_names,'exact');
verbatim;
% % find position of variables in var_list_
if ~isempty(var_list_)
y_pos_var_list_=strmatch('y',var_list_,'exact');
pi_pos_var_list_=strmatch('pi',var_list_,'exact');
else
y_pos_var_list_=y_pos;
pi_pos_var_list_=pi_pos;
end
weight_grid=0:0.01:1;
n_grid_points=length(weight_grid);
var_y=NaN(n_grid_points,1);
var_pi=NaN(n_grid_points,1);
for grid_iter=1:n_grid_points
M_.osr.variable_weights(pi_pos,pi_pos) = weight_grid(grid_iter);
M_.osr.variable_weights(y_pos,y_pos) = (1-weight_grid(grid_iter));
oo_.osr = osr(var_list_,M_.osr.param_names,M_.osr.variable_indices,M_.osr.variable_weights);
if oo_.osr.error_indicator==0
var_y(grid_iter)=oo_.var(y_pos_var_list_,y_pos_var_list_);
var_pi(grid_iter)=oo_.var(pi_pos_var_list_,pi_pos_var_list_);
end
end
end;
figure
plot(var_y,var_pi)
```

@jpfeifer I am not sure what this code is doing. Previous posts suggest that it finds the optimal coefficients of the loss function. But in my case, there is no change in the coefficients. Am I missing something here. Here is my mod file.

mf_frontier.mod (5.8 KB)

Your code is computing a so-called Taylor curve.

It changes the weight of output vs. inflation in the objective function, computes the OSR coefficients minimizing the objective for each weighting scheme and plots the resulting policy frontier/Taylor curve by drawing the output-inflation variance trade-off.

But the problem is the values(weights) of the coefficients of the objective function are not changing at all. They are fixed at the initial values.

That’s not true:

```
M_.osr.variable_weights(pi_pos,pi_pos) = weight_grid(grid_iter);
M_.osr.variable_weights(y_pos,y_pos) = (1-weight_grid(grid_iter));
```

changes the weights

i got same problem

@jpfeifer No my initial value was beta3=0.7 and it remains 0.7 after the iteration. There is no change in values.

mf_frontier.mod (5.8 KB)

You did not tell us what you are trying to do in the first place. The loop does not even try to change `beta3`

.