/
EndFeedback.jl
63 lines (58 loc) · 2.52 KB
/
EndFeedback.jl
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
using DRIPs
using Test
using LinearAlgebra
@testset "Endogenous Feedback" begin
ρ = 0.6; #persistence of money growth
σ_u = 0.1; #std. deviation of shocks to money growth
α = 0.8; #degree of strategic complementarity
L = 40; #length of truncation
Hq = ρ.^(0:L-1); #state-space rep. of Δq
## specifying the primitives of the drip
ω = 0.2;
β = 0.99;
A = [1 zeros(1,L-2) 0; Matrix(I,L-1,L-1) zeros(L-1,1)];
Q = [σ_u; zeros(L-1,1)];
## Function to iterate over ge
function ge_drip(ω,β,A,Q, #primitives of drip except for H because H is endogenous
α, #strategic complementarity
Hq, #state space rep. of Δq
L; #length of truncation
H0 = Hq, #optional: initial guess for H (Hq is the true solution when α=0)
maxit = 200, #optional: max number of iterations for GE code
tol = 1e-4) #optional: tolerance for iterations
# set primitives
err = 1;
iter = 0;
M = [zeros(1,L-1) 0; Matrix(I,L-1,L-1) zeros(L-1,1)];
# iterate on GE
while (err > tol) & (iter < maxit)
if iter == 0
global ge = Drip(ω,β,A,Q,H0, w = 0.9);
else
global ge = Drip(ω,β,A,Q,H0;Ω0 = ge.ss.Ω ,Σ0 = ge.ss.Σ_1);
end
XFUN(jj) = ((I-ge.ss.K*ge.ss.Y')*ge.A)^jj * (ge.ss.K*ge.ss.Y') * (M')^jj
X = DRIPs.infinitesum(XFUN; maxit=L, start = 0); #E[x⃗]=X×x⃗
XpFUN(jj) = α^jj * X^(jj)
Xp = DRIPs.infinitesum(XpFUN; maxit=L, start = 0);
H1 = (1-α)*Xp'*Hq;
err= 0.5*norm(H1-H0,2)/norm(H0)+0.5*err;
H0 = H1;
iter += 1;
end
return(ge,err)
end;
println("Solving RI with Endogenous Feedback ...")
ge,err = ge_drip(ω,β,A,Q,α,Hq,L) # remove suppress to see convergence log
@test ge.ss.err < 1e-4
@test err < 1e-4
ge,err = ge_drip(0.001,β,A,Q,α,Hq,L) # remove suppress to see convergence log
@test ge.ss.err < 1e-4
@test err < 1e-4
ge,err = ge_drip(0.1,β,A,Q,α,Hq,L) # remove suppress to see convergence log
@test ge.ss.err < 1e-4
@test err < 1e-4
ge,err = ge_drip(1,β,A,Q,α,Hq,L) # remove suppress to see convergence log
@test ge.ss.err < 1e-4
@test err < 1e-4
end