File: example1_macro.mod

package info (click to toggle)
dynare 4.6.3-4
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 74,896 kB
  • sloc: cpp: 98,057; ansic: 28,929; pascal: 13,844; sh: 5,947; objc: 4,236; yacc: 4,215; makefile: 2,583; lex: 1,534; fortran: 877; python: 647; ruby: 291; lisp: 152; xml: 22
file content (234 lines) | stat: -rw-r--r-- 4,644 bytes parent folder | download | duplicates (2)
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
// Various tests for the macroprocessor

var y, c, k, a, h, b;
varexo e, u;

@#ifndef NOTDEFINED
parameters beta, rho, alpha, delta, theta, psi, tau;
@#else
@#error "IFNDEF PROBLEM"
@#endif

@#ifdef NOTDEFINED
@#error "IFDEF PROBLEM"
@#else
alpha = 0.36;
rho   = 0.95;
tau   = 0.025;
beta  = 0.99;
delta = 0.025;
psi   = 0;
theta = 2.95;
phi   = 0.1;
@#endif

@#define a = 5
@#define b = 2*(a + 3)/4-1
@#if b != 3
@#error "Arithmetic problem"
@#endif

@#define v = [ "a", 1, 2:3]
@#define empty = []
@#define z = v[2:3]
@#if z != [ 1, [ 2, 3 ]] || length(v) != 3 || 5 in v || !("a" in v) || length(empty) != 0
@#error "Array problem"
@#endif

@#define w = [ 1 ]
@#for elt in v
@#define w = w + [ elt ]
@#endfor
@#if w != [ 1, "a", 1, 2:3]
@#error "For loop problem 1"
@#endif

@#define w = [ ]
@#for (i,j) in [(1,2),(1,3),(1,4)]
@#define w = w + [i, j]
@#endfor
@#if w != [ 1, 2, 1, 3, 1, 4]
@#error "For loop problem 2"
@#endif

@#define s = "abcde"
@#if length(s) != 5 || s[3:4] != "cd"
@#error "String problem"
@#endif

@#define f(y, z) = y + "bar" + z
@#if f("foo", "baz") != "foobarbaz"
@#error "Function problem"
@#endif


@#define x = 1:3

@#define y = [ i in x when i > 1 ]
@#if y != [ 2, 3 ]
@# error "One-dimensional comprehension problem"
@#endif

@#define z = [ (i,j) in x^2 when i != j ]
@#if z != [ (1,2), (1,3), (2,1), (2,3), (3,1), (3,2) ]
@# error "Two-dimensional comprehension problem"
@#endif

@#define t = 2:4
@#define tt = [ (i,j) in t^2 when (i,j) in [ (k,l) in x^2 when k != l ] ]
@#if tt != [ (2,3), (3,2) ]
@# error "Nested comprehension problem"
@#endif



model;
c*theta*h^(1+psi)=(1-alpha)*y;
k = beta*(((exp(b)*c)/(exp(b(+1))*c(+1)))
    *(exp(b(+1))*alpha*y(+1)+(1-delta)*k));
y = exp(a)*(k(-1)^alpha)*(h^(1-alpha));
k = exp(b)*(y-c)+(1-delta)*k(-1);
a = rho*a(-1)+tau*b(-1) + e;
b = tau*a(-1)+rho*b(-1) + u;
end;

initval;
y = 1.08068253095672;
c = 0.80359242014163;
h = 0.29175631001732;
k = 11.08360443260358;
a = 0;
b = 0;
e = 0;
u = 0;
end;

@#define DEFINEDvar=0

@#ifndef DEFINEDvar
@#error "IFNDEF PROBLEM"
@#else
shocks;
var e; stderr 0.009;
var u; stderr 0.009;
var e, u = phi*0.009*0.009;
end;
@#endif

@#ifdef DEFINEDvar
stoch_simul;
@#elseif true
@#error "ELSEIF PROBLEM"
@#else
@#error "IFDEF PROBLEM"
@#endif

@#if false
@#error "IF ERROR"
@#elseif false
@#error "ELSEIF ERROR"
@#elseif defined(DEFINEDvar)
@#echo "Good"
@#else
@#error "ELSE ERROR"
@#endif

@#define a = 1
@#define f(x) = x + a
@#define a = 2
@#define g(a) = f(1) + a
@#define a = 3
@#define h(a) = g(2) + a

@#if f(1) != 4
@#error "Problem with functions 1"
@#endif

@#if g(2) != 6
@#error "Problem with functions 2"
@#endif

@#if h(1) != 7
@#error "Problem with functions 3"
@#endif

@#if h(g(f(1))+1) != 15
@#error "Problem with functions 4"
@#endif

@#define zerotol = 1e-15
@#if exp(ln(5)) <= 5-zerotol && exp(ln(5)) >= 5+zerotol
@#error "Problem with math functions"
@#endif

@#if log(0) != -inf || 1/0 != inf
@#error "Problem with inf"
@#endif

@#if 5 < nan
@#error "Problem with NaN comparison"
@#endif

@#if 5 >= inf
@#error "Problem with inf comparison"
@#endif

@#if "Aaaaaaaa" > "B" || "AA" != "AA"
@#error "String comparison"
@#endif

@#define A = "La crise economique"
@#if A[1,8,3,7,4,10,13,2,5,16,12,9,11,14,15,6,17:19] != "Le scenario comique"
@#error "Problem with string indexing/comparison"
@#endif

@#define f(x) = x + "C"
@#if "A" + f("B") != "ABC"
@#error "Problem with String concatenation"
@#endif

@#define z = [[i,"A",i:j,j] for (i,j) in (1:3)^2 when i < j]
@#if z != [[1, "A", [1, 2], 2], [1, "A", [1, 2, 3], 3], [2, "A", [2, 3], 3]]
@#error "Problem with array comprehension"
@#endif

@#if [(i,j) in (1:2)^2 when i<j] != [(1, 2)]
@#error "Problem with set comprehension"
@#endif

@#define f(x) = [(j,i+1) for (i,j) in x^2]
@#if f(1:2) != [(1, 2), (2, 2), (1, 3), (2, 3)]
@#error "Problem with functional comprehension"
@#endif

@#if [(j,i+1) for (i,j) in (1:2)*(1:2) when i < j] != [(2, 2)]
@#error "Problem with functional comprehension"
@#endif

@#if exp(log(5)) > 5-1e-14 && exp(log(5)) < 5+1e-14

@#else
@#error "Numeric comparison incorrect"
@#endif

@#if ([1] + (array)(real) "2") != [1, 2]
@#error "Cast error"
@#endif

@#if -3:-1.5:3 != [] || 3:-1:-0.1 != [3, 2, 1, 0] \\
     || 1:1 != [1] || 1:0:1 != [] \\
     || -1:5:-1 != [-1] || -1:-5:-1 != [-1] \\ // Inline comment
     || 0:0:0 != [] || 0:0 != [0]
@#error "Range error"
@#endif

@#if (bool)"FaLse" || !(bool)"TRUE" || (bool)"0" || !(bool)"-3"
@#error "Error in cast of string to bool"
@#endif

@#if !(true || "A") || (0 && "A")
    @#error "problem with short circuit || or && operator"
@#endif

@#echomacrovars(save)
@#echomacrovars