Skip to content

Commit

Permalink
works on all examples
Browse files Browse the repository at this point in the history
  • Loading branch information
thorek1 committed Nov 10, 2023
1 parent b1223b1 commit 55f87f7
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 44 deletions.
23 changes: 12 additions & 11 deletions src/MacroModelling.jl
Original file line number Diff line number Diff line change
Expand Up @@ -313,36 +313,37 @@ function write_obc_violation_equations(𝓂)
if dyn_1
if maximisation
push!(cond1, :(push!(constraint_values, $(x.args[3].args[2]))))
push!(cond2, :(push!(constraint_values, $(x.args[3].args[2]))))
# push!(cond2, :(push!(constraint_values, $(x.args[3].args[2]))))
else
push!(cond1, :(push!(constraint_values, -$(x.args[3].args[2]))))
push!(cond2, :(push!(constraint_values, -$(x.args[3].args[2])))) # RBC
# push!(cond2, :(push!(constraint_values, -$(x.args[3].args[2])))) # RBC
end
end

if dyn_2
if maximisation
push!(cond1, :(push!(constraint_values, $(x.args[3].args[3]))))
push!(cond2, :(push!(constraint_values, $(x.args[3].args[3])))) # testmax
# push!(cond2, :(push!(constraint_values, $(x.args[3].args[3])))) # testmax
else
push!(cond1, :(push!(constraint_values, -$(x.args[3].args[3]))))
push!(cond2, :(push!(constraint_values, -$(x.args[3].args[3])))) # RBC
# push!(cond2, :(push!(constraint_values, -$(x.args[3].args[3])))) # RBC
end
end

if maximisation
push!(cond1, :(push!(shock_sign_indicators, true)))
push!(cond2, :(push!(shock_sign_indicators, true)))
# push!(cond2, :(push!(shock_sign_indicators, true)))
else
push!(cond1, :(push!(shock_sign_indicators, false)))
push!(cond2, :(push!(shock_sign_indicators, false)))
# push!(cond2, :(push!(shock_sign_indicators, false)))
end

:(if isapprox($plchldr, $ineq_plchldr_1, atol = 1e-12)
$(Expr(:block, cond1...))
else
$(Expr(:block, cond2...))
end)
# :(if isapprox($plchldr, $ineq_plchldr_1, atol = 1e-12)
# $(Expr(:block, cond1...))
# else
# $(Expr(:block, cond2...))
# end)
:($(Expr(:block, cond1...)))
end :
x :
x :
Expand Down
39 changes: 22 additions & 17 deletions src/get_functions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -921,25 +921,26 @@ function get_irf(𝓂::β„³;
JuMP.@variable(model, x[1:num_shocks*periods_per_shock])

# Now loop through obc_shock_bounds to set the bounds on these variables.
# for (idx, v) in enumerate(𝓂.var[obc_inequalities_idx])
# maxmin_indicators = 𝓂.obc_violation_function(x, past_states, past_shocks, state_update, reference_steady_state, 𝓂, unconditional_forecast_horizon, JuMP.AffExpr.(present_shocks))[2]
# for (idx, v) in enumerate(maxmin_indicators)
# idxs = (idx - 1) * periods_per_shock + 1:idx * periods_per_shock
# # if contains(string(v), "α΅’α΅‡αΆœβΊ")
# if 𝓂.obc_violation_function(x, past_states, past_shocks, state_update, reference_steady_state, 𝓂, unconditional_forecast_horizon, JuMP.AffExpr.(present_shocks))[2][idx]
# # JuMP.set_upper_bound.(x[idxs], 0)
# JuMP.set_lower_bound.(x[idxs], 0)
# else
# JuMP.set_upper_bound.(x[idxs], 0)
# # JuMP.set_lower_bound.(x[idxs], 0)
# end
# # else
# # if 𝓂.obc_violation_function(x, past_states, past_shocks, state_update, reference_steady_state, 𝓂, unconditional_forecast_horizon, JuMP.AffExpr.(present_shocks))[2][idx]
# # JuMP.set_lower_bound.(x[idxs], 0)
# # else
# # JuMP.set_upper_bound.(x[idxs], 0)
# # end
# # end
# if v
# # if 𝓂.obc_violation_function(x, past_states, past_shocks, state_update, reference_steady_state, 𝓂, unconditional_forecast_horizon, JuMP.AffExpr.(present_shocks))[2][idx]
# JuMP.set_upper_bound.(x[idxs], 0)
# # JuMP.set_lower_bound.(x[idxs], 0)
# else
# # JuMP.set_upper_bound.(x[idxs], 0)
# JuMP.set_lower_bound.(x[idxs], 0)
# end
# # # else
# # # if 𝓂.obc_violation_function(x, past_states, past_shocks, state_update, reference_steady_state, 𝓂, unconditional_forecast_horizon, JuMP.AffExpr.(present_shocks))[2][idx]
# # # JuMP.set_lower_bound.(x[idxs], 0)
# # # else
# # # JuMP.set_upper_bound.(x[idxs], 0)
# # # end
# # # end
# end

JuMP.@objective(model, Min, x' * β„’.I * x)

JuMP.@constraint(model, 𝓂.obc_violation_function(x, past_states, past_shocks, state_update, reference_steady_state, 𝓂, unconditional_forecast_horizon, JuMP.AffExpr.(present_shocks))[1] .<= 0)
Expand All @@ -948,6 +949,10 @@ function get_irf(𝓂::β„³;

solved = JuMP.termination_status(model) ∈ [JuMP.OPTIMAL,JuMP.LOCALLY_SOLVED]

# precision = JuMP.objective_value(model)

# if precision > eps(Float32) @warn "Bounds enforced up to reduced precision: $precision" end # I need the dual value (constraints). this relates to the shock size

present_states = state_update(past_states,JuMP.value.(past_shocks))
present_shocks[contains.(string.(𝓂.timings.exo),"α΅’α΅‡αΆœ")] .= JuMP.value.(x)

Expand Down
37 changes: 21 additions & 16 deletions src/plotting.jl
Original file line number Diff line number Diff line change
Expand Up @@ -482,23 +482,24 @@ function plot_irf(𝓂::β„³;
JuMP.@variable(model, x[1:num_shocks*periods_per_shock])

# Now loop through obc_shock_bounds to set the bounds on these variables.
# for (idx, v) in enumerate(𝓂.var[obc_inequalities_idx])
# maxmin_indicators = 𝓂.obc_violation_function(x, past_states, past_shocks, state_update, reference_steady_state, 𝓂, unconditional_forecast_horizon, JuMP.AffExpr.(present_shocks))[2]
# for (idx, v) in enumerate(maxmin_indicators)
# idxs = (idx - 1) * periods_per_shock + 1:idx * periods_per_shock
# # if contains(string(v), "α΅’α΅‡αΆœβΊ")
# if 𝓂.obc_violation_function(x, past_states, past_shocks, state_update, reference_steady_state, 𝓂, unconditional_forecast_horizon, JuMP.AffExpr.(present_shocks))[2][idx]
# # JuMP.set_upper_bound.(x[idxs], 0)
# JuMP.set_lower_bound.(x[idxs], 0)
# else
# JuMP.set_upper_bound.(x[idxs], 0)
# # JuMP.set_lower_bound.(x[idxs], 0)
# end
# # else
# # if 𝓂.obc_violation_function(x, past_states, past_shocks, state_update, reference_steady_state, 𝓂, unconditional_forecast_horizon, JuMP.AffExpr.(present_shocks))[2][idx]
# # JuMP.set_lower_bound.(x[idxs], 0)
# # else
# # JuMP.set_upper_bound.(x[idxs], 0)
# # end
# # end
# if v
# # if 𝓂.obc_violation_function(x, past_states, past_shocks, state_update, reference_steady_state, 𝓂, unconditional_forecast_horizon, JuMP.AffExpr.(present_shocks))[2][idx]
# JuMP.set_upper_bound.(x[idxs], 0)
# # JuMP.set_lower_bound.(x[idxs], 0)
# else
# # JuMP.set_upper_bound.(x[idxs], 0)
# JuMP.set_lower_bound.(x[idxs], 0)
# end
# # # else
# # # if 𝓂.obc_violation_function(x, past_states, past_shocks, state_update, reference_steady_state, 𝓂, unconditional_forecast_horizon, JuMP.AffExpr.(present_shocks))[2][idx]
# # # JuMP.set_lower_bound.(x[idxs], 0)
# # # else
# # # JuMP.set_upper_bound.(x[idxs], 0)
# # # end
# # # end
# end

JuMP.@objective(model, Min, x' * β„’.I * x)
Expand All @@ -508,6 +509,10 @@ function plot_irf(𝓂::β„³;
JuMP.optimize!(model)

solved = JuMP.termination_status(model) ∈ [JuMP.OPTIMAL,JuMP.LOCALLY_SOLVED]

# precision = JuMP.objective_value(model)

# if precision > eps(Float32) @warn "Bounds enforced up to reduced precision: $precision" end # I need the dual value (constraints). this relates to the shock size

present_states = state_update(past_states,JuMP.value.(past_shocks))
present_shocks[contains.(string.(𝓂.timings.exo),"α΅’α΅‡αΆœ")] .= JuMP.value.(x)
Expand Down

0 comments on commit 55f87f7

Please sign in to comment.