Fixes for julia 0.6.x.
Updated the preprocessor module (adds new static and dynamic routines which only return the jacobian).time-shift
parent
909956f0bc
commit
d96aca093e
|
@ -1,6 +1,6 @@
|
|||
module DynareModel
|
||||
##
|
||||
# Copyright (C) 2015 Dynare Team
|
||||
# Copyright (C) 2015-2018 Dynare Team
|
||||
#
|
||||
# This file is part of Dynare.
|
||||
#
|
||||
|
@ -20,7 +20,7 @@ module DynareModel
|
|||
|
||||
export Model, Endo, Exo, ExoDet, Param, dynare_model
|
||||
|
||||
abstract Atom
|
||||
abstract type Atom end
|
||||
|
||||
immutable Endo <: Atom
|
||||
name::String
|
||||
|
@ -88,6 +88,7 @@ type Model
|
|||
aux_vars::Vector{AuxVars}
|
||||
pred_vars::Vector{Int}
|
||||
obs_vars::Vector{Int}
|
||||
state_var::Vector{Int}
|
||||
orig_endo_nbr::Int
|
||||
orig_eq_nbr::Int
|
||||
eq_nbr::Int
|
||||
|
@ -106,6 +107,14 @@ type Model
|
|||
maximum_endo_lead::Int
|
||||
maximum_exo_lag::Int
|
||||
maximum_exo_lead::Int
|
||||
orig_maximum_lag::Int
|
||||
orig_maximum_lead::Int
|
||||
orig_maximum_endo_lag::Int
|
||||
orig_maximum_endo_lead::Int
|
||||
orig_maximum_exo_lag::Int
|
||||
orig_maximum_exo_lead::Int
|
||||
orig_maximum_exo_det_lag::Int
|
||||
orig_maximum_exo_det_lead::Int
|
||||
lead_lag_incidence::Matrix{Int}
|
||||
nnzderivatives::Vector{Int}
|
||||
analytical_steady_state::Bool
|
||||
|
@ -130,18 +139,19 @@ function dynare_model()
|
|||
return Model("", # fname
|
||||
"", # dname
|
||||
"", # dynare_version
|
||||
Array(Endo,0), # endo
|
||||
Array(Exo,0), # exo
|
||||
Array(ExoDet,0), # exo_det
|
||||
Array(Param,0), # param
|
||||
Array(AuxVars,0), # aux_vars
|
||||
Array(Int,0), # pred_vars
|
||||
Array(Int,0), # obs_vars
|
||||
Vector{Endo}(), # endo
|
||||
Vector{Exo}(), # exo
|
||||
Vector{ExoDet}(), # exo_det
|
||||
Vector{Param}(), # param
|
||||
Vector{AuxVars}(), # aux_vars
|
||||
Vector{Int}(), # pred_vars
|
||||
Vector{Int}(), # obs_vars
|
||||
Vector{Int}(), # state_var
|
||||
0, # orig_endo_nbr
|
||||
0, # orig_eq_nbr
|
||||
0, # eq_nbr
|
||||
0, # ramsey_eq_nbr
|
||||
Array(DetShocks,0), # det_shocks
|
||||
Vector{DetShocks}(), # det_shocks
|
||||
0, # nstatic
|
||||
0, # nfwrd
|
||||
0, # npred
|
||||
|
@ -155,19 +165,27 @@ function dynare_model()
|
|||
0, # maximum_endo_lead
|
||||
0, # maximum_exo_lag
|
||||
0, # maximum_exo_lead
|
||||
Array(Int, 3, 0), # lead_lag_incidence
|
||||
zeros(Int, 3), # nnzderivatives
|
||||
0, # orig_maximum_lag
|
||||
0, # orig_maximum_lead
|
||||
0, # orig_maximum_endo_lag
|
||||
0, # orig_maximum_endo_lead
|
||||
0, # orig_maximum_exo_lag
|
||||
0, # orig_maximum_exo_lead
|
||||
0, # orig_maximum_exo_det_lag
|
||||
0, # orig_maximum_exo_det_lead
|
||||
Matrix{Int}(0,0), # lead_lag_incidence
|
||||
zeros(Int64,3), # nnzderivatives
|
||||
false, # analytical_steady_state
|
||||
false, # user_written_analytical_steady_state
|
||||
false, # static_and_dynamic_models_differ
|
||||
Array(String,0), # equation_tags
|
||||
Array(Int64,1), # exo_names_orig_ord
|
||||
Array(Float64, 0, 0), # sigma_e (Cov matrix of the structural innovations)
|
||||
Array(Float64, 0, 0), # correlation_matrix (Corr matrix of the structural innovations)
|
||||
Array(Float64, 0, 0), # h (Cov matrix of the measurement errors)
|
||||
Array(Float64, 0, 0), # correlation_matrix_me (Cov matrix of the measurement errors)
|
||||
Vector{String}(), # equation_tags
|
||||
Vector{Int}(), # exo_names_orig_ord
|
||||
Matrix{Float64}(0,0), # sigma_e (Cov matrix of the structural innovations)
|
||||
Matrix{Float64}(0,0), # correlation_matrix (Corr matrix of the structural innovations)
|
||||
Matrix{Float64}(0,0), # h (Cov matrix of the measurement errors)
|
||||
Matrix{Float64}(0,0), # correlation_matrix_me (Cov matrix of the measurement errors)
|
||||
true, # sigma_e_is_diagonal
|
||||
Array(Float64, 0), # params
|
||||
Vector{Float64}(), # params
|
||||
function()end, # static
|
||||
function()end, # static_params_derivs
|
||||
function()end, # dynamic
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
module DynareOutput
|
||||
##
|
||||
# Copyright (C) 2015 Dynare Team
|
||||
# Copyright (C) 2015-2018 Dynare Team
|
||||
#
|
||||
# This file is part of Dynare.
|
||||
#
|
||||
|
@ -28,8 +28,8 @@ end
|
|||
|
||||
function dynare_output()
|
||||
return Output("", # dynare_version
|
||||
Array(Float64, 0), # steady_state
|
||||
Array(Float64, 0) # exo_steady_state
|
||||
Vector{Float64}(), # steady_state
|
||||
Vector{Float64}() # exo_steady_state
|
||||
)
|
||||
end
|
||||
|
||||
|
|
|
@ -112,7 +112,7 @@ function simulate_perfect_foresight_model!(endogenousvariables::Matrix{Float64},
|
|||
i_cols_A += ny
|
||||
end
|
||||
end
|
||||
err = maximum(abs(rd))
|
||||
err = maximum(abs.(rd))
|
||||
println("Iter. ", iteration, "\t err. ", round(err, 12))
|
||||
if err<options.pfmsolver.tolf
|
||||
iteration -= 1
|
||||
|
@ -121,7 +121,7 @@ function simulate_perfect_foresight_model!(endogenousvariables::Matrix{Float64},
|
|||
A = sparse(iA[1:m], jA[1:m], vA[1:m])
|
||||
dy = -A\rd
|
||||
Y[i_upd] += dy
|
||||
if maximum(abs(dy))<options.pfmsolver.tolx
|
||||
if maximum(abs.(dy))<options.pfmsolver.tolx
|
||||
convergence = true
|
||||
end
|
||||
end
|
||||
|
|
|
@ -47,22 +47,26 @@ function steady!(model::Model, oo::Output)
|
|||
end
|
||||
|
||||
function steady(model::Model, oo::Output, yinit::Vector{Float64})
|
||||
ojectivefunction!(y::Vector{Float64}, fval::Vector{Float64}, fjac::Array{Float64}) = model.static(y, oo.exo_steady_state, model.params, fval, fjac)
|
||||
r = nlsolve(only_fg!(ojectivefunction!), yinit, show_trace=false)
|
||||
f!(fval::Vector{Float64}, y::Vector{Float64}) = model.static(y, oo.exo_steady_state, model.params, fval)
|
||||
j!(fjac::Matrix{Float64}, y::Vector{Float64}) = model.static(y, oo.exo_steady_state, model.params, fjac)
|
||||
fj!(fval::Vector{Float64}, fjac::Matrix{Float64}, y::Vector{Float64}) = model.static(y, oo.exo_steady_state, model.params, fval, fjac)
|
||||
r = nlsolve(f!, j!, fj!, yinit, show_trace=false)
|
||||
if converged(r)
|
||||
return r.zero
|
||||
else
|
||||
return fill(nan(Float64), length(yinit))
|
||||
return fill(NaN, length(yinit))
|
||||
end
|
||||
end
|
||||
|
||||
function steady!(model::Model, oo::Output, yinit::Vector{Float64})
|
||||
ojectivefunction!(y::Vector{Float64}, fval::Vector{Float64}, fjac::Array{Float64}) = model.static(y, oo.exo_steady_state, model.params, fval, fjac)
|
||||
r = nlsolve(only_fg!(ojectivefunction!), yinit, show_trace=false)
|
||||
f!(fval::Vector{Float64}, y::Vector{Float64}) = model.static(y, oo.exo_steady_state, model.params, fval)
|
||||
j!(fjac::Matrix{Float64}, y::Vector{Float64}) = model.static(y, oo.exo_steady_state, model.params, fjac)
|
||||
fj!(fval::Vector{Float64}, fjac::Matrix{Float64}, y::Vector{Float64}) = model.static(y, oo.exo_steady_state, model.params, fval, fjac)
|
||||
r = nlsolve(f!, j!, fj!, yinit, show_trace=false)
|
||||
if converged(r)
|
||||
oo.steady_state = r.zero
|
||||
else
|
||||
oo.steady_state = fill(nan(Float64), length(yinit))
|
||||
oo.steady_state = fill(NaN, length(yinit))
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 7a4312c48bf6a1e05ecd7d3c04075ed3017b37e4
|
||||
Subproject commit 84c6bf5daf051779e4620ad9f7a2c2aa52b623f5
|
|
@ -3,90 +3,78 @@ if isempty(findin([abspath("../../../julia")], LOAD_PATH))
|
|||
unshift!(LOAD_PATH, abspath("../../../julia"))
|
||||
end
|
||||
|
||||
# Load Dynare package
|
||||
importall Dynare
|
||||
using Dynare
|
||||
using SteadyState
|
||||
|
||||
|
||||
# Compile the rbc.mod file -> produce a module with the model definition.
|
||||
|
||||
@dynare "rbc1.mod"
|
||||
|
||||
importall SteadyState
|
||||
|
||||
# First call to the steady state routine (analytical)
|
||||
@time SteadyState.steady!(model_, oo_)
|
||||
|
||||
# First call to the steady state routine (analytical)
|
||||
@time SteadyState.steady!(model_, oo_)
|
||||
|
||||
paramsinit = copy(model_.params);
|
||||
steadyState = deepcopy(oo_.steady_state)
|
||||
|
||||
yinit = deepcopy(oo_.steady_state)
|
||||
|
||||
y_init = copy(yinit)
|
||||
y_init[1] = 1.1*yinit[1]
|
||||
y_init[2] = 0.9*yinit[2]
|
||||
y_init = copy(steadyState)
|
||||
y_init[1] = 1.1*steadyState[1]
|
||||
y_init[2] = 0.9*steadyState[2]
|
||||
|
||||
# First call to the steady state routine (numerical)
|
||||
println("First call to the numerical steady state routine")
|
||||
@time SteadyState.steady!(model_, oo_, yinit)
|
||||
@time SteadyState.steady!(model_, oo_, y_init)
|
||||
|
||||
# Check results
|
||||
@assert maximum(abs(oo_.steady_state-yinit))<1e-9
|
||||
@assert maximum(abs.(oo_.steady_state-steadyState))<1e-6
|
||||
|
||||
y_init = copy(yinit)
|
||||
yinit[1] = 1.1*yinit[1]
|
||||
yinit[2] = 0.9*yinit[2]
|
||||
yinit = deepcopy(steadyState)
|
||||
yinit[1] = 1.1*steadyState[1]
|
||||
yinit[2] = 0.9*steadyState[2]
|
||||
|
||||
# Second call to the steady state routine (numerical)
|
||||
println("Second call to the numerical steady state routine")
|
||||
@time SteadyState.steady!(model_, oo_, yinit)
|
||||
|
||||
params = model_.params
|
||||
|
||||
# change alpha
|
||||
println("Change α")
|
||||
model_.params[4] = max(min(1.0, model_.params[4]*1.2), 0.0)
|
||||
ys = SteadyState.steady(model_, oo_)
|
||||
y_init = copy(yinit)
|
||||
@time SteadyState.steady!(model_, oo_, y_init)
|
||||
y_init = copy(yinit)
|
||||
@time SteadyState.steady!(model_, oo_, y_init)
|
||||
@assert maximum(abs(oo_.steady_state-ys))<1e-9
|
||||
model_.params = deepcopy(params)
|
||||
model_.params[4] = max(min(1.0, params[4]*1.1), 0.0)
|
||||
@time ys = SteadyState.steady(model_, oo_) # Analytical steady state
|
||||
@time SteadyState.steady!(model_, oo_, steadyState)
|
||||
@assert maximum(abs.(oo_.steady_state-ys))<1e-6
|
||||
|
||||
# change delta
|
||||
println("Change δ")
|
||||
model_.params[6] = max(min(1.0, model_.params[6]*1.2), 0.0)
|
||||
ys = SteadyState.steady(model_, oo_)
|
||||
y_init = copy(yinit)
|
||||
@time SteadyState.steady!(model_, oo_, y_init)
|
||||
y_init = copy(yinit)
|
||||
@time SteadyState.steady!(model_, oo_, y_init)
|
||||
@assert maximum(abs(oo_.steady_state-ys))<1e-9
|
||||
model_.params = deepcopy(params)
|
||||
model_.params[6] = max(min(1.0, params[6]*1.1), 0.0)
|
||||
@time ys = SteadyState.steady(model_, oo_) # Analytical steady state
|
||||
@time SteadyState.steady!(model_, oo_, steadyState)
|
||||
@assert maximum(abs.(oo_.steady_state-ys))<1e-6
|
||||
|
||||
# change beta
|
||||
println("Change β")
|
||||
model_.params[1] = max(min(1-1e-6, model_.params[1]*0.99), 0.0)
|
||||
ys = SteadyState.steady(model_, oo_)
|
||||
y_init = copy(yinit)
|
||||
@time SteadyState.steady!(model_, oo_, y_init)
|
||||
y_init = copy(yinit)
|
||||
@time SteadyState.steady!(model_, oo_, y_init)
|
||||
@assert maximum(abs(oo_.steady_state-ys))<1e-9
|
||||
model_.params = deepcopy(params)
|
||||
model_.params[1] = max(min(1-1e-6, params[1]*0.99), 0.0)
|
||||
@time ys = SteadyState.steady(model_, oo_) # Analytical steady state
|
||||
@time SteadyState.steady!(model_, oo_, steadyState)
|
||||
@assert maximum(abs.(oo_.steady_state-ys))<1e-6
|
||||
|
||||
# change tau
|
||||
println("Change τ")
|
||||
model_.params[3] /= 1.5
|
||||
ys = SteadyState.steady(model_, oo_)
|
||||
y_init = copy(yinit)
|
||||
@time SteadyState.steady!(model_, oo_, y_init)
|
||||
y_init = copy(yinit)
|
||||
@time SteadyState.steady!(model_, oo_, y_init)
|
||||
@assert maximum(abs(oo_.steady_state-ys))<1e-9
|
||||
model_.params = deepcopy(params)
|
||||
model_.params[3] = params[3]/1.1
|
||||
@time ys = SteadyState.steady(model_, oo_)
|
||||
@time SteadyState.steady!(model_, oo_, steadyState)
|
||||
@assert maximum(abs.(oo_.steady_state-ys))<1e-6
|
||||
|
||||
# change Epsilon
|
||||
println("Change ϵ")
|
||||
model_.params[5] *= 1.5
|
||||
ys = SteadyState.steady(model_, oo_)
|
||||
y_init = copy(yinit)
|
||||
@time SteadyState.steady!(model_, oo_, y_init)
|
||||
y_init = copy(yinit)
|
||||
@time SteadyState.steady!(model_, oo_, y_init)
|
||||
@assert maximum(abs(oo_.steady_state-ys))<1e-9
|
||||
model_.params = deepcopy(params)
|
||||
model_.params[5] = params[5]*1.1
|
||||
@time ys = SteadyState.steady(model_, oo_)
|
||||
@time SteadyState.steady!(model_, oo_, steadyState)
|
||||
@assert maximum(abs.(oo_.steady_state-ys))<1e-6
|
||||
|
|
|
@ -3,18 +3,20 @@ if isempty(findin([abspath("../../../julia")], LOAD_PATH))
|
|||
unshift!(LOAD_PATH, abspath("../../../julia"))
|
||||
end
|
||||
|
||||
# Load Dynare package
|
||||
importall Dynare
|
||||
using PyPlot
|
||||
# Load packages
|
||||
using Plots
|
||||
using Dynare
|
||||
using SteadyState
|
||||
using PerfectForesightModelSolver
|
||||
|
||||
plotlyjs() # Choose a backend
|
||||
|
||||
|
||||
# Compile the rbc.mod file -> produce a module with the model definition.
|
||||
|
||||
@dynare "rbc1.mod"
|
||||
|
||||
importall SteadyState
|
||||
importall PerfectForesightModelSolver
|
||||
|
||||
# First call to the steady state routine (analytical)
|
||||
@time SteadyState.steady!(model_, oo_)
|
||||
|
||||
println(oo_.steady_state)
|
||||
|
@ -32,10 +34,9 @@ exogenousvariables = repmat(oo_.exo_steady_state', options_.pfmsolver.periods+2,
|
|||
|
||||
n = 200
|
||||
dates = collect(0:n-1)
|
||||
plt[:figure](1)
|
||||
#plt[:figure](1)
|
||||
plot(dates, vec(endogenousvariables[1,1:n]), color="black", linewidth=2.0, linestyle="-")
|
||||
|
||||
|
||||
# Initialize paths for the endogenous variables
|
||||
endogenousvariables = repmat(oo_.steady_state, 1, options_.pfmsolver.periods+2)
|
||||
# Destroy part of the initial stock of physical capital...
|
||||
|
@ -65,19 +66,19 @@ exogenousvariables[10+1, 1] = 2
|
|||
# Simulate the paths for the endogenous variables, given the expected shock
|
||||
@time simulate_perfect_foresight_model!(endogenousvariables, exogenousvariables, oo_.steady_state, model_, options_)
|
||||
|
||||
n = 200
|
||||
dates = collect(0:n-1)
|
||||
plt[:figure](2)
|
||||
subplot(221)
|
||||
title("Efficiency")
|
||||
plot(dates, vec(endogenousvariables[5,1:n]), color="black", linewidth=2.0, linestyle="-")
|
||||
subplot(223)
|
||||
title("Output")
|
||||
plot(dates, vec(endogenousvariables[2,1:n]), color="black", linewidth=2.0, linestyle="-")
|
||||
subplot(222)
|
||||
title("Consumption")
|
||||
plot(dates, vec(endogenousvariables[4,1:n]), color="black", linewidth=2.0, linestyle="-")
|
||||
subplot(224)
|
||||
title("Labour")
|
||||
plot(dates, vec(endogenousvariables[3,1:n]), color="black", linewidth=2.0, linestyle="-")
|
||||
suptitle("Expected positive expected shock")
|
||||
# dates = collect(0:n-1)
|
||||
# n = 200
|
||||
# plt[:figure](2)
|
||||
# subplot(221)
|
||||
# title("Efficiency")
|
||||
# plot(dates, vec(endogenousvariables[5,1:n]), color="black", linewidth=2.0, linestyle="-")
|
||||
# subplot(223)
|
||||
# title("Output")
|
||||
# plot(dates, vec(endogenousvariables[2,1:n]), color="black", linewidth=2.0, linestyle="-")
|
||||
# subplot(222)
|
||||
# title("Consumption")
|
||||
# plot(dates, vec(endogenousvariables[4,1:n]), color="black", linewidth=2.0, linestyle="-")
|
||||
# subplot(224)
|
||||
# title("Labour")
|
||||
# plot(dates, vec(endogenousvariables[3,1:n]), color="black", linewidth=2.0, linestyle="-")
|
||||
# suptitle("Expected positive expected shock")
|
||||
|
|
|
@ -3,14 +3,12 @@ if isempty(findin([abspath("../../../julia")], LOAD_PATH))
|
|||
unshift!(LOAD_PATH, abspath("../../../julia"))
|
||||
end
|
||||
|
||||
# Load Dynare package
|
||||
importall Dynare
|
||||
# Load Dynare package(s)
|
||||
using Dynare
|
||||
using SteadyState
|
||||
|
||||
# Compile the rbc.mod file -> produce a module with the model definition.
|
||||
@dynare "rbc1.mod"
|
||||
|
||||
|
||||
@dynare "rbc2.mod"
|
||||
|
||||
importall SteadyState
|
||||
|
||||
steady!(model_, oo_)
|
||||
# Compute the steady state
|
||||
steady_state!(model_, oo_)
|
||||
|
|
|
@ -17,4 +17,5 @@ importall Dynare
|
|||
# using rbc1
|
||||
|
||||
print(rbc1.model_.fname)
|
||||
|
||||
print(rbc2.model_.fname)
|
||||
|
|
Loading…
Reference in New Issue