diff --git a/tests/Makefile.am b/tests/Makefile.am index 2004024367a943e1922a8cf3c6ea334c1af7a82c..734945b24c640cfb74017c712c23654c064b2b74 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -21,6 +21,12 @@ MODFILES = \ optimal_policy/osr_example.mod \ optimal_policy/osr_example_objective_correctness.mod \ optimal_policy/osr_example_obj_corr_non_stat_vars.mod \ + optimal_policy/OSR/osr_obj_corr_algo_1.mod \ + optimal_policy/OSR/osr_obj_corr_algo_3.mod \ + optimal_policy/OSR/osr_obj_corr_algo_4.mod \ + optimal_policy/OSR/osr_obj_corr_algo_7.mod \ + optimal_policy/OSR/osr_obj_corr_algo_8.mod \ + optimal_policy/OSR/osr_obj_corr_algo_9.mod \ optimal_policy/ramsey_.mod \ optimal_policy/nk_ramsey.mod \ optimal_policy/nk_ramsey_model.mod \ diff --git a/tests/optimal_policy/OSR/osr_obj_corr_algo_1.mod b/tests/optimal_policy/OSR/osr_obj_corr_algo_1.mod new file mode 100644 index 0000000000000000000000000000000000000000..65dcf699197b6a25fa4f90fb5f47bb1ad006ed63 --- /dev/null +++ b/tests/optimal_policy/OSR/osr_obj_corr_algo_1.mod @@ -0,0 +1,109 @@ +// Example of optimal simple rule using opt_algo=4 +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; +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(opt_algo=1); +%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=1.35533; +gammac0=1.39664; +gamma_y_=16.6667; +gamma_inf_=9.13199; + +%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)))./cell2mat(struct2cell(oo_.osr.optim_params))))>1e-4 + error('Parameters should be identical') +end diff --git a/tests/optimal_policy/OSR/osr_obj_corr_algo_3.mod b/tests/optimal_policy/OSR/osr_obj_corr_algo_3.mod new file mode 100644 index 0000000000000000000000000000000000000000..a54224fc82b68e164886cf358565199a2aff6d14 --- /dev/null +++ b/tests/optimal_policy/OSR/osr_obj_corr_algo_3.mod @@ -0,0 +1,109 @@ +// Example of optimal simple rule using opt_algo=4 +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; +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(opt_algo=3); +%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=1.35533; +gammac0=1.39664; +gamma_y_=16.6667; +gamma_inf_=9.13199; + +%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)))./cell2mat(struct2cell(oo_.osr.optim_params))))>1e-4 + error('Parameters should be identical') +end diff --git a/tests/optimal_policy/OSR/osr_obj_corr_algo_4.mod b/tests/optimal_policy/OSR/osr_obj_corr_algo_4.mod new file mode 100644 index 0000000000000000000000000000000000000000..cbbabab6b1d37eae2a4bedc840a9701b19a1929c --- /dev/null +++ b/tests/optimal_policy/OSR/osr_obj_corr_algo_4.mod @@ -0,0 +1,110 @@ +// Example of optimal simple rule using opt_algo=4 +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-20; +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(opt_algo=4); +%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=1.35533; +gammac0=1.39664; +gamma_y_=16.6667; +gamma_inf_=9.13199; + +%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)))./cell2mat(struct2cell(oo_.osr.optim_params))))>1e-4 + error('Parameters should be identical') +end diff --git a/tests/optimal_policy/OSR/osr_obj_corr_algo_7.mod b/tests/optimal_policy/OSR/osr_obj_corr_algo_7.mod new file mode 100644 index 0000000000000000000000000000000000000000..fea4424572182b35a18db473ea8a46c36452719c --- /dev/null +++ b/tests/optimal_policy/OSR/osr_obj_corr_algo_7.mod @@ -0,0 +1,109 @@ +// Example of optimal simple rule using opt_algo=2 +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; +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(opt_algo=7); +%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=1.35533; +gammac0=1.39664; +gamma_y_=16.6667; +gamma_inf_=9.13199; + +%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)))./cell2mat(struct2cell(oo_.osr.optim_params))))>1e-4 + error('Parameters should be identical') +end diff --git a/tests/optimal_policy/OSR/osr_obj_corr_algo_8.mod b/tests/optimal_policy/OSR/osr_obj_corr_algo_8.mod new file mode 100644 index 0000000000000000000000000000000000000000..77d014d2f1e85f8eef3d55f4857b27b3808df1ff --- /dev/null +++ b/tests/optimal_policy/OSR/osr_obj_corr_algo_8.mod @@ -0,0 +1,109 @@ +// Example of optimal simple rule using opt_algo=2 +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; +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(opt_algo=8); +%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=1.35533; +gammac0=1.39664; +gamma_y_=16.6667; +gamma_inf_=9.13199; + +%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)))./cell2mat(struct2cell(oo_.osr.optim_params))))>1e-4 + error('Parameters should be identical') +end diff --git a/tests/optimal_policy/OSR/osr_obj_corr_algo_9.mod b/tests/optimal_policy/OSR/osr_obj_corr_algo_9.mod new file mode 100644 index 0000000000000000000000000000000000000000..59a2fa250f62137bbd77a12b7920b3dd81c0d3c8 --- /dev/null +++ b/tests/optimal_policy/OSR/osr_obj_corr_algo_9.mod @@ -0,0 +1,109 @@ +// Example of optimal simple rule using opt_algo=3 +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; +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(opt_algo=9); +%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=1.35533; +gammac0=1.39664; +gamma_y_=16.6667; +gamma_inf_=9.13199; + +%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)))./cell2mat(struct2cell(oo_.osr.optim_params))))>1e-4 + error('Parameters should be identical') +end