RJDennis / SolveDSGE.jl

A Julia package to solve, simulate, and analyze nonlinear DSGE models.
MIT License
82 stars 25 forks source link

Error when assigning parameters #34

Closed mcreel closed 3 years ago

mcreel commented 3 years ago

I am trying to assign parameters to a model, along the lines of model2a.txt in the test directory. The model works fine when parameters are given in the .txt file, but errors when they are assigned. The model and solution file are below, the assignment or not is determined by un-commenting the relevant block in the .txt file, and by commenting/uncommenting the assign_parameters line in the .jl file.

The beginning part of the error message, when assigning. is

The model's variables are now in this order: ["z", "η", "k", "y", "c", "n", "r", "w", "MUC", "MUL"] The following parameters do not have values assigned: ["α", "β", "δ", "γ", "ρ₁", "σ₁", "ρ₂", "σ₂", "ψ"] ERROR: LoadError: UndefVarError: pax not defined Stacktrace: [1] nlsolve_static_equations(f::Vector{ForwardDiff.Dual{ForwardDiff.Tag{SolveDSGE.va is a missing pax.

I am using SolveDSGE v0.4.6. By the way, the package is very nice and fast, and seems to agree with what I used to get using Dynare and Octave. Any help much appreciated. Thanks, M.

Here are the two files: .txt file: `# CK 2 shock model from "Indirect Likelihood Inference"

states: k, z, η end

jumps: y, c, n, r, w, MUC, MUL end

shocks: ϵ u end

parameters: α = 0.33 β = 0.99 δ = 0.025 γ = 2.0 ρ₁ = 0.9 σ₁ = 0.02 ρ₂ = 0.7 σ₂ = 0.01 ψ = 3.4174389608451694 end

parameters:

α

β

δ

γ

ρ₁

σ₁

ρ₂

σ₂

ψ

end

equations: MUC = c^(-γ) MUL = ψexp(η) r = α exp(z) k^(α-1) n^(1-α) w = (1-α)exp(z) k^α n^(-α) MUC = βMUC(+1) (1 + r(+1) - δ) MUL/MUC = w z(+1) = ρ₁z + σ₁u η(+1) = ρ₂η + σ₂ϵ y = exp(z) (k^α) (n^(1-α)) k(+1) = y - c + (1-δ)k end `

.jl solution file: `using SolveDSGE

filename = "CK.txt" path = joinpath(@DIR,filename) process_model(path) processed_filename = "CK_processed.txt" processed_path = joinpath(@DIR,processed_filename)

dsge = retrieve_processed_model(processed_path)

function ParamsAndSS() α = 0.33 β = 0.99 δ = 0.025 γ = 2.0 ρ₁ = 0.9 σ₁ = 0.02 ρ₂ = 0.7 σ₂ = 0.01 nss = 1.0/3.0 c1 = ((1/β + δ - 1)/α)^(1/(1-α)) kss = nss/c1 iss = δkss; yss = kss^α nss^(1-α) css = yss - iss; MUCss = css^(-γ) rss = α kss^(α-1) nss^(1-α) wss = (1-α) (kss)^α nss^(-α) MULss = wssMUCss ψ = (css^(-γ)) (1-α) (kss^α) (nss^(-α)) p = [α, β, δ, γ, ρ₁, σ₁, ρ₂, σ₂, ψ] ss = [0.0, 0.0, kss, yss, css, nss, rss, wss, MUCss, MULss] return p, ss end

Use this to verify steady stats

tol = 1e-8 maxiters = 1000 p, ss = ParamsAndSS()

dsge = assign_parameters(dsge, p)

ss = compute_steady_state(dsge, ss, tol, maxiters) scheme = PerturbationScheme(ss, 1.0, "third") solution = solve_model(dsge, scheme) `

mcreel commented 3 years ago

I see that a comment in the .jl file was formatted as a section. I can provide links to the two files, if that would help.

Edit: here's the location of the two files: https://github.com/mcreel/Sandbox/tree/master/SolveDSGE

RJDennis commented 3 years ago

It's a parser error. I'll fix that as soon as I get time. In the meantime it works for me when you change the variable name 'r' to something like 'real'. Also, because of the various substitutions I'm doing within the equations, keeping the multiplication operator between parameters and variables in the shock processes is a good idea.

mcreel commented 3 years ago

Thanks. Actually, I saw that the problem was in the processed model file, and that made me think that I should simplify parameter names. I will try that, and will close this when I get it to work.

mcreel commented 3 years ago

Thanks, it's working perfectly now.