using dynare for a solver for OSR and calibration

This forum is closed. You can read the posts but cannot write. We have migrated the forum to a new location where you will have to reset your password.
Forum rules
This forum is closed. You can read the posts but cannot write. We have migrated the forum to a new location (https://forum.dynare.org) where you will have to reset your password.

using dynare for a solver for OSR and calibration

Postby dominik » Fri Oct 17, 2014 10:21 am

Hi

for my project i need to search for the optimal simple monetary policy rule and calibrate some moments using volatilities.
My initial approach for both types of problems was to use a solver like fmincon, since both are problems of the type
max f(x) for x element X
where x is a vector of parameters and f(x) is a subset of the dynare output.

Yet it seems you can not call dynare and access the dynare output inside a matlab function , at least i didnt manage.
Is there a way this can be done? If not is there a generic optimization function included in matlab?

Thanks
Dominik
dominik
 
Posts: 22
Joined: Tue May 13, 2014 1:48 pm

Re: using dynare for a solver for OSR and calibration

Postby jpfeifer » Fri Oct 17, 2014 6:50 pm

------------
Johannes Pfeifer
University of Cologne
https://sites.google.com/site/pfeiferecon/
jpfeifer
 
Posts: 6940
Joined: Sun Feb 21, 2010 4:02 pm
Location: Cologne, Germany

Re: using dynare for a solver for OSR and calibration

Postby dominik » Mon Oct 20, 2014 1:33 pm

Hi,,
thanks for the reply, but i believe u posted the wrong link. it leads me to someone with a problem with initial values...
Dominik
dominik
 
Posts: 22
Joined: Tue May 13, 2014 1:48 pm

Re: using dynare for a solver for OSR and calibration

Postby jpfeifer » Mon Oct 20, 2014 2:00 pm

------------
Johannes Pfeifer
University of Cologne
https://sites.google.com/site/pfeiferecon/
jpfeifer
 
Posts: 6940
Joined: Sun Feb 21, 2010 4:02 pm
Location: Cologne, Germany

Re: using dynare for a solver for OSR and calibration

Postby dominik » Mon Oct 20, 2014 3:25 pm

Thanks!
I found the example from your paper the most instructive. https://sites.google.com/site/pfeiferec ... edirects=0

Here is a quick and easy example for anyone who wants to optimize over some output of dynare:
(In this example I optimize over a scalar between 1.1 and 10 using fmincon)

At the end of your usual mod file write

Code: Select all
[fhat,xhat] = fmincon(@tominimize,1.5,[],[],[],[],1.1,10)


Furthermore save this matlab function in the current folder
Code: Select all
global oo_ M_ options_ % get Dynare structures; used to pass them on to resol.m

%% set parameter for use in Dynare
set_param_value('phi1',xopt(1));

[oo_.dr,info,M_,options_,oo_] = resol(0,M_,options_,oo_); %run model solution in Dynare

if info %solution was not successful
    fval=10e6+sum([xopt(1),xopt(2),xopt(3),log(xopt(4)) ].^2); %return with penalty
else
       % compute objective function
    fval=oo_.steady_state(1); %this is an arbitary choice; here you can have e.g. some value function for optimal policy or some model moment for SMM
end
dominik
 
Posts: 22
Joined: Tue May 13, 2014 1:48 pm

Re: using dynare for a solver for OSR and calibration

Postby dominik » Mon Oct 27, 2014 11:09 am

Hi,

the above works fine for the OSR purpose (where all relevant statistics are in oo_.dr) if you want to do SMM you need to add some lines because resol doesnt update oo_ completely.
In particular the theoretical variance and mean are not recomputed.

Here is what you need to add to the above code after the resol comand to get the theoretical moments recomputed:

Code: Select all
if isempty(options_.qz_criterium)
    options_.qz_criterium = 1+1e-6;
end 
options_.noprint=1;
disp_th_moments(oo_.dr, M_.endo_names(1:M_.orig_endo_nbr, :));


Note that you cant change the shock variances with set_param_value. Hence write
var uA = sigma_A^2; by var uA=1 ;
and
uA by uA*sigma_A
dominik
 
Posts: 22
Joined: Tue May 13, 2014 1:48 pm

Re: using dynare for a solver for OSR and calibration

Postby jpfeifer » Thu Oct 30, 2014 9:11 am

A more general version that also allows for IRF matching would be to use

Code: Select all
if isempty(options_.qz_criterium)
    options_.qz_criterium = 1+1e-6;
end
options_.noprint=1;
set_param_value('nu',nu);
% manually set the parameter that is looped over
info=stoch_simul(var_list_);
% get decision rules by directly calling Dynare routine directly instead of
% all of Dynare
if info~=0
    error('The model did not correctly solve')
end
------------
Johannes Pfeifer
University of Cologne
https://sites.google.com/site/pfeiferecon/
jpfeifer
 
Posts: 6940
Joined: Sun Feb 21, 2010 4:02 pm
Location: Cologne, Germany

Re: using dynare for a solver for OSR and calibration

Postby jpfeifer » Sun Nov 02, 2014 12:24 pm

In case of osr running osr with different starting values for a parameter nu, one would need inside of the loop:
Code: Select all
set_param_value('nu',nu);
oo_.osr = osr(var_list_,osr_params_,obj_var_,optim_weights_);
------------
Johannes Pfeifer
University of Cologne
https://sites.google.com/site/pfeiferecon/
jpfeifer
 
Posts: 6940
Joined: Sun Feb 21, 2010 4:02 pm
Location: Cologne, Germany


Return to Dynare help

Who is online

Users browsing this forum: No registered users and 13 guests