It would be awesome to see if the discrete-time version of this problem can be solved with @Norman package SequenceJacobians.jl.
It’s a wip but I was able to figure out how to solve the simple RBC model w/ his pkg in the examples:
using SequenceJacobians, NLsolve;
# Define RBC Model ################################################################
@simple function firm(K, L, Z, α, δ)
r = α * Z * (lag(K) / L)^(α-1) - δ
w = (1-α) * Z * (lag(K) / L)^α
Y = Z * lag(K)^α * L^(1-α)
return r, w, Y
end
@simple function household(K, L, w, eis, frisch, φ, δ)
C = (w / (φ * L^(1/frisch)))^eis
I = K - (1 - δ) * lag(K)
return C, I
end
@simple function mkt_clearing(r, C, Y, I, K, L, w, eis, β)
goods_mkt = Y - C - I
euler = C^(-1/eis) - β*(1+lead(r))*lead(C)^(-1/eis)
walras = C + K - (1+r)*lag(K) - w*L
return goods_mkt, euler, walras
end
rbcblocks() = (firm_blk(), household_blk(), mkt_clearing_blk())
################################################################
m = model(rbcblocks()) # vsrcs(m) == [:K, :L, :Z, :α, :δ, :eis, :frisch, :φ, :β]
calis = [:L=>1, :eis=>1, :frisch=>1, :δ=>0.025, :α=>0.11]
tars = [:goods_mkt=>0, :r=>0.01, :euler=>0, :Y=>1]
inits = [:φ=>0.9, :β=>0.99, :K=>2, :Z=>1]
# [:K init 2, :L=1, :Z init 1.0, :α=0.11, :δ=0.025, :eis=1, :frisch=1, :φ init 0.9, :β init 0.99]
ss = SteadyState(m, calis, inits, tars)
f!(y, x) = residuals!(y, ss, x)
r = solve!(NLsolve_Solver, f!, ss.inits) # r[1] # getval(ss, :K)
J = TotalJacobian(model(ss), [:Z,:K,:L], [:euler, :goods_mkt], getvarvals(ss), 300)
GJ = GEJacobian(J, :Z)
dZ = zeros(300)
dZ[11:end] .= getvarvals(ss)[:Z] .* 0.01 .* 0.8.^(0:289)
irfs = linirf(GJ, :Z=>dZ)
dCdZ = irfs[:Z][:C]
dwdZ = irfs[:Z][:w]
dYdZ = irfs[:Z][:Y]
ε = randn(10_000)
# simulate(GJ,exovar, endovar, ε, ρ, σ=1.0; kwargs...)
s = simulate(GJ, :Z, :K, ε, 0.9)
s = simulate(GJ, :Z, :K, ε, 0.9, 1.00)
#
s = simulate(GJ, :Z, :K, ε, 0.9, 0.02)
s = simulate(GJ, :Z, :K, ε, 0.9, 0.00)
s = simulate(GJ, :Z, :K, ε, 0.9, 0.10)
#
s = simulate(GJ, :Z, :K, ε, 0.2, 0.02)
s = simulate(GJ, :Z, :K, ε, 0.2, 0.00)
s = simulate(GJ, :Z, :K, ε, 0.2, 0.10)