Skip to content

Commit

Permalink
Fixed bug in deal_with_lags() function
Browse files Browse the repository at this point in the history
  • Loading branch information
RJDennis committed Jul 15, 2022
1 parent 4b5f27d commit 7298440
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 241 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "SolveDSGE"
uuid = "00bf1f32-23ad-54cc-bf6e-3216db8a43a2"
authors = ["Richard Dennis <richard.dennis@glasgow.ac.uk>"]
version = "0.5.3"
version = "0.5.4"

[deps]
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Expand Down
226 changes: 0 additions & 226 deletions examples/example_aiyagari/model_aiyagari_processed.txt

This file was deleted.

42 changes: 28 additions & 14 deletions src/parser_functions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -485,12 +485,14 @@ the model's equations accordingly.
Internal function; not exposed to users.
"""
function deal_with_lags(equations::Array{Q,1},states::Array{Q,1},jumps::Array{Q,1},variables::Array{Q,1}) where {Q<:AbstractString}
function deal_with_lags(equations::Array{Q,1},states::Array{Q,1},jumps::Array{Q,1}) where {Q<:AbstractString}

lag_variables = string.(variables,"(-1)")
variables = [states;jumps]
var_index = sortperm(length.(variables),rev=true)

lag_variables = string.(variables,"(-1)")

reorganized_equations = copy(equations)
reorganized_states = copy(states)

# First we determine if any equation contains a lagged variable.

Expand All @@ -508,21 +510,33 @@ function deal_with_lags(equations::Array{Q,1},states::Array{Q,1},jumps::Array{Q,
in its place and augment the list of state variables and the set of model
equations. =#

if model_has_lags == true
for j in eachindex(lag_variables)
if sum(occursin.(lag_variables[j],equations)) != 0
for i in eachindex(equations)
if model_has_lags == false
return equations, states, variables
else
new_states = String[]
new_eqns = String[]
#for j in eachindex(lag_variables)
for j in var_index
flag = false
for i in eachindex(equations)
if occursin(lag_variables[j],reorganized_equations[i]) == true
reorganized_equations[i] = replace(reorganized_equations[i],lag_variables[j] => string(variables[j],"lag"))
flag = true
end
reorganized_states = [reorganized_states; string(variables[j],"lag")]
reorganized_equations = [reorganized_equations; string(variables[j],"lag(+1) = ",variables[j])]
end
if flag == true
push!(new_states,string(variables[j],"lag"))
push!(new_eqns,string(variables[j],"lag(+1) = ",variables[j]))
end
end
end

reorganized_states = [states; new_states]
reorganized_equations = [reorganized_equations; new_eqns]
reorganized_variables = [reorganized_states; jumps]

reorganized_variables = [reorganized_states; jumps]
return reorganized_equations, reorganized_states, reorganized_variables

return reorganized_equations, reorganized_states, reorganized_variables
end

end

Expand Down Expand Up @@ -568,7 +582,7 @@ function get_re_model_primatives(model_array::Array{Q,1}) where {Q<:AbstractStri
end

reordered_equations, states, shocks = reorder_equations(equations,shocks,states,jumps,parameters)
reorganized_equations, states, variables = deal_with_lags(reordered_equations,states,jumps,variables)
reorganized_equations, states, variables = deal_with_lags(reordered_equations,states,jumps)

re_model_primatives = REModelPrimatives(states,jumps,shocks,variables,parameters,parametervalues,reorganized_equations,unassigned_parameters,solvers)

Expand Down Expand Up @@ -1212,4 +1226,4 @@ function assign_parameters(model::REModelPartial,paramdict::Dict{Q,T}) where {T<

return newmod

end
end

0 comments on commit 7298440

Please sign in to comment.