| 1 |
// example 1 from Collard's guide to Dynare |
| 2 |
var y, c, k, a, h, b; |
| 3 |
varexo e,u; |
| 4 |
|
| 5 |
parameters beta, rho, alpha, delta, theta, psi, tau, phi; |
| 6 |
|
| 7 |
alpha = 0.36; |
| 8 |
rho = 0.95; |
| 9 |
tau = 0.025; |
| 10 |
beta = 0.99; |
| 11 |
delta = 0.025; |
| 12 |
psi = 0; |
| 13 |
theta = 2.95; |
| 14 |
|
| 15 |
phi = 0.1; |
| 16 |
|
| 17 |
model; |
| 18 |
c*theta*h^(1+psi)=(1-alpha)*y; |
| 19 |
k = beta*(((exp(b)*c)/(exp(b(+1))*c(+1))) |
| 20 |
*(exp(b(+1))*alpha*y(+1)+(1-delta)*k)); |
| 21 |
y = exp(a)*(k(-1)^alpha)*(h^(1-alpha)); |
| 22 |
k = exp(b)*(y-c)+(1-delta)*k(-1); |
| 23 |
a = rho*a(-1)+tau*b(-1) + e; |
| 24 |
b = tau*a(-1)+rho*b(-1) + u; |
| 25 |
end; |
| 26 |
|
| 27 |
initval; |
| 28 |
y = 1.08068253095672; |
| 29 |
c = 0.80359242014163; |
| 30 |
h = 0.29175631001732; |
| 31 |
k = 5; |
| 32 |
a = 0; |
| 33 |
b = 0; |
| 34 |
e = 0; |
| 35 |
u = 0; |
| 36 |
end; |
| 37 |
|
| 38 |
shocks; |
| 39 |
var e; stderr 0.009; |
| 40 |
var u; stderr 0.009; |
| 41 |
//var e, u = phi*0.009*0.009; |
| 42 |
end; |
| 43 |
|
| 44 |
varobs a y; |
| 45 |
|
| 46 |
|
| 47 |
@#for order in [1,2] |
| 48 |
options_.order=@{order}; |
| 49 |
stoch_simul(conditional_variance_decomposition = 100,irf=0) a y k; |
| 50 |
if max(abs(sum(oo_.variance_decomposition,2)-100))>1e-6 |
| 51 |
error(['Variance decomposition at order ',num2str(options_.order),' does not work']) |
| 52 |
end |
| 53 |
|
| 54 |
stoch_simul(conditional_variance_decomposition = [1 2 3 5 10 100],irf=0) a y k; |
| 55 |
if max(max(abs(sum(oo_.conditional_variance_decomposition,3)-1)))>1e-6 |
| 56 |
error(['Conditional variance decomposition at order ',num2str(options_.order),' does not work']) |
| 57 |
end |
| 58 |
|
| 59 |
shocks; |
| 60 |
var y; stderr 0.01; |
| 61 |
var a; stderr 0.009; |
| 62 |
end; |
| 63 |
|
| 64 |
stoch_simul(conditional_variance_decomposition = [1 2 3 5 10 200],irf=0) a y k; |
| 65 |
if max(max(abs(sum(oo_.conditional_variance_decomposition,3)-1)))>1e-6 |
| 66 |
error(['Conditional variance decomposition at order ',num2str(options_.order),' does not work']) |
| 67 |
end |
| 68 |
if max(max(abs(sum(oo_.conditional_variance_decomposition_ME,3)-1)))>1e-6 |
| 69 |
error(['Conditional variance decomposition at order ',num2str(options_.order),' does not work']) |
| 70 |
end |
| 71 |
|
| 72 |
nvar = size(var_list_,1); |
| 73 |
SubsetOfVariables=zeros(nvar,1); |
| 74 |
for i=1:nvar |
| 75 |
i_tmp = strmatch(var_list_(i,:),M_.endo_names,'exact'); |
| 76 |
SubsetOfVariables(i) = i_tmp; |
| 77 |
end |
| 78 |
|
| 79 |
[observable_pos,index_observables,index_subset]=intersect(SubsetOfVariables,options_.varobs_id,'stable'); |
| 80 |
y_pos=strmatch('y',var_list_,'exact'); |
| 81 |
y_pos_varobs=strmatch('y',options_.varobs,'exact'); |
| 82 |
a_pos_varobs=strmatch('a',options_.varobs,'exact'); |
| 83 |
|
| 84 |
if (oo_.conditional_variance_decomposition_ME(index_observables(y_pos_varobs),end,end)+oo_.var(y_pos,y_pos)/(oo_.var(y_pos,y_pos)+M_.H(y_pos_varobs,y_pos_varobs)))-1>1e-5... |
| 85 |
|| abs(oo_.conditional_variance_decomposition_ME(index_observables(a_pos_varobs),1,end)-0.5)>1e-5 |
| 86 |
error(['Conditional variance decomposition at order ',num2str(options_.order),' with ME does not work']) |
| 87 |
end |
| 88 |
|
| 89 |
if (oo_.variance_decomposition_ME(index_observables(y_pos_varobs),end)/100+oo_.var(y_pos,y_pos)/(oo_.var(y_pos,y_pos)+M_.H(y_pos_varobs,y_pos_varobs)))-1>1e-5 |
| 90 |
error(['Unconditional variance decomposition at order ',num2str(options_.order),' with ME does not work']) |
| 91 |
end |
| 92 |
|
| 93 |
shocks; |
| 94 |
var y; stderr 0; |
| 95 |
end; |
| 96 |
|
| 97 |
@#endfor |
| 98 |
|
| 99 |
%% do simulated moments |
| 100 |
@#for order in [1,2] |
| 101 |
options_.order=@{order}; |
| 102 |
|
| 103 |
shocks; |
| 104 |
var y; stderr 0.01; |
| 105 |
var a; stderr 0.009; |
| 106 |
end; |
| 107 |
|
| 108 |
stoch_simul(irf=0,periods=1000000) a y k; |
| 109 |
if max(abs(sum(oo_.variance_decomposition,2)-100))>2 |
| 110 |
error(['Variance decomposition at order ',num2str(options_.order),' does not work']) |
| 111 |
end |
| 112 |
|
| 113 |
[observable_pos,index_observables,index_subset]=intersect(SubsetOfVariables,options_.varobs_id,'stable'); |
| 114 |
y_pos=strmatch('y',var_list_,'exact'); |
| 115 |
y_pos_varobs=strmatch('y',options_.varobs,'exact'); |
| 116 |
a_pos_varobs=strmatch('a',options_.varobs,'exact'); |
| 117 |
|
| 118 |
if (oo_.variance_decomposition_ME(index_observables(y_pos_varobs),end)/100+oo_.var(y_pos,y_pos)/(oo_.var(y_pos,y_pos)+M_.H(y_pos_varobs,y_pos_varobs)))-1>5e-4 |
| 119 |
error(['Unconditional variance decomposition at order ',num2str(options_.order),' with ME does not work']) |
| 120 |
end |
| 121 |
|
| 122 |
shocks; |
| 123 |
var y; stderr 0; |
| 124 |
end; |
| 125 |
|
| 126 |
@#endfor |