| 1 |
//test solvers for decision rules as well as accessing matlab namespace from steady state file (see #1639) |
| 2 |
|
| 3 |
@#define Blocks = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15","16", "17", "18", "19", "20", "21", "22", "23", "24", "25","26", "27", "28", "29", "30", "31", "32", "33", "34", "35","36", "37", "38", "39", "40", "41", "42", "43", "44", "45","46", "47", "48", "49", "50", "51", "52", "53", "54", "55","56", "57", "58", "59", "60", "61", "62", "63", "64", "65","66", "67", "68", "69", "70", "71", "72", "73", "74", "75","76", "77", "78", "79", "80", "81", "82", "83", "84", "85","86", "87", "88", "89", "90", "91", "92", "93", "94", "95","96", "97", "98", "99", "100", "101", "102", "103", "104", "105", "106", "107", "108", "109", "110", "111", "112", "113", "114", "115","116", "117", "118", "119", "120", "121", "122", "123", "124", "125","126", "127", "128", "129", "130", "131", "132", "133", "134", "135","136", "137", "138", "139", "140", "141", "142", "143", "144", "145","146", "147", "148", "149", "150", "151", "152", "153", "154", "155","156", "157", "158", "159", "160", "161", "162", "163", "164", "165","166", "167", "168", "169", "170", "171", "172", "173", "174", "175","176", "177", "178", "179", "180", "181", "182", "183", "184", "185","186", "187", "188", "189", "190", "191", "192", "193", "194", "195","196", "197", "198", "199", "200"] |
| 4 |
|
| 5 |
@#define blocks = Blocks[1:20] |
| 6 |
|
| 7 |
@#for block in blocks |
| 8 |
var y_@{block} c_@{block} k_@{block} m_@{block} n_@{block} R_@{block} pi_@{block} z_@{block} u_@{block}; |
| 9 |
@#endfor |
| 10 |
|
| 11 |
@#for block in blocks |
| 12 |
varexo e_@{block} sigma_@{block}; |
| 13 |
@#endfor |
| 14 |
|
| 15 |
// sigma stands for phi in the eq 2.37 p.69 |
| 16 |
|
| 17 |
parameters alpha beta delta gamm phi1 eta a b rho phi2 Psi thetass; |
| 18 |
//phi1 stands for capital phi in eq.2.68 and 2.69 |
| 19 |
//phi2 stands for lowercase phi in eq. 2.66 |
| 20 |
|
| 21 |
alpha = 0.36; |
| 22 |
beta = 0.989; |
| 23 |
gamm = 0.5; |
| 24 |
delta = 0.019; |
| 25 |
phi1 = 2; |
| 26 |
phi2 = 0; |
| 27 |
eta = 1; |
| 28 |
a = 0.95; |
| 29 |
b = 2.56; |
| 30 |
rho = 0.95; |
| 31 |
Psi = 1.47630583; |
| 32 |
thetass = 1.0125; |
| 33 |
|
| 34 |
model(use_dll); |
| 35 |
|
| 36 |
@#for block in blocks |
| 37 |
(a*exp(c_@{block})^(1-b)+(1-a)*exp(m_@{block})^(1-b))^((b-phi1)/(1-b))*a*exp(c_@{block})^(-b) = (a*exp(c_@{block})^(1-b)+(1-a)*exp(m_@{block})^(1-b))^((b-phi1)/(1-b))*(1-a)*exp(m_@{block})^(-b)+beta*(a*exp(c_@{block}(+1))^(1-b)+(1-a)*exp(m_@{block}(+1))^(1-b))^((b-phi1)/(1-b))*a*exp(c_@{block}(+1))^(-b)/(1+pi_@{block}(+1)); |
| 38 |
|
| 39 |
Psi*(1-exp(n_@{block}))^(-eta)/(a*exp(c_@{block})^(-b)*(a*exp(c_@{block})^(1-b) + (1-a)*exp(m_@{block})^(1-b))^((b-phi1)/(1-b))) = (1-alpha)*exp(y_@{block})/exp(n_@{block}); |
| 40 |
|
| 41 |
(a*exp(c_@{block})^(1-b)+(1-a)*exp(m_@{block})^(1-b))^((b-phi1)/(1-b))*a*exp(c_@{block})^(-b) = beta*exp(R_@{block}(+1))*(a*exp(c_@{block}(+1))^(1-b)+(1-a)*exp(m_@{block}(+1))^(1-b))^((b-phi1)/(1-b))*a*exp(c_@{block}(+1))^(-b); |
| 42 |
|
| 43 |
exp(R_@{block}) = alpha*exp(y_@{block})/exp(k_@{block}(-1)) + 1-delta; |
| 44 |
|
| 45 |
exp(k_@{block}) = (1-delta)*exp(k_@{block}(-1))+exp(y_@{block})-exp(c_@{block}); |
| 46 |
|
| 47 |
exp(y_@{block}) = exp(z_@{block})*exp(k_@{block}(-1))^alpha*exp(n_@{block})^(1-alpha); |
| 48 |
|
| 49 |
exp(m_@{block}) = exp(m_@{block}(-1))*(u_@{block}+thetass)/(1+pi_@{block}); |
| 50 |
|
| 51 |
z_@{block} = rho*z_@{block}(-1) + e_@{block}; |
| 52 |
|
| 53 |
u_@{block} = gamm*u_@{block}(-1) + phi2*z_@{block}(-1) + sigma_@{block}; |
| 54 |
|
| 55 |
@#endfor |
| 56 |
|
| 57 |
end; |
| 58 |
|
| 59 |
shocks; |
| 60 |
@#for block in blocks |
| 61 |
var e_@{block}; stderr 0.007; |
| 62 |
var sigma_@{block};stderr 0.0089; |
| 63 |
@#endfor |
| 64 |
end; |
| 65 |
|
| 66 |
steady_state_model; |
| 67 |
// solving in levels |
| 68 |
// calibrating n = 1/3 and recovering the value of Psi |
| 69 |
// adapting solution Walsh (2003) p. 84 |
| 70 |
en = 1/3; |
| 71 |
eR = 1/beta; |
| 72 |
y_k = matlab.namespace.y_k(alpha, beta, delta); |
| 73 |
ek = en*y_k^(-1/(1-alpha)); |
| 74 |
ec = ek*(y_k-delta); |
| 75 |
em = ec*(a/(1-a))^(-1/b)*((thetass-beta)/thetass)^(-1/b); |
| 76 |
ey = ek*y_k; |
| 77 |
Xss = a*ec^(1-b)*(1+(a/(1-a))^(-1/b)*((thetass-beta)/thetass)^((b-1)/b)); |
| 78 |
Psi = (1-alpha)*(ey/en)*Xss^((b-phi1)/(1-b))*a*ec^(-b)*(1-en)^eta; |
| 79 |
@#for block in blocks |
| 80 |
pi_@{block} = thetass-1; |
| 81 |
n_@{block} = log(en); |
| 82 |
k_@{block} = log(ek); |
| 83 |
m_@{block} = log(em); |
| 84 |
c_@{block} = log(ec); |
| 85 |
y_@{block} = log(ey); |
| 86 |
R_@{block} = log(eR); |
| 87 |
@#endfor |
| 88 |
end; |
| 89 |
|
| 90 |
steady; |
| 91 |
|
| 92 |
loop_size = 100; |
| 93 |
|
| 94 |
tic; |
| 95 |
for i=1:loop_size |
| 96 |
stoch_simul(order=1,irf=0,noprint,nomoments,dr=default); |
| 97 |
dr = oo_.dr; |
| 98 |
end; |
| 99 |
e1 = toc; |
| 100 |
|
| 101 |
tic; |
| 102 |
for i=1:loop_size |
| 103 |
stoch_simul(order=1,irf=0,noprint,nomoments,dr=cycle_reduction); |
| 104 |
DR = oo_.dr; |
| 105 |
end; |
| 106 |
e2 = toc; |
| 107 |
|
| 108 |
tic; |
| 109 |
for i=1:loop_size |
| 110 |
stoch_simul(order=1,irf=0,noprint,nomoments,dr=cycle_reduction,dr_cycle_reduction_tol=1e-6); |
| 111 |
DR_ = oo_.dr; |
| 112 |
end; |
| 113 |
e3 = toc; |
| 114 |
|
| 115 |
tic; |
| 116 |
for i=1:loop_size |
| 117 |
stoch_simul(order=1,irf=0,noprint,nomoments,dr=cycle_reduction,dr_cycle_reduction_tol=1e-5); |
| 118 |
DR__ = oo_.dr; |
| 119 |
end; |
| 120 |
e4 = toc; |
| 121 |
|
| 122 |
tic; |
| 123 |
for i=1:loop_size |
| 124 |
stoch_simul(order=1,irf=0,noprint,nomoments,dr=cycle_reduction,dr_cycle_reduction_tol=1e-4); |
| 125 |
DR___ = oo_.dr; |
| 126 |
end; |
| 127 |
e5 = toc; |
| 128 |
|
| 129 |
tic; |
| 130 |
for i=1:loop_size |
| 131 |
stoch_simul(order=1,irf=0,noprint,nomoments,dr=cycle_reduction,dr_cycle_reduction_tol=1e-3); |
| 132 |
DR____ = oo_.dr; |
| 133 |
end; |
| 134 |
e6 = toc; |
| 135 |
|
| 136 |
tic; |
| 137 |
for i=1:loop_size |
| 138 |
stoch_simul(order=1,irf=0,noprint,nomoments,dr=cycle_reduction,dr_cycle_reduction_tol=1e-2); |
| 139 |
DR_____ = oo_.dr; |
| 140 |
end; |
| 141 |
e7 = toc; |
| 142 |
|
| 143 |
tic; |
| 144 |
for i=1:loop_size |
| 145 |
stoch_simul(order=1,irf=0,noprint,nomoments,dr=cycle_reduction,dr_cycle_reduction_tol=200); |
| 146 |
DR______ = oo_.dr; |
| 147 |
end; |
| 148 |
e8 = toc; |
| 149 |
|
| 150 |
disp(['Elapsed time (QZ algorithm): ' num2str(e1)]) |
| 151 |
disp(['Elapsed time (Cycle reduction algorithm, tol = 1e-7): ' num2str(e2)]) |
| 152 |
disp(['Elapsed time (Cycle reduction algorithm, tol = 1e-6): ' num2str(e3)]) |
| 153 |
disp(['Elapsed time (Cycle reduction algorithm, tol = 1e-5): ' num2str(e4)]) |
| 154 |
disp(['Elapsed time (Cycle reduction algorithm, tol = 1e-4): ' num2str(e5)]) |
| 155 |
disp(['Elapsed time (Cycle reduction algorithm, tol = 1e-3): ' num2str(e6)]) |
| 156 |
disp(['Elapsed time (Cycle reduction algorithm, tol = 1e-2): ' num2str(e7)]) |
| 157 |
disp(['Elapsed time (Cycle reduction algorithm, tol = 1e-1): ' num2str(e8)]) |
| 158 |
|
| 159 |
if e1<e2 |
| 160 |
disp(['cycle reduction algorithm is slower than QZ algorithm in solving the model (' int2str(M_.endo_nbr) ' equations)!']) |
| 161 |
end |
| 162 |
|
| 163 |
dx = max(max(dr.ghx-DR.ghx)); |
| 164 |
du = max(max(dr.ghu-DR.ghu)); |
| 165 |
dx_ = max(max(dr.ghx-DR_.ghx)); |
| 166 |
du_ = max(max(dr.ghu-DR_.ghu)); |
| 167 |
dx__ = max(max(dr.ghx-DR__.ghx)); |
| 168 |
du__ = max(max(dr.ghu-DR__.ghu)); |
| 169 |
dx___ = max(max(dr.ghx-DR___.ghx)); |
| 170 |
du___ = max(max(dr.ghu-DR___.ghu)); |
| 171 |
dx____ = max(max(dr.ghx-DR____.ghx)); |
| 172 |
du____ = max(max(dr.ghu-DR____.ghu)); |
| 173 |
dx_____ = max(max(dr.ghx-DR_____.ghx)); |
| 174 |
du_____ = max(max(dr.ghu-DR_____.ghu)); |
| 175 |
dx______ = max(max(dr.ghx-DR______.ghx)); |
| 176 |
du______ = max(max(dr.ghu-DR______.ghu)); |
| 177 |
|
| 178 |
|
| 179 |
if dx>1e-8 |
| 180 |
error('QZ and Cycle reduction algorithms don''t return the same results (tolerance parameter is 1e-7)!') |
| 181 |
end |
| 182 |
|
| 183 |
if du>1e-8 |
| 184 |
error('QZ and Cycle reduction algorithms don''t return the same results (tolerance parameter is 1e-7)!') |
| 185 |
end |
| 186 |
|
| 187 |
if dx_>1e-8 || du_>1e-8 |
| 188 |
disp('QZ and Cycle reduction algorithms don''t return the same results (tolerance parameter is 1e-6)!') |
| 189 |
else |
| 190 |
[dx, dx_] |
| 191 |
[du, du_] |
| 192 |
end |
| 193 |
|
| 194 |
if dx__>1e-8 || du__>1e-8 |
| 195 |
disp('QZ and Cycle reduction algorithms don''t return the same results (tolerance parameter is 1e-5)!') |
| 196 |
else |
| 197 |
[dx, dx_, dx__] |
| 198 |
[du, du_, du__] |
| 199 |
end |
| 200 |
|
| 201 |
if dx___>1e-8 || du___>1e-8 |
| 202 |
disp('QZ and Cycle reduction algorithms don''t return the same results (tolerance parameter is 1e-4)!') |
| 203 |
else |
| 204 |
[dx, dx_, dx__, dx___] |
| 205 |
[du, du_, du__, du___] |
| 206 |
end |
| 207 |
|
| 208 |
if dx____>1e-8 || du____>1e-8 |
| 209 |
disp('QZ and Cycle reduction algorithms don''t return the same results (tolerance parameter is 1e-3)!') |
| 210 |
else |
| 211 |
[dx, dx_, dx__, dx___,dx____] |
| 212 |
[du, du_, du__, du___,du____] |
| 213 |
end |
| 214 |
|
| 215 |
if dx_____>1e-8 || du_____>1e-8 |
| 216 |
disp('QZ and Cycle reduction algorithms don''t return the same results (tolerance parameter is 1e-2)!') |
| 217 |
else |
| 218 |
[dx, dx_, dx__, dx___,dx____,dx_____] |
| 219 |
[du, du_, du__, du___,du____,du_____] |
| 220 |
end |
| 221 |
|
| 222 |
if dx_____>1e-8 || du_____>1e-8 |
| 223 |
disp('QZ and Cycle reduction algorithms don''t return the same results (tolerance parameter is 1e-1)!') |
| 224 |
else |
| 225 |
[dx, dx_, dx__, dx___,dx____,dx_____,dx______] |
| 226 |
[du, du_, du__, du___,du____,du_____,du______] |
| 227 |
end |