-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestpert.m
More file actions
240 lines (189 loc) · 5.21 KB
/
testpert.m
File metadata and controls
240 lines (189 loc) · 5.21 KB
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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
(* Note: these models are somewhat contrived (not much economic content)
and are meant to test out various aspects of the code. Nonetheless,
they may serve as useful examples of what the code is capable of. The
arbitrary-precision calculations at the end may be of particular
interest.
*)
(*
Print["\n\n"] ;
Print["Test 1: A simple, contrived New Keynesian model"] ;
eqns={
Y[t] == alpha *Y[t+1] - gamma *(E^(r[t+1]-pi[t+1]) -1) + eps[y][t],
pi[t] == beta *pi[t+1] + delta *Y[t] + eps[pi][t],
r[t] == tayly *Y[t-1] + taylpi *pi[t-1]
}
logvars = {}
logrules = Map[#[x_]->E^(#[x])&, logvars]
parametervalues={
alpha->1,
beta->0.99,
gamma->0.15,
delta->0.25,
tayly->0.5,
taylpi->1.5
}
test1 = eqns /.logrules //.parametervalues
Print["The output is: "]
Print[AIMSeries[test1,4] //TableForm]
*)
(*
Print["\n\n"] ;
Print["Test 2: A version of the model with no shocks\n"] ;
Print["Note: some Windows versions of Mathematica will crash on this test"] ;
Print[" due to improper handling of multiplication by an empty matrix"] ;
Print[" that is caused by the lack of shocks in the model."] ;
Print["If you are using Windows, just comment out this test (Test 2) and re-run"] ;
Print[" testpert.m. You will also have to make sure that your models always have"] ;
Print[" at least one shock in them to avoid a crash."] ;
eqns={
Y[t] == alpha *Y[t+1] - gamma *(E^(r[t+1]-pi[t+1]) -1),
pi[t] == beta *pi[t+1] + delta *Y[t],
r[t] == tayly *Y[t-1] + taylpi *pi[t-1]
}
logvars = {}
logrules = Map[#[x_]->E^(#[x])&, logvars]
parametervalues={
alpha->1,
beta->0.99,
gamma->0.15,
delta->0.25,
tayly->0.5,
taylpi->1.5
}
test2 = eqns /.logrules //.parametervalues
Print["The output is: "]
Print[AIMSeries[test2,4] //TableForm]
*)
(*
Print["\n\n"] ;
Print["Test 3: A version of the model with no lags"] ;
eqns={
Y[t] == alpha *Y[t+1] - gamma *(E^(r[t+1]-pi[t+1]) -1) + eps[y][t],
pi[t] == beta *pi[t+1] + delta *Y[t] + eps[pi][t],
r[t] == tayly *Y[t] + taylpi *pi[t]
}
logvars = {}
logrules = Map[#[x_]->E^(#[x])&, logvars]
parametervalues={
alpha->1,
beta->0.99,
gamma->0.15,
delta->0.25,
tayly->0.5,
taylpi->1.5
}
test3 = eqns /.logrules //.parametervalues
Print[AIMSeries[test3,4] //TableForm]
*)
(*
Print["\n\n"] ;
Print["Test 4: A version of the model with no leads"] ;
eqns={
Y[t] == alpha *Y[t-1] - gamma *(E^(r[t]-pi[t]) -1) + eps[y][t],
pi[t] == beta *pi[t-1] + delta *Y[t-1] + eps[pi][t],
r[t] == tayly *Y[t-1] + taylpi *pi[t-1]
}
logvars = {}
logrules = Map[#[x_]->E^(#[x])&, logvars]
parametervalues={
alpha->1,
beta->0.99,
gamma->0.15,
delta->0.25,
tayly->0.5,
taylpi->1.5
}
test4 = eqns /.logrules //.parametervalues
Print[AIMSeries[test4,4] //TableForm]
*)
(*
Print["\n\n"] ;
Print["Test 5: A version of the model with multiple lags"] ;
eqns={
Y[t] == alpha *Y[t+1] - gamma *(E^(r[t+1]-pi[t+1]) -1) + eps[y][t],
pi[t] == beta *pi[t-4] + delta *Y[t] + eps[pi][t],
r[t] == tayly * Y[t-1] + taylpi *pi[t-1]
}
logvars = {}
logrules = Map[#[x_]->E^(#[x])&, logvars]
parametervalues={
alpha->1,
beta->0.99,
gamma->0.15,
delta->0.25,
tayly->0.5,
taylpi->1.5
}
test5 = eqns /.logrules //.parametervalues
Print[AIMSeries[test5,3] //TableForm]
*)
(*
Print["\n\n"] ;
Print["Test 6: A version of the model with multiple leads"] ;
eqns={
Y[t] == alpha *Y[t+1] - gamma *(E^(r[t+1]-pi[t+1]) -1) + eps[y][t],
pi[t] == beta *pi[t+4] + delta *Y[t] + eps[pi][t],
r[t] == tayly *Y[t-1] + taylpi *pi[t-1]
}
parametervalues={
alpha->1,
beta->0.99,
gamma->0.15,
delta->0.25,
tayly->0.5,
taylpi->1.5
}
logvars = {}
logrules = Map[#[x_]->E^(#[x])&, logvars]
test6 = eqns /.logrules //.parametervalues
Print[AIMSeries[test6,3] //TableForm]
*)
(*
Print["\n\n"] ;
Print["Test 7: A version of the model with one equation"] ;
eqns = Y[t] == alpha *Y[t+1] + beta *Y[t-1] + E^eps[y][t]
test7 = eqns /. {alpha->.9, beta->.05}
Print[AIMSeries[test7,4] //TableForm]
*)
(*
Print["\n\n"] ;
Print["Test 8: A version of the model with eps[_][t+1]"] ;
eqns={
Y[t] == alpha *Y[t+1] - gamma *(E^(r[t+1]-pi[t+1]) -1) + eps[y][t],
pi[t] == beta *pi[t+1] + delta *Y[t] + eps[pi][t+1],
r[t] == tayly * Y[t-1] + taylpi *pi[t-1]
}
parametervalues={
alpha->1,
beta->0.99,
gamma->0.15,
delta->0.25,
tayly->0.5,
taylpi->1.5
}
logvars = {}
logrules = Map[#[x_]->E^(#[x])&, logvars]
test8 = eqns /.logrules /.parametervalues
Print[AIMSeries[test8,4] //TableForm]
*)
Print["\n\n"] ;
Print["Test 9: A version of the model with arbitrary precision coefficients"];
eqns={
Y[t] == alpha *Y[t+1] - gamma *(E^(r[t+1]-pi[t+1]) -1) + eps[y][t],
pi[t] == beta *pi[t+1] + delta *Y[t] + eps[pi][t],
r[t] == tayly * Y[t-1] + taylpi *pi[t-1]
}
parametervalues={
alpha->1`60, (* 60 digits of precision *)
beta->0.99`60,
gamma->0.15`60,
delta->0.25`60,
tayly->0.5`60,
taylpi->1.5`60
}
logvars = {}
logrules = Map[#[x_]->E^(#[x])&, logvars]
test9 = eqns /.logrules /.parametervalues
AIMZeroTol=10^-15
AIMSS[test9,AIMPrecision->50]
Print[AIMSeries[test9,4] //TableForm]