Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
dynare
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Frédéric Karamé
dynare
Commits
4aaebfbe
Commit
4aaebfbe
authored
Nov 2, 2014
by
Johannes Pfeifer
Browse files
Options
Downloads
Patches
Plain Diff
Add unit test to check whether objective function matches and whether covariances actually work
parent
ecbe428b
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
tests/Makefile.am
+1
-0
1 addition, 0 deletions
tests/Makefile.am
tests/optimal_policy/osr_example_objective_correctness.mod
+110
-0
110 additions, 0 deletions
tests/optimal_policy/osr_example_objective_correctness.mod
with
111 additions
and
0 deletions
tests/Makefile.am
+
1
−
0
View file @
4aaebfbe
...
@@ -19,6 +19,7 @@ MODFILES = \
...
@@ -19,6 +19,7 @@ MODFILES = \
example1_macroif.mod
\
example1_macroif.mod
\
t_sgu_ex1.mod
\
t_sgu_ex1.mod
\
optimal_policy/osr_example.mod
\
optimal_policy/osr_example.mod
\
optimal_policy/osr_example_objective_correctness.mod
\
optimal_policy/ramsey.mod
\
optimal_policy/ramsey.mod
\
optimal_policy/nk_ramsey.mod
\
optimal_policy/nk_ramsey.mod
\
optimal_policy/nk_ramsey_model.mod
\
optimal_policy/nk_ramsey_model.mod
\
...
...
This diff is collapsed.
Click to expand it.
tests/optimal_policy/osr_example_objective_correctness.mod
0 → 100644
+
110
−
0
View file @
4aaebfbe
// Example of optimal simple rule
var y inflation r dummy_var;
varexo y_ inf_;
parameters delta sigma alpha kappa gammax0 gammac0 gamma_y_ gamma_inf_;
delta = 0.44;
kappa = 0.18;
alpha = 0.48;
sigma = -0.06;
model(linear);
y = delta * y(-1) + (1-delta)*y(+1)+sigma *(r - inflation(+1)) + y_;
inflation = alpha * inflation(-1) + (1-alpha) * inflation(+1) + kappa*y + inf_;
dummy_var=0.9*dummy_var(-1)+0.01*y;
r = gammax0*y(-1)+gammac0*inflation(-1)+gamma_y_*y_+gamma_inf_*inf_;
end;
shocks;
var y_;
stderr 0.63;
var inf_;
stderr 0.4;
end;
options_.nograph=1;
options_.nocorr=1;
options_.osr.tolf=1e-15;
osr_params gammax0 gammac0 gamma_y_ gamma_inf_;
optim_weights;
inflation 1;
y 1;
dummy_var 1;
end;
gammax0 = 0.2;
gammac0 = 1.5;
gamma_y_ = 8;
gamma_inf_ = 3;
osr;
%compute objective function manually
objective=oo_.var(strmatch('y',M_.endo_names,'exact'),strmatch('y',M_.endo_names,'exact'))+oo_.var(strmatch('inflation',M_.endo_names,'exact'),strmatch('inflation',M_.endo_names,'exact'))+oo_.var(strmatch('dummy_var',M_.endo_names,'exact'),strmatch('dummy_var',M_.endo_names,'exact'));
if abs(oo_.osr.objective_function-objective)>1e-8
error('Objective Function is wrong')
end
%redo computation with covariance specified
optim_weights;
inflation 1;
y 1;
dummy_var 1;
y,inflation 0.5;
end;
osr;
%compute objective function manually
objective=oo_.var(strmatch('y',M_.endo_names,'exact'),strmatch('y',M_.endo_names,'exact'))+oo_.var(strmatch('inflation',M_.endo_names,'exact'),strmatch('inflation',M_.endo_names,'exact'))++oo_.var(strmatch('dummy_var',M_.endo_names,'exact'),strmatch('dummy_var',M_.endo_names,'exact'))+0.5*oo_.var(strmatch('y',M_.endo_names,'exact'),strmatch('inflation',M_.endo_names,'exact'));
if abs(oo_.osr.objective_function-objective)>1e-8
error('Objective Function is wrong')
end
% gammax0= 3.94954;
% gammac0= 4.39418;
% gamma_y_= 16.6664;
% gamma_inf_= 8.28523;
%redo computation with double weight on one covariance
optim_weights;
inflation 1;
y 1;
dummy_var 1;
y,inflation 1;
end;
osr;
%compute objective function manually
objective=oo_.var(strmatch('y',M_.endo_names,'exact'),strmatch('y',M_.endo_names,'exact'))+oo_.var(strmatch('inflation',M_.endo_names,'exact'),strmatch('inflation',M_.endo_names,'exact'))++oo_.var(strmatch('dummy_var',M_.endo_names,'exact'),strmatch('dummy_var',M_.endo_names,'exact'))+1*oo_.var(strmatch('y',M_.endo_names,'exact'),strmatch('inflation',M_.endo_names,'exact'));
if abs(oo_.osr.objective_function-objective)>1e-8
error('Objective Function is wrong')
end
oo_covar_single=oo_;
%redo computation with single weight on both covariances
optim_weights;
inflation 1;
y 1;
dummy_var 1;
y,inflation 0.5;
inflation,y 0.5;
end;
osr;
%compute objective function manually
objective=oo_.var(strmatch('y',M_.endo_names,'exact'),strmatch('y',M_.endo_names,'exact'))+oo_.var(strmatch('inflation',M_.endo_names,'exact'),strmatch('inflation',M_.endo_names,'exact'))+oo_.var(strmatch('dummy_var',M_.endo_names,'exact'),strmatch('dummy_var',M_.endo_names,'exact'))+0.5*oo_.var(strmatch('y',M_.endo_names,'exact'),strmatch('inflation',M_.endo_names,'exact'))+0.5*oo_.var(strmatch('inflation',M_.endo_names,'exact'),strmatch('y',M_.endo_names,'exact'));
if abs(oo_.osr.objective_function-objective)>1e-8
error('Objective Function is wrong')
end
if abs(oo_.osr.objective_function-oo_covar_single.osr.objective_function)>1e-8
error('Objective Function is wrong')
end
if max(abs(cell2mat(struct2cell(oo_.osr.optim_params))-cell2mat(struct2cell(oo_covar_single.osr.optim_params))))>1e-5
error('Parameters should be identical')
end
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment