Debian Codegraph @

tests/decision_rules/k_order/burnside_k_order.mod

raw
1 /*
2 Check the policy functions obtained by perturbation at a high approximation
3 order, using the Burnside (1998, JEDC) model (for which the analytical form of
4 the policy function is known).
5
6 As shown by Burnside, the policy function for yₜ is:
7
8 yₜ = βⁱ exp[aᵢ+bᵢ(xₜ−xₛₛ)]
9
10
11 where:
12 θ² ⎛ 2ρ 1−ρ²ⁱ⎞
13 — aᵢ = iθxₛₛ + σ² ─────── ⎢i − ────(1−ρⁱ) + ρ² ─────⎥
14 2(1−ρ)² ⎝ 1−ρ 1−ρ² ⎠
15
16 θρ
17 — bᵢ = ───(1−ρⁱ)
18 1−ρ
19
20 — xₛₛ is the steady state of x
21 — σ is the standard deviation of e.
22
23 With some algebra, it can be shown that the derivative of yₜ at the deterministic
24 steady state is equal to:
25
26 ∂ᵐ⁺ⁿ⁺²ᵖ yₜ ∞ (2p)!
27 ──────────────── = ∑ βⁱ bᵢᵐ⁺ⁿ ρᵐ ───── cᵢᵖ exp(iθxₛₛ)
28 ∂ᵐxₜ₋₁ ∂ⁿeₜ ∂²ᵖs ⁱ⁼¹ p!
29
30 where:
31 — s is the stochastic scale factor
32
33 θ² ⎛ 2ρ 1−ρ²ⁱ⎞
34 — cᵢ = ─────── ⎢i − ────(1−ρⁱ) + ρ² ─────⎥
35 2(1−ρ)² ⎝ 1−ρ 1−ρ² ⎠
36
37 Note that derivatives with respect to an odd order for s (i.e. ∂²ᵖ⁺¹s) are always
38 equal to zero.
39
40 The policy function as returned in the oo_.dr.g_* matrices has the following properties:
41 — its elements are pre-multiplied by the Taylor coefficients;
42 — derivatives w.r.t. the stochastic scale factor have already been summed up;
43 — symmetric elements are folded (and they are not pre-multiplied by the number of repetitions).
44
45 As a consequence, the element gₘₙ corresponding to the m-th derivative w.r.t.
46 to xₜ₋₁ and the n-th derivative w.r.t. to eₜ is given by:
47
48 1 ∞ cᵢᵖ
49 gₘₙ = ────── ∑ ∑ βⁱ bᵢᵐ⁺ⁿ ρᵐ ──── exp(iθxₛₛ)
50 (m+n)! 0≤2p≤k-m-n ⁱ⁼¹ p!
51
52 where k is the order of approximation.
53
54 */
55
56 @#define k =7
57
58 var y x;
59 varexo e;
60
61 parameters beta theta rho xbar;
62 xbar = 0.0179;
63 rho = -0.139;
64 theta = -1.5;
65 theta = -10;
66 beta = 0.95;
67
68 model;
69 y = beta*exp(theta*x(+1))*(1+y(+1));
70 x = (1-rho)*xbar + rho*x(-1)+e;
71 end;
72
73 shocks;
74 var e; stderr 0.0348;
75 end;
76
77 initval;
78 x = xbar;
79 y = beta*exp(theta*xbar)/(1-beta*exp(theta*xbar));
80 end;
81
82 steady;
83
84 stoch_simul(order=@{k},k_order_solver,irf=0,drop=0,periods=100);
85
86 % Verify that the policy function coefficients are correct
87 sigma2=M_.Sigma_e;
88 i = 1:800;
89 c = theta^2*sigma2/(2*(1-rho)^2)*(i-2*rho*(1-rho.^i)/(1-rho)+rho^2*(1-rho.^(2*i))/(1-rho^2));
90 b = theta*rho*(1-rho.^i)/(1-rho);
91
92 for ord = 0:@{k}
93 g = oo_.dr.(['g_' num2str(ord)])(2,:); % Retrieve computed policy function for variable y
94
95 for m = 0:ord % m is the derivation order with respect to x(-1)
96 v = 0;
97 for p = 0:floor((@{k}-ord)/2) % 2p is the derivation order with respect to s
98 if ord+2*p > 0 % Skip the deterministic steady state constant
99 v = v + sum(beta.^i.*exp(theta*xbar*i).*b.^ord.*rho^m.*c.^p)/factorial(ord)/factorial(p);
100 end
101 end
102 if abs(v-g(ord+1-m)) > 1e-14
103 error(['Error in matrix oo_.dr.g_' num2str(ord)])
104 end
105 end
106 end
107
108 % Verify that the simulated time series is correct
109 xss = oo_.steady_state(2);
110 xlag = xss;
111
112 for T = 1:size(oo_.endo_simul,2)
113 e_ = oo_.exo_simul(T);
114 y_ = oo_.steady_state(1);
115 for ord = 0:@{k}
116 g = oo_.dr.(['g_' num2str(ord)])(2,:); % Retrieve computed policy function for variable y
117 for m = 0:ord
118 y_ = y_ + g(ord+1-m)*(xlag-xss)^m*e_^(ord-m)*nchoosek(ord,m);
119 end
120 end
121 if abs(y_-oo_.endo_simul(1,T)) > 1e-14
122 error(['Error in k_order_simul DLL'])
123 end
124 xlag = oo_.endo_simul(2,T);
125 end