diff --git a/src/MacroModelling.jl b/src/MacroModelling.jl index e5052518..a52b40c9 100644 --- a/src/MacroModelling.jl +++ b/src/MacroModelling.jl @@ -4780,6 +4780,28 @@ function calculate_third_order_solution(βˆ‡β‚::AbstractMatrix{<: Real}, #first end +function get_relevant_steady_states(𝓂::β„³, algorithm::Symbol) + full_NSSS = sort(union(𝓂.var,𝓂.aux,𝓂.exo_present)) + + full_NSSS[indexin(𝓂.aux,full_NSSS)] = map(x -> Symbol(replace(string(x), r"ᴸ⁽⁻?[⁰¹²³⁴⁡⁢⁷⁸⁹]+⁾" => "")), 𝓂.aux) + + if any(x -> contains(string(x), "β—–"), full_NSSS) + full_NSSS_decomposed = decompose_name.(full_NSSS) + full_NSSS = [length(a) > 1 ? string(a[1]) * "{" * join(a[2],"}{") * "}" * (a[end] isa Symbol ? string(a[end]) : "") : string(a[1]) for a in full_NSSS_decomposed] + end + + relevant_SS = get_steady_state(𝓂, algorithm = algorithm, return_variables_only = true, derivatives = false) + + reference_steady_state = [s ∈ 𝓂.exo_present ? 0 : relevant_SS(s) for s in full_NSSS] + + relevant_NSSS = get_steady_state(𝓂, algorithm = :first_order, return_variables_only = true, derivatives = false) + + NSSS = [s ∈ 𝓂.exo_present ? 0 : relevant_NSSS(s) for s in full_NSSS] + + SSS_delta = NSSS - reference_steady_state + + return reference_steady_state, NSSS, SSS_delta +end function irf(state_update::Function, diff --git a/src/get_functions.jl b/src/get_functions.jl index c016d110..571bf2c0 100644 --- a/src/get_functions.jl +++ b/src/get_functions.jl @@ -539,41 +539,11 @@ function get_conditional_forecast(𝓂::β„³, shocks = Matrix{Union{Nothing,Number}}(nothing,length(𝓂.exo),periods) end - # write_parameters_input!(𝓂,parameters, verbose = verbose) - solve!(𝓂, parameters = parameters, verbose = verbose, dynamics = true, algorithm = algorithm) state_update, pruning = parse_algorithm_to_state_update(algorithm, 𝓂, false) - reference_steady_state, (solution_error, iters) = 𝓂.solution.outdated_NSSS ? 𝓂.SS_solve_func(𝓂.parameter_values, 𝓂, verbose, false, 𝓂.solver_parameters) : (copy(𝓂.solution.non_stochastic_steady_state), (eps(), 0)) - - NSSS = reference_steady_state[1:length(𝓂.var)] - - if algorithm == :second_order - SSS_delta = NSSS - 𝓂.solution.perturbation.second_order.stochastic_steady_state - elseif algorithm == :pruned_second_order - SSS_delta = NSSS - 𝓂.solution.perturbation.pruned_second_order.stochastic_steady_state - elseif algorithm == :third_order - SSS_delta = NSSS - 𝓂.solution.perturbation.third_order.stochastic_steady_state - elseif algorithm == :pruned_third_order - SSS_delta = NSSS - 𝓂.solution.perturbation.pruned_third_order.stochastic_steady_state - else - SSS_delta = zeros(length(𝓂.var)) - - reference_steady_state = NSSS - end - - if levels - if algorithm == :second_order - reference_steady_state = 𝓂.solution.perturbation.second_order.stochastic_steady_state - elseif algorithm == :pruned_second_order - reference_steady_state = 𝓂.solution.perturbation.pruned_second_order.stochastic_steady_state - elseif algorithm == :third_order - reference_steady_state = 𝓂.solution.perturbation.third_order.stochastic_steady_state - elseif algorithm == :pruned_third_order - reference_steady_state = 𝓂.solution.perturbation.pruned_third_order.stochastic_steady_state - end - end + reference_steady_state, NSSS, SSS_delta = get_relevant_steady_states(𝓂, algorithm) unspecified_initial_state = initial_state == [0.0] @@ -1021,36 +991,8 @@ function get_irf(𝓂::β„³; solve!(𝓂, parameters = parameters, verbose = verbose, dynamics = true, algorithm = algorithm, obc = occasionally_binding_constraints || obc_shocks_included) - reference_steady_state, (solution_error, iters) = 𝓂.solution.outdated_NSSS ? 𝓂.SS_solve_func(𝓂.parameter_values, 𝓂, verbose, false, 𝓂.solver_parameters) : (copy(𝓂.solution.non_stochastic_steady_state), (eps(), 0)) - - NSSS = reference_steady_state[1:length(𝓂.var)] - - if algorithm == :second_order - SSS_delta = NSSS - 𝓂.solution.perturbation.second_order.stochastic_steady_state - elseif algorithm == :pruned_second_order - SSS_delta = NSSS - 𝓂.solution.perturbation.pruned_second_order.stochastic_steady_state - elseif algorithm == :third_order - SSS_delta = NSSS - 𝓂.solution.perturbation.third_order.stochastic_steady_state - elseif algorithm == :pruned_third_order - SSS_delta = NSSS - 𝓂.solution.perturbation.pruned_third_order.stochastic_steady_state - else - SSS_delta = zeros(length(𝓂.var)) - - reference_steady_state = NSSS - end - - if levels - if algorithm == :second_order - reference_steady_state = 𝓂.solution.perturbation.second_order.stochastic_steady_state - elseif algorithm == :pruned_second_order - reference_steady_state = 𝓂.solution.perturbation.pruned_second_order.stochastic_steady_state - elseif algorithm == :third_order - reference_steady_state = 𝓂.solution.perturbation.third_order.stochastic_steady_state - elseif algorithm == :pruned_third_order - reference_steady_state = 𝓂.solution.perturbation.pruned_third_order.stochastic_steady_state - end - end - + reference_steady_state, NSSS, SSS_delta = get_relevant_steady_states(𝓂, algorithm) + unspecified_initial_state = initial_state == [0.0] if unspecified_initial_state diff --git a/src/plotting.jl b/src/plotting.jl index d06c7854..7d89345c 100644 --- a/src/plotting.jl +++ b/src/plotting.jl @@ -415,37 +415,8 @@ function plot_irf(𝓂::β„³; solve!(𝓂, parameters = parameters, verbose = verbose, dynamics = true, algorithm = algorithm, obc = occasionally_binding_constraints || obc_shocks_included) - NSSS, (solution_error, iters) = 𝓂.solution.outdated_NSSS ? 𝓂.SS_solve_func(𝓂.parameter_values, 𝓂, verbose, false, 𝓂.solver_parameters) : (𝓂.solution.non_stochastic_steady_state, (eps(), 0)) - - full_SS = sort(union(𝓂.var,𝓂.aux,𝓂.exo_present)) - full_SS[indexin(𝓂.aux,full_SS)] = map(x -> Symbol(replace(string(x), r"ᴸ⁽⁻?[⁰¹²³⁴⁡⁢⁷⁸⁹]+⁾" => "")), 𝓂.aux) - - NSSS_labels = [sort(union(𝓂.exo_present,𝓂.var))...,𝓂.calibration_equations_parameters...] - - reference_steady_state = [s ∈ 𝓂.exo_present ? 0 : NSSS[indexin([s],NSSS_labels)...] for s in full_SS] - - if algorithm == :second_order - SSS_delta = reference_steady_state - 𝓂.solution.perturbation.second_order.stochastic_steady_state - elseif algorithm == :pruned_second_order - SSS_delta = reference_steady_state - 𝓂.solution.perturbation.pruned_second_order.stochastic_steady_state - elseif algorithm == :third_order - SSS_delta = reference_steady_state - 𝓂.solution.perturbation.third_order.stochastic_steady_state - elseif algorithm == :pruned_third_order - SSS_delta = reference_steady_state - 𝓂.solution.perturbation.pruned_third_order.stochastic_steady_state - else - SSS_delta = zeros(length(reference_steady_state)) - end - - if algorithm == :second_order - reference_steady_state = 𝓂.solution.perturbation.second_order.stochastic_steady_state - elseif algorithm == :pruned_second_order - reference_steady_state = 𝓂.solution.perturbation.pruned_second_order.stochastic_steady_state - elseif algorithm == :third_order - reference_steady_state = 𝓂.solution.perturbation.third_order.stochastic_steady_state - elseif algorithm == :pruned_third_order - reference_steady_state = 𝓂.solution.perturbation.pruned_third_order.stochastic_steady_state - end - + reference_steady_state, NSSS, SSS_delta = get_relevant_steady_states(𝓂, algorithm) + unspecified_initial_state = initial_state == [0.0] if unspecified_initial_state @@ -1062,6 +1033,7 @@ function plot_solution(𝓂::β„³, SS_and_std[2] = SS_and_std[2] isa KeyedArray ? axiskeys(SS_and_std[2],1) isa Vector{String} ? rekey(SS_and_std[2], 1 => axiskeys(SS_and_std[2],1).|> x->Symbol.(replace.(x, "{" => "β—–", "}" => "β——"))) : SS_and_std[2] : SS_and_std[2] full_NSSS = sort(union(𝓂.var,𝓂.aux,𝓂.exo_present)) + full_NSSS[indexin(𝓂.aux,full_NSSS)] = map(x -> Symbol(replace(string(x), r"ᴸ⁽⁻?[⁰¹²³⁴⁡⁢⁷⁸⁹]+⁾" => "")), 𝓂.aux) full_SS = [s ∈ 𝓂.exo_present ? 0 : SS_and_std[1](s) for s in full_NSSS]