Skip to content

Useful example for the readme: comparison w/ closed form for deterministic NCGM #38

@azev77

Description

@azev77
using SolveDSGE, Plots;
cd("my_directory")

# write .txt model in Julia
# deterministic Neoclassical Growth Model 
open("Det_NCGM.txt", "w") do io
    println(io,"# ncgm\n")
    println(io,"states:\nk \nend\n")
    println(io,"jumps:\nc \nend\n")
    println(io,"shocks:\nend\n")
    println(io,"parameters:\nβ=0.99, σ=1.0, δ=1.0, α=.3 \nend\n")
    println(io,"equations:")
    println(io,"k(+1) = (1-δ)*k + k^α - c")
    println(io,"(c(+1))^σ = β*(c^σ)*(1-δ + α*(k(+1)^(α-1.0)) )")
    println(io,"end")
end;

###########################################################################
path = joinpath(@__DIR__,"Det_NCGM.txt")
process_model(path)
dsge = retrieve_processed_model(path)
x = ones(dsge.number_variables)  #Guess ["k", "c"]
tol = 1e-8; maxiters = 1_000; #Int(1e+3);
ss = compute_steady_state(dsge,x,tol,maxiters) # wrong ss

kss=(((1/.99) + 1 -1)/.3)^(1/(.3-1.0))
css = kss^.3 - kss
ss = [kss, css]
ss = [kss, css]

###########################################################################
# Perturbation, Order = 1,2,3
###########################################################################
cutoff = 1.0; # Perturbation HP 
N   = PerturbationScheme(ss,cutoff,"first")
NN  = PerturbationScheme(ss,cutoff,"second")
NNN = PerturbationScheme(ss,cutoff,"third")

soln_fo = solve_model(dsge,N)
soln_so = solve_model(dsge,NN)
soln_to = solve_model(dsge,NNN)

###########################################################################
# Projection, ChebyshevSchemeDet # not working...
###########################################################################

###########################################################################
# Analysis 
###########################################################################
T = 100; # num Sim pds 
sss = ss[1:dsge.number_states]; #ss for states only 

sim_d1 = simulate(soln_fo, sss*.8, T)
sim_d2 = simulate(soln_so, sss*.8, T)
sim_d3 = simulate(soln_to, sss*.8, T)
# Closed Form Sol 
k_cf    = zeros(T+1) 
k_cf[1] = sss[1]*.8
c_cf    = zeros(T)
for t in 1:T
    k_cf[t+1] = (.3*.99) * (k_cf[t]^.3)  #k(+1) = (.3*.99) * (k^.3)
    c_cf[t]   = (1-.3*.99) * (k_cf[t]^.3) #c     = (1-.3*.99) * (k^.3)
end

p1 = plot()
plot!(k_cf[2:T+1] , lab="k_t closed form")
plot!(c_cf        , lab="c_t closed form")
plot!(1:T, sim_d1')
plot!(1:T, sim_d2')
plot!(1:T, sim_d3')

sim_d1 = simulate(soln_fo, sss*1.2, T)
sim_d2 = simulate(soln_so, sss*1.2, T)
sim_d3 = simulate(soln_to, sss*1.2, T)
k_cf    = zeros(T+1)
k_cf[1] = sss[1]*1.2
c_cf    = zeros(T)
for t in 1:T
    k_cf[t+1] = (.3*.99) * (k_cf[t]^.3)
    c_cf[t]   = (1-.3*.99) * (k_cf[t]^.3)
end
p1 = plot()
plot!(k_cf[2:T+1] , lab="k_t closed form")
plot!(c_cf        , lab="c_t closed form")
plot!(1:T, sim_d1')
plot!(1:T, sim_d2')
plot!(1:T, sim_d3')

Start 20% below ss:
image
Start 20% above ss:
image

A few issues:

  1. compute_steady_state() gives the wrong steady state, so I used the closed form here
  2. the projection methods don't seem to work for this problem, not sure why,,,
  3. At some point it would be great if we could automatically plot the policy fcns (then I can compare w/ sol from vfi etc)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions