diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 13957bc4..b17c174a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,26 +21,59 @@ jobs: - windows-latest arch: - x64 + test_set: + - "estimation" + - "higher_order" + - "plots" + - "basic" include: - os: ubuntu-latest prefix: xvfb-run - version: '1.8' os: ubuntu-latest arch: x64 + test_set: "basic" + - version: '1.8' + os: ubuntu-latest + arch: x64 + test_set: "plots" + - version: '^1.10.0-0' + os: ubuntu-latest + arch: x64 + test_set: "estimation" + allow_failure: true + - version: '^1.10.0-0' + os: ubuntu-latest + arch: x64 + test_set: "higher_order" + allow_failure: true + - version: '^1.10.0-0' + os: ubuntu-latest + arch: x64 + test_set: "plots" + allow_failure: true - version: '^1.10.0-0' os: ubuntu-latest arch: x64 + test_set: "basic" allow_failure: true - version: 'nightly' os: ubuntu-latest arch: x64 + test_set: "basic" allow_failure: true steps: - uses: actions/checkout@v4 - uses: julia-actions/setup-julia@v1 with: version: ${{ matrix.version }} - arch: ${{ matrix.arch }} + arch: ${{ matrix.arch }} + - name: Set Custom Test Environment Variable + if: matrix.os == 'windows-latest' + run: echo "TEST_SET=${{ matrix.test_set }}" | Out-File -Append -FilePath $env:GITHUB_ENV -Encoding utf8 + - name: Set Custom Test Environment Variable (Unix) + if: matrix.os != 'windows-latest' + run: echo "TEST_SET=${{ matrix.test_set }}" >> $GITHUB_ENV - name: Set JULIA_NUM_THREADS for Julia 1.9 on Ubuntu if: matrix.version == '1.9' && matrix.os == 'ubuntu-latest' run: echo "JULIA_NUM_THREADS=2" >> $GITHUB_ENV diff --git a/Project.toml b/Project.toml index f592265a..3afd0420 100644 --- a/Project.toml +++ b/Project.toml @@ -14,12 +14,15 @@ DynarePreprocessor_jll = "23afba7c-24e5-5ee2-bc2c-b42e07f0492a" ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210" ImplicitDifferentiation = "57b37032-215b-411a-8a7c-41a003a55207" JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6" +JuMP = "4076af6c-e467-56ae-b986-b466b2749572" Krylov = "ba0b0d4f-ebba-5204-a429-3ac8c609bfb7" LaTeXStrings = "b964fa9f-0449-5b57-a5c2-d3ea65f4040f" LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" LinearOperators = "5c8ed15e-5a4c-59e4-a42b-c7e8811fb125" MacroTools = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09" +MadNLP = "2621e9c9-9eb4-46b1-8089-e8c72242dfb6" MatrixEquations = "99c1a7ee-ab34-5fd5-8076-27c950a045f4" +NLopt = "76087f3c-5699-56af-9a33-bf431cd00edd" PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a" REPL = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb" Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" @@ -33,7 +36,6 @@ SpeedMapping = "f1835b91-879b-4a3f-a438-e4baacf14412" Subscripts = "2b7f82d5-8785-4f63-971e-f18ddbeb808e" SymPyPythonCall = "bc8888f7-b21e-4b7c-a06a-5d9c9496438c" Symbolics = "0c5d862f-8b57-4792-8d23-62f2024744c7" -ThreadedSparseArrays = "59d54670-b8ac-4d81-ab7a-bb56233e17ab" Unicode = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5" [weakdeps] @@ -41,32 +43,53 @@ StatsPlots = "f3b207a7-027a-5e70-b257-86293d7955fd" Turing = "fce5fe82-541a-59a6-adf8-730c64b5f9a0" [compat] -AbstractDifferentiation = "^0.5" +AbstractDifferentiation = "^0.5, 0.6" +Aqua = "^0.8" AxisKeys = "^0.2" BlockTriangularForm = "^0.1" +CSV = "^0.10" ChainRulesCore = "^1" +DataFrames = "^1" DataStructures = "^0.18" DocStringExtensions = "^0.8, 0.9" +DynamicPPL = "0.23, 0.24" DynarePreprocessor_jll = "^6.2" +FiniteDifferences = "^0.12" ForwardDiff = "^0.10" ImplicitDifferentiation = "^0.5" +JET = "0.7, 0.8" JSON = "^0.21" +JuMP = "^1" Krylov = "^0.9" LaTeXStrings = "^1" +LineSearches = "^7" +LinearAlgebra = "^1" LinearOperators = "^2" +MCMCChains = "^6" MacroTools = "^0.5" +MadNLP = "^0.7" MatrixEquations = "^2" +NLopt = "0.6, ^1" +Optim = "^1" +Plots = "^1" PrecompileTools = "^1" +REPL = "^1" +Random = "^1" RecursiveFactorization = "^0.2" Reexport = "^1" Requires = "^1" RuntimeGeneratedFunctions = "^0.5" +SparseArrays = "^1" SpecialFunctions = "^2" SpeedMapping = "^0.3" +StatsPlots = "^0.15" Subscripts = "^0.1" SymPyPythonCall = "^0.2" Symbolics = "^5" -ThreadedSparseArrays = "^0.2" +Test = "^1" +Turing = "^0.29" +Unicode = "^1" +Zygote = "^0.6" julia = "1.8" [extras] diff --git a/README.md b/README.md index 377df202..b1ded3d6 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,9 @@ **Author: Thore Kockerols (@thorek1)** -`MacroModelling.jl` is a Julia package for developing and solving dynamic stochastic general equilibrium (DSGE) models. These kinds of models describe the behavior of a macroeconomy and are particularly suited for counterfactual analysis (economic policy evaluation) and exploring / quantifying specific mechanisms (academic research). Due to the complexity of these models, efficient numerical tools are required, as analytical solutions are often unavailable. `MacroModelling.jl` serves as a tool for handling the complexities involved, such as forward-looking expectations, nonlinearity, and high dimensionality. +`MacroModelling.jl` is a Julia package for developing and solving dynamic stochastic general equilibrium (DSGE) models. + +These kinds of models describe the behavior of a macroeconomy and are particularly suited for counterfactual analysis (economic policy evaluation) and exploring / quantifying specific mechanisms (academic research). Due to the complexity of these models, efficient numerical tools are required, as analytical solutions are often unavailable. `MacroModelling.jl` serves as a tool for handling the complexities involved, such as forward-looking expectations, nonlinearity, and high dimensionality. The goal of this package is to reduce coding time and speed up model development by providing functions for working with discrete-time DSGE models. The user-friendly syntax, automatic variable declaration, and effective steady state solver facilitate fast prototyping of models. Furthermore, the package allows the user to work with nonlinear model solutions (up to third order (pruned) perturbation) and estimate the model using gradient based samplers (e.g. NUTS, or HMC). Currently, `DifferentiableStateSpaceModels.jl` is the only other package providing functionality to estimate using gradient based samplers but the use is limited to models with an analytical solution of the non stochastic steady state (NSSS). Larger models tend to not have an analytical solution of the NSSS and `MacroModelling.jl` can also use gradient based sampler in this case. The target audience for the package includes central bankers, regulators, graduate students, and others working in academia with an interest in DSGE modelling. @@ -20,6 +22,7 @@ As of now the package can: - parse a model written with user friendly syntax (variables are followed by time indices `...[2], [1], [0], [-1], [-2]...`, or `[x]` for shocks) - (tries to) solve the model only knowing the model equations and parameter values (no steady state file needed) - calculate first, second, and third order (pruned) perturbation solutions using (forward or reverse-mode) automatic differentiation (AD) +- handle occasionally binding constraints - calculate (generalised) impulse response functions, simulate the model, or do conditional forecasts - calibrate parameters using (non stochastic) steady state relationships - match model moments (also for pruned higher order solutions) @@ -78,7 +81,7 @@ The package contains the following models in the `models` folder: - [Aguiar and Gopinath (2007)](https://www.journals.uchicago.edu/doi/10.1086/511283) `Aguiar_Gopinath_2007.jl` - [Ascari and Sbordone (2014)](https://www.aeaweb.org/articles?id=10.1257/jel.52.3.679) `Ascari_sbordone_2014.jl` - [Backus, Kehoe, and Kydland (1992)](https://www.jstor.org/stable/2138686) `Backus_Kehoe_Kydland_1992` -- [Baxter and King (1993)](https://www.jstor.org/stable/2117521) `Baxter_and_King_1993.jl` +- [Baxter and King (1993)](https://www.jstor.org/stable/2117521) `Baxter_King_1993.jl` - [Caldara et al. (2012)](https://www.sciencedirect.com/science/article/abs/pii/S1094202511000433) `Caldara_et_al_2012.jl` - [Gali (2015)](https://press.princeton.edu/books/hardcover/9780691164786/monetary-policy-inflation-and-the-business-cycle) - Chapter 3 `Gali_2015_chapter_3_nonlinear.jl` - [Gali and Monacelli (2005)](https://crei.cat/wp-content/uploads/users/pages/roes8739.pdf) - CPI inflation-based Taylor rule `Gali_Monacelli_2005_CITR.jl` @@ -87,6 +90,7 @@ The package contains the following models in the `models` folder: - [Ireland (2004)](http://irelandp.com/pubs/tshocksnk.pdf) `Ireland_2004.jl` - [Jermann and Quadrini (2012)](https://www.aeaweb.org/articles?id=10.1257/aer.102.1.238) - RBC `JQ_2012_RBC.jl` - [New Area-Wide Model (2008)](https://www.ecb.europa.eu/pub/pdf/scpwps/ecbwp944.pdf) - Euro Area - US `NAWM_EAUS_2008.jl` +- [QUEST3 (2008)](https://www.sciencedirect.com/science/article/abs/pii/S026499930800076X) `QUEST3_2009.jl` - [Schmitt-Grohé and Uribe (2003)](https://www.sciencedirect.com/science/article/abs/pii/S0022199602000569) - debt premium `SGU_2003_debt_premium.jl` - [Schorfheide (2000)](https://onlinelibrary.wiley.com/doi/abs/10.1002/jae.582) `FS2000.jl` - [Smets and Wouters (2003)](https://onlinelibrary.wiley.com/doi/10.1162/154247603770383415) `SW03.jl` @@ -103,7 +107,7 @@ The package contains the following models in the `models` folder: **Perturbation solution order**|1, 2, 3|k|1|1, 2, 3|1, 2, 3|1, 2|1|1|1 to 5|1|1||1 to 5| **Pruning**|yes|yes||||yes|||yes||||| **Automatic derivation of first order conditions**|||||||||||yes|| -**Handles occasionally binding constraints**||yes|yes|yes|yes||||yes|||yes|| +**Handles occasionally binding constraints**|yes|yes|yes|yes|yes||||yes|||yes|| **Global solution**||||yes|yes|||||||yes|| **Estimation**|yes|yes|yes|||||yes|yes|yes|yes||| **Balanced growth path**||yes|yes||||yes|yes|yes|yes||||| diff --git a/benchmark/SW07_estimation.jl b/benchmark/SW07_estimation.jl index 5c2ed485..e5fadfd3 100644 --- a/benchmark/SW07_estimation.jl +++ b/benchmark/SW07_estimation.jl @@ -374,7 +374,7 @@ function calculate_kalman_filter_loglikelihoods(𝓂::ℳ, data::AbstractArray{F end end - SS_and_pars, solution_error = 𝓂.SS_solve_func(parameters, 𝓂, true, verbose) + SS_and_pars, (solution_error, iters) = 𝓂.SS_solve_func(parameters, 𝓂, verbose, false, 𝓂.solver_parameters) if solution_error > tol || isnan(solution_error) return -Inf @@ -473,7 +473,7 @@ function calculate_kalman_filter_loglikelihoods(𝓂::ℳ, data::AbstractArray{F end end - SS_and_pars, solution_error = 𝓂.SS_solve_func(parameters, 𝓂, true, verbose) + SS_and_pars, (solution_error, iters) = 𝓂.SS_solve_func(parameters, 𝓂, verbose, false, 𝓂.solver_parameters) if solution_error > tol || isnan(solution_error) return -Inf diff --git a/benchmark/test_solver.jl b/benchmark/test_solver.jl index 1777044d..3147af6a 100644 --- a/benchmark/test_solver.jl +++ b/benchmark/test_solver.jl @@ -1,195 +1,158 @@ using MacroModelling -include("models/RBC_CME_calibration_equations_and_parameter_definitions_lead_lags_numsolve.jl") -include("models/RBC_CME_calibration_equations_and_parameter_definitions.jl") -include("models/SW03.jl") -include("models/GNSS_2010.jl") -include("models/Ghironi_Melitz_2005.jl") -include("models/SGU_2003_debt_premium.jl") -include("models/NAWM_EAUS_2008.jl") # stands out -include("models/JQ_2012_RBC.jl") -include("models/Ireland_2004.jl") -include("models/Caldara_et_al_2012.jl") -include("models/Gali_Monacelli_2005_CITR.jl") -include("models/Gali_2015_chapter_3_nonlinear.jl") -include("models/Aguiar_Gopinath_2007.jl") -include("models/Ascari_Sbordone_2014.jl")# stands out -include("models/FS2000.jl") -include("models/SW07.jl") +include("../test/models/RBC_CME_calibration_equations_and_parameter_definitions_lead_lags_numsolve.jl") +# include("../test/models/RBC_CME_calibration_equations_and_parameter_definitions.jl") +include("../models/Backus_Kehoe_Kydland_1992.jl") +include("../models/Baxter_King_1993.jl") +include("../models/SW03.jl") +include("../models/GNSS_2010.jl") +include("../models/Ghironi_Melitz_2005.jl") +include("../models/SGU_2003_debt_premium.jl") +include("../models/NAWM_EAUS_2008.jl") # stands out +include("../models/JQ_2012_RBC.jl") +include("../models/Ireland_2004.jl") +include("../models/Caldara_et_al_2012.jl") +include("../models/Gali_Monacelli_2005_CITR.jl") +include("../models/Gali_2015_chapter_3_nonlinear.jl") +include("../models/Aguiar_Gopinath_2007.jl") +include("../models/Ascari_Sbordone_2014.jl") # stands out +include("../models/FS2000.jl") +include("../models/SW07.jl") +include("../models/RBC_baseline.jl") +include("../models/Guerrieri_Iacoviello_2017.jl") # stands out + + +all_models = [ + m, + Backus_Kehoe_Kydland_1992, + Baxter_King_1993, + SW03, + GNSS_2010, + Ghironi_Melitz_2005, + SGU_2003_debt_premium, + NAWM_EAUS_2008, + JQ_2012_RBC, + Ireland_2004, + Caldara_et_al_2012, + Gali_Monacelli_2005_CITR, + Gali_2015_chapter_3_nonlinear, + Aguiar_Gopinath_2007, + Ascari_Sbordone_2014, + FS2000, + SW07, + Guerrieri_Iacoviello_2017 +]; + + + +function calc_total_iters(model, par_inputs, starting_point) + outmodel = try model.SS_solve_func(model.parameter_values, model, false, starting_point, par_inputs) catch end + # outmodel = model.SS_solve_func(model.parameter_values, model, false, starting_point, par_inputs) + + outmodel isa Tuple{Vector{Float64}, Tuple{Float64, Int64}} ? + (outmodel[2][1] > eps(Float64)) || !isfinite(outmodel[2][1]) ? + 1000000 : + outmodel[2][2] : + 1000000 +end + +par_inputs = m.solver_parameters +calc_total_iters(m, par_inputs, 0.897) using Optimization, OptimizationNLopt + f = OptimizationFunction((x,verbose)-> begin total_iters = 0 x[1:2] = sort(x[1:2], rev = true) - par_inputs = Dict( - :ϕ̄ => x[1], - :ϕ̂ => x[2], - :μ̄¹ => x[3], - :μ̄² => x[4], - :p̄¹ => x[5], - :p̄² => x[6], - :ρ => x[7], - :ρ¹ => x[8], - :ρ² => x[9], - :ρ³ => x[10], - :ν => x[11], - :λ¹ => x[12], - :λ² => x[13], - :λ̂¹ => x[14], - :λ̂² => x[15], - :λ̅¹ => x[16], - :λ̅² => x[17], - :λ̂̅¹ => x[18], - :λ̂̅² => x[19], - :transformation_level => Int(abs(round(x[20]))), - :backtracking_order => Int(abs(round(x[21]))) - ) -# println(par_inputs) - outSW07 = try SW07.SS_solve_func(SW07.parameter_values, SW07, false, verbose, par_inputs, x[end]) catch end - - total_iters += outSW07 isa Tuple{Vector{Float64}, Float64, Int64} ? (outSW07[2] > eps(Float64)) || !isfinite(outSW07[2]) ? 1000000 : outSW07[3] : 1000000 - - outAscari_Sbordone_2014 = try Ascari_Sbordone_2014.SS_solve_func(Ascari_Sbordone_2014.parameter_values, Ascari_Sbordone_2014, false, verbose, par_inputs, x[end]) catch end - # println(outAscari_Sbordone_2014[1][10]) - total_iters += outAscari_Sbordone_2014 isa Tuple{Vector{Float64}, Float64, Int64} ? (outAscari_Sbordone_2014[2] > eps(Float64)) || !isfinite(outAscari_Sbordone_2014[2]) ? 1000000 : outAscari_Sbordone_2014[3] : 1000000 - # || !isapprox(outAscari_Sbordone_2014[1][10], 3.88351239274375, atol = 1e-6) - - outSW03 = try SW03.SS_solve_func(SW03.parameter_values, SW03, false, verbose, par_inputs, x[end]) catch end - - total_iters += outSW03 isa Tuple{Vector{Float64}, Float64, Int64} ? (outSW03[2] > eps(Float64)) || !isfinite(outSW03[2]) ? 1000000 : outSW03[3] : 1000000 - - outNAWM_EAUS_2008 = try NAWM_EAUS_2008.SS_solve_func(NAWM_EAUS_2008.parameter_values, NAWM_EAUS_2008, false, verbose, par_inputs, x[end]) catch end - - total_iters += outNAWM_EAUS_2008 isa Tuple{Vector{Float64}, Float64, Int64} ? (outNAWM_EAUS_2008[2] > eps(Float64)) || !isfinite(outNAWM_EAUS_2008[2]) ? 1000000 : outNAWM_EAUS_2008[3] : 1000000 - - outGali_Monacelli_2005_CITR = try Gali_Monacelli_2005_CITR.SS_solve_func(Gali_Monacelli_2005_CITR.parameter_values, Gali_Monacelli_2005_CITR, false, verbose, par_inputs, x[end]) catch end - - total_iters += outGali_Monacelli_2005_CITR isa Tuple{Vector{Float64}, Float64, Int64} ? (outGali_Monacelli_2005_CITR[2] > eps(Float64)) || !isfinite(outGali_Monacelli_2005_CITR[2]) ? 1000000 : outGali_Monacelli_2005_CITR[3] : 1000000 - - outGali_2015_chapter_3_nonlinear = try Gali_2015_chapter_3_nonlinear.SS_solve_func(Gali_2015_chapter_3_nonlinear.parameter_values, Gali_2015_chapter_3_nonlinear, false, verbose, par_inputs, x[end]) catch end - - total_iters += outGali_2015_chapter_3_nonlinear isa Tuple{Vector{Float64}, Float64, Int64} ? (outGali_2015_chapter_3_nonlinear[2] > eps(Float64)) || !isfinite(outGali_2015_chapter_3_nonlinear[2]) ? 1000000 : outGali_2015_chapter_3_nonlinear[3] : 1000000 - - outAguiar_Gopinath_2007 = try Aguiar_Gopinath_2007.SS_solve_func(Aguiar_Gopinath_2007.parameter_values, Aguiar_Gopinath_2007, false, verbose, par_inputs, x[end]) catch end - - total_iters += outAguiar_Gopinath_2007 isa Tuple{Vector{Float64}, Float64, Int64} ? (outAguiar_Gopinath_2007[2] > eps(Float64)) || !isfinite(outAguiar_Gopinath_2007[2]) ? 1000000 : outAguiar_Gopinath_2007[3] : 1000000 - - outCaldara_et_al_2012 = try Caldara_et_al_2012.SS_solve_func(Caldara_et_al_2012.parameter_values, Caldara_et_al_2012, false, verbose, par_inputs, x[end]) catch end - - total_iters += outCaldara_et_al_2012 isa Tuple{Vector{Float64}, Float64, Int64} ? (outCaldara_et_al_2012[2] > eps(Float64)) || !isfinite(outCaldara_et_al_2012[2]) ? 1000000 : outCaldara_et_al_2012[3] : 1000000 - outGhironi_Melitz_2005 = try Ghironi_Melitz_2005.SS_solve_func(Ghironi_Melitz_2005.parameter_values, Ghironi_Melitz_2005, false, verbose, par_inputs, x[end]) catch end + par_inputs = MacroModelling.solver_parameters( + eps(),eps(),250, x[1], x[2], x[3], x[4], x[5], x[6], x[7], x[8], x[9], x[10], x[11], x[12], x[13], x[14], x[15], x[16], x[17], x[18], x[19],Int(abs(round(x[20]))),x[21],Int(abs(round(x[22]))) + ) - total_iters += outGhironi_Melitz_2005 isa Tuple{Vector{Float64}, Float64, Int64} ? (outGhironi_Melitz_2005[2] > eps(Float64)) || !isfinite(outGhironi_Melitz_2005[2]) ? 1000000 : outGhironi_Melitz_2005[3] : 1000000 - - outGNSS_2010 = try GNSS_2010.SS_solve_func(GNSS_2010.parameter_values, GNSS_2010, false, verbose, par_inputs, x[end]) catch end - - total_iters += outGNSS_2010 isa Tuple{Vector{Float64}, Float64, Int64} ? (outGNSS_2010[2] > eps(Float64)) || !isfinite(outGNSS_2010[2]) ? 1000000 : outGNSS_2010[3] : 1000000 - - outSGU_2003_debt_premium = try SGU_2003_debt_premium.SS_solve_func(SGU_2003_debt_premium.parameter_values, SGU_2003_debt_premium, false, verbose, par_inputs, x[end]) catch end - - total_iters += outSGU_2003_debt_premium isa Tuple{Vector{Float64}, Float64, Int64} ? (outSGU_2003_debt_premium[2] > eps(Float64)) || !isfinite(outSGU_2003_debt_premium[2]) ? 1000000 : outSGU_2003_debt_premium[3] : 1000000 - - outJQ_2012_RBC = try JQ_2012_RBC.SS_solve_func(JQ_2012_RBC.parameter_values, JQ_2012_RBC, false, verbose, par_inputs, x[end]) catch end - - total_iters += outJQ_2012_RBC isa Tuple{Vector{Float64}, Float64, Int64} ? (outJQ_2012_RBC[2] > eps(Float64)) || !isfinite(outJQ_2012_RBC[2]) ? 1000000 : outJQ_2012_RBC[3] : 1000000 - - outIreland_2004 = try Ireland_2004.SS_solve_func(Ireland_2004.parameter_values, Ireland_2004, false, verbose, par_inputs, x[end]) catch end - - total_iters += outIreland_2004 isa Tuple{Vector{Float64}, Float64, Int64} ? (outIreland_2004[2] > eps(Float64)) || !isfinite(outIreland_2004[2]) ? 1000000 : outIreland_2004[3] : 1000000 - - outFS2000 = try FS2000.SS_solve_func(FS2000.parameter_values, FS2000, false, verbose, par_inputs, x[end]) catch end - - total_iters += outFS2000 isa Tuple{Vector{Float64}, Float64, Int64} ? (outFS2000[2] > eps(Float64)) || !isfinite(outFS2000[2]) ? 1000000 : outFS2000[3] : 1000000 - - outRBC_lead_lags = try RBC_lead_lags.SS_solve_func(RBC_lead_lags.parameter_values, RBC_lead_lags, false, verbose, par_inputs, x[end]) catch end - - total_iters += outRBC_lead_lags isa Tuple{Vector{Float64}, Float64, Int64} ? (outRBC_lead_lags[2] > eps(Float64)) || !isfinite(outRBC_lead_lags[2]) ? 1000000 : outRBC_lead_lags[3] : 1000000 - - outRBC_param = try RBC_param.SS_solve_func(RBC_param.parameter_values, RBC_param, false, verbose, par_inputs, x[end]) catch end - - total_iters += outRBC_param isa Tuple{Vector{Float64}, Float64, Int64} ? (outRBC_param[2] > eps(Float64)) || !isfinite(outRBC_param[2]) ? 1000000 : outRBC_param[3] : 1000000 - - # total_iters >= 1000000 ? NaN : total_iters + total_iters = 0 + for model in all_models + total_iters += calc_total_iters(model, par_inputs, x[end]) + end - total_iters_pars = sum(abs2,vcat(x[[3,4]]...,[1 .- x[12:19]]...)) * 10 + total_iters_pars = sum(abs2,vcat(x[[3,4]]..., [1 .- x[12:19]]..., x[21] / 100)) * 10 # println(total_iters) - return Float64(total_iters + total_iters_pars),total_iters + return Float64(total_iters + total_iters_pars), total_iters end) -innit = [ - 3.307670699324403 - 0.8887 - 0.023813243535282552 - 0.026833357448752496 - 2.442999997612768 - 1.49949375 - 0.0008014110419103691 - 0.041527311524283926 - 0.048143903530580914 - 0.0033122894690720854 - 0.5401102854078268 - 0.11292946464826276 - 0.00011413295389511516 - 0.6553524666109665 - 0.02388678809616366 - 0.99778 - 0.00011413295389511516 - 0.6553524666109665 - 0.02388678809616366 - 0.99778 - 1.0 - 3.0 -] - - - -innit = [ - 2.1463884211036226 - 0.9929437566596109 - 0.6773423825308124 - 0.0 - 4.435883184171622 - 0.1545259444769216 - 0.16236330077946382 - 0.04628182054753979 - 0.5711216406099425 - 0.0 - 0.6804997522959056 - 0.8391805314686501 - 0.15117829923684067 - 0.08883112140047633 - 0.7130603312464207 - 0.935850006981596 -] - -innit = [ - 5.0 - 0.8725 - 0.0027 - 0.0 - 8.04 - 0.0 - 0.076 - 0.235 - 0.51 - 0.0 - 0.62 - 0.422 - 1.0 - 0.5047 - 1.0 - 0.422 - 1.0 - 0.5047 - 1.0 - 1.0 - 2.0 - 0.7688 -] +# innit = [ +# 3.307670699324403 +# 0.8887 +# 0.023813243535282552 +# 0.026833357448752496 +# 2.442999997612768 +# 1.49949375 +# 0.0008014110419103691 +# 0.041527311524283926 +# 0.048143903530580914 +# 0.0033122894690720854 +# 0.5401102854078268 +# 0.11292946464826276 +# 0.00011413295389511516 +# 0.6553524666109665 +# 0.02388678809616366 +# 0.99778 +# 0.00011413295389511516 +# 0.6553524666109665 +# 0.02388678809616366 +# 0.99778 +# 1.0 +# 3.0 +# ] + + + +# innit = [ +# 2.1463884211036226 +# 0.9929437566596109 +# 0.6773423825308124 +# 0.0 +# 4.435883184171622 +# 0.1545259444769216 +# 0.16236330077946382 +# 0.04628182054753979 +# 0.5711216406099425 +# 0.0 +# 0.6804997522959056 +# 0.8391805314686501 +# 0.15117829923684067 +# 0.08883112140047633 +# 0.7130603312464207 +# 0.935850006981596 +# ] + +# innit = [ +# 5.0 +# 0.8725 +# 0.0027 +# 0.0 +# 8.04 +# 0.0 +# 0.076 +# 0.235 +# 0.51 +# 0.0 +# 0.62 +# 0.422 +# 1.0 +# 0.5047 +# 1.0 +# 0.422 +# 1.0 +# 0.5047 +# 1.0 +# 1.0 +# 0.0 +# 2.0 +# 0.7688 +# ] innit = [ @@ -213,7 +176,8 @@ innit = [ 1 1 2.5 - 3 + 0.0 + 2.55 0.5 ] @@ -221,26 +185,144 @@ innit = [ lbs = zero(innit) # lbs .+= eps()*2 -lbs[21] = -.5 -lbs[21] = 2 +lbs[20] = -.5 +lbs[21] = -100 +lbs[22] = 2.45 lbs[end] = -100 + ubs = zero(innit) ubs .+= 1 ubs[1:2] .= 10 ubs[5:6] .= 100 ubs[20] = 4.5 -ubs[21] = 3 +ubs[21] = 100 +ubs[22] = 2.55 ubs[end] = 100 prob = OptimizationProblem(f, innit, false, lb = lbs, ub = ubs) f(innit,true) +# using BenchmarkTools + +# max_minutes = 1 * 60 +max_hours = 24 * 60 ^ 2 +# Start 1200 (PT time) + +sol_ESCH = solve(prob, NLopt.GN_ESCH(), maxtime = max_hours); sol_ESCH.minimum + +innit2 = deepcopy(sol_ESCH.u) + + + +@benchmark f(innit2,true) + + + +x = innit2 + + + + +x[1:2] = sort(x[1:2], rev = true) + +par_inputs = MacroModelling.solver_parameters( + eps(),eps(),250, x[1], x[2], x[3], x[4], x[5], x[6], x[7], x[8], x[9], x[10], x[11], x[12], x[13], x[14], x[15], x[16], x[17], x[18], x[19],Int(abs(round(x[20]))),x[21],Int(abs(round(x[22]))) +) + +total_iters = 0 +for model in all_models + iter = calc_total_iters(model, par_inputs, x[end]) + println(iter, "\t ", model.model_name) + total_iters += iter +end +total_iters + + +x[1:2] = sort(x[1:2], rev = true) + +par_inputs = MacroModelling.solver_parameters( + eps(),eps(),250, x[1], x[2], x[3], x[4], x[5], x[6], x[7], x[8], x[9], x[10], x[11], x[12], x[13], x[14], x[15], x[16], x[17], x[18], x[19],Int(abs(round(x[20]))),x[21],Int(abs(round(x[22]))) +) + +@benchmark calc_total_iters(NAWM_EAUS_2008, par_inputs, x[23]) + +@benchmark calc_total_iters(Guerrieri_Iacoviello_2017, par_inputs, x[23]) + +calc_total_iters(Aguiar_Gopinath_2007, par_inputs, x[end]) + +calc_total_iters(Ascari_Sbordone_2014, par_inputs, x[23]) + +calc_total_iters(FS2000, par_inputs, x[23]) + +calc_total_iters(SW03, par_inputs, x[end]) + +calc_total_iters(SW07, par_inputs, x[end]) + + +model = Backus_Kehoe_Kydland_1992 +starting_point = .9#x[end] +outmodel = model.SS_solve_func(model.parameter_values, model, false, starting_point, par_inputs) + + outmodel isa Tuple{Vector{Float64}, Tuple{Float64, Int64}} ? + (outmodel[2][1] > eps(Float64)) || !isfinite(outmodel[2][1]) ? + 1000000 : + outmodel[2][2] : + 1000000 + + + +innit2 = [ 2.9286687462521286 +1.0934322881820666 +8.040292279055312e-5 +0.0010349673716525869 +9.612040527215113 +50.1236879266217 +0.5669837295436179 +0.5151760400524997 +0.44424209515580787 +0.0017803001645317015 +0.20165426073261922 +0.9893989333367081 +0.9992664322446558 +0.9947474775878444 +0.9947619544912081 +0.9758001846468876 +0.992316474092166 +0.9753918769395817 +0.9907848466210624 +0.5322997748902552 +0.0007004948302871516 +2.4590286886069483 +25.260971258391464] + +x = sol_ESCH.u + + +x[1:2] = sort(x[1:2], rev = true) + +par_inputs = MacroModelling.solver_parameters( + eps(),eps(),250, x[1], x[2], x[3], x[4], x[5], x[6], x[7], x[8], x[9], x[10], x[11], x[12], x[13], x[14], x[15], x[16], x[17], x[18], x[19],Int(abs(round(x[20]))),x[21],Int(abs(round(x[22]))) +) + +calc_total_iters(NAWM_EAUS_2008, par_inputs, x[end]) + +calc_total_iters(Guerrieri_Iacoviello_2017,innit2[1:end-1],innit[end]) +innit2 +sort(innit2[1:2], rev = true) +x = innit2 +par_inputs = MacroModelling.solver_parameters( + eps(),eps(),250, x[1], x[2], x[3], x[4], x[5], x[6], x[7], x[8], x[9], x[10], x[11], x[12], x[13], x[14], x[15], x[16], x[17], x[18], x[19],Int(abs(round(x[20]))),x[21],Int(abs(round(x[22]))) + ) + + +calc_total_iters(Guerrieri_Iacoviello_2017,par_inputs,innit2[end]) + +Guerrieri_Iacoviello_2017.SS_solve_func(Guerrieri_Iacoviello_2017.parameter_values, Guerrieri_Iacoviello_2017, false, innit2[end], par_inputs) + + -maxt = 10 * 60 -sol_ESCH = solve(prob, NLopt.GN_ESCH(), maxtime = maxt); sol_ESCH.minimum -innit = sol_ESCH.u innit = [7.971710350206478 0.9041767277613695 0.02578560981066282 @@ -321,6 +403,8 @@ f(innit, true) f(round.(innit, digits = 8),false) +prob = OptimizationProblem(f, innit2, false, lb = lbs, ub = ubs) + sol_BOBYQA = solve(prob, NLopt.LN_BOBYQA()); sol_BOBYQA.minimum # fast and solves sol_SBPLX = solve(prob, NLopt.LN_SBPLX()); sol_SBPLX.minimum @@ -354,6 +438,113 @@ sol_Multi = solve(prob, MultistartOptimization.TikTak(40), NLopt.LN_SBPLX()); so sol_Multi = solve(prob, NLopt.G_MLSL_LDS(), local_method = NLopt.LN_SBPLX(), maxtime = maxt) + + + + + + + + + + +all_models = [ + # m, + # Backus_Kehoe_Kydland_1992, + # Baxter_King_1993, + # SW03, + # GNSS_2010, + # Ghironi_Melitz_2005, + # SGU_2003_debt_premium, + # NAWM_EAUS_2008, + # JQ_2012_RBC, + # Ireland_2004, + # Caldara_et_al_2012, + # Gali_Monacelli_2005_CITR, + # Gali_2015_chapter_3_nonlinear, + # Aguiar_Gopinath_2007, + # Ascari_Sbordone_2014, + # FS2000, + # SW07, + Guerrieri_Iacoviello_2017 +]; + + + +function calc_total_iters(model, par_inputs, starting_point) + outmodel = try model.SS_solve_func(model.parameter_values, model, false, starting_point, par_inputs) catch end + # outmodel = model.SS_solve_func(model.parameter_values, model, false, starting_point, par_inputs) + + outmodel isa Tuple{Vector{Float64}, Tuple{Float64, Int64}} ? + (outmodel[2][1] > eps(Float64)) || !isfinite(outmodel[2][1]) ? + 1000000 : + outmodel[2][2] : + 1000000 +end + + +f = OptimizationFunction((x,verbose)-> begin + total_iters = 0 + + # x[1:2] = sort(x[1:2], rev = true) + + # par_inputs = MacroModelling.solver_parameters( + # eps(),eps(),250, x[1], x[2], x[3], x[4], x[5], x[6], x[7], x[8], x[9], x[10], x[11], x[12], x[13], x[14], x[15], x[16], x[17], x[18], x[19],Int(abs(round(x[20]))),x[21],Int(abs(round(x[22]))) + # ) + + total_iters = 0 + for model in all_models + total_iters += calc_total_iters(model, model.solver_parameters, x[end]) + end + + # total_iters_pars = sum(abs2,vcat(x[[3,4]]..., [1 .- x[12:19]]..., x[21] / 100)) * 10 + + return Float64(total_iters), total_iters +end) + +innit = [ + 0.5 +] + + + +lbs = zero(innit) +# lbs .+= eps()*2 +# lbs[20] = -.5 +# lbs[21] = -100 +# lbs[22] = 2.45 +lbs[end] = -100 + +ubs = zero(innit) +ubs .+= 1 +# ubs[1:2] .= 10 +# ubs[5:6] .= 100 +# ubs[20] = 4.5 +# ubs[21] = 100 +# ubs[22] = 2.55 +ubs[end] = 100 + +prob = OptimizationProblem(f, innit, false, lb = lbs, ub = ubs) + +maxt = 10 * 60 +using OptimizationBBO +sol_BBO = solve(prob, BBO_adaptive_de_rand_1_bin_radiuslimited(), maxtime = maxt); sol_BBO.minimum #gets the far off parameters when only few models are involved + +sol_BBO.u +f(sol_BBO.u, false) + + +# 71.69060992965288 works +Guerrieri_Iacoviello_2017.SS_solve_func(Guerrieri_Iacoviello_2017.parameter_values, Guerrieri_Iacoviello_2017, false, sol_BBO.u[1], Guerrieri_Iacoviello_2017.solver_parameters) + + +sol_ESCH = solve(prob, NLopt.GN_ESCH(), maxtime = maxt); sol_ESCH.minimum + +f(71.69,[]) +Guerrieri_Iacoviello_2017.SS_solve_func(Guerrieri_Iacoviello_2017.parameter_values, Guerrieri_Iacoviello_2017, false, sol_ESCH.u[1], Guerrieri_Iacoviello_2017.solver_parameters) +Guerrieri_Iacoviello_2017.SS_solve_func(Guerrieri_Iacoviello_2017.parameter_values, Guerrieri_Iacoviello_2017, false, 0.0-10*eps(Float32), Guerrieri_Iacoviello_2017.solver_parameters) + + innit = xx xx = innit sqrt(170) diff --git a/docs/Project.toml b/docs/Project.toml index 22073006..f0bf4fb9 100644 --- a/docs/Project.toml +++ b/docs/Project.toml @@ -11,6 +11,7 @@ MCMCChains = "c7f686f2-ff18-58e9-bc7b-31028e88f75d" MCMCDiagnosticTools = "be115224-59cd-429b-ad48-344e309966f0" MacroModelling = "687ffad2-3618-405e-ac50-e0f7b9c75e44" Optim = "429524aa-4258-5aef-a3af-852621145aeb" +Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" StatsPlots = "f3b207a7-027a-5e70-b257-86293d7955fd" Turing = "fce5fe82-541a-59a6-adf8-730c64b5f9a0" diff --git a/docs/make.jl b/docs/make.jl index f7d98f83..18dae71e 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -14,6 +14,8 @@ makedocs( sitename = "MacroModelling.jl", authors = "Thore Kockerols", doctest = true, + # doctest = false, + # draft = true, format = Documenter.HTML(size_threshold = 204800*10), modules = [MacroModelling], pages = [ @@ -27,6 +29,7 @@ makedocs( ], "How-to guides" => [ "Programmatic model writing using for-loops" => "how-to/loops.md", + "Occasionally binding constraints" => "how-to/obc.md", # "how_to.md" ], # "Model syntax" => "dsl.md", diff --git a/docs/src/assets/Gali_2015_chapter_3_obc__eps_z.png b/docs/src/assets/Gali_2015_chapter_3_obc__eps_z.png new file mode 100644 index 00000000..0fbfe3ea Binary files /dev/null and b/docs/src/assets/Gali_2015_chapter_3_obc__eps_z.png differ diff --git a/docs/src/assets/Gali_2015_chapter_3_obc__shock_matrix__1.png b/docs/src/assets/Gali_2015_chapter_3_obc__shock_matrix__1.png new file mode 100644 index 00000000..f9b2e6b0 Binary files /dev/null and b/docs/src/assets/Gali_2015_chapter_3_obc__shock_matrix__1.png differ diff --git a/docs/src/assets/Gali_2015_chapter_3_obc__simulation__1.png b/docs/src/assets/Gali_2015_chapter_3_obc__simulation__1.png new file mode 100644 index 00000000..54cf82da Binary files /dev/null and b/docs/src/assets/Gali_2015_chapter_3_obc__simulation__1.png differ diff --git a/docs/src/assets/Gali_2015_chapter_3_obc__simulation__2.png b/docs/src/assets/Gali_2015_chapter_3_obc__simulation__2.png new file mode 100644 index 00000000..69633619 Binary files /dev/null and b/docs/src/assets/Gali_2015_chapter_3_obc__simulation__2.png differ diff --git a/docs/src/assets/Gali_2015_chapter_3_obc__simulation__no.png b/docs/src/assets/Gali_2015_chapter_3_obc__simulation__no.png new file mode 100644 index 00000000..d14e4c7e Binary files /dev/null and b/docs/src/assets/Gali_2015_chapter_3_obc__simulation__no.png differ diff --git a/docs/src/assets/borrowing_constraint__no_obc.png b/docs/src/assets/borrowing_constraint__no_obc.png new file mode 100644 index 00000000..b6f8e67f Binary files /dev/null and b/docs/src/assets/borrowing_constraint__no_obc.png differ diff --git a/docs/src/assets/borrowing_constraint__obc.png b/docs/src/assets/borrowing_constraint__obc.png new file mode 100644 index 00000000..08d59ca6 Binary files /dev/null and b/docs/src/assets/borrowing_constraint__obc.png differ diff --git "a/docs/src/assets/borrowing_constraint__\316\265_neg.png" "b/docs/src/assets/borrowing_constraint__\316\265_neg.png" new file mode 100644 index 00000000..e8deaee1 Binary files /dev/null and "b/docs/src/assets/borrowing_constraint__\316\265_neg.png" differ diff --git "a/docs/src/assets/borrowing_constraint__\316\265_pos.png" "b/docs/src/assets/borrowing_constraint__\316\265_pos.png" new file mode 100644 index 00000000..77488072 Binary files /dev/null and "b/docs/src/assets/borrowing_constraint__\316\265_pos.png" differ diff --git a/docs/src/how-to/loops.md b/docs/src/how-to/loops.md index 8a3388e5..6c068aae 100644 --- a/docs/src/how-to/loops.md +++ b/docs/src/how-to/loops.md @@ -49,7 +49,14 @@ Note that the package internally writes out the for loop and creates two equatio Putting these these elements together we can write the multi-country model equations of the Backus, Kehoe and Kydland (1992) model like this: -```julia +```@setup howto_loops +ENV["GKSwstype"] = "100" +using Random +Random.seed!(30) +``` + +```@repl howto_loops +using MacroModelling @model Backus_Kehoe_Kydland_1992 begin for co in [H, F] Y{co}[0] = ((LAMBDA{co}[0] * K{co}[-4]^theta{co} * N{co}[0]^(1 - theta{co}))^(-nu{co}) + sigma{co} * Z{co}[-1]^(-nu{co}))^(-1 / nu{co}) @@ -132,7 +139,7 @@ y_ratio = 0.9 Making use of this and continuing the example of the Backus, Kehoe and Kydland (1992) model we can define the parameters as follows: -```julia +```@repl howto_loops @parameters Backus_Kehoe_Kydland_1992 begin F_H_ratio = .9 K{F}[ss] / K{H}[ss] = F_H_ratio | beta{F} diff --git a/docs/src/how-to/obc.md b/docs/src/how-to/obc.md new file mode 100644 index 00000000..2dd14c1f --- /dev/null +++ b/docs/src/how-to/obc.md @@ -0,0 +1,465 @@ +# Occasionally Binding Constraints + +Occasionally binding constraints are a form of nonlinearity frequently used to model effects like the zero lower bound on interest rates, or borrowing constraints. Perturbation methods are not able to capture them as they are local approximations. Nonetheless, there are ways to combine the speed of perturbation solutions and the flexibility of occasionally binding constraints. `MacroModelling.jl` provides a convenient way to write down the constraints and automatically enforces the constraint equation with shocks. More specifically, the constraint equation is enforced for each periods unconditional forecast (default forecast horizon of 40 periods) by constraint equation specific anticipated shocks, while minimising the shock size. + +This guide will demonstrate how to write down models containing occasionally binding constraints (e.g. effective lower bound and borrowing constraint), show some potential problems the user may encounter and how to overcome them, and go through some use cases. + +Common problems that may occur are that no perturbation solution is found, or that the algorithm cannot find a combination of shocks which enforce the constraint equation. The former has to do with the fact that occasionally binding constraints can give rise to more than one steady state but only one is suitable for a perturbation solution. The latter has to do with the dynamics of the model and the fact that we use a finite amount of shocks to enforce the constraint equation. + +Beyond the examples outlined in this guide there is a version of Smets and Wouters (2003) with the ELB in the models folder (filename: `SW03_obc.jl`). + +## Example: Effective lower bound on interest rates + +### Writing a model with occasionally binding constraints + +Let us take the [gali2015; Chapter 3](@citet) model containing a Taylor rule and implement an effective lower bound on interest rates. The Taylor rule in the model: `R[0] = 1 / β * Pi[0] ^ ϕᵖⁱ * (Y[0] / Y[ss]) ^ ϕʸ * exp(nu[0])` needs to be modified so that `R[0]` never goes below an effective lower bound `R̄`. We can do this using the `max` operator: `R[0] = max(R̄ , 1 / β * Pi[0] ^ ϕᵖⁱ * (Y[0] / Y[ss]) ^ ϕʸ * exp(nu[0]))` + +The model definition after the change of the Taylor rule looks like this: + +```@setup howto_obc +ENV["GKSwstype"] = "100" +using Random +Random.seed!(30) +``` + +```@repl howto_obc +using MacroModelling +@model Gali_2015_chapter_3_obc begin + W_real[0] = C[0] ^ σ * N[0] ^ φ + + [0] = β * (C[1] / C[0]) ^ (-σ) * Z[1] / Z[0] / Pi[1] + + R[0] = 1 / Q[0] + + Y[0] = A[0] * (N[0] / S[0]) ^ (1 - α) + + R[0] = Pi[1] * realinterest[0] + + C[0] = Y[0] + + log(A[0]) = ρ_a * log(A[-1]) + std_a * eps_a[x] + + log(Z[0]) = ρ_z * log(Z[-1]) - std_z * eps_z[x] + + nu[0] = ρ_ν * nu[-1] + std_nu * eps_nu[x] + + MC[0] = W_real[0] / (S[0] * Y[0] * (1 - α) / N[0]) + + 1 = θ * Pi[0] ^ (ϵ - 1) + (1 - θ) * Pi_star[0] ^ (1 - ϵ) + + S[0] = (1 - θ) * Pi_star[0] ^ (( - ϵ) / (1 - α)) + θ * Pi[0] ^ (ϵ / (1 - α)) * S[-1] + + Pi_star[0] ^ (1 + ϵ * α / (1 - α)) = ϵ * x_aux_1[0] / x_aux_2[0] * (1 - τ) / (ϵ - 1) + + x_aux_1[0] = MC[0] * Y[0] * Z[0] * C[0] ^ (-σ) + β * θ * Pi[1] ^ (ϵ + α * ϵ / (1 - α)) * x_aux_1[1] + + x_aux_2[0] = Y[0] * Z[0] * C[0] ^ (-σ) + β * θ * Pi[1] ^ (ϵ - 1) * x_aux_2[1] + + log_y[0] = log(Y[0]) + + log_W_real[0] = log(W_real[0]) + + log_N[0] = log(N[0]) + + pi_ann[0] = 4 * log(Pi[0]) + + i_ann[0] = 4 * log(R[0]) + + r_real_ann[0] = 4 * log(realinterest[0]) + + M_real[0] = Y[0] / R[0] ^ η + + R[0] = max(R̄ , 1 / β * Pi[0] ^ ϕᵖⁱ * (Y[0] / Y[ss]) ^ ϕʸ * exp(nu[0])) + +end +``` + +In the background the system of equations is augmented by a series of anticipated shocks added to the equation containing the constraint (max/min operator). This explains the large number of auxilliary variables and shocks. + +Next we define the parameters including the new parameter defining the effective lower bound (which we set to 1, which implements a zero lower bound): + +```@repl howto_obc +@parameters Gali_2015_chapter_3_obc begin + R̄ = 1.0 + + σ = 1 + + φ = 5 + + ϕᵖⁱ = 1.5 + + ϕʸ = 0.125 + + θ = 0.75 + + ρ_ν = 0.5 + + ρ_z = 0.5 + + ρ_a = 0.9 + + β = 0.99 + + η = 3.77 + + α = 0.25 + + ϵ = 9 + + τ = 0 + + std_a = .01 + + std_z = .05 + + std_nu = .0025 + +end +``` + +### Verify the non stochastic steady state + +Let's check out the non stochastic steady state (NSSS): + +```@repl howto_obc +SS(Gali_2015_chapter_3_obc) +``` + +There are a few things to note here. First, we get the NSSS values of the auxilliary variables related to the occasionally binding constraint. Second, the NSSS value of `R` is 1, and thereby the effective lower bound is binding in the NSSS. While this is a viable NSSS it is not a viable approximation point for perturbation. We can only find a perturbation solution if the effective lower bound is not binding in NSSS. Calling `get_solution` reveals that there is no stable solution at this NSSS: + +```@repl howto_obc +get_solution(Gali_2015_chapter_3_obc) +``` + +In order to get the other viable NSSS we have to restrict the values of R to be larger than the effective lower bound. We can do this by adding a constraint on the variable in the `@parameter` section. Let us redefine the model: + +```@repl howto_obc +@model Gali_2015_chapter_3_obc begin + W_real[0] = C[0] ^ σ * N[0] ^ φ + + Q[0] = β * (C[1] / C[0]) ^ (-σ) * Z[1] / Z[0] / Pi[1] + + R[0] = 1 / Q[0] + + Y[0] = A[0] * (N[0] / S[0]) ^ (1 - α) + + R[0] = Pi[1] * realinterest[0] + + C[0] = Y[0] + + log(A[0]) = ρ_a * log(A[-1]) + std_a * eps_a[x] + + log(Z[0]) = ρ_z * log(Z[-1]) - std_z * eps_z[x] + + nu[0] = ρ_ν * nu[-1] + std_nu * eps_nu[x] + + MC[0] = W_real[0] / (S[0] * Y[0] * (1 - α) / N[0]) + + 1 = θ * Pi[0] ^ (ϵ - 1) + (1 - θ) * Pi_star[0] ^ (1 - ϵ) + + S[0] = (1 - θ) * Pi_star[0] ^ (( - ϵ) / (1 - α)) + θ * Pi[0] ^ (ϵ / (1 - α)) * S[-1] + + Pi_star[0] ^ (1 + ϵ * α / (1 - α)) = ϵ * x_aux_1[0] / x_aux_2[0] * (1 - τ) / (ϵ - 1) + + x_aux_1[0] = MC[0] * Y[0] * Z[0] * C[0] ^ (-σ) + β * θ * Pi[1] ^ (ϵ + α * ϵ / (1 - α)) * x_aux_1[1] + + x_aux_2[0] = Y[0] * Z[0] * C[0] ^ (-σ) + β * θ * Pi[1] ^ (ϵ - 1) * x_aux_2[1] + + log_y[0] = log(Y[0]) + + log_W_real[0] = log(W_real[0]) + + log_N[0] = log(N[0]) + + pi_ann[0] = 4 * log(Pi[0]) + + i_ann[0] = 4 * log(R[0]) + + r_real_ann[0] = 4 * log(realinterest[0]) + + M_real[0] = Y[0] / R[0] ^ η + + R[0] = max(R̄ , 1 / β * Pi[0] ^ ϕᵖⁱ * (Y[0] / Y[ss]) ^ ϕʸ * exp(nu[0])) + +end + +@parameters Gali_2015_chapter_3_obc begin + R̄ = 1.0 + + σ = 1 + + φ = 5 + + ϕᵖⁱ = 1.5 + + ϕʸ = 0.125 + + θ = 0.75 + + ρ_ν = 0.5 + + ρ_z = 0.5 + + ρ_a = 0.9 + + β = 0.99 + + η = 3.77 + + α = 0.25 + + ϵ = 9 + + τ = 0 + + std_a = .01 + + std_z = .05 + + std_nu = .0025 + + R > 1.000001 +end +``` + +and check the NSSS once more: + +```@repl howto_obc +SS(Gali_2015_chapter_3_obc) +``` + +Now we get `R > R̄`, so that the constraint is not binding in the NSSS and we can work with a stable first order solution: + +```@repl howto_obc +get_solution(Gali_2015_chapter_3_obc) +``` + +### Generate model output + +Having defined the system with an occasionally binding constraint we can simply simulate the model by calling: + +```@repl howto_obc +import StatsPlots +plot_simulations(Gali_2015_chapter_3_obc) +``` + +![Simulation_elb](../assets/Gali_2015_chapter_3_obc__simulation__1.png) + +In the background an optimisation problem is set up to find the smallest shocks in magnitude which enforce the equation containing the occasionally binding constraint over the unconditional forecast horizon (default 40 periods) at each period of the simulation. The plots show multiple spells of a binding effective lower bound and many other variables are skewed as a result of the nonlinearity. It can happen that it is not possible to find a combination of shocks which enforce the occasionally binding constraint equation. In this case one solution can be to make the horizon larger over which the algorithm tries to enforce the equation. You can do this by setting the parameter at the beginning of the `@model` section: `@model Gali_2015_chapter_3_obc max_obc_horizon = 60 begin ... end`. + +Next let us change the effective lower bound to `0.99` and plot once more: + +```@repl howto_obc +plot_simulations(Gali_2015_chapter_3_obc, parameters = :R̄ => 0.99) +``` + +![Simulation_elb2](../assets/Gali_2015_chapter_3_obc__simulation__2.png) + +Now, the effect of the effective lower bound becomes less important as it binds less often. + +If you want to ignore the occasionally binding constraint you can simply call: + +```@repl howto_obc +plot_simulations(Gali_2015_chapter_3_obc, ignore_obc = true) +``` + +![Simulation_no_elb](../assets/Gali_2015_chapter_3_obc__simulation__no.png) + +and you get the simulation based on the first order solution approximated around the NSSS, which is the same as the one for the model without the modified Taylor rule. + +We can plot the impulse response functions for the `eps_z` shock, while setting the parameter of the occasionally binding constraint back to `1`, as follows: + +```@repl howto_obc +plot_irf(Gali_2015_chapter_3_obc, shocks = :eps_z, parameters = :R̄ => 1.0) +``` + +![IRF_elb](../assets/Gali_2015_chapter_3_obc__eps_z.png) + +As you can see `R` remains above the effective lower bound in the first period. + +Next, let us simulate the model using a series of shocks. E.g. three positive shocks to `eps_z` in periods 5, 10, and 15 in decreasing magnitude: + +```@repl howto_obc +shcks = zeros(1,15) +shcks[5] = 3.0 +shcks[10] = 2.0 +shcks[15] = 1.0 + +sks = KeyedArray(shcks; Shocks = [:eps_z], Periods = 1:15) + +plot_irf(Gali_2015_chapter_3_obc, shocks = sks, periods = 10) +``` + +![Shock_series_elb](../assets/Gali_2015_chapter_3_obc__shock_matrix__1.png) + +The effective lower bound is binding after all three shocks but the length of the constraint being binding varies with the shock size and is completely endogenous. + +Last but not least, we can get the simulated moments of the model (theoretical moments are not available): + +```@repl howto_obc +sims = get_irf(Gali_2015_chapter_3_obc, periods = 1000, shocks = :simulate, levels = true) +``` + +Let's look at the mean and standard deviation of borrowing: + +```@repl howto_obc +import Statistics +Statistics.mean(sims(:Y,:,:)) +``` + +and + +```@repl howto_obc +Statistics.std(sims(:Y,:,:)) +``` + +Compare this to the theoretical mean of the model without the occasionally binding constraint: + +```@repl howto_obc +get_mean(borrowing_constraint) +``` + +and the theoretical standard deviation: + +```@repl howto_obc +get_std(borrowing_constraint) +``` + +The mean of output is lower in the model with effective lower bound compared to the model without and the standard deviation is higher. + +## Example: Borrowing constraint + +### Model definition + +Let us start with a consumption-saving model containing a borrowing constraint (see [@citet cuba2019likelihood] for details). Output is exogenously given, and households can only borrow up to a fraction of output and decide between saving and consumption. The first order conditions of the model are: + +```math +\begin{align*} +Y_t + B_t &= C_t + R B_{t-1}\\ +\log(Y_t) &= \rho \log(Y_{t-1}) + \sigma \varepsilon_t\\ +C_t^{-\gamma} &= \beta R \mathbb{E}_t (C_{t+1}^{-\gamma}) + \lambda_t\\ +0 &= \lambda_t (B_t - mY_t) +\end{align*} +``` + +in order to write this model down we need to express the Karush-Kuhn-Tucker condition (last equation) using a max (or min) operator, so that it becomes: + +```math +0 = \max(B_t - mY_t, -\lambda_t) +``` + +We can write this model containing an occasionally binding constraint in a very convenient way: + +```@repl howto_obc +@model borrowing_constraint begin + Y[0] + B[0] = C[0] + R * B[-1] + + log(Y[0]) = ρ * log(Y[-1]) + σ * ε[x] + + C[0]^(-γ) = β * R * C[1]^(-γ) + λ[0] + + 0 = max(B[0] - m * Y[0], -λ[0]) +end +``` + +In the background the system of equations is augmented by a series of anticipated shocks added to the equation containing the constraint (max/min operator). This explains the large number of auxilliary variables and shocks. + +Next we define the parameters as usual: + +```@repl howto_obc +@parameters borrowing_constraint begin + R = 1.05 + β = 0.945 + ρ = 0.9 + σ = 0.05 + m = 1 + γ = 1 +end +``` + +### Working with the model + +For the non stochastic steady state (NSSS) to exist the constraint has to be binding (`B[0] = m * Y[0]`). This implies a wedge in the Euler equation (`λ > 0`). + +We can check this by getting the NSSS: + +```@repl howto_obc +SS(borrowing_constraint) +``` + +A common task is to plot impulse response function for positive and negative shocks. This should allow us to understand the role of the constraint. + +First, we need to import the StatsPlots package and then we can plot the positive shock. + +```@repl howto_obc +import StatsPlots +plot_irf(borrowing_constraint) +``` + +![Positive_shock](../assets/borrowing_constraint__ε_pos.png) + +We can see that the constraint is no longer binding in the first five periods because `Y` and `B` do not increase by the same amount. They should move by the same amount in the case of a negative shock: + +```@repl howto_obc +import StatsPlots +plot_irf(borrowing_constraint, negative_shock = true) +``` + +![Negative_shock](../assets/borrowing_constraint__ε_neg.png) + +and indeed in this case they move by the same amount. The difference between a positive and negative shock demonstrates the influence of the occasionally binding constraint. + +Another common exercise is to plot the impulse response functions from a series of shocks. Let's assume in period 10 there is a positive shocks and in period 30 a negative one. Let's view the results for 50 more periods. We can do this as follows: + +```@repl howto_obc +shcks = zeros(1,30) +shcks[10] = .6 +shcks[30] = -.6 + +sks = KeyedArray(shcks; Shocks = [:ε], Periods = 1:30) + +plot_irf(borrowing_constraint, shocks = sks, periods = 50) +``` + +![Simulation](../assets/borrowing_constraint__obc.png) + +In this case the difference between the shocks and the impact of the constraint become quite obvious. Let's compare this with a version of the model that ignores the occasionally binding constraint. In order to plot the impulse response functions without dynamically enforcing the constraint we can simply write: + +```@repl howto_obc +plot_irf(borrowing_constraint, shocks = sks, periods = 50, ignore_obc = true) +``` + +![Simulation](../assets/borrowing_constraint__no_obc.png) + +Another interesting statistic is model moments. As there are no theoretical moments we have to rely on simulated data: + +```@repl howto_obc +sims = get_irf(borrowing_constraint, periods = 1000, shocks = :simulate, levels = true) +``` + +Let's look at the mean and standard deviation of borrowing: + +```@repl howto_obc +import Statistics +Statistics.mean(sims(:B,:,:)) +``` + +and + +```@repl howto_obc +Statistics.std(sims(:B,:,:)) +``` + +Compare this to the theoretical mean of the model without the occasionally binding constraint: + +```@repl howto_obc +get_mean(borrowing_constraint) +``` + +and the theoretical standard deviation: + +```@repl howto_obc +get_std(borrowing_constraint) +``` + +The mean of borrowing is lower in the model with occasionally binding constraints compared to the model without and the standard deviation is higher. diff --git a/docs/src/index.md b/docs/src/index.md index 8d4f24c3..e6994574 100644 --- a/docs/src/index.md +++ b/docs/src/index.md @@ -2,7 +2,9 @@ **Author: Thore Kockerols (@thorek1)** -`MacroModelling.jl` is a Julia package for developing and solving dynamic stochastic general equilibrium (DSGE) models. These kinds of models describe the behavior of a macroeconomy and are particularly suited for counterfactual analysis (economic policy evaluation) and exploring / quantifying specific mechanisms (academic research). Due to the complexity of these models, efficient numerical tools are required, as analytical solutions are often unavailable. `MacroModelling.jl` serves as a tool for handling the complexities involved, such as forward-looking expectations, nonlinearity, and high dimensionality. +`MacroModelling.jl` is a Julia package for developing and solving dynamic stochastic general equilibrium (DSGE) models. + +These kinds of models describe the behavior of a macroeconomy and are particularly suited for counterfactual analysis (economic policy evaluation) and exploring / quantifying specific mechanisms (academic research). Due to the complexity of these models, efficient numerical tools are required, as analytical solutions are often unavailable. `MacroModelling.jl` serves as a tool for handling the complexities involved, such as forward-looking expectations, nonlinearity, and high dimensionality. The goal of this package is to reduce coding time and speed up model development by providing functions for working with discrete-time DSGE models. The user-friendly syntax, automatic variable declaration, and effective steady state solver facilitate fast prototyping of models. Furthermore, the package allows the user to work with nonlinear model solutions (up to third order (pruned) perturbation) and estimate the model using gradient based samplers (e.g. NUTS, of HMC). Currently, `DifferentiableStateSpaceModels.jl` is the only other package providing functionality to estimate using gradient based samplers but the use is limited to models with an analytical solution of the non stochastic steady state (NSSS). Larger models tend to not have an analytical solution of the NSSS and `MacroModelling.jl` can also use gradient based sampler in this case. The target audience for the package includes central bankers, regulators, graduate students, and others working in academia with an interest in DSGE modelling. @@ -11,6 +13,7 @@ As of now the package can: - parse a model written with user friendly syntax (variables are followed by time indices `...[2], [1], [0], [-1], [-2]...`, or `[x]` for shocks) - (tries to) solve the model only knowing the model equations and parameter values (no steady state file needed) - calculate first, second, and third order (pruned) perturbation solutions (see [villemot2011solving](@citet), [andreasen2018pruning](@citet) and [levintal2017fifth](@citet)) using (forward or reverse-mode) automatic differentiation (AD) +- handle occasionally binding constraints - calculate (generalised) impulse response functions, simulate the model, or do conditional forecasts - calibrate parameters using (non stochastic) steady state relationships - match model moments (also for pruned higher order solutions) @@ -31,7 +34,7 @@ The package contains the following models in the `models` folder: - [Aguiar and Gopinath (2007)](https://www.journals.uchicago.edu/doi/10.1086/511283) `Aguiar_Gopinath_2007.jl` - [Ascari and Sbordone (2014)](https://www.aeaweb.org/articles?id=10.1257/jel.52.3.679) `Ascari_sbordone_2014.jl` - [Backus, Kehoe, and Kydland (1992)](https://www.jstor.org/stable/2138686) `Backus_Kehoe_Kydland_1992` -- [Baxter and King (1993)](https://www.jstor.org/stable/2117521) `Baxter_and_King_1993.jl` +- [Baxter and King (1993)](https://www.jstor.org/stable/2117521) `Baxter_King_1993.jl` - [Caldara et al. (2012)](https://www.sciencedirect.com/science/article/abs/pii/S1094202511000433) `Caldara_et_al_2012.jl` - [Gali (2015)](https://press.princeton.edu/books/hardcover/9780691164786/monetary-policy-inflation-and-the-business-cycle) - Chapter 3 `Gali_2015_chapter_3_nonlinear.jl` - [Gali and Monacelli (2005)](https://crei.cat/wp-content/uploads/users/pages/roes8739.pdf) - CPI inflation-based Taylor rule `Gali_Monacelli_2005_CITR.jl` @@ -40,6 +43,7 @@ The package contains the following models in the `models` folder: - [Ireland (2004)](http://irelandp.com/pubs/tshocksnk.pdf) `Ireland_2004.jl` - [Jermann and Quadrini (2012)](https://www.aeaweb.org/articles?id=10.1257/aer.102.1.238) - RBC `JQ_2012_RBC.jl` - [New Area-Wide Model (2008)](https://www.ecb.europa.eu/pub/pdf/scpwps/ecbwp944.pdf) - Euro Area - US `NAWM_EAUS_2008.jl` +- [QUEST3 (2008)](https://www.sciencedirect.com/science/article/abs/pii/S026499930800076X) `QUEST3_2009.jl` - [Schmitt-Grohé and Uribe (2003)](https://www.sciencedirect.com/science/article/abs/pii/S0022199602000569) - debt premium `SGU_2003_debt_premium.jl` - [Schorfheide (2000)](https://onlinelibrary.wiley.com/doi/abs/10.1002/jae.582) `FS2000.jl` - [Smets and Wouters (2003)](https://onlinelibrary.wiley.com/doi/10.1162/154247603770383415) `SW03.jl` @@ -56,7 +60,7 @@ The package contains the following models in the `models` folder: **Perturbation solution order**|1, 2, 3|k|1|1, 2, 3|1, 2, 3|1, 2|1|1|1 to 5|1|1||1 to 5| **Pruning**|yes|yes||||yes|||yes||||| **Automatic derivation of first order conditions**|||||||||||yes|| -**Handles occasionally binding constraints**||yes|yes|yes|yes||||yes|||yes|| +**Handles occasionally binding constraints**|yes|yes|yes|yes|yes||||yes|||yes|| **Global solution**||||yes|yes|||||||yes|| **Estimation**|yes|yes|yes|||||yes|yes|yes|yes||| **Balanced growth path**||yes|yes||||yes|yes|yes|yes||||| diff --git a/docs/src/refs.bib b/docs/src/refs.bib index 9cb28f2a..a9e03aee 100644 --- a/docs/src/refs.bib +++ b/docs/src/refs.bib @@ -6,6 +6,17 @@ @book{durbin2012time doi={10.1093/acprof:oso/9780199641178.001.0001} } +@article{cuba2019likelihood, + title={Likelihood evaluation of models with occasionally binding constraints}, + author={Cuba-Borda, Pablo and Guerrieri, Luca and Iacoviello, Matteo and Zhong, Molin}, + journal={Journal of Applied Econometrics}, + volume={34}, + number={7}, + pages={1073--1085}, + year={2019}, + publisher={Wiley Online Library} +} + @article{andreasen2018pruning, author = {Andreasen, Martin M and Fernández-Villaverde, Jesús and Rubio-Ramírez, Juan F}, title = "{The Pruned State-Space System for Non-Linear DSGE Models: Theory and Empirical Applications}", diff --git a/docs/src/unfinished_docs/todo.md b/docs/src/unfinished_docs/todo.md index f83e375b..24d8fb75 100644 --- a/docs/src/unfinished_docs/todo.md +++ b/docs/src/unfinished_docs/todo.md @@ -2,9 +2,12 @@ ## High priority -- [ ] implement occasionally binding constraints with shocks -- [ ] nonlinear estimation using unscented kalman filter -- [ ] nonlinear conditional forecasts +- [ ] add technical details about SS solver, obc solver, and other algorithms +- [ ] rm obc vars from get_SS +- [ ] functions to reverse state_update (input: previous shock and current state, output previous state), find shocks corresponding to bringing one state to the next +- [ ] cover nested case: min(50,a+b+max(c,10)) +- [ ] nonlinear estimation using unscented kalman filter / inversion filter (minimization problem: find shocks to match states with data) +- [ ] nonlinear conditional forecasts for higher order and obc - [ ] add balanced growth path handling - [ ] feedback: write out RBC equations, provide option for external SS guess, sell the sampler better (ESS vs dynare), more details on algorithm (SS solver) - [ ] higher order solutions: some kron matrix mults are later compressed. write custom compressed kron mult; check if sometimes dense mult is faster? (e.g. GNSS2010 seems dense at higher order) @@ -66,6 +69,9 @@ - [ ] weed out SS solver and saved objects - [x] check if higher order effects might distort results for autocorr (problem with order deffinition) - doesnt seem to be the case; full_covar yields same result +- [x] implement occasionally binding constraints with shocks +- [x] add QUEST3 tests +- [x] add obc tests - [x] highlight NUTS sampler compatibility - [x] differentiate more vs diffstatespace - [x] reorder other toolboxes according to popularity diff --git a/models/Baxter_and_King_1993.jl b/models/Baxter_King_1993.jl similarity index 94% rename from models/Baxter_and_King_1993.jl rename to models/Baxter_King_1993.jl index ca461767..31fbd8d2 100644 --- a/models/Baxter_and_King_1993.jl +++ b/models/Baxter_King_1993.jl @@ -1,4 +1,4 @@ -@model Baxter_and_King_1993 begin +@model Baxter_King_1993 begin uc[0] = c[0]^-1 ul[0] = θ_l * l[0]^-1 @@ -34,7 +34,7 @@ w[0] = fn[0] end -@parameters Baxter_and_King_1993 begin +@parameters Baxter_King_1993 begin A = 1.0 γ_x = 1.016 diff --git a/models/FS2000.jl b/models/FS2000.jl index c2441691..2b43995d 100644 --- a/models/FS2000.jl +++ b/models/FS2000.jl @@ -44,3 +44,6 @@ end z_e_a = 0.035449 z_e_m = 0.008862 end + +# Translated from: https://archives.dynare.org/documentation/examples.html +# be aware that dynare dynamics differ if c[2] or P[2] (not sure which one) are not declared explicitly as an auxilliary variable (c_lead(0) = c(+1);). The system in dynare has one less variable and the higher order solutions are different for the stochastic vol term. \ No newline at end of file diff --git a/test/models/Gali_2015_chapter_3_nonlinear.jl b/models/Gali_2015_chapter_3_obc.jl similarity index 86% rename from test/models/Gali_2015_chapter_3_nonlinear.jl rename to models/Gali_2015_chapter_3_obc.jl index cc6b116f..e45d7806 100644 --- a/test/models/Gali_2015_chapter_3_nonlinear.jl +++ b/models/Gali_2015_chapter_3_obc.jl @@ -1,4 +1,4 @@ -@model Gali_2015_chapter_3_nonlinear begin +@model Gali_2015_chapter_3_obc begin W_real[0] = C[0] ^ σ * N[0] ^ φ Q[0] = β * (C[1] / C[0]) ^ (-σ) * Z[1] / Z[0] / Pi[1] @@ -9,7 +9,7 @@ R[0] = Pi[1] * realinterest[0] - R[0] = 1 / β * Pi[0] ^ ϕᵖⁱ * (Y[0] / Y[ss]) ^ ϕʸ * exp(nu[0]) + R[0] = max(R̄ , 1 / β * Pi[0] ^ ϕᵖⁱ * (Y[0] / Y[ss]) ^ ϕʸ * exp(nu[0])) C[0] = Y[0] @@ -48,7 +48,9 @@ end -@parameters Gali_2015_chapter_3_nonlinear verbose = true begin +@parameters Gali_2015_chapter_3_obc begin + R̄ = 1.0 + σ = 1 φ = 5 @@ -81,5 +83,5 @@ end std_nu = .0025 + R > 1.000001 end - diff --git a/models/Guerrieri_Iacoviello_2017.jl b/models/Guerrieri_Iacoviello_2017.jl new file mode 100644 index 00000000..3f9f0941 --- /dev/null +++ b/models/Guerrieri_Iacoviello_2017.jl @@ -0,0 +1,196 @@ +@model Guerrieri_Iacoviello_2017 begin + c[0] + c1[0] + ik[0] = y[0] + + uc[0] = BETA * r[0] / dp[1] * uc[1] + + uc[0] * w[0] / xw[0] = az[0] * n[0] ^ ETA + + uc[0] * q[0] = uh[0] + uc[1] * BETA * q[1] + + c1[0] + q[0] * (h1[0] - h1[-1]) + r[-1] * b[-1] / dp[0] = w1[0] * n1[0] + b[0] + INDTR * log(ap[0]) + + uc1[0] * (1 - lm[0]) = BETA1 * (r[0] / dp[1] - RHOD * lm[1] / dp[1]) * uc1[1] + + w1[0] * uc1[0] / xw1[0] = az[0] * n1[0] ^ ETA + + q[0] * uc1[0] = uh1[0] + uc1[1] * q[1] * BETA1 + q[0] * uc1[0] * lm[0] * (1 - RHOD) * M + + y[0] = n[0] ^ ((1 - ALPHA) * (1 - SIGMA)) * n1[0] ^ ((1 - ALPHA) * SIGMA) * k[-1] ^ ALPHA + + y[0] * (1 - ALPHA) * (1 - SIGMA) = n[0] * w[0] * xp[0] + + y[0] * (1 - ALPHA) * SIGMA = n1[0] * w1[0] * xp[0] + + log(dp[0] / PIBAR) - LAGP * log(dp[-1] / PIBAR) = BETA * (log(dp[1] / PIBAR) - log(dp[0] / PIBAR) * LAGP) - (1 - TETAP) * (1 - BETA * TETAP) / TETAP * log(xp[0] / XP_SS) + log(ap[0]) * (1 - INDTR) + + log(dw[0] / PIBAR) - LAGW * log(dw[-1] / PIBAR) = BETA * (log(dw[1] / PIBAR) - log(dw[0] / PIBAR) * LAGW) - (1 - TETAW) * (1 - BETA * TETAW) / TETAW * log(xw[0] / XW_SS) + log(aw[0]) + + log(dw1[0] / PIBAR) - LAGW * log(dw1[-1] / PIBAR) = log(aw[0]) + BETA * (log(dw1[1] / PIBAR) - LAGW * log(dw1[0] / PIBAR)) - (1 - TETAW) * (1 - BETA * TETAW) / TETAW * log(xw1[0] / XW_SS) + + log(rnot[0]) = TAYLOR_R * log(r[-1]) + (1 - TAYLOR_R) * TAYLOR_P * (log(dp[0] / PIBAR) * 0.25 + 0.25 * log(dp[-1] / PIBAR) + 0.25 * log(dp[-2] / PIBAR) + 0.25 * log(dp[-3] / PIBAR)) + (1 - TAYLOR_R) * TAYLOR_Y * log(y[0] / lly) + (1 - TAYLOR_R) * TAYLOR_Q / 4 * log(q[0] / q[-1]) + (1 - TAYLOR_R) * log(PIBAR / BETA) + log(arr[0]) + + uc[0] = (1 - EC) / (1 - BETA * EC) * (az[0] / (c[0] - EC * c[-1]) - BETA * EC * az[1] / (c[1] - c[0] * EC)) + + uc1[0] = (1 - EC) / (1 - BETA1 * EC) * (az[0] / (c1[0] - EC * c1[-1]) - az[1] * BETA1 * EC / (c1[1] - c1[0] * EC)) + + uh[0] = (1 - EH) / (1 - BETA * EH) * JEI * (az[0] * aj[0] / (1 - h1[0] - EH * (1 - h1[-1])) - az[1] * BETA * EH * aj[1] / (1 - h1[1] - EH * (1 - h1[0]))) + + uh1[0] = JEI * (1 - EH) / (1 - BETA1 * EH) * (az[0] * aj[0] / (h1[0] - h1[-1] * EH) - aj[1] * az[1] * BETA1 * EH / (h1[1] - h1[0] * EH)) + + uc[0] * qk[0] * (1 - PHIK * (ik[0] - ik[-1]) / llik) = uc[0] - PHIK * BETA * uc[1] * qk[1] * (ik[1] - ik[0]) / llik + + uc[0] * qk[0] / ak[0] = BETA * uc[1] * (rk[1] + qk[1] * (1 - DK) / ak[1]) + + k[0] / ak[0] = ik[0] + k[-1] * (1 - DK) / ak[0] + + y[0] * ALPHA = k[-1] * xp[0] * rk[0] + + dw[0] = w[0] * dp[0] / w[-1] + + dw1[0] = dp[0] * w1[0] / w1[-1] + + log(aj[0]) = RHO_J * log(aj[-1]) + z_j[0] + + z_j[0] = RHO_J2 * z_j[-1] + eps_j[x] + + log(ak[0]) = RHO_K * log(ak[-1]) + STD_K * eps_k[x] + + log(ap[0]) = RHO_P * log(ap[-1]) + STD_P * eps_p[x] + + log(aw[0]) = RHO_W * log(aw[-1]) + STD_W * eps_w[x] + + log(arr[0]) = RHO_R * log(arr[-1]) + STD_R * eps_r[x] + + log(az[0]) = RHO_Z * log(az[-1]) + STD_Z * eps_z[x] + + 0 = min(bnot[0] - b[0], lm[0]) + # bnot[0] = b[0] + + bnot[0] = h1[0] * q[0] * (1 - RHOD) * M + b[-1] * RHOD / dp[0] + + maxlev[0] = b[0] - bnot[0] + + r[0] = max(RBAR, rnot[0]) + # r[0] = rnot[0] + +end + + +@parameters Guerrieri_Iacoviello_2017 begin + RBAR = 1 + + BETA = 0.995 + + BETA1 = 0.9921849949330452 + + EC = 0.6841688730310923 + + EH = 0.8798650668795864 + + ETA = 1 + + JEI = 0.04 + + M = 0.9 + + ALPHA = 0.3 + + PHIK = 4.120924218703865 + + DK = 0.025 + + LAGP = 0 + + LAGW = 0 + + PIBAR = 1.005 + + INDTR = 0 + + SIGMA = 0.5012798413194606 + + TAYLOR_P = 1.719559906725518 + + TAYLOR_Q = 0 + + TAYLOR_R = 0.5508743735338286 + + TAYLOR_Y = 0.09436959071018983 + + TETAP = 0.9182319022631061 + + TETAW = 0.9162909334165672 + + XP_SS = 1.2 + + XW_SS = 1.2 + + RHO_J = 0.983469150669198 + + RHO_K = 0.7859395713107814 + + RHO_P = 0 + + RHO_R = 0.623204934949152 + + RHO_W = 0 + + RHO_Z = 0.7555575007590176 + + STD_J = 0.07366860797541266 + + STD_K = 0.03601489154765812 + + STD_P = 0.002964296803248907 + + STD_R = 0.001315097718876929 + + STD_W = 0.00996414482032244 + + STD_Z = 0.01633680112129254 + + RHO_J2 = 0 + + RHOD = 0.6945068431131589 + + ITAYLOR_W = 0 + + llr = 1 / BETA + + llrk = llr - (1-DK) + + llxp = XP_SS + + llxw = XW_SS + + llxw1 = XW_SS + + lllm = (1 - BETA1/BETA) / (1 - BETA1*RHOD/PIBAR) + + QHTOC = JEI/(1-BETA) + + QH1TOC1 = JEI/(1-BETA1-lllm*M*(1-RHOD)) + + KTOY = ALPHA/(llxp*llrk) + + BTOQH1 = M*(1-RHOD)/(1-RHOD/PIBAR) + + C1TOY = (1-ALPHA)*SIGMA/(1+(1/BETA-1)*BTOQH1*QH1TOC1)*(1/llxp) + + CTOY = (1-C1TOY-DK*KTOY) + + lln = ((1-SIGMA)*(1-ALPHA)/(llxp*llxw*CTOY))^(1/(1+ETA)) + + lln1 = (SIGMA*(1-ALPHA)/(llxp*llxw1*C1TOY))^(1/(1+ETA)) + + lly = KTOY^(ALPHA/(1-ALPHA))*lln^(1-SIGMA)*lln1^SIGMA + + llctot = lly-DK*KTOY*lly + + llik = KTOY*DK*lly + + llk = KTOY*lly + + llq = QHTOC*CTOY*lly + QH1TOC1*C1TOY*lly + +end diff --git a/models/Iacoviello_2005_linear.jl b/models/Iacoviello_2005_linear.jl new file mode 100644 index 00000000..55d405e7 --- /dev/null +++ b/models/Iacoviello_2005_linear.jl @@ -0,0 +1,135 @@ +@model Iacoviello_2005_linear begin + Ŷ[0] = ctoY * ĉ[0] + c1toY * c1̂[0] + c2toY * c2̂[0] + ItoY * Î[0] + + c1̂[0] = c1̂[1] - rr̂[0] + + Î[0] = K̂[-1] + γ * (Î[1] - K̂[0]) + (1 - γ * (1 - δ)) * (Ŷ[1] - X̂[1] - K̂[0]) / ψ + (ĉ[0] - ĉ[1]) / ψ + + q̂[0] = γe * q̂[1] + (1 - γe) * (Ŷ[1] - X̂[1] - ĥ[0]) - rr̂[0] * m * β - (1 - m * β) * (ĉ[1] - ĉ[0]) - fie * (ĥ[0] - ĥ[-1] - γ * (ĥ[1] - ĥ[0])) + + q̂[0] = q̂[1] * γh + (1 - γh) * (ĵ[0] - h2̂[0]) - rr̂[0] * β * m2 + (1 - β * m2) * (c2̂[0] - ω * c2̂[1]) - fih * (h2̂[0] - h2̂[-1] - β2 * (h2̂[1] - h2̂[0])) + + q̂[0] = c1̂[0] + q̂[1] * β + ĵ[0] * (1 - β) + ĥ[0] * ι + h2̂[0] * ι2 - c1̂[1] * β + fih * ((ĥ[0] - ĥ[-1]) * htoh1 + (h2̂[0] - h2̂[-1]) * h2toh1 - (ĥ[1] - ĥ[0]) * β * htoh1 - (h2̂[1] - h2̂[0]) * β * h2toh1) + + b̂[0] = q̂[1] + ĥ[0] - rr̂[0] + + b2̂[0] = q̂[1] + h2̂[0] - rr̂[0] + + Ŷ[0] = η * (Â[0] + ĥ[-1] * υ + K̂[-1] * my) / (η - (1 - υ - my)) - (1 - υ - my) * (X̂[0] + c1̂[0] * α + c2̂[0] * (1 - α)) / (η - (1 - υ - my)) + + pî[0] = β * pî[1] - X̂[0] * κ + û[0] + + K̂[0] = Î[0] * δ + K̂[-1] * (1 - δ) + + b̂[0] * btoY = ItoY * Î[0] + ctoY * ĉ[0] + (ĥ[0] - ĥ[-1]) * qhtoY + btoY * R * (R̂[-1] + b̂[-1] - pî[0]) - (1 - s1 - s2) * (Ŷ[0] - X̂[0]) + + b2̂[0] * b2toY = c2toY * c2̂[0] + (h2̂[0] - h2̂[-1]) * qh2toY + R * b2toY * (R̂[-1] + b2̂[-1] - pî[0]) - s2 * (Ŷ[0] - X̂[0]) + + R̂[0] = (1 - rR) * (1 + rpi) * pî[-1] + (1 - rR) * rY * Ŷ[-1] + R̂[-1] * rR + eR̂[x] + + rr̂[0] = R̂[0] - pî[1] + + ĵ[0] = ρj * ĵ[-1] + eĵ[x] + + û[0] = ρu * û[-1] + eû[x] + + Â[0] = ρA * Â[-1] + eÂ[x] + +end + + +@parameters Iacoviello_2005_linear begin + β = 0.99 + + β2 = 0.95 + + γ = 0.98 + + j = 0.1 + + η = 1.01 + + my = 0.3 + + υ = 0.03 + + ψ = 2 + + δ = 0.03 + + fie = 0 + + fih = 0 + + X = 1.05 + + thη = 0.75 + + α = 0.64 + + m = 0.89 + + m2 = 0.55 + + ρu = 0.59 + + ρj = 0.85 + + ρA = 0.03 + + σu = 0.17 + + σj = 24.89 + + σA = 2.24 + + σR = 0.29 + + rR = 0.73 + + rpi = 0.27 + + rY = 0.13 + + γe = (1-m)*γ+m*β + + γh = β2+m2*(β-β2) + + ω = (β2-β2*m2)/(1-β*m2) + + κ = (1-thη)*(1-β*thη)/thη + + s1 = (α*(1-my-υ)+X-1)/X + + s2 = (1-my-υ)*(1-α)/X + + qhtoY = γ*υ/(X*(1-γe)) + + btoY = m*β*qhtoY + + qh1toY = j*s1/(1-β)+qhtoY*m*j+m2*j*s2/(1-β2-m2*(β-β2-j*(1-β))) + + qh2toY = j*s2/(1-β2-m2*(β-β2-j*(1-β))) + + c1toY = s1+(1-β)*(m*qhtoY+m2*qh2toY) + + htoh1 = qhtoY/qh1toY + + h2toh1 = qh2toY/qh1toY + + b2toY = s2*m2*β*j/(1-β2-m2*(β-β2)+(1-β)*m2*j) + + c2toY = s2*(1-β2-m2*(β-β2))/(1-β2-m2*(β-β2)+(1-β)*m2*j) + + ctoY = (my+υ-my*γ*δ/(1-γ*(1-δ))-qhtoY*X*m*(1-β))/X + + ItoY = 1-ctoY-c1toY-c2toY + + ι = (1-β)*htoh1 + + ι2 = (1-β)*h2toh1 + + R = 1/β + +end + diff --git a/models/QUEST3_2009.jl b/models/QUEST3_2009.jl new file mode 100644 index 00000000..eb941fed --- /dev/null +++ b/models/QUEST3_2009.jl @@ -0,0 +1,486 @@ +@model QUEST3_2009 begin + interest[0] = ((1 + E_INOM[0]) ^ 4 - interestq_exog ^ 4) / interestq_exog ^ 4 + + inflation[0] = 0.25 * (inflationq[0] + inflationq[-1] + inflationq[-2] + inflationq[-3]) + + inflationq[0] = (1 + 4 * E_PHIC[0] - inflationannual_exog) / inflationannual_exog + + outputgap[0] = E_LYGAP[0] + + E_INOM[0] = ILAGE * E_INOM[-1] + (1 - ILAGE) * (E_EX_R + GP0 + TINFE * (E_PHIC[0] - GP0) + TYE1 * E_LYGAP[-1]) + TYE2 * (E_LYGAP[0] - E_LYGAP[-1]) + E_ZEPS_M[0] + + exp(E_LUCYN[0]) = exp(E_ZEPS_C[0]) * (exp(E_LCNLCSN[0]) * (1 - HABE / (1 + E_GCNLC[0] - GY0))) ^ (-SIGC) * (1 - OMEGE * exp(E_ZEPS_L[0]) * (exp(E_LL[0]) - HABLE * exp(E_LL[-1])) ^ KAPPAE) ^ (1 - SIGC) + + exp(E_LUCLCYN[0]) = (1 - OMEGE * exp(E_ZEPS_L[0]) * (exp(E_LL[0]) - HABLE * exp(E_LL[-1])) ^ KAPPAE) ^ (1 - SIGC) * exp(E_LCLCSN[0]) ^ (-SIGC) + + E_VL[0] = exp(E_ZEPS_L[0]) * OMEGE * KAPPAE * exp(E_ZEPS_C[0]) * (exp(E_LCNLCSN[0]) * (1 - HABE / (1 + E_GCNLC[0] - GY0))) ^ (1 - SIGC) * (1 - OMEGE * exp(E_ZEPS_L[0]) * (exp(E_LL[0]) - HABLE * exp(E_LL[-1])) ^ KAPPAE) ^ (-SIGC) * (exp(E_LL[0]) - HABLE * exp(E_LL[-1])) ^ (KAPPAE - 1) + + E_VLLC[0] = exp(E_ZEPS_L[0]) * (exp(E_LL[0]) - HABLE * exp(E_LL[-1])) ^ (KAPPAE - 1) * OMEGE * KAPPAE * (1 - OMEGE * exp(E_ZEPS_L[0]) * (exp(E_LL[0]) - HABLE * exp(E_LL[-1])) ^ KAPPAE) ^ (-SIGC) * exp(E_LCLCSN[0]) ^ (1 - SIGC) + + 1 / BETAE - 1 = E_INOM[0] + E_GUC[1] - E_PHIC[1] + + E_LUCYN[0] - E_LUCYN[-1] = E_GUC[0] + SIGC * (E_GY[0] - GY0 - E_PHIC[0] + E_PHI[0]) + + exp(E_LCLCSN[0]) * (1 + TVAT) = (1 - E_TW[0] - SSC) * E_WS[0] + E_WS[0] * E_TRW[0] - E_TAXYN[0] + + E_WS[0] = exp(E_LL[0] - E_LYWR[0]) + + exp(E_LCSN[0]) = exp(E_LCLCSN[0]) * SLCFLAG * SLC + exp(E_LCNLCSN[0]) * (1 - SLCFLAG * SLC) + + (1 + TVAT) * ((E_VL[0] * (1 - SLC) + E_VLLC[0] * SLC) / (exp(E_LUCYN[0]) * (1 - SLC) + exp(E_LUCLCYN[0]) * SLC)) ^ (1 - WRLAG) * ((1 - E_TW[0] - SSC) / (1 + TVAT) * (THETAE - 1) / THETAE / exp(E_LYWR[-1]) / (1 + E_GY[0] - GY0)) ^ WRLAG = (1 - E_TW[0] - SSC) * (THETAE - 1) / THETAE / exp(E_LYWR[0]) + GAMIFLAG * GAMWE / THETAE / exp(E_LYWR[0]) * (E_WPHI[0] - GP0 - GY0 - (1 - SFWE) * (E_PHI[-1] - GP0)) - GAMWE * BETAE * GAMIFLAG / THETAE / exp(E_LYWR[0]) * (E_WPHI[1] - GP0 - GY0 - (1 - SFWE) * (E_PHI[0] - GP0)) + + (1 + E_ZEPS_W[0]) / exp(E_LYWR[0]) = E_ETA[0] * ALPHAE / exp(E_LL[0]) * (1 + E_LOL[0]) - 1 / exp(E_LYWR[0]) * GAMLE * (E_LL[0] - E_LL[-1]) + GAMLE * 1 / exp(E_LYWR[1]) * (1 + E_GY[1] - GY0) / (1 + E_R[0]) * (E_LL[1] - E_LL[0]) + + GAMIE * (exp(E_LIK[0]) - (GY0 + DELTAE + GPOP0 + GPCPI0)) + GAMI2E * (E_GI[0] - GY0 - GPCPI0) - GAMI2E / (1 + E_INOM[0]) * (E_GI[1] - GY0 - GPCPI0) = E_Q[0] - 1 + + E_ETA[0] * (1 - TP) * (1 - ALPHAE) * exp(E_LYKPPI[0]) = E_Q[0] - (GPCPI0 + 1 - E_R[0] - DELTAE - RPREMK - E_ZEPS_RPREMK[0] - E_PHIPI[1]) * E_Q[1] + (1 - TP) * (A1E * (E_UCAP[0] - UCAP0) + A2E * (E_UCAP[0] - UCAP0) ^ 2) + + exp(E_LYKPPI[0]) * E_ETA[0] * (1 - ALPHAE) = E_UCAP[0] * (A1E + (E_UCAP[0] - UCAP0) * 2 * A2E) + + E_ETA[0] = 1 - (TAUE + E_ZEPS_ETA[0]) - GAMIFLAG * GAMPE * (BETAE * (SFPE * E_PHI[1] + E_PHI[-1] * (1 - SFPE) - GP0) - (E_PHI[0] - GP0)) + + E_MRY[0] = (1 + E_INOM[0]) ^ (-ZETE) + + E_GK[0] - (GY0 + GPCPI0) = exp(E_LIK[0]) - (GY0 + DELTAE + GPOP0 + GPCPI0) + + E_GKG[0] - (GY0 + GPCPI0) = exp(E_LIKG[0]) - (GPCPI0 + GY0 + GPOP0 + DELTAGE) + + E_LISN[0] = GPCPI0 + GY0 + E_LIK[0] - E_LYKPPI[0] - E_GK[0] + + E_GY[0] = (1 - ALPHAE) * (E_GK[0] + E_GUCAP[0]) + ALPHAE * (E_GTFP[0] + E_GL[0] * (1 + LOL)) + E_GKG[0] * (1 - ALPHAGE) + + E_R[0] = E_INOM[0] - E_PHI[1] + + E_LYGAP[0] = (1 - ALPHAE) * (log(E_UCAP[0]) - log(E_UCAP0[0])) + ALPHAE * (E_LL[0] - E_LL0[0]) + + E_LL0[0] = RHOL0 * E_LL0[-1] + E_LL[0] * (1 - RHOL0) + + E_UCAP0[0] = RHOUCAP0 * E_UCAP0[-1] + E_UCAP[0] * (1 - RHOUCAP0) + + exp(E_LPCP[0]) = (SE + (1 - SE) * exp(E_LPMP[0]) ^ (1 - SIGIME)) ^ (1 / (1 - SIGIME)) + + exp(E_LPMP[0]) = (1 + E_ZEPS_ETAM[0] + GAMIFLAG * GAMPME * (GP0 + BETAE * (SFPME * E_PHIM[1] + (1 - SFPME) * E_PHIM[-1] - GP0) - E_PHIM[0])) * exp(E_LER[0]) ^ ALPHAX + + exp(E_LPXP[0]) = 1 + E_ZEPS_ETAX[0] + GAMIFLAG * GAMPXE * (GP0 + BETAE * (SFPXE * E_PHIX[1] + (1 - SFPXE) * E_PHIX[-1] - GP0) - E_PHIX[0]) + + 1 = exp(E_LCSN[0]) + exp(E_LISN[0]) + exp(E_LIGSN[0]) + exp(E_LGSN[0]) + E_TBYN[0] + + E_TBYN[0] = exp(E_LEXYN[0]) - exp(E_LIMYN[0]) + E_ZEPS_EX[0] + + exp(E_LIMYN[0]) = (exp(E_LCSN[0]) + exp(E_LISN[0]) + exp(E_LIGSN[0]) + exp(E_LGSN[0])) * (1 - SE) * exp(RHOPCPM * (E_LPCP[-1] - E_LPMP[-1]) + (1 - RHOPCPM) * (E_LPCP[0] - E_LPMP[0])) ^ SIGIME * exp(E_LPMP[0] - E_LPCP[0]) + + exp(E_LEXYN[0]) = exp(E_LPXP[0]) * (1 - SE) * exp(RHOPWPX * (E_LER[-1] * SE * ALPHAX - E_LPXP[-1]) + (1 - RHOPWPX) * (E_LER[0] * SE * ALPHAX - E_LPXP[0])) ^ SIGEXE * exp(E_LYWY[0]) ^ ALPHAX + + E_INOM[0] = E_INOMW[0] + E_GE[1] - RPREME * E_BWRY[0] + E_ZEPS_RPREME[0] + + E_BWRY[0] = E_TBYN[0] + (1 + E_INOM[0] - E_PHI[1] - E_GY[0] - GPOP0) * E_BWRY[-1] + + exp(E_LBGYN[0]) = exp(E_LIGSN[0]) + exp(E_LGSN[0]) + (1 + E_R[0] - E_GY[0] - GPOP0) * exp(E_LBGYN[-1]) + E_TRW[0] * exp(E_LL[0] - E_LYWR[0]) - E_WS[0] * (E_TW[0] + SSC) - TP * (1 - E_WS[0]) - TVAT * exp(E_LCSN[0]) - E_TAXYN[0] + + E_GG[0] - GY0 = GSLAG * (E_GG[-1] - GY0) + GFLAG * GVECM * (E_LGSN[-1] - log(GSN)) + (E_LYGAP[0] - E_LYGAP[-1]) * GFLAG * G1E + GFLAG * GEXOFLAG * E_ZEPS_G[0] + (1 - GFLAG) * (E_ZEPS_G[0] - E_ZEPS_G[-1]) + + E_GIG[0] - GY0 - GPCPI0 = IGSLAG * (E_GIG[-1] - GY0 - GPCPI0) + IGFLAG * IGVECM * (E_LIGSN[-1] - log(IGSN)) + (E_LYGAP[0] - E_LYGAP[-1]) * IGFLAG * IG1E + IGFLAG * IGEXOFLAG * E_ZEPS_IG[0] + (1 - IGFLAG) * (E_ZEPS_IG[0] - E_ZEPS_IG[-1]) + + E_GIG[0] - E_GI[0] = E_LIGSN[0] - E_LISN[0] - E_LIGSN[-1] + E_LISN[-1] + + E_TRW[0] = TRSN + TRFLAG * TR1E * (1 - exp(E_LL[0]) - (1 - L0)) + E_ZEPS_TR[0] + + E_TAXYN[0] - E_TAXYN[-1] = BGADJ1 * (exp(E_LBGYN[-1]) - BGTAR) + BGADJ2 * (exp(E_LBGYN[0]) - exp(E_LBGYN[-1])) + + E_TW[0] = TW0 * (1 + E_LYGAP[0] * TW1 * TWFLAG) + + E_TRYN[0] = E_TRW[0] * exp(E_LL[0] - E_LYWR[0]) + + E_TRTAXYN[0] = E_TRW[0] * exp(E_LL[0] - E_LYWR[0]) - E_TAXYN[0] + + E_WSW[0] = (1 - E_TW[0] - SSC) * E_WS[0] + + E_INOMW[0] = (1 - RII) * E_EX_INOMW + RII * E_INOMW[-1] + RIP * (E_PHIW[-1] - GPW0) + RIX * (E_GYW[-1] - GYW0) + STD_EPS_INOMW *E_EPS_INOMW[x] + + E_PHIW[0] - GPW0 = RPI * (E_INOMW[-1] - E_EX_INOMW) + (E_PHIW[-1] - GPW0) * RPP + (E_GYW[-1] - GYW0) * RPX + STD_EPS_PW * E_EPS_PW[x] + + E_GYW[0] - GYW0 = (E_INOMW[-1] - E_EX_INOMW) * RXI + (E_PHIW[-1] - GPW0) * RXP + (E_GYW[-1] - GYW0) * RXX + RXY * (E_LYWY[-1] - LYWY0) + STD_EPS_YW * E_EPS_YW[x] + + E_LYWY[0] - E_LYWY[-1] = E_GYW[0] - E_GY[0] + + E_GTFP[0] - GTFP0 = STD_EPS_Y * E_EPS_Y[x] + + E_LOL[0] - LOL = RHOLOL * (E_LOL[-1] - LOL) + STD_EPS_LOL * E_EPS_LOL[x] + + E_PHIPI[0] = GPCPI0 + E_ZEPS_PPI[0] + + E_ZEPS_C[0] = RHOCE * E_ZEPS_C[-1] + STD_EPS_C * E_EPS_C[x] + + E_ZEPS_ETA[0] = RHOETA * E_ZEPS_ETA[-1] + STD_EPS_ETA * E_EPS_ETA[x] + + E_ZEPS_ETAM[0] = RHOETAM * E_ZEPS_ETAM[-1] + STD_EPS_ETAM * E_EPS_ETAM[x] + + E_ZEPS_ETAX[0] = RHOETAX * E_ZEPS_ETAX[-1] + STD_EPS_ETAX * E_EPS_ETAX[x] + + E_ZEPS_EX[0] = RHOEXE * E_ZEPS_EX[-1] + STD_EPS_EX * E_EPS_EX[x] + + E_ZEPS_G[0] = E_ZEPS_G[-1] * RHOGE + STD_EPS_G * E_EPS_G[x] + + E_ZEPS_IG[0] = E_ZEPS_IG[-1] * RHOIG + IGEXOFLAG * STD_EPS_IG * E_EPS_IG[x] + + E_ZEPS_L[0] = RHOLE * E_ZEPS_L[-1] + STD_EPS_L * E_EPS_L[x] + + E_ZEPS_M[0] = STD_EPS_M * E_EPS_M[x] + + E_ZEPS_PPI[0] = STD_EPS_PPI * E_EPS_PPI[x] + RHOPPI1 * E_ZEPS_PPI[-1] + RHOPPI2 * E_ZEPS_PPI[-2] + RHOPPI3 * E_ZEPS_PPI[-3] + RHOPPI4 * E_ZEPS_PPI[-4] + + E_ZEPS_RPREME[0] = RHORPE * E_ZEPS_RPREME[-1] + STD_EPS_RPREME * E_EPS_RPREME[x] + + E_ZEPS_RPREMK[0] = RHORPK * E_ZEPS_RPREMK[-1] + STD_EPS_RPREMK * E_EPS_RPREMK[x] + + E_ZEPS_W[0] = STD_EPS_W * E_EPS_W[x] + + E_ZEPS_TR[0] = RHOTR * E_ZEPS_TR[-1] + TREXOFLAG * STD_EPS_TR * E_EPS_TR[x] + + E_PHIC[0] + E_GC[0] - E_GY[0] - E_PHI[0] = E_LCSN[0] - E_LCSN[-1] + + E_PHIC[0] + E_GCLC[0] - E_GY[0] - E_PHI[0] = E_LCLCSN[0] - E_LCLCSN[-1] + + E_PHIC[0] + E_GCNLC[0] - E_GY[0] - E_PHI[0] = E_LCNLCSN[0] - E_LCNLCSN[-1] + + E_PHIW[0] + E_GE[0] - E_PHI[0] = E_LER[0] - E_LER[-1] + + E_PHIX[0] + E_GEX[0] - E_GY[0] - E_PHI[0] = E_LEXYN[0] - E_LEXYN[-1] + + E_PHIC[0] + E_GG[0] - E_GY[0] - E_PHI[0] = E_LGSN[0] - E_LGSN[-1] + + E_GI[0] - E_GK[-1] = E_LIK[0] - E_LIK[-1] + + E_GIG[0] - E_GKG[-1] = E_LIKG[0] - E_LIKG[-1] + + E_PHIM[0] + E_GIM[0] - E_GY[0] - E_PHI[0] = E_LIMYN[0] - E_LIMYN[-1] + + E_PHIPI[0] + E_GY[0] - E_GK[0] = E_LYKPPI[0] - E_LYKPPI[-1] + + E_GL[0] = E_LL[0] - E_LL[-1] + + E_GTAX[0] - E_GY[0] - E_PHI[0] = log(E_TAXYN[0]/E_TAXYN[-1]) + + E_GTFPUCAP[0] = (1 - ALPHAE) * E_GUCAP[0] + ALPHAE * E_GTFP[0] + + E_GTR[0] - E_GL[0] - E_WRPHI[0] = log(E_TRW[0]/E_TRW[-1]) + + E_GUCAP[0] = log(E_UCAP[0]/E_UCAP[-1]) + + E_GWRY[0] = E_LYWR[-1] - E_LYWR[0] + + E_GY[0] - E_GYPOT[0] = E_LYGAP[0] - E_LYGAP[-1] + + E_BGYN[0] = exp(E_LBGYN[0]) + + E_DBGYN[0] = E_BGYN[0] - E_BGYN[-1] + + E_CLCSN[0] = exp(E_LCLCSN[0]) + + E_GSN[0] = exp(E_LGSN[0]) + + E_LTRYN[0] = log(E_TRYN[0]) + + E_PHIC[0] - E_PHI[0] = E_LPCP[0] - E_LPCP[-1] + + E_PHIM[0] - E_PHI[0] = E_LPMP[0] - E_LPMP[-1] + + E_PHIX[0] - E_PHI[0] = E_LPXP[0] - E_LPXP[-1] + + E_PHI[0] + E_GY[0] - E_WPHI[0] = E_LYWR[0] - E_LYWR[-1] + + E_WPHI[0] = E_PHI[0] + E_WRPHI[0] + + E_GYL[0] = E_GY[0] + GPOP0 + + E_GCL[0] = GPOP0 + E_GC[0] + + E_GIL[0] = GPOP0 + E_GI[0] + + E_GGL[0] = GPOP0 + E_GG[0] + + E_GEXL[0] = GPOP0 + E_GEX[0] + DGEX + + E_GIML[0] = GPOP0 + E_GIM[0] + DGIM + + E_PHIML[0] = E_PHIM[0] + DGPM + + E_PHIXL[0] = E_PHIX[0] + DGPX + + E_LCY[0] = E_LCSN[0] - E_LPCP[0] + + E_LGY[0] = E_LGSN[0] - E_LPCP[0] + + E_LWS[0] = E_LL[0] - E_LYWR[0] + +end + + +@parameters QUEST3_2009 begin + STD_EPS_INOMW = 0.0023 + + STD_EPS_PW = 0.0029 + + STD_EPS_YW = 0.0044 + + STD_EPS_PPI = 0.00312216772065 + + STD_EPS_C = 0.0597 + + STD_EPS_ETA = 0.1500 + + STD_EPS_ETAM = 0.0202 + + STD_EPS_ETAX = 0.0648 + + STD_EPS_EX = 0.0044 + + STD_EPS_G = 0.0048 + + STD_EPS_IG = 0.0056 + + STD_EPS_L = 0.0283 + + STD_EPS_LOL = 0.0048 + + STD_EPS_M = 0.0013 + + STD_EPS_RPREME = 0.0017 + + STD_EPS_RPREMK = 0.0070 + + STD_EPS_TR = 0.0022 + + STD_EPS_W = 0.0437 + + STD_EPS_Y = 0.0121 + + A2E = 0.0453 + + G1E = (-0.0754) + + GAMIE = 76.0366 + + GAMI2E = 1.1216 + + GAMLE = 58.2083 + + GAMPE = 61.4415 + + GAMPME = 1.6782 + + GAMPXE = 26.1294 + + GAMWE = 1.2919 + + GSLAG = (-0.4227) + + GVECM = (-0.1567) + + HABE = 0.5634 + + HABLE = 0.8089 + + IG1E = 0.1497 + + IGSLAG = 0.4475 + + IGVECM = (-0.1222) + + ILAGE = 0.9009 + + KAPPAE = 1.9224 + + RHOCE = 0.9144 + + RHOETA = 0.1095 + + RHOETAM = 0.9557 + + RHOETAX = 0.8109 + + RHOGE = 0.2983 + + RHOIG = 0.8530 + + RHOLE = 0.9750 + + RHOL0 = 0.9334 + + RHOPCPM = 0.6652 + + RHOPWPX = 0.2159 + + RHORPE = 0.9842 + + RHORPK = 0.9148 + + RHOUCAP0 = 0.9517 + + RPREME = 0.0200 + + RPREMK = 0.0245 + + SE = 0.8588 + + SFPE = 0.8714 + + SFPME = 0.7361 + + SFPXE = 0.9180 + + SFWE = 0.7736 + + SIGC = 4.0962 + + SIGEXE = 2.5358 + + SIGIME = 1.1724 + + SLC = 0.3507 + + TINFE = 1.9590 + + TR1E = 0.9183 + + RHOTR = 0.8636 + + TYE1 = 0.4274 + + TYE2 = 0.0783 + + WRLAG = 0.2653 + + ALPHAX = 0.5 + + BETAE = 0.996 + + ALPHAE = 0.52 + + ALPHAGE = 0.9 + + BGADJ2 = 0.004 + + BGADJ1 = 0.001*BGADJ2 + + BGTAR = 2.4 + + DELTAE = 0.025 + + DELTAGE = 0.0125 + + DGIM = 0.00738619107021 + + DGEX = 0.00738619107021 + + DGPM = (-0.00396650612294) + + DGPX = (-0.00396650612294) + + LOL = 0 + + RHOEXE = 0.975 + + RHOLOL = 0.99 + + SSC = 0.2 + + TAUE = 0.1000 + + THETAE = 1.6 + + TP = 0.2 + + TRSN = 0.36 + + TVAT = 0.2 + + TW0 = 0.2 + + TW1 = 0.8 + + ZETE = 0.4000 + + GFLAG = 1 + + IGFLAG = 1 + + TRFLAG = 1 + + TWFLAG = 1 + + GEXOFLAG = 1 + + IGEXOFLAG = 1 + + TREXOFLAG = 1 + + SLCFLAG = 1 + + GAMIFLAG = 1 + + A1E = 0.0669 + + OMEGE = 1.4836 + + GSN = 0.203 + + IGSN = 0.025 + + GPCPI0 = 0 + + GP0 = 0.005 + + GPW0 = GP0 + + GPOP0 = 0.00113377677398 + + GY0 = 0.003 + + GTFP0 = (ALPHAE+ALPHAGE-1)/ALPHAE*GY0-(2-ALPHAE-ALPHAGE)/ALPHAE*GPCPI0 + + GYW0 = GY0 + + UCAP0 = 1 + + L0 = 0.65 + + E_EX_R = 1/BETAE-1 + + E_EX_INOMW = GP0+E_EX_R + + LYWY0 = 0 + + RXY = (-0.0001) + + RII = 0.887131978334279 + + RIP = 0.147455589872832 + + RIX = 0.120095599681076 + + RPI = 0.112067224979767 + + RPP = 0.502758194258928 + + RPX = 0.082535400836409 + + RXI = 0.073730131176521 + + RXP = (-0.302655015002645) + + RXX = 0.495000246553550 + + RHOPPI1 = 0.24797097628284 + + RHOPPI2 = 0.13739098460472 + + RHOPPI3 = 0.10483962746747 + + RHOPPI4 = 0.09282876044442 + + interestq_exog = 1.00901606 + + inflationannual_exog = 1.02 + +end diff --git a/models/SW03.jl b/models/SW03.jl index 1505c9b5..542c4e58 100644 --- a/models/SW03.jl +++ b/models/SW03.jl @@ -148,15 +148,25 @@ end std_scaling_factor = 10 - std_eta_b = 0.336 / std_scaling_factor - std_eta_L = 3.52 / std_scaling_factor - std_eta_I = 0.085 / std_scaling_factor - std_eta_a = 0.598 / std_scaling_factor - std_eta_w = 0.6853261 / std_scaling_factor - std_eta_p = 0.7896512 / std_scaling_factor - std_eta_G = 0.325 / std_scaling_factor - std_eta_R = 0.081 / std_scaling_factor - std_eta_pi = 0.017 / std_scaling_factor + std_eta_b = σ_eta_b / std_scaling_factor + std_eta_L = σ_eta_L / std_scaling_factor + std_eta_I = σ_eta_I / std_scaling_factor + std_eta_a = σ_eta_a / std_scaling_factor + std_eta_w = σ_eta_w / std_scaling_factor + std_eta_p = σ_eta_p / std_scaling_factor + std_eta_G = σ_eta_G / std_scaling_factor + std_eta_R = σ_eta_R / std_scaling_factor + std_eta_pi = σ_eta_pi / std_scaling_factor + + σ_eta_b = 0.336 + σ_eta_L = 3.52 + σ_eta_I = 0.085 + σ_eta_a = 0.598 + σ_eta_w = 0.6853261 + σ_eta_p = 0.7896512 + σ_eta_G = 0.325 + σ_eta_R = 0.081 + σ_eta_pi = 0.017 calibr_pi_obj | 1 = pi_obj[ss] calibr_pi | pi[ss] = pi_obj[ss] diff --git a/models/SW03_obc.jl b/models/SW03_obc.jl new file mode 100644 index 00000000..e27ab5ff --- /dev/null +++ b/models/SW03_obc.jl @@ -0,0 +1,175 @@ +@model SW03_obc begin + -q[0] + beta * ((1 - tau) * q[1] + epsilon_b[1] * (r_k[1] * z[1] - psi^-1 * r_k[ss] * (-1 + exp(psi * (-1 + z[1])))) * (C[1] - h * C[0])^(-sigma_c)) + + -q_f[0] + beta * ((1 - tau) * q_f[1] + epsilon_b[1] * (r_k_f[1] * z_f[1] - psi^-1 * r_k_f[ss] * (-1 + exp(psi * (-1 + z_f[1])))) * (C_f[1] - h * C_f[0])^(-sigma_c)) + + -r_k[0] + alpha * epsilon_a[0] * mc[0] * L[0]^(1 - alpha) * (K[-1] * z[0])^(-1 + alpha) + + -r_k_f[0] + alpha * epsilon_a[0] * mc_f[0] * L_f[0]^(1 - alpha) * (K_f[-1] * z_f[0])^(-1 + alpha) + + -G[0] + T[0] + + -G[0] + G_bar * epsilon_G[0] + + -G_f[0] + T_f[0] + + -G_f[0] + G_bar * epsilon_G[0] + + -L[0] + nu_w[0]^-1 * L_s[0] + + -L_s_f[0] + L_f[0] * (W_i_f[0] * W_f[0]^-1)^(lambda_w^-1 * (-1 - lambda_w)) + + L_s_f[0] - L_f[0] + + L_s_f[0] + lambda_w^-1 * L_f[0] * W_f[0]^-1 * (-1 - lambda_w) * (-W_disutil_f[0] + W_i_f[0]) * (W_i_f[0] * W_f[0]^-1)^(-1 + lambda_w^-1 * (-1 - lambda_w)) + + Pi_ws_f[0] - L_s_f[0] * (-W_disutil_f[0] + W_i_f[0]) + + Pi_ps_f[0] - Y_f[0] * (-mc_f[0] + P_j_f[0]) * P_j_f[0]^(-lambda_p^-1 * (1 + lambda_p)) + + -Q[0] + epsilon_b[0]^-1 * q[0] * (C[0] - h * C[-1])^(sigma_c) + + -Q_f[0] + epsilon_b[0]^-1 * q_f[0] * (C_f[0] - h * C_f[-1])^(sigma_c) + + -W[0] + epsilon_a[0] * mc[0] * (1 - alpha) * L[0]^(-alpha) * (K[-1] * z[0])^alpha + + -W_f[0] + epsilon_a[0] * mc_f[0] * (1 - alpha) * L_f[0]^(-alpha) * (K_f[-1] * z_f[0])^alpha + + -Y_f[0] + Y_s_f[0] + + Y_s[0] - nu_p[0] * Y[0] + + -Y_s_f[0] + Y_f[0] * P_j_f[0]^(-lambda_p^-1 * (1 + lambda_p)) + + beta * epsilon_b[1] * (C_f[1] - h * C_f[0])^(-sigma_c) - epsilon_b[0] * R_f[0]^-1 * (C_f[0] - h * C_f[-1])^(-sigma_c) + + beta * epsilon_b[1] * pi[1]^-1 * (C[1] - h * C[0])^(-sigma_c) - epsilon_b[0] * R[0]^-1 * (C[0] - h * C[-1])^(-sigma_c) + + Y_f[0] * P_j_f[0]^(-lambda_p^-1 * (1 + lambda_p)) - lambda_p^-1 * Y_f[0] * (1 + lambda_p) * (-mc_f[0] + P_j_f[0]) * P_j_f[0]^(-1 - lambda_p^-1 * (1 + lambda_p)) + + epsilon_b[0] * W_disutil_f[0] * (C_f[0] - h * C_f[-1])^(-sigma_c) - omega * epsilon_b[0] * epsilon_L[0] * L_s_f[0]^sigma_l + + -1 + xi_p * (pi[0]^-1 * pi[-1]^gamma_p)^(-lambda_p^-1) + (1 - xi_p) * pi_star[0]^(-lambda_p^-1) + + -1 + (1 - xi_w) * (w_star[0] * W[0]^-1)^(-lambda_w^-1) + xi_w * (W[-1] * W[0]^-1)^(-lambda_w^-1) * (pi[0]^-1 * pi[-1]^gamma_w)^(-lambda_w^-1) + + -Phi - Y_s[0] + epsilon_a[0] * L[0]^(1 - alpha) * (K[-1] * z[0])^alpha + + -Phi - Y_f[0] * P_j_f[0]^(-lambda_p^-1 * (1 + lambda_p)) + epsilon_a[0] * L_f[0]^(1 - alpha) * (K_f[-1] * z_f[0])^alpha + + std_eta_b * eta_b[x] - log(epsilon_b[0]) + rho_b * log(epsilon_b[-1]) + + -std_eta_L * eta_L[x] - log(epsilon_L[0]) + rho_L * log(epsilon_L[-1]) + + std_eta_I * eta_I[x] - log(epsilon_I[0]) + rho_I * log(epsilon_I[-1]) + + std_eta_w * eta_w[x] - f_1[0] + f_2[0] + + std_eta_a * eta_a[x] - log(epsilon_a[0]) + rho_a * log(epsilon_a[-1]) + + std_eta_p * eta_p[x] - g_1[0] + g_2[0] * (1 + lambda_p) + + std_eta_G * eta_G[x] - log(epsilon_G[0]) + rho_G * log(epsilon_G[-1]) + + -f_1[0] + beta * xi_w * f_1[1] * (w_star[0]^-1 * w_star[1])^(lambda_w^-1) * (pi[1]^-1 * pi[0]^gamma_w)^(-lambda_w^-1) + epsilon_b[0] * w_star[0] * L[0] * (1 + lambda_w)^-1 * (C[0] - h * C[-1])^(-sigma_c) * (w_star[0] * W[0]^-1)^(-lambda_w^-1 * (1 + lambda_w)) + + -f_2[0] + beta * xi_w * f_2[1] * (w_star[0]^-1 * w_star[1])^(lambda_w^-1 * (1 + lambda_w) * (1 + sigma_l)) * (pi[1]^-1 * pi[0]^gamma_w)^(-lambda_w^-1 * (1 + lambda_w) * (1 + sigma_l)) + omega * epsilon_b[0] * epsilon_L[0] * (L[0] * (w_star[0] * W[0]^-1)^(-lambda_w^-1 * (1 + lambda_w)))^(1 + sigma_l) + + -g_1[0] + beta * xi_p * pi_star[0] * g_1[1] * pi_star[1]^-1 * (pi[1]^-1 * pi[0]^gamma_p)^(-lambda_p^-1) + epsilon_b[0] * pi_star[0] * Y[0] * (C[0] - h * C[-1])^(-sigma_c) + + -g_2[0] + beta * xi_p * g_2[1] * (pi[1]^-1 * pi[0]^gamma_p)^(-lambda_p^-1 * (1 + lambda_p)) + epsilon_b[0] * mc[0] * Y[0] * (C[0] - h * C[-1])^(-sigma_c) + + -nu_w[0] + (1 - xi_w) * (w_star[0] * W[0]^-1)^(-lambda_w^-1 * (1 + lambda_w)) + xi_w * nu_w[-1] * (W[-1] * pi[0]^-1 * W[0]^-1 * pi[-1]^gamma_w)^(-lambda_w^-1 * (1 + lambda_w)) + + -nu_p[0] + (1 - xi_p) * pi_star[0]^(-lambda_p^-1 * (1 + lambda_p)) + xi_p * nu_p[-1] * (pi[0]^-1 * pi[-1]^gamma_p)^(-lambda_p^-1 * (1 + lambda_p)) + + -K[0] + K[-1] * (1 - tau) + I[0] * (1 - 0.5 * varphi * (-1 + I[-1]^-1 * epsilon_I[0] * I[0])^2) + + -K_f[0] + K_f[-1] * (1 - tau) + I_f[0] * (1 - 0.5 * varphi * (-1 + I_f[-1]^-1 * epsilon_I[0] * I_f[0])^2) + + U[0] - beta * U[1] - epsilon_b[0] * ((1 - sigma_c)^-1 * (C[0] - h * C[-1])^(1 - sigma_c) - omega * epsilon_L[0] * (1 + sigma_l)^-1 * L_s[0]^(1 + sigma_l)) + + U_f[0] - beta * U_f[1] - epsilon_b[0] * ((1 - sigma_c)^-1 * (C_f[0] - h * C_f[-1])^(1 - sigma_c) - omega * epsilon_L[0] * (1 + sigma_l)^-1 * L_s_f[0]^(1 + sigma_l)) + + -epsilon_b[0] * (C[0] - h * C[-1])^(-sigma_c) + q[0] * (1 - 0.5 * varphi * (-1 + I[-1]^-1 * epsilon_I[0] * I[0])^2 - varphi * I[-1]^-1 * epsilon_I[0] * I[0] * (-1 + I[-1]^-1 * epsilon_I[0] * I[0])) + beta * varphi * I[0]^-2 * epsilon_I[1] * q[1] * I[1]^2 * (-1 + I[0]^-1 * epsilon_I[1] * I[1]) + + -epsilon_b[0] * (C_f[0] - h * C_f[-1])^(-sigma_c) + q_f[0] * (1 - 0.5 * varphi * (-1 + I_f[-1]^-1 * epsilon_I[0] * I_f[0])^2 - varphi * I_f[-1]^-1 * epsilon_I[0] * I_f[0] * (-1 + I_f[-1]^-1 * epsilon_I[0] * I_f[0])) + beta * varphi * I_f[0]^-2 * epsilon_I[1] * q_f[1] * I_f[1]^2 * (-1 + I_f[0]^-1 * epsilon_I[1] * I_f[1]) + + -C[0] - I[0] - T[0] + Y[0] - psi^-1 * r_k[ss] * K[-1] * (-1 + exp(psi * (-1 + z[0]))) + + -C_f[0] - I_f[0] + Pi_ws_f[0] - T_f[0] + Y_f[0] + L_s_f[0] * W_disutil_f[0] - L_f[0] * W_f[0] - psi^-1 * r_k_f[ss] * K_f[-1] * (-1 + exp(psi * (-1 + z_f[0]))) + + epsilon_b[0] * (K[-1] * r_k[0] - r_k[ss] * K[-1] * exp(psi * (-1 + z[0]))) * (C[0] - h * C[-1])^(-sigma_c) + + epsilon_b[0] * (K_f[-1] * r_k_f[0] - r_k_f[ss] * K_f[-1] * exp(psi * (-1 + z_f[0]))) * (C_f[0] - h * C_f[-1])^(-sigma_c) + + + # Perceived inflation objective + std_eta_pi * eta_pi[x] - log(pi_obj[0]) + rho_pi_bar * log(pi_obj[-1]) + log(calibr_pi_obj) * (1 - rho_pi_bar) + + # Taylor rule with effective lower bound + log(R[0]) = max(R̄ , r_Delta_pi * (-log(pi[ss]^-1 * pi[-1]) + log(pi[ss]^-1 * pi[0])) + r_Delta_y * (-log(Y[ss]^-1 * Y[-1]) + log(Y[ss]^-1 * Y[0]) + log(Y_f[ss]^-1 * Y_f[-1]) - log(Y_f[ss]^-1 * Y_f[0])) + rho * log(R[ss]^-1 * R[-1]) + (1 - rho) * (log(pi_obj[0]) + r_pi * (-log(pi_obj[0]) + log(pi[ss]^-1 * pi[-1])) + r_Y * (log(Y[ss]^-1 * Y[0]) - log(Y_f[ss]^-1 * Y_f[0]))) - calibr_pi + std_eta_R * eta_R[x] - log(R[ss]^-1)) + +end + +@parameters SW03_obc begin + R̄ = 0.0 # effective lower bound + + lambda_p = 0.368 + G_bar = 0.362 + lambda_w = 0.5 + Phi = 0.819 + + alpha = 0.3 + beta = 0.99 + gamma_w = 0.763 + gamma_p = 0.469 + h = 0.573 + omega = 1 + psi = 0.169 + + r_pi = 1.684 + r_Y = 0.099 + r_Delta_pi = 0.14 + r_Delta_y = 0.159 + + sigma_c = 1.353 + sigma_l = 2.4 + tau = 0.025 + varphi = 6.771 + xi_w = 0.737 + xi_p = 0.908 + + rho = 0.961 + rho_b = 0.855 + rho_L = 0.889 + rho_I = 0.927 + rho_a = 0.823 + rho_G = 0.949 + rho_pi_bar = 0.924 + + std_scaling_factor = 10 + + std_eta_b = σ_eta_b / std_scaling_factor + std_eta_L = σ_eta_L / std_scaling_factor + std_eta_I = σ_eta_I / std_scaling_factor + std_eta_a = σ_eta_a / std_scaling_factor + std_eta_w = σ_eta_w / std_scaling_factor + std_eta_p = σ_eta_p / std_scaling_factor + std_eta_G = σ_eta_G / std_scaling_factor + std_eta_R = σ_eta_R / std_scaling_factor + std_eta_pi = σ_eta_pi / std_scaling_factor + + σ_eta_b = 0.336 + σ_eta_L = 3.52 + σ_eta_I = 0.085 + σ_eta_a = 0.598 + σ_eta_w = 0.6853261 + σ_eta_p = 0.7896512 + σ_eta_G = 0.325 + σ_eta_R = 0.081 + σ_eta_pi = 0.017 + + calibr_pi_obj | 1 = pi_obj[ss] + calibr_pi | pi[ss] = pi_obj[ss] +end diff --git a/src/MacroModelling.jl b/src/MacroModelling.jl index 428d0f82..0741f9b1 100644 --- a/src/MacroModelling.jl +++ b/src/MacroModelling.jl @@ -3,12 +3,14 @@ module MacroModelling import DocStringExtensions: FIELDS, SIGNATURES, TYPEDEF, TYPEDSIGNATURES, TYPEDFIELDS # import StatsFuns: normcdf -import ThreadedSparseArrays +# import ThreadedSparseArrays using PrecompileTools import SpecialFunctions: erfcinv, erfc import SymPyPythonCall as SPyPyC import Symbolics import ForwardDiff as ℱ +import JuMP +import MadNLP, NLopt # MadNLP doesnt support noninear constraints # StatusSwitchingQP not reliable # import Zygote import SparseArrays: SparseMatrixCSC, SparseVector, AbstractSparseArray#, sparse, spzeros, droptol!, sparsevec, spdiagm, findnz#, sparse! import LinearAlgebra as ℒ @@ -60,9 +62,9 @@ end export @model, @parameters, solve! -export plot_irfs, plot_irf, plot_IRF, plot_simulations, plot_solution#, plot +export plot_irfs, plot_irf, plot_IRF, plot_simulations, plot_solution, plot_simulation#, plot export plot_conditional_variance_decomposition, plot_forecast_error_variance_decomposition, plot_fevd, plot_model_estimates, plot_shock_decomposition -export get_irfs, get_irf, get_IRF, simulate, get_simulation +export get_irfs, get_irf, get_IRF, simulate, get_simulation, get_simulations export get_conditional_forecast, plot_conditional_forecast export get_solution, get_first_order_solution, get_perturbation_solution, get_second_order_solution, get_third_order_solution export get_steady_state, get_SS, get_ss, get_non_stochastic_steady_state, get_stochastic_steady_state, get_SSS, steady_state, SS, SSS, ss, sss @@ -121,7 +123,330 @@ Base.show(io::IO, 𝓂::ℳ) = println(io, # "\nNon-stochastic-steady-state found: ",!𝓂.solution.outdated_NSSS ) +check_for_dynamic_variables(ex::Int) = false +check_for_dynamic_variables(ex::Float64) = false +check_for_dynamic_variables(ex::Symbol) = occursin(r"₍₁₎|₍₀₎|₍₋₁₎",string(ex)) +function check_for_dynamic_variables(ex::Expr) + dynamic_indicator = Bool[] + + postwalk(x -> + x isa Expr ? + x.head == :ref ? + occursin(r"^(ss|stst|steady|steadystate|steady_state){1}$"i,string(x.args[2])) ? + x : + begin + push!(dynamic_indicator,true) + x + end : + x : + x, + ex) + + any(dynamic_indicator) +end + + +function transform_expression(expr::Expr) + # Dictionary to store the transformations for reversing + reverse_transformations = Dict{Symbol, Expr}() + + # Counter for generating unique placeholders + unique_counter = Ref(0) + + # Step 1: Replace min/max calls and record their original form + function replace_min_max(expr) + if expr isa Expr && expr.head == :call && (expr.args[1] == :min || expr.args[1] == :max) + # Replace min/max functions with a placeholder + # placeholder = Symbol("minimal__P", unique_counter[]) + placeholder = :minmax__P + unique_counter[] += 1 + + # Store the original min/max call for reversal + reverse_transformations[placeholder] = expr + + return placeholder + else + return expr + end + end + + # Step 2: Transform :ref fields in the rest of the expression + function transform_ref_fields(expr) + if expr isa Expr && expr.head == :ref && isa(expr.args[1], Symbol) + # Handle :ref expressions + if isa(expr.args[2], Number) || isa(expr.args[2], Symbol) + new_symbol = Symbol(expr.args[1], "_", expr.args[2]) + else + # Generate a unique placeholder for complex :ref + unique_counter[] += 1 + placeholder = Symbol("__placeholder", unique_counter[]) + new_symbol = placeholder + end + + # Record the reverse transformation + reverse_transformations[new_symbol] = expr + + return new_symbol + else + return expr + end + end + + + # Replace equality sign with minus + function replace_equality_with_minus(expr) + if expr isa Expr && expr.head == :(=) + return Expr(:call, :-, expr.args...) + else + return expr + end + end + + # Apply transformations + expr = postwalk(replace_min_max, expr) + expr = postwalk(transform_ref_fields, expr) + transformed_expr = postwalk(replace_equality_with_minus, expr) + + return transformed_expr, reverse_transformations +end + + +function reverse_transformation(transformed_expr::Expr, reverse_dict::Dict{Symbol, Expr}) + # Function to replace the transformed symbols with their original form + function revert_symbol(expr) + if expr isa Symbol && haskey(reverse_dict, expr) + return reverse_dict[expr] + else + return expr + end + end + + # Revert the expression using postwalk + reverted_expr = postwalk(revert_symbol, transformed_expr) + + return reverted_expr +end + + +function transform_obc(ex::Expr) + transformed_expr, reverse_dict = transform_expression(ex) + + for symbs in get_symbols(transformed_expr) + eval(:($symbs = SPyPyC.symbols($(string(symbs)), real = true, finite = true))) + end + + eq = eval(transformed_expr) + + soll = try SPyPyC.solve(eq, eval(:minmax__P)) + catch + end + + if length(soll) == 1 + sorted_minmax = Expr(:call, reverse_dict[:minmax__P].args[1], :($(reverse_dict[:minmax__P].args[2]) - $(Meta.parse(string(soll[1])))), :($(reverse_dict[:minmax__P].args[3]) - $(Meta.parse(string(soll[1]))))) + return reverse_transformation(sorted_minmax, reverse_dict) + else + @error "Occasionally binding constraint not well-defined. See documentation for examples." + end +end + + + +function set_up_obc_violation_function!(𝓂) + present_varss = collect(reduce(union,match_pattern.(get_symbols.(𝓂.dyn_equations),r"₍₀₎$"))) + + sort!(present_varss ,by = x->replace(string(x),r"₍₀₎$"=>"")) + + # write indices in auxiliary objects + dyn_var_present_list = map(x->Set{Symbol}(map(x->Symbol(replace(string(x),"₍₀₎" => "")),x)),collect.(match_pattern.(get_symbols.(𝓂.dyn_equations),r"₍₀₎"))) + + dyn_var_present = Symbol.(replace.(string.(sort(collect(reduce(union,dyn_var_present_list)))), r"ᴸ⁽⁻?[⁰¹²³⁴⁵⁶⁷⁸⁹]+⁾" => "")) + + SS_and_pars_names = vcat(Symbol.(replace.(string.(sort(union(𝓂.var,𝓂.exo_past,𝓂.exo_future))), r"ᴸ⁽⁻?[⁰¹²³⁴⁵⁶⁷⁸⁹]+⁾" => "")), 𝓂.calibration_equations_parameters) + + dyn_var_present_idx = indexin(dyn_var_present , SS_and_pars_names) + + alll = [] + for (i,var) in enumerate(present_varss) + if !(match(r"^χᵒᵇᶜ", string(var)) === nothing) + push!(alll,:($var = Y[$(dyn_var_present_idx[i]),1:end-1])) + end + end + + calc_obc_violation = :(function calculate_obc_violation(x::Vector, + initial_state, + state_update, + reference_steady_state, + 𝓂, + algorithm, + periods, + shock_values) + T = 𝓂.timings + + # if algorithm ∈ [:first_order, :riccati, :linear_time_iteration, :quadratic_iteration] + # Ytype = JuMP.AffExpr + # elseif algorithm ∈ [:pruned_second_order, :second_order] + # Ytype = JuMP.QuadExpr + # elseif algorithm ∈ [:pruned_third_order, :third_order] + # Ytype = JuMP.NonlinearExpr + # end + + # Y = zeros(Ytype, T.nVars, periods+2) + + Y = zeros(JuMP.AffExpr, T.nVars, periods+1) + + shock_values[contains.(string.(T.exo),"ᵒᵇᶜ")] .= x + + zero_shock = zero(shock_values) + + Y[:,1] = state_update(initial_state, shock_values) + + for t in 1:periods + Y[:,t+1] = state_update(Y[:,t], zero_shock) + end + + Y .+= reference_steady_state[1:T.nVars] + + $(alll...) + + constraint_values = Vector[] + # shock_sign_indicators = Bool[] + + $(𝓂.obc_violation_equations...) + + return vcat(constraint_values...)#, shock_sign_indicators + end) + + 𝓂.obc_violation_function = @RuntimeGeneratedFunction(calc_obc_violation) + + return nothing +end + + +function check_for_minmax(expr) + contains_minmax = Bool[] + + postwalk(x -> + x isa Expr ? + x.head == :call ? + x.args[1] ∈ [:max,:min] ? + begin + push!(contains_minmax,true) + x + end : + x : + x : + x, + expr) + + any(contains_minmax) +end + + +function write_obc_violation_equations(𝓂) + eqs = Expr[] + for (i,eq) in enumerate(𝓂.dyn_equations) + if check_for_minmax(eq) + minmax_fixed_eqs = postwalk(x -> + x isa Expr ? + x.head == :call ? + length(x.args) == 3 ? + x.args[3] isa Expr ? + x.args[3].args[1] ∈ [:Min, :min, :Max, :max] ? + begin + plchldr = Symbol(replace(string(x.args[2]), "₍₀₎" => "")) + + ineq_plchldr_1 = x.args[3].args[2] isa Symbol ? Symbol(replace(string(x.args[3].args[2]), "₍₀₎" => "")) : x.args[3].args[2] + + arg1 = x.args[3].args[2] + arg2 = x.args[3].args[3] + + dyn_1 = check_for_dynamic_variables(x.args[3].args[2]) + dyn_2 = check_for_dynamic_variables(x.args[3].args[3]) + + cond1 = Expr[] + cond2 = Expr[] + + maximisation = contains(string(plchldr), "⁺") + + # 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])))) + # else + # push!(cond1, :(push!(constraint_values, -$(x.args[3].args[2])))) + # # 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 + # else + # push!(cond1, :(push!(constraint_values, -$(x.args[3].args[3])))) + # # push!(cond2, :(push!(constraint_values, -$(x.args[3].args[3])))) # RBC + # end + # end + + + if maximisation + push!(cond1, :(push!(constraint_values, [sum($(x.args[3].args[2]) .* $(x.args[3].args[3]))]))) + push!(cond1, :(push!(constraint_values, $(x.args[3].args[2])))) + push!(cond1, :(push!(constraint_values, $(x.args[3].args[3])))) + # push!(cond1, :(push!(constraint_values, max.($(x.args[3].args[2]), $(x.args[3].args[3]))))) + else + push!(cond1, :(push!(constraint_values, [sum($(x.args[3].args[2]) .* $(x.args[3].args[3]))]))) + push!(cond1, :(push!(constraint_values, -$(x.args[3].args[2])))) + push!(cond1, :(push!(constraint_values, -$(x.args[3].args[3])))) + # push!(cond1, :(push!(constraint_values, min.($(x.args[3].args[2]), $(x.args[3].args[3]))))) + end + + # if maximisation + # push!(cond1, :(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))) + # end + + # :(if isapprox($plchldr, $ineq_plchldr_1, atol = 1e-12) + # $(Expr(:block, cond1...)) + # else + # $(Expr(:block, cond2...)) + # end) + :($(Expr(:block, cond1...))) + end : + x : + x : + x : + x : + x, + eq) + + push!(eqs, minmax_fixed_eqs) + end + end + + return eqs +end + +# function parse_obc_shock_bounds(expr::Expr) +# # Determine the order of the shock and bound in the expression +# shock_first = isa(expr.args[2], Symbol) + +# # Extract the shock and bound from the expression +# shock = shock_first ? expr.args[2] : expr.args[3] +# bound_expr = shock_first ? expr.args[3] : expr.args[2] + +# # Evaluate the bound expression to get a numerical value +# bound = eval(bound_expr) |> Float64 + +# # Determine whether the bound is a lower or upper bound based on the comparison operator and order +# is_upper_bound = (expr.args[1] in (:<, :≤) && shock_first) || (expr.args[1] in (:>, :≥) && !shock_first) + +# return shock, is_upper_bound, bound +# end @@ -601,6 +926,106 @@ function match_pattern(strings::Union{Set,Vector}, pattern::Regex) return filter(r -> match(pattern, string(r)) !== nothing, strings) end +# try: run optim only if there is a violation / capture case with small shocks and set them to zero +function parse_occasionally_binding_constraints(equations_block; max_obc_horizon::Int = 40) + # precision_factor = 1e #factor to force the optimiser to have non-relevatn shocks at zero + + eqs = [] + obc_shocks = Expr[] + + for arg in equations_block.args + if isa(arg,Expr) + if check_for_minmax(arg) + arg_trans = transform_obc(arg) + else + arg_trans = arg + end + + eq = postwalk(x -> + x isa Expr ? + x.head == :call ? + x.args[1] == :max ? + begin + + obc_vars_left = Expr(:ref, Meta.parse("χᵒᵇᶜ⁺ꜝ" * super(string(length(obc_shocks) + 1)) * "ꜝˡ" ), 0) + obc_vars_right = Expr(:ref, Meta.parse("χᵒᵇᶜ⁺ꜝ" * super(string(length(obc_shocks) + 1)) * "ꜝʳ" ), 0) + + if !(x.args[2] isa Symbol) && check_for_dynamic_variables(x.args[2]) + push!(eqs, :($obc_vars_left = $(x.args[2]))) + else + obc_vars_left = x.args[2] + end + + if !(x.args[3] isa Symbol) && check_for_dynamic_variables(x.args[3]) + push!(eqs, :($obc_vars_right = $(x.args[3]))) + else + obc_vars_right = x.args[3] + end + + obc_inequality = Expr(:ref, Meta.parse("Χᵒᵇᶜ⁺ꜝ" * super(string(length(obc_shocks) + 1)) * "ꜝ" ), 0) + + push!(eqs, :($obc_inequality = $(Expr(x.head, x.args[1], obc_vars_left, obc_vars_right)))) + + obc_shock = Expr(:ref, Meta.parse("ϵᵒᵇᶜ⁺ꜝ" * super(string(length(obc_shocks) + 1)) * "ꜝ"), 0) + + push!(obc_shocks, obc_shock) + + :($obc_inequality - $obc_shock) + end : + x.args[1] == :min ? + begin + obc_vars_left = Expr(:ref, Meta.parse("χᵒᵇᶜ⁻ꜝ" * super(string(length(obc_shocks) + 1)) * "ꜝˡ" ), 0) + obc_vars_right = Expr(:ref, Meta.parse("χᵒᵇᶜ⁻ꜝ" * super(string(length(obc_shocks) + 1)) * "ꜝʳ" ), 0) + + if !(x.args[2] isa Symbol) && check_for_dynamic_variables(x.args[2]) + push!(eqs, :($obc_vars_left = $(x.args[2]))) + else + obc_vars_left = x.args[2] + end + + if !(x.args[3] isa Symbol) && check_for_dynamic_variables(x.args[3]) + push!(eqs, :($obc_vars_right = $(x.args[3]))) + else + obc_vars_right = x.args[3] + end + + obc_inequality = Expr(:ref, Meta.parse("Χᵒᵇᶜ⁻ꜝ" * super(string(length(obc_shocks) + 1)) * "ꜝ" ), 0) + + push!(eqs, :($obc_inequality = $(Expr(x.head, x.args[1], obc_vars_left, obc_vars_right)))) + + obc_shock = Expr(:ref, Meta.parse("ϵᵒᵇᶜ⁻ꜝ" * super(string(length(obc_shocks) + 1)) * "ꜝ"), 0) + + push!(obc_shocks, obc_shock) + + :($obc_inequality - $obc_shock) + end : + x : + x : + x, + arg_trans) + + push!(eqs, eq) + end + end + + for obc in obc_shocks + # push!(eqs, :($(obc) = $(Expr(:ref, obc.args[1], -1)) * 0.3 + $(Expr(:ref, Meta.parse(string(obc.args[1]) * "ᴸ⁽⁻" * super(string(max_obc_horizon)) * "⁾"), 0)))) + push!(eqs, :($(obc) = $(Expr(:ref, Meta.parse(string(obc.args[1]) * "ᴸ⁽⁻" * super(string(max_obc_horizon)) * "⁾"), 0)))) + + push!(eqs, :($(Expr(:ref, Meta.parse(string(obc.args[1]) * "ᴸ⁽⁻⁰⁾"), 0)) = activeᵒᵇᶜshocks * $(Expr(:ref, Meta.parse(string(obc.args[1]) * "⁽" * super(string(max_obc_horizon)) * "⁾"), :x)))) + + for i in 1:max_obc_horizon + push!(eqs, :($(Expr(:ref, Meta.parse(string(obc.args[1]) * "ᴸ⁽⁻" * super(string(i)) * "⁾"), 0)) = $(Expr(:ref, Meta.parse(string(obc.args[1]) * "ᴸ⁽⁻" * super(string(i-1)) * "⁾"), -1)) + activeᵒᵇᶜshocks * $(Expr(:ref, Meta.parse(string(obc.args[1]) * "⁽" * super(string(max_obc_horizon-i)) * "⁾"), :x)))) + end + end + + return Expr(:block, eqs...) +end + + +# compatibility with SymPy +Max = max +Min = min function simplify(ex::Expr) ex_ss = convert_to_ss_equation(ex) @@ -611,7 +1036,11 @@ function simplify(ex::Expr) parsed = ex_ss |> eval |> string |> Meta.parse - postwalk(x -> x isa Expr ? x.args[1] == :conjugate ? x.args[2] : x : x, parsed) + postwalk(x -> x isa Expr ? + x.args[1] == :conjugate ? + x.args[2] : + x : + x, parsed) end function convert_to_ss_equation(eq::Expr) @@ -903,6 +1332,20 @@ end # transformation of NSSS problem +function transform(x::Vector{T}, option::Int, shift::AbstractFloat) where T <: Real + if option == 4 + return asinh.(asinh.(asinh.(asinh.(x .+ shift)))) + elseif option == 3 + return asinh.(asinh.(asinh.(x .+ shift))) + elseif option == 2 + return asinh.(asinh.(x .+ shift)) + elseif option == 1 + return asinh.(x .+ shift) + elseif option == 0 + return x .+ shift + end +end + function transform(x::Vector{T}, option::Int) where T <: Real if option == 4 return asinh.(asinh.(asinh.(asinh.(x)))) @@ -917,6 +1360,20 @@ function transform(x::Vector{T}, option::Int) where T <: Real end end +function undo_transform(x::Vector{T}, option::Int, shift::AbstractFloat) where T <: Real + if option == 4 + return sinh.(sinh.(sinh.(sinh.(x)))) .- shift + elseif option == 3 + return sinh.(sinh.(sinh.(x))) .- shift + elseif option == 2 + return sinh.(sinh.(x)) .- shift + elseif option == 1 + return sinh.(x) .- shift + elseif option == 0 + return x .- shift + end +end + function undo_transform(x::Vector{T}, option::Int) where T <: Real if option == 4 return sinh.(sinh.(sinh.(sinh.(x)))) @@ -936,46 +1393,54 @@ function levenberg_marquardt(f::Function, initial_guess::Array{T,1}, lower_bounds::Array{T,1}, upper_bounds::Array{T,1}; - xtol::T = eps(), - ftol::T = eps(), - iterations::S = 250, - ϕ̄::T = 8.0, - ϕ̂::T = 0.904, - μ̄¹::T = 0.026, - μ̄²::T = 0.0, - p̄¹::T = 1.0, - p̄²::T = 0.0, - ρ::T = 0.1, - ρ¹::T = 0.17, - ρ²::T = 0.07, - ρ³::T = 0.01, - ν::T = 0.8, - λ¹::T = 0.84, - λ²::T = 1.0, - λ̂¹::T = 0.5, - λ̂²::T = 1.0, - λ̅¹::T = 0.0128, - λ̅²::T = 1.0, - λ̂̅¹::T = 0.9815, - λ̂̅²::T = 1.0, - transformation_level::S = 3, - backtracking_order::S = 2) where {T <: AbstractFloat, S <: Integer} + parameters::solver_parameters = solver_parameters(eps(), eps(), 250, 2.9912988764832833, 0.8725, 0.0027, 0.028948770826150612, 8.04, 4.076413176215408, 0.06375413238034794, 0.24284340766769424, 0.5634017580097571, 0.009549630552246828, 0.6342888355132347, 0.5275522227754195, 1.0, 0.06178989216048817, 0.5234277812131813, 0.422, 0.011209254402846185, 0.5047, 0.6020757011698457, 1, 0.0, 2) + ) where {T <: AbstractFloat} # issues with optimization: https://www.gurobi.com/documentation/8.1/refman/numerics_gurobi_guidelines.html + xtol = parameters.xtol + ftol = parameters.ftol + iterations = parameters.iterations + ϕ̄ = parameters.ϕ̄ + ϕ̂ = parameters.ϕ̂ + μ̄¹ = parameters.μ̄¹ + μ̄² = parameters.μ̄² + p̄¹ = parameters.p̄¹ + p̄² = parameters.p̄² + ρ = parameters.ρ + ρ¹ = parameters.ρ¹ + ρ² = parameters.ρ² + ρ³ = parameters.ρ³ + ν = parameters.ν + λ¹ = parameters.λ¹ + λ² = parameters.λ² + λ̂¹ = parameters.λ̂¹ + λ̂² = parameters.λ̂² + λ̅¹ = parameters.λ̅¹ + λ̅² = parameters.λ̅² + λ̂̅¹ = parameters.λ̂̅¹ + λ̂̅² = parameters.λ̂̅² + transformation_level = parameters.transformation_level + shift = parameters.shift + backtracking_order = parameters.backtracking_order + @assert size(lower_bounds) == size(upper_bounds) == size(initial_guess) - @assert lower_bounds < upper_bounds + @assert all(lower_bounds .< upper_bounds) @assert backtracking_order ∈ [2,3] "Backtracking order can only be quadratic (2) or cubic (3)." max_linesearch_iterations = 1000 function f̂(x) f(undo_transform(x,transformation_level)) + # f(undo_transform(x,transformation_level,shift)) end upper_bounds = transform(upper_bounds,transformation_level) + # upper_bounds = transform(upper_bounds,transformation_level,shift) lower_bounds = transform(lower_bounds,transformation_level) + # lower_bounds = transform(lower_bounds,transformation_level,shift) current_guess = copy(transform(initial_guess,transformation_level)) + # current_guess = copy(transform(initial_guess,transformation_level,shift)) previous_guess = similar(current_guess) guess_update = similar(current_guess) @@ -1002,6 +1467,7 @@ function levenberg_marquardt(f::Function, if !all(isfinite,∇̂) return undo_transform(current_guess,transformation_level), (iter, Inf, Inf, upper_bounds) + # return undo_transform(current_guess,transformation_level,shift), (iter, Inf, Inf, upper_bounds) end ∇̄ = RF.lu(∇̂, check = false) @@ -1081,13 +1547,16 @@ function levenberg_marquardt(f::Function, largest_step = maximum(abs, previous_guess - current_guess) largest_residual = maximum(abs, f(undo_transform(current_guess,transformation_level))) + # largest_residual = maximum(abs, f(undo_transform(current_guess,transformation_level,shift))) if largest_step <= xtol || largest_residual <= ftol return undo_transform(current_guess,transformation_level), (iter, largest_step, largest_residual, f(undo_transform(current_guess,transformation_level))) + # return undo_transform(current_guess,transformation_level,shift), (iter, largest_step, largest_residual, f(undo_transform(current_guess,transformation_level,shift))) end end best_guess = undo_transform(current_guess,transformation_level) + # best_guess = undo_transform(current_guess,transformation_level,shift) return best_guess, (iterations, largest_step, largest_residual, f(best_guess)) end @@ -1231,8 +1700,8 @@ function remove_redundant_SS_vars!(𝓂::ℳ, Symbolics::symbolics) redundant_idx = getindex(1:length(redundant_vars), (length.(redundant_vars) .> 0) .& (length.(Symbolics.var_list) .> 1)) for i in redundant_idx - for var_to_solve in redundant_vars[i] - soll = try SPyPyC.solve(ss_equations[i],var_to_solve) + for var_to_solve_for in redundant_vars[i] + soll = try SPyPyC.solve(ss_equations[i],var_to_solve_for) catch end @@ -1241,8 +1710,8 @@ function remove_redundant_SS_vars!(𝓂::ℳ, Symbolics::symbolics) end if length(soll) == 0 || soll == SPyPyC.Sym[0] # take out variable if it is redundant from that euation only - push!(Symbolics.var_redundant_list[i],var_to_solve) - ss_equations[i] = ss_equations[i].subs(var_to_solve,1).replace(SPyPyC.Sym(ℯ),exp(1)) # replace euler constant as it is not translated to julia properly + push!(Symbolics.var_redundant_list[i],var_to_solve_for) + ss_equations[i] = ss_equations[i].subs(var_to_solve_for,1).replace(SPyPyC.Sym(ℯ),exp(1)) # replace euler constant as it is not translated to julia properly end end @@ -1299,27 +1768,55 @@ function solve_steady_state!(𝓂::ℳ, symbolic_SS, Symbolics::symbolics; verbo relevant_pars_across = [] NSSS_solver_cache_init_tmp = [] + min_max_errors = [] + n_block = 1 while n > 0 if length(eqs[:,eqs[2,:] .== n]) == 2 - var_to_solve = collect(unknowns)[vars[:,vars[2,:] .== n][1]] + var_to_solve_for = collect(unknowns)[vars[:,vars[2,:] .== n][1]] + + eq_to_solve = ss_equations[eqs[:,eqs[2,:] .== n][1]] - soll = try SPyPyC.solve(ss_equations[eqs[:,eqs[2,:] .== n][1]],var_to_solve) + # eliminate min/max from equations if solving for variables inside min/max. set to the variable we solve for automatically + parsed_eq_to_solve_for = eq_to_solve |> string |> Meta.parse + + minmax_fixed_eqs = postwalk(x -> + x isa Expr ? + x.head == :call ? + x.args[1] ∈ [:Max,:Min] ? + Symbol(var_to_solve_for) ∈ get_symbols(x.args[2]) ? + x.args[2] : + Symbol(var_to_solve_for) ∈ get_symbols(x.args[3]) ? + x.args[3] : + x : + x : + x : + x, + parsed_eq_to_solve_for) + + if parsed_eq_to_solve_for != minmax_fixed_eqs + [push!(atoms_in_equations, a) for a in setdiff(get_symbols(parsed_eq_to_solve_for), get_symbols(minmax_fixed_eqs))] + push!(min_max_errors,:(solution_error += abs($parsed_eq_to_solve_for))) + eq_to_solve = eval(minmax_fixed_eqs) + end + + soll = try SPyPyC.solve(eq_to_solve,var_to_solve_for) catch end if isnothing(soll) # println("Could not solve single variables case symbolically.") - println("Failed finding solution symbolically for: ",var_to_solve," in: ",ss_equations[eqs[:,eqs[2,:] .== n][1]]) + println("Failed finding solution symbolically for: ",var_to_solve_for," in: ",eq_to_solve) # solve numerically continue # elseif PythonCall.pyconvert(Bool,soll[1].is_number) + elseif soll[1].is_number == true # ss_equations = ss_equations.subs(var_to_solve,soll[1]) - ss_equations = [eq.subs(var_to_solve,soll[1]) for eq in ss_equations] + ss_equations = [eq.subs(var_to_solve_for,soll[1]) for eq in ss_equations] - push!(𝓂.solved_vars,Symbol(var_to_solve)) + push!(𝓂.solved_vars,Symbol(var_to_solve_for)) push!(𝓂.solved_vals,Meta.parse(string(soll[1]))) if (𝓂.solved_vars[end] ∈ 𝓂.➕_vars) @@ -1331,12 +1828,14 @@ function solve_steady_state!(𝓂::ℳ, symbolic_SS, Symbolics::symbolics; verbo push!(atoms_in_equations_list,[]) else - push!(𝓂.solved_vars,Symbol(var_to_solve)) + push!(𝓂.solved_vars,Symbol(var_to_solve_for)) push!(𝓂.solved_vals,Meta.parse(string(soll[1]))) # atoms = reduce(union,soll[1].atoms()) + [push!(atoms_in_equations, Symbol(a)) for a in soll[1].atoms()] - push!(atoms_in_equations_list, Set(Symbol.(soll[1].atoms()))) + push!(atoms_in_equations_list, Set(union(setdiff(get_symbols(parsed_eq_to_solve_for), get_symbols(minmax_fixed_eqs)),Symbol.(soll[1].atoms())))) + # println(atoms_in_equations) # push!(atoms_in_equations, soll[1].atoms()) @@ -1630,7 +2129,9 @@ function solve_steady_state!(𝓂::ℳ, symbolic_SS, Symbolics::symbolics; verbo inits, lbs, ubs, + solver_parameters, # fail_fast_solvers_only = fail_fast_solvers_only, + cold_start, verbose))) # push!(SS_solve_func,:(solution = block_solver_RD([$(calib_pars_input...),$(other_vars_input...)])))#, @@ -1643,7 +2144,8 @@ function solve_steady_state!(𝓂::ℳ, symbolic_SS, Symbolics::symbolics; verbo # ubs, # fail_fast_solvers_only = fail_fast_solvers_only, # verbose = verbose))) - push!(SS_solve_func,:(solution_error += solution[2])) + push!(SS_solve_func,:(iters += solution[2][2])) + push!(SS_solve_func,:(solution_error += solution[2][1])) push!(SS_solve_func,:(sol = solution[1])) # push!(SS_solve_func,:(solution_error += sum(abs2,𝓂.ss_solve_blocks[$(n_block)]([$(calib_pars_input...),$(other_vars_input...)],solution)))) # push!(SS_solve_func,:(sol = solution)) @@ -1708,6 +2210,7 @@ function solve_steady_state!(𝓂::ℳ, symbolic_SS, Symbolics::symbolics; verbo push!(SS_solve_func,:($(dyn_exos...))) + push!(SS_solve_func, min_max_errors...) # push!(SS_solve_func,:(push!(NSSS_solver_cache_tmp, params_scaled_flt))) push!(SS_solve_func,:(if length(NSSS_solver_cache_tmp) == 0 NSSS_solver_cache_tmp = [params_scaled_flt] else NSSS_solver_cache_tmp = [NSSS_solver_cache_tmp...,params_scaled_flt] end)) @@ -1743,9 +2246,11 @@ function solve_steady_state!(𝓂::ℳ, symbolic_SS, Symbolics::symbolics; verbo solve_exp = :(function solve_SS(parameters::Vector{Real}, - 𝓂::ℳ, + 𝓂::ℳ, # fail_fast_solvers_only::Bool, - verbose::Bool) + verbose::Bool, + cold_start::Union{Bool,Float64}, + solver_parameters::solver_parameters) params_flt = typeof(parameters) == Vector{Float64} ? parameters : ℱ.value.(parameters) current_best = sum(abs2,𝓂.NSSS_solver_cache[end][end] - params_flt) @@ -1779,12 +2284,13 @@ function solve_steady_state!(𝓂::ℳ, symbolic_SS, Symbolics::symbolics; verbo $(𝓂.calibration_equations_no_var...) NSSS_solver_cache_tmp = [] solution_error = 0.0 + iters = 0 $(SS_solve_func...) if scale == 1 # return ComponentVector([$(sort(union(𝓂.var,𝓂.exo_past,𝓂.exo_future))...), $(𝓂.calibration_equations_parameters...)], Axis([sort(union(𝓂.exo_present,𝓂.var))...,𝓂.calibration_equations_parameters...])), solution_error # NSSS_solution = [$(Symbol.(replace.(string.(sort(union(𝓂.var,𝓂.exo_past,𝓂.exo_future))), r"ᴸ⁽⁻?[⁰¹²³⁴⁵⁶⁷⁸⁹]+⁾" => ""))...), $(𝓂.calibration_equations_parameters...)] # NSSS_solution[abs.(NSSS_solution) .< 1e-12] .= 0 # doesnt work with Zygote - return [$(Symbol.(replace.(string.(sort(union(𝓂.var,𝓂.exo_past,𝓂.exo_future))), r"ᴸ⁽⁻?[⁰¹²³⁴⁵⁶⁷⁸⁹]+⁾" => ""))...), $(𝓂.calibration_equations_parameters...)] , solution_error + return [$(Symbol.(replace.(string.(sort(union(𝓂.var,𝓂.exo_past,𝓂.exo_future))), r"ᴸ⁽⁻?[⁰¹²³⁴⁵⁶⁷⁸⁹]+⁾" => ""))...), $(𝓂.calibration_equations_parameters...)], (solution_error, iters) end end end @@ -2009,12 +2515,15 @@ function solve_steady_state!(𝓂::ℳ; verbose::Bool = false) inits, lbs, ubs, + solver_parameters, + cold_start, # fail_fast_solvers_only = fail_fast_solvers_only, verbose))) # push!(SS_solve_func,:(solution = block_solver_RD(length([$(calib_pars_input...),$(other_vars_input...)]) == 0 ? [0.0] : [$(calib_pars_input...),$(other_vars_input...)])))#, - push!(SS_solve_func,:(solution_error += solution[2])) + push!(SS_solve_func,:(iters += solution[2][2])) + push!(SS_solve_func,:(solution_error += solution[2][1])) push!(SS_solve_func,:(sol = solution[1])) # push!(SS_solve_func,:(solution = block_solver_RD(length([$(calib_pars_input...),$(other_vars_input...)]) == 0 ? [0.0] : [$(calib_pars_input...),$(other_vars_input...)])))#, @@ -2071,7 +2580,7 @@ function solve_steady_state!(𝓂::ℳ; verbose::Bool = false) end push!(SS_solve_func,:($(dyn_exos...))) - + # push!(SS_solve_func,:(push!(NSSS_solver_cache_tmp, params_scaled_flt))) push!(SS_solve_func,:(if length(NSSS_solver_cache_tmp) == 0 NSSS_solver_cache_tmp = [params_scaled_flt] else NSSS_solver_cache_tmp = [NSSS_solver_cache_tmp...,params_scaled_flt] end)) @@ -2101,7 +2610,9 @@ function solve_steady_state!(𝓂::ℳ; verbose::Bool = false) solve_exp = :(function solve_SS(parameters::Vector{Real}, 𝓂::ℳ, # fail_fast_solvers_only::Bool, - verbose::Bool) + verbose::Bool, + cold_start::Union{Bool,Float64}, + solver_parameters::solver_parameters) params_flt = typeof(parameters) == Vector{Float64} ? parameters : ℱ.value.(parameters) current_best = sum(abs2,𝓂.NSSS_solver_cache[end][end] - params_flt) @@ -2134,11 +2645,12 @@ function solve_steady_state!(𝓂::ℳ; verbose::Bool = false) $(par_bounds...) $(𝓂.calibration_equations_no_var...) NSSS_solver_cache_tmp = [] + iters = 0 solution_error = 0.0 $(SS_solve_func...) if scale == 1 # return ComponentVector([$(sort(union(𝓂.var,𝓂.exo_past,𝓂.exo_future))...), $(𝓂.calibration_equations_parameters...)], Axis([sort(union(𝓂.exo_present,𝓂.var))...,𝓂.calibration_equations_parameters...])), solution_error - return [$(Symbol.(replace.(string.(sort(union(𝓂.var,𝓂.exo_past,𝓂.exo_future))), r"ᴸ⁽⁻?[⁰¹²³⁴⁵⁶⁷⁸⁹]+⁾" => ""))...), $(𝓂.calibration_equations_parameters...)] , solution_error + return [$(Symbol.(replace.(string.(sort(union(𝓂.var,𝓂.exo_past,𝓂.exo_future))), r"ᴸ⁽⁻?[⁰¹²³⁴⁵⁶⁷⁸⁹]+⁾" => ""))...), $(𝓂.calibration_equations_parameters...)] , (solution_error, iters) end end end @@ -2164,19 +2676,32 @@ function block_solver(parameters_and_solved_vars::Vector{Float64}, guess::Vector{Float64}, lbs::Vector{Float64}, ubs::Vector{Float64}, + parameters::solver_parameters, + cold_start::Union{Bool,Float64}, verbose::Bool; tol::AbstractFloat = eps(), # timeout = 120, - starting_points::Vector{Float64} = [0.897, 1.2, .9, .75, 1.5, -.5, 2, .25] + starting_points::Vector{Float64} = [0.7688, 0.897, 1.2, .9, .75, 1.5, -.5, 2, .25] # fail_fast_solvers_only = true, # verbose::Bool = false ) - sol_values = guess - sol_minimum = sum(abs2,ss_solve_blocks(parameters_and_solved_vars,sol_values)) + if cold_start isa Float64 + sol_values = max.(lbs,min.(ubs, fill(cold_start,length(guess)))) + sol_minimum = 1 + elseif cold_start isa Bool + if cold_start + sol_values = max.(lbs,min.(ubs, fill(0.0,length(guess)))) + sol_minimum = sum(abs2,ss_solve_blocks(parameters_and_solved_vars,sol_values)) + else + sol_values = guess + sol_minimum = sum(abs2,ss_solve_blocks(parameters_and_solved_vars,sol_values)) + iters = 0 - if verbose && sol_minimum < tol - println("Block: ",n_block," - Solved using previous solution; maximum residual = ",maximum(abs,ss_solve_blocks(parameters_and_solved_vars, sol_values))) + if verbose && sol_minimum < tol + println("Block: ",n_block," - Solved using previous solution; maximum residual = ",maximum(abs,ss_solve_blocks(parameters_and_solved_vars, sol_values))) + end + end end # try modified LM to solve hard SS problems @@ -2185,28 +2710,40 @@ function block_solver(parameters_and_solved_vars::Vector{Float64}, previous_sol_init = max.(lbs,min.(ubs, sol_values)) - sol_new, info = SS_optimizer(x->ss_solve_blocks(parameters_and_solved_vars, x), + sol_new, info = SS_optimizer( + x->ss_solve_blocks(parameters_and_solved_vars, x), previous_sol_init, lbs, - ubs) # alternatively use .001)#, μ = μ, p = p)# catch e end + ubs, + parameters = parameters + ) # alternatively use .001)#, μ = μ, p = p)# catch e end sol_minimum = isnan(sum(abs2,info[4])) ? Inf : sum(abs2,info[4]) sol_values = max.(lbs,min.(ubs, sol_new )) + iters = info[1] if sol_minimum < tol if verbose println("Block: ",n_block," - Solved using ",string(SS_optimizer)," and previous best non-converged solution; maximum residual = ",maximum(abs,ss_solve_blocks(parameters_and_solved_vars, sol_values))) end - else + elseif cold_start isa Bool && !cold_start # if the previous non-converged best guess as a starting point does not work, try the standard starting points for starting_point in starting_points if sol_minimum > tol standard_inits = max.(lbs,min.(ubs, fill(starting_point,length(guess)))) standard_inits[ubs .<= 1] .= .1 # capture cases where part of values is small - sol_new, info = SS_optimizer(x->ss_solve_blocks(parameters_and_solved_vars, x),standard_inits,lbs,ubs)# catch e end + + sol_new, info = SS_optimizer( + x->ss_solve_blocks(parameters_and_solved_vars, x), + standard_inits, + lbs, + ubs, + parameters = parameters + )# catch e end sol_minimum = isnan(sum(abs2,info[4])) ? Inf : sum(abs2,info[4]) sol_values = max.(lbs,min.(ubs, sol_new)) + iters = info[1] if sol_minimum < tol && verbose println("Block: ",n_block," - Solved using ",string(SS_optimizer)," and starting point: ",starting_point,"; maximum residual = ",maximum(abs,ss_solve_blocks(parameters_and_solved_vars, sol_values))) @@ -2219,7 +2756,7 @@ function block_solver(parameters_and_solved_vars::Vector{Float64}, end end - return sol_values, sol_minimum + return sol_values, (sol_minimum, iters) end # needed for Julia 1.8 @@ -2231,10 +2768,12 @@ function block_solver(parameters_and_solved_vars::Vector{ℱ.Dual{Z,S,N}}, guess::Vector{Float64}, lbs::Vector{Float64}, ubs::Vector{Float64}, + parameters::solver_parameters, + cold_start::Union{Bool,Float64}, verbose::Bool ; tol::AbstractFloat = eps(), # timeout = 120, - starting_points::Vector{Float64} = [0.897, 1.2, .9, .75, 1.5, -.5, 2, .25] + starting_points::Vector{Float64} = [0.7688, 0.897, 1.2, .9, .75, 1.5, -.5, 2, .25] # fail_fast_solvers_only = true, # verbose::Bool = false ) where {Z,S,N} @@ -2247,7 +2786,7 @@ function block_solver(parameters_and_solved_vars::Vector{ℱ.Dual{Z,S,N}}, if verbose println("Solution for derivatives.") end # get f(vs) - val, min = block_solver(inp, + val, (min, iter) = block_solver(inp, n_block, ss_solve_blocks, # SS_optimizer, @@ -2255,6 +2794,8 @@ function block_solver(parameters_and_solved_vars::Vector{ℱ.Dual{Z,S,N}}, guess, lbs, ubs, + parameters, + cold_start, verbose; tol = tol, # timeout = timeout, @@ -2281,7 +2822,7 @@ function block_solver(parameters_and_solved_vars::Vector{ℱ.Dual{Z,S,N}}, # pack: SoA -> AoS return reshape(map(val, eachrow(jvp)) do v, p ℱ.Dual{Z}(v, p...) # Z is the tag - end, size(val)), min + end, size(val)), (min, iter) end @@ -2369,7 +2910,7 @@ second_order_stochastic_steady_state_iterative_solution = ID.ImplicitFunction(se function calculate_second_order_stochastic_steady_state(parameters::Vector{M}, 𝓂::ℳ; verbose::Bool = false, pruning::Bool = false) where M - SS_and_pars, solution_error = 𝓂.SS_solve_func(parameters, 𝓂, verbose) + SS_and_pars, (solution_error, iters) = 𝓂.SS_solve_func(parameters, 𝓂, verbose, false, 𝓂.solver_parameters) ∇₁ = calculate_jacobian(parameters, SS_and_pars, 𝓂) |> Matrix @@ -2492,7 +3033,7 @@ end function calculate_third_order_stochastic_steady_state(parameters::Vector{M}, 𝓂::ℳ; verbose::Bool = false, pruning::Bool = false, tol::AbstractFloat = eps()) where M - SS_and_pars, solution_error = 𝓂.SS_solve_func(parameters, 𝓂, verbose) + SS_and_pars, (solution_error, iters) = 𝓂.SS_solve_func(parameters, 𝓂, verbose, false, 𝓂.solver_parameters) ∇₁ = calculate_jacobian(parameters, SS_and_pars, 𝓂) |> Matrix @@ -2542,7 +3083,8 @@ function solve!(𝓂::ℳ; algorithm::Symbol = :riccati, symbolic_SS::Bool = false, verbose::Bool = false, - silent::Bool = false) + silent::Bool = false, + tol::AbstractFloat = eps()) @assert algorithm ∈ all_available_algorithms @@ -2571,23 +3113,25 @@ function solve!(𝓂::ℳ; (any([:third_order,:pruned_third_order] .∈ ([algorithm],)) && any([:third_order,:pruned_third_order] .∈ (𝓂.solution.outdated_algorithms,))) - SS_and_pars, solution_error = 𝓂.solution.outdated_NSSS ? 𝓂.SS_solve_func(𝓂.parameter_values, 𝓂, verbose) : (𝓂.solution.non_stochastic_steady_state, eps()) + SS_and_pars, (solution_error, iters) = 𝓂.solution.outdated_NSSS ? 𝓂.SS_solve_func(𝓂.parameter_values, 𝓂, verbose, false, 𝓂.solver_parameters) : (𝓂.solution.non_stochastic_steady_state, (eps(), 0)) + + if solution_error > tol + @warn "Could not find non stochastic steady steady." + end - # @assert solution_error < eps() "Could not find non stochastic steady steady." - ∇₁ = calculate_jacobian(𝓂.parameter_values, SS_and_pars, 𝓂) |> Matrix sol_mat, solved = calculate_first_order_solution(∇₁; T = 𝓂.timings) @assert solved "Could not find stable first order solution." - state_update₁ = function(state::Vector{Float64}, shock::Vector{Float64}) sol_mat * [state[𝓂.timings.past_not_future_and_mixed_idx]; shock] end + state_update₁ = function(state::Vector{T}, shock::Vector{S}) where {T,S} sol_mat * [state[𝓂.timings.past_not_future_and_mixed_idx]; shock] end 𝓂.solution.perturbation.first_order = perturbation_solution(sol_mat, state_update₁) 𝓂.solution.outdated_algorithms = setdiff(𝓂.solution.outdated_algorithms,[:riccati, :first_order]) 𝓂.solution.non_stochastic_steady_state = SS_and_pars - 𝓂.solution.outdated_NSSS = false + 𝓂.solution.outdated_NSSS = solution_error > tol end @@ -2600,7 +3144,7 @@ function solve!(𝓂::ℳ; @assert converged "Solution does not have a stochastic steady state. Try reducing shock sizes by multiplying them with a number < 1." - state_update₂ = function(state::Vector{Float64}, shock::Vector{Float64}) + state_update₂ = function(state::Vector{T}, shock::Vector{S}) where {T,S} aug_state = [state[𝓂.timings.past_not_future_and_mixed_idx] 1 shock] @@ -2621,7 +3165,7 @@ function solve!(𝓂::ℳ; @assert converged "Solution does not have a stochastic steady state. Try reducing shock sizes by multiplying them with a number < 1." - state_update₂ = function(pruned_states::Vector{Vector{Float64}}, shock::Vector{Float64}) + state_update₂ = function(pruned_states::Vector{Vector{T}}, shock::Vector{S}) where {T,S} aug_state₁ = [pruned_states[1][𝓂.timings.past_not_future_and_mixed_idx]; 1; shock] aug_state₂ = [pruned_states[2][𝓂.timings.past_not_future_and_mixed_idx]; 0; zero(shock)] @@ -2642,7 +3186,7 @@ function solve!(𝓂::ℳ; @assert converged "Solution does not have a stochastic steady state. Try reducing shock sizes by multiplying them with a number < 1." - state_update₃ = function(state::Vector{Float64}, shock::Vector{Float64}) + state_update₃ = function(state::Vector{T}, shock::Vector{S}) where {T,S} aug_state = [state[𝓂.timings.past_not_future_and_mixed_idx] 1 shock] @@ -2660,7 +3204,7 @@ function solve!(𝓂::ℳ; @assert converged "Solution does not have a stochastic steady state. Try reducing shock sizes by multiplying them with a number < 1." - state_update₃ = function(pruned_states::Vector{Vector{Float64}}, shock::Vector{Float64}) + state_update₃ = function(pruned_states::Vector{Vector{T}}, shock::Vector{S}) where {T,S} aug_state₁ = [pruned_states[1][𝓂.timings.past_not_future_and_mixed_idx]; 1; shock] aug_state₁̂ = [pruned_states[1][𝓂.timings.past_not_future_and_mixed_idx]; 0; shock] aug_state₂ = [pruned_states[2][𝓂.timings.past_not_future_and_mixed_idx]; 0; zero(shock)] @@ -2682,37 +3226,44 @@ function solve!(𝓂::ℳ; if any([:quadratic_iteration, :binder_pesaran] .∈ ([algorithm],)) && any([:quadratic_iteration, :binder_pesaran] .∈ (𝓂.solution.outdated_algorithms,)) - SS_and_pars, solution_error = 𝓂.solution.outdated_NSSS ? 𝓂.SS_solve_func(𝓂.parameter_values, 𝓂, verbose) : (𝓂.solution.non_stochastic_steady_state, eps()) + SS_and_pars, (solution_error, iters) = 𝓂.solution.outdated_NSSS ? 𝓂.SS_solve_func(𝓂.parameter_values, 𝓂, verbose, false, 𝓂.solver_parameters) : (𝓂.solution.non_stochastic_steady_state, (eps(), 0)) + + if solution_error > tol + @warn "Could not find non stochastic steady steady." + end ∇₁ = calculate_jacobian(𝓂.parameter_values, SS_and_pars, 𝓂) |> Matrix sol_mat, converged = calculate_quadratic_iteration_solution(∇₁; T = 𝓂.timings) - state_update₁ₜ = function(state::Vector{Float64}, shock::Vector{Float64}) sol_mat * [state[𝓂.timings.past_not_future_and_mixed_idx]; shock] end + state_update₁ₜ = function(state::Vector{T}, shock::Vector{S}) where {T,S} sol_mat * [state[𝓂.timings.past_not_future_and_mixed_idx]; shock] end 𝓂.solution.perturbation.quadratic_iteration = perturbation_solution(sol_mat, state_update₁ₜ) 𝓂.solution.outdated_algorithms = setdiff(𝓂.solution.outdated_algorithms,[:quadratic_iteration, :binder_pesaran]) 𝓂.solution.non_stochastic_steady_state = SS_and_pars - 𝓂.solution.outdated_NSSS = false + 𝓂.solution.outdated_NSSS = solution_error > tol end if :linear_time_iteration == algorithm && :linear_time_iteration ∈ 𝓂.solution.outdated_algorithms - SS_and_pars, solution_error = 𝓂.solution.outdated_NSSS ? 𝓂.SS_solve_func(𝓂.parameter_values, 𝓂, verbose) : (𝓂.solution.non_stochastic_steady_state, eps()) + SS_and_pars, (solution_error, iters) = 𝓂.solution.outdated_NSSS ? 𝓂.SS_solve_func(𝓂.parameter_values, 𝓂, verbose, false, 𝓂.solver_parameters) : (𝓂.solution.non_stochastic_steady_state, (eps(), 0)) + + if solution_error > tol + @warn "Could not find non stochastic steady steady." + end ∇₁ = calculate_jacobian(𝓂.parameter_values, SS_and_pars, 𝓂) |> Matrix sol_mat = calculate_linear_time_iteration_solution(∇₁; T = 𝓂.timings) - state_update₁ₜ = function(state::Vector{Float64}, shock::Vector{Float64}) sol_mat * [state[𝓂.timings.past_not_future_and_mixed_idx]; shock] end + state_update₁ₜ = function(state::Vector{T}, shock::Vector{S}) where {T,S} sol_mat * [state[𝓂.timings.past_not_future_and_mixed_idx]; shock] end 𝓂.solution.perturbation.linear_time_iteration = perturbation_solution(sol_mat, state_update₁ₜ) 𝓂.solution.outdated_algorithms = setdiff(𝓂.solution.outdated_algorithms,[:linear_time_iteration]) 𝓂.solution.non_stochastic_steady_state = SS_and_pars - 𝓂.solution.outdated_NSSS = false - + 𝓂.solution.outdated_NSSS = solution_error > tol end end @@ -3156,6 +3707,8 @@ write_parameters_input!(𝓂::ℳ, parameters::Pair{String,Float64}; verbose::Bo write_parameters_input!(𝓂::ℳ, parameters::Tuple{Pair{Symbol,Float64},Vararg{Pair{Symbol,Float64}}}; verbose::Bool = true) = write_parameters_input!(𝓂::ℳ, Dict(parameters), verbose = verbose) +# write_parameters_input!(𝓂::ℳ, parameters::Tuple{Pair{Union{Symbol,String},Union{Float64,Int}},Vararg{Pair{Union{Symbol,String},Union{Float64,Int}}}}; verbose::Bool = true) = write_parameters_input!(𝓂::ℳ, Dict(parameters), verbose = verbose) +# write_parameters_input!(𝓂::ℳ, parameters::Tuple{Pair{Symbol,Int},Vararg{Pair{String,Float64}}}; verbose::Bool = true) = write_parameters_input!(𝓂::ℳ, Dict(parameters), verbose = verbose) write_parameters_input!(𝓂::ℳ, parameters::Tuple{Pair{String,Float64},Vararg{Pair{String,Float64}}}; verbose::Bool = true) = write_parameters_input!(𝓂::ℳ, Dict([i[1] |> Meta.parse |> replace_indices => i[2] for i in parameters]) , verbose = verbose) write_parameters_input!(𝓂::ℳ, parameters::Vector{Pair{Symbol, Float64}}; verbose::Bool = true) = write_parameters_input!(𝓂::ℳ, Dict(parameters), verbose = verbose) @@ -3366,7 +3919,7 @@ function SS_parameter_derivatives(parameters::Vector{ℱ.Dual{Z,S,N}}, parameter params = copy(𝓂.parameter_values) params = convert(Vector{ℱ.Dual{Z,S,N}},params) params[parameters_idx] = parameters - 𝓂.SS_solve_func(params, 𝓂, verbose) + 𝓂.SS_solve_func(params, 𝓂, verbose, false, 𝓂.solver_parameters) end @@ -3375,7 +3928,7 @@ function SS_parameter_derivatives(parameters::ℱ.Dual{Z,S,N}, parameters_idx::I params = copy(𝓂.parameter_values) params = convert(Vector{ℱ.Dual{Z,S,N}},params) params[parameters_idx] = parameters - 𝓂.SS_solve_func(params, 𝓂, verbose) + 𝓂.SS_solve_func(params, 𝓂, verbose, false, 𝓂.solver_parameters) end @@ -4007,10 +4560,205 @@ end +function irf(state_update::Function, + obc_state_update::Function, + model::JuMP.Model, + x::Vector{JuMP.VariableRef}, + initial_state::Vector{Float64}, + level::Vector{Float64}, + pruning::Bool, + unspecified_initial_state::Bool, + T::timings; + algorithm::Symbol = :first_order, + periods::Int = 40, + shocks::Union{Symbol_input,String_input,Matrix{Float64},KeyedArray{Float64}} = :all, + variables::Union{Symbol_input,String_input} = :all, + negative_shock::Bool = false) + + shocks = shocks isa KeyedArray ? axiskeys(shocks,1) isa Vector{String} ? rekey(shocks, 1 => axiskeys(shocks,1) .|> Meta.parse .|> replace_indices) : shocks : shocks + + shocks = shocks isa String_input ? shocks .|> Meta.parse .|> replace_indices : shocks + + if shocks isa Matrix{Float64} + @assert size(shocks)[1] == T.nExo "Number of rows of provided shock matrix does not correspond to number of shocks. Please provide matrix with as many rows as there are shocks in the model." + + periods += size(shocks)[2] + + shock_history = zeros(T.nExo, periods) + + shock_history[:,1:size(shocks)[2]] = shocks + + shock_idx = 1 + elseif shocks isa KeyedArray{Float64} + shock_input = map(x->Symbol(replace(string(x),"₍ₓ₎" => "")),axiskeys(shocks)[1]) + + periods += size(shocks)[2] + + @assert length(setdiff(shock_input, T.exo)) == 0 "Provided shocks which are not part of the model." + + shock_history = zeros(T.nExo, periods) + + shock_history[indexin(shock_input,T.exo),1:size(shocks)[2]] = shocks + + shock_idx = 1 + else + shock_idx = parse_shocks_input_to_index(shocks,T) + end + + var_idx = parse_variables_input_to_index(variables, T) + + axis1 = T.var[var_idx] + + if any(x -> contains(string(x), "◖"), axis1) + axis1_decomposed = decompose_name.(axis1) + axis1 = [length(a) > 1 ? string(a[1]) * "{" * join(a[2],"}{") * "}" * (a[end] isa Symbol ? string(a[end]) : "") : string(a[1]) for a in axis1_decomposed] + end + + if shocks == :simulate + shock_history = randn(T.nExo,periods) + + shock_history[contains.(string.(T.exo),"ᵒᵇᶜ"),:] .= 0 + + Y = zeros(T.nVars,periods,1) + + if pruning + if algorithm == :pruned_second_order + pruned_state¹ = unspecified_initial_state ? zero(initial_state) : copy(initial_state) + pruned_state² = copy(initial_state) + + for t in 1:periods + Y[:,t,1] = state_update([pruned_state¹, pruned_state²], shock_history[:,t]) + end + elseif algorithm == :pruned_third_order + pruned_state¹ = unspecified_initial_state ? zero(initial_state) : copy(initial_state) + pruned_state² = copy(initial_state) + pruned_state³ = unspecified_initial_state ? zero(initial_state) : copy(initial_state) + + for t in 1:periods + Y[:,t,1] = state_update([pruned_state¹, pruned_state², pruned_state³], shock_history[:,t]) + end + end + else + past_states = initial_state + always_solved = true + + for t in 1:periods + past_states, past_shocks, solved, model, x = obc_state_update(past_states, shock_history[:,t], state_update, algorithm, model, x) + + if !solved @warn "No solution at iteration $t" end + + always_solved = always_solved && solved + + if !always_solved break end + + Y[:,t,1] = past_states + shock_history[:,t] = past_shocks + end + end + + return KeyedArray(Y[var_idx,:,:] .+ level[var_idx]; Variables = axis1, Periods = 1:periods, Shocks = [:simulate]) + elseif shocks == :none + Y = zeros(T.nVars,periods,1) + + shck = T.nExo == 0 ? Vector{Float64}(undef, 0) : zeros(T.nExo) + + if pruning + if algorithm == :pruned_second_order + pruned_state¹ = unspecified_initial_state ? zero(initial_state) : copy(initial_state) + pruned_state² = copy(initial_state) + + for t in 1:periods + Y[:,t,1] = state_update([pruned_state¹, pruned_state²], shck) + end + elseif algorithm == :pruned_third_order + pruned_state¹ = unspecified_initial_state ? zero(initial_state) : copy(initial_state) + pruned_state² = copy(initial_state) + pruned_state³ = unspecified_initial_state ? zero(initial_state) : copy(initial_state) + + for t in 1:periods + Y[:,t,1] = state_update([pruned_state¹, pruned_state², pruned_state³], shck) + end + end + else + past_states = initial_state + always_solved = true + + for t in 1:periods + past_states, _, solved, model, x = obc_state_update(past_states, shck, state_update, algorithm, model, x) + + if !solved @warn "No solution at iteration $t" end + + always_solved = always_solved && solved + + if !always_solved break end + + Y[:,t,1] = past_states + end + end + + return KeyedArray(Y[var_idx,:,:] .+ level[var_idx]; Variables = axis1, Periods = 1:periods, Shocks = [:none]) + else + Y = zeros(T.nVars,periods,length(shock_idx)) + + for (i,ii) in enumerate(shock_idx) + if shocks != :simulate && shocks isa Union{Symbol_input,String_input} + shock_history = zeros(T.nExo,periods) + shock_history[ii,1] = negative_shock ? -1 : 1 + end + + if pruning + if algorithm == :pruned_second_order + pruned_state¹ = unspecified_initial_state ? zero(initial_state) : copy(initial_state) + pruned_state² = copy(initial_state) + + for t in 1:periods + Y[:,t,i] = state_update([pruned_state¹, pruned_state²], shock_history[:,t]) + end + elseif algorithm == :pruned_third_order + pruned_state¹ = unspecified_initial_state ? zero(initial_state) : copy(initial_state) + pruned_state² = copy(initial_state) + pruned_state³ = unspecified_initial_state ? zero(initial_state) : copy(initial_state) + + for t in 1:periods + Y[:,t,i] = state_update([pruned_state¹, pruned_state², pruned_state³], shock_history[:,t]) + end + end + else + past_states = initial_state + always_solved = true + + for t in 1:periods + past_states, past_shocks, solved, model, x = obc_state_update(past_states, shock_history[:,t], state_update, algorithm, model, x) + + if !solved @warn "No solution at iteration $t" end + + always_solved = always_solved && solved + + if !always_solved break end + + Y[:,t,1] = past_states + shock_history[:,t] = past_shocks + end + end + end + + axis2 = shocks isa Union{Symbol_input,String_input} ? [T.exo[shock_idx]...] : [:Shock_matrix] + + if any(x -> contains(string(x), "◖"), axis2) + axis2_decomposed = decompose_name.(axis2) + axis2 = [length(a) > 1 ? string(a[1]) * "{" * join(a[2],"}{") * "}" * (a[end] isa Symbol ? string(a[end]) : "") : string(a[1]) for a in axis2_decomposed] + end + + return KeyedArray(Y[var_idx,:,:] .+ level[var_idx]; Variables = axis1, Periods = 1:periods, Shocks = axis2) + end +end + + + function irf(state_update::Function, initial_state::Vector{Float64}, - level::Vector{Float64}, + level::Vector{Float64}, pruning::Bool, unspecified_initial_state::Bool, T::timings; @@ -4062,6 +4810,8 @@ function irf(state_update::Function, if shocks == :simulate shock_history = randn(T.nExo,periods) + shock_history[contains.(string.(T.exo),"ᵒᵇᶜ"),:] .= 0 + Y = zeros(T.nVars,periods,1) if pruning @@ -4314,10 +5064,12 @@ function parse_variables_input_to_index(variables::Union{Symbol_input,String_inp variables = variables isa String_input ? variables .|> Meta.parse .|> replace_indices : variables - if variables == :all - return indexin(setdiff(T.var,T.aux),sort(union(T.var,T.aux,T.exo_present))) + if variables == :all_excluding_auxilliary_and_obc + return indexin(setdiff(T.var[.!contains.(string.(T.var),"ᵒᵇᶜ")],T.aux),sort(union(T.var,T.aux,T.exo_present))) # return indexin(setdiff(setdiff(T.var,T.exo_present),T.aux),sort(union(T.var,T.aux,T.exo_present))) - elseif variables == :all_including_auxilliary + elseif variables == :all_excluding_obc + return indexin(T.var[.!contains.(string.(T.var),"ᵒᵇᶜ")],sort(union(T.var,T.aux,T.exo_present))) + elseif variables == :all return 1:length(union(T.var,T.aux,T.exo_present)) elseif variables isa Matrix{Symbol} if length(setdiff(variables,T.var)) > 0 @@ -4350,6 +5102,8 @@ function parse_shocks_input_to_index(shocks::Union{Symbol_input,String_input}, T if shocks == :all shock_idx = 1:T.nExo + elseif shocks == :all_excluding_obc + shock_idx = findall(.!contains.(string.(T.exo),"ᵒᵇᶜ")) elseif shocks == :none shock_idx = 1 elseif shocks == :simulate @@ -4411,7 +5165,7 @@ end function calculate_covariance(parameters::Vector{<: Real}, 𝓂::ℳ; verbose::Bool = false) - SS_and_pars, solution_error = 𝓂.SS_solve_func(parameters, 𝓂, verbose) + SS_and_pars, (solution_error, iters) = 𝓂.SS_solve_func(parameters, 𝓂, verbose, false, 𝓂.solver_parameters, 0) ∇₁ = calculate_jacobian(parameters, SS_and_pars, 𝓂) @@ -4446,7 +5200,7 @@ function calculate_mean(parameters::Vector{T}, 𝓂::ℳ; verbose::Bool = false, # Theoretical mean identical for 2nd and 3rd order pruned solution. @assert algorithm ∈ [:linear_time_iteration, :riccati, :first_order, :quadratic_iteration, :binder_pesaran, :pruned_second_order, :pruned_third_order] "Theoretical mean only available for first order, pruned second and third order perturbation solutions." - SS_and_pars, solution_error = 𝓂.SS_solve_func(parameters, 𝓂, verbose) + SS_and_pars, (solution_error, iters) = 𝓂.SS_solve_func(parameters, 𝓂, verbose, false, 𝓂.solver_parameters) if algorithm ∈ [:linear_time_iteration, :riccati, :first_order, :quadratic_iteration, :binder_pesaran] return SS_and_pars[1:𝓂.timings.nVars], solution_error @@ -4523,7 +5277,7 @@ function solve_matrix_equation_forward(ABC::Vector{Float64}; if length(coords) == 1 lengthA = length(coords[1][1]) vA = ABC[1:lengthA] - A = sparse(coords[1]...,vA,dims[1]...) |> ThreadedSparseArrays.ThreadedSparseMatrixCSC + A = sparse(coords[1]...,vA,dims[1]...)# |> ThreadedSparseArrays.ThreadedSparseMatrixCSC C = reshape(ABC[lengthA+1:end],dims[2]...) if solver != :doubling B = A' @@ -4536,9 +5290,9 @@ function solve_matrix_equation_forward(ABC::Vector{Float64}; vB = ABC[lengthA .+ (1:lengthB)] vC = ABC[lengthA + lengthB + 1:end] - A = sparse(coords[1]...,vA,dims[1]...) |> ThreadedSparseArrays.ThreadedSparseMatrixCSC - B = sparse(coords[2]...,vB,dims[2]...) |> ThreadedSparseArrays.ThreadedSparseMatrixCSC - C = sparse(coords[3]...,vC,dims[3]...) |> ThreadedSparseArrays.ThreadedSparseMatrixCSC + A = sparse(coords[1]...,vA,dims[1]...)# |> ThreadedSparseArrays.ThreadedSparseMatrixCSC + B = sparse(coords[2]...,vB,dims[2]...)# |> ThreadedSparseArrays.ThreadedSparseMatrixCSC + C = sparse(coords[3]...,vC,dims[3]...)# |> ThreadedSparseArrays.ThreadedSparseMatrixCSC else lengthA = dims[1][1] * dims[1][2] A = reshape(ABC[1:lengthA],dims[1]...) @@ -4631,10 +5385,10 @@ function solve_matrix_equation_conditions(ABC::Vector{<: Real}, if length(coords) == 1 lengthA = length(coords[1][1]) vA = ABC[1:lengthA] - A = sparse(coords[1]...,vA,dims[1]...) |> ThreadedSparseArrays.ThreadedSparseMatrixCSC + A = sparse(coords[1]...,vA,dims[1]...)# |> ThreadedSparseArrays.ThreadedSparseMatrixCSC C = reshape(ABC[lengthA+1:end],dims[2]...) if solver != :doubling - B = A' |> sparse |> ThreadedSparseArrays.ThreadedSparseMatrixCSC + B = A' |> sparse# |> ThreadedSparseArrays.ThreadedSparseMatrixCSC end elseif length(coords) == 3 lengthA = length(coords[1][1]) @@ -4644,9 +5398,9 @@ function solve_matrix_equation_conditions(ABC::Vector{<: Real}, vB = ABC[lengthA .+ (1:lengthB)] vC = ABC[lengthA + lengthB + 1:end] - A = sparse(coords[1]...,vA,dims[1]...) |> ThreadedSparseArrays.ThreadedSparseMatrixCSC - B = sparse(coords[2]...,vB,dims[2]...) |> ThreadedSparseArrays.ThreadedSparseMatrixCSC - C = sparse(coords[3]...,vC,dims[3]...) |> ThreadedSparseArrays.ThreadedSparseMatrixCSC + A = sparse(coords[1]...,vA,dims[1]...)# |> ThreadedSparseArrays.ThreadedSparseMatrixCSC + B = sparse(coords[2]...,vB,dims[2]...)# |> ThreadedSparseArrays.ThreadedSparseMatrixCSC + C = sparse(coords[3]...,vC,dims[3]...)# |> ThreadedSparseArrays.ThreadedSparseMatrixCSC else lengthA = dims[1][1] * dims[1][2] A = reshape(ABC[1:lengthA],dims[1]...) @@ -4683,11 +5437,11 @@ function solve_matrix_equation_forward(abc::Vector{ℱ.Dual{Z,S,N}}; lengthA = length(coords[1][1]) vA = ABC[1:lengthA] - A = sparse(coords[1]...,vA,dims[1]...) |> ThreadedSparseArrays.ThreadedSparseMatrixCSC + A = sparse(coords[1]...,vA,dims[1]...)# |> ThreadedSparseArrays.ThreadedSparseMatrixCSC # C = reshape(ABC[lengthA+1:end],dims[2]...) droptol!(A,eps()) - B = sparse(A') |> ThreadedSparseArrays.ThreadedSparseMatrixCSC + B = sparse(A')# |> ThreadedSparseArrays.ThreadedSparseMatrixCSC partials = zeros(dims[1][1] * dims[1][2] + dims[2][1] * dims[2][2], size(partial_values,2)) partials[vcat(coords[1][1] + (coords[1][2] .- 1) * dims[1][1], dims[1][1] * dims[1][2] + 1:end),:] = partial_values @@ -4710,9 +5464,9 @@ function solve_matrix_equation_forward(abc::Vector{ℱ.Dual{Z,S,N}}; vB = ABC[lengthA .+ (1:lengthB)] # vC = ABC[lengthA + lengthB + 1:end] - A = sparse(coords[1]...,vA,dims[1]...) |> ThreadedSparseArrays.ThreadedSparseMatrixCSC - B = sparse(coords[2]...,vB,dims[2]...) |> ThreadedSparseArrays.ThreadedSparseMatrixCSC - # C = sparse(coords[3]...,vC,dims[3]...) |> ThreadedSparseArrays.ThreadedSparseMatrixCSC + A = sparse(coords[1]...,vA,dims[1]...)# |> ThreadedSparseArrays.ThreadedSparseMatrixCSC + B = sparse(coords[2]...,vB,dims[2]...)# |> ThreadedSparseArrays.ThreadedSparseMatrixCSC + # C = sparse(coords[3]...,vC,dims[3]...)# |> ThreadedSparseArrays.ThreadedSparseMatrixCSC partials = spzeros(dims[1][1] * dims[1][2] + dims[2][1] * dims[2][2] + dims[3][1] * dims[3][2], size(partial_values,2)) partials[vcat( @@ -4738,7 +5492,7 @@ function solve_matrix_equation_forward(abc::Vector{ℱ.Dual{Z,S,N}}; A = reshape(ABC[1:lengthA],dims[1]...) |> sparse droptol!(A, eps()) # C = reshape(ABC[lengthA+1:end],dims[2]...) - B = sparse(A') |> ThreadedSparseArrays.ThreadedSparseMatrixCSC + B = sparse(A')# |> ThreadedSparseArrays.ThreadedSparseMatrixCSC partials = partial_values @@ -4908,7 +5662,6 @@ function calculate_second_order_moments( values = vcat(v1, vec(collect(-C))) Σᶻ₂, info = solve_matrix_equation_AD(values, coords = coordinates, dims = dimensions, solver = :doubling) - Σʸ₂ = ŝ_to_y₂ * Σᶻ₂ * ŝ_to_y₂' + ê_to_y₂ * Γ₂ * ê_to_y₂' @@ -5211,7 +5964,7 @@ function calculate_kalman_filter_loglikelihood(𝓂::ℳ, data::AbstractArray{Fl end end - SS_and_pars, solution_error = 𝓂.SS_solve_func(parameters, 𝓂, verbose) + SS_and_pars, (solution_error, iters) = 𝓂.SS_solve_func(parameters, 𝓂, verbose, false, 𝓂.solver_parameters) if solution_error > tol || isnan(solution_error) return -Inf @@ -5271,9 +6024,15 @@ function calculate_kalman_filter_loglikelihood(𝓂::ℳ, data::AbstractArray{Fl if Fdet < eps() return -Inf end - loglik += log(Fdet) + v' / F * v + F̄ = ℒ.lu(F, check = false) + + if !ℒ.issuccess(F̄) return -Inf end + + invF = inv(F̄) + + loglik += log(Fdet) + v' * invF * v - K = P * C' / F + K = P * C' * invF P = A * (P - K * C * P) * A' + 𝐁 @@ -5299,7 +6058,7 @@ function filter_and_smooth(𝓂::ℳ, data_in_deviations::AbstractArray{Float64} parameters = 𝓂.parameter_values - SS_and_pars, solution_error = 𝓂.SS_solve_func(parameters, 𝓂, verbose) + SS_and_pars, (solution_error, iters) = 𝓂.SS_solve_func(parameters, 𝓂, verbose, false, 𝓂.solver_parameters) @assert solution_error < tol "Could not solve non stochastic steady state." diff --git a/src/common_docstrings.jl b/src/common_docstrings.jl index 543977c8..95cbd7c2 100644 --- a/src/common_docstrings.jl +++ b/src/common_docstrings.jl @@ -3,8 +3,8 @@ const VERBOSE = "`verbose` [Default: `false`, Type: `Bool`]: print information a const MODEL = "`𝓂`: the object created by [`@model`](@ref) and [`@parameters`](@ref) for which to get the solution." const PARAMETER_VALUES = "`parameters` [Type: `Vector`]: Parameter values in alphabetical order (sorted by parameter name)." const PARAMETERS = "`parameters` [Default: `nothing`]: If nothing is provided, the solution is calculated for the parameters defined previously. Acceptable inputs are a vector of parameter values, a vector or tuple of pairs of the parameter `Symbol` or `String` and value. If the new parameter values differ from the previously defined the solution will be recalculated." -const VARIABLES = "`variables` [Default: `:all`]: variables for which to show the results. Inputs can be a variable name passed on as either a `Symbol` or `String` (e.g. `:y` or \"y\"), or `Tuple`, `Matrix` or `Vector` of `String` or `Symbol`. Any variables not part of the model will trigger a warning. `:all` will contain all variables but not the auxilliary ones. `:all_including_auxilliary` also includes the auxilliary variables in the output." -const SHOCKS = "`shocks` [Default: `:all`]: shocks for which to calculate the IRFs. Inputs can be a shock name passed on as either a `Symbol` or `String` (e.g. `:y`, or \"y\"), or `Tuple`, `Matrix` or `Vector` of `String` or `Symbol`. `:simulate` triggers random draws of all shocks. A series of shocks can be passed on using either a `Matrix{Float64}`, or a `KeyedArray{Float64}` as input with shocks (`Symbol` or `String`) in rows and periods in columns. The period of the simulation will correspond to the length of the input in the period dimension + the number of periods defined in `periods`. If the series of shocks is input as a `KeyedArray{Float64}` make sure to name the rows with valid shock names of type `Symbol`. Any shocks not part of the model will trigger a warning. `:none` in combination with an `initial_state` can be used for deterministic simulations." +const VARIABLES = "`variables` [Default: `:all_excluding_obc`]: variables for which to show the results. Inputs can be a variable name passed on as either a `Symbol` or `String` (e.g. `:y` or \"y\"), or `Tuple`, `Matrix` or `Vector` of `String` or `Symbol`. Any variables not part of the model will trigger a warning. `:all_excluding_auxilliary_and_obc` contains all shocks less those related to auxilliary variables and related to occasionally binding constraints (obc). `:all_excluding_obc` contains all shocks less those related to auxilliary variables. `:all` will contain all variables." +const SHOCKS = "`shocks` [Default: `:all_excluding_obc`]: shocks for which to calculate the IRFs. Inputs can be a shock name passed on as either a `Symbol` or `String` (e.g. `:y`, or \"y\"), or `Tuple`, `Matrix` or `Vector` of `String` or `Symbol`. `:simulate` triggers random draws of all shocks (excluding occasionally binding constraints (obc) related shocks). `:all_excluding_obc` will contain all shocks but not the obc related ones.`:all` will contain also the obc related shocks. A series of shocks can be passed on using either a `Matrix{Float64}`, or a `KeyedArray{Float64}` as input with shocks (`Symbol` or `String`) in rows and periods in columns. The period of the simulation will correspond to the length of the input in the period dimension + the number of periods defined in `periods`. If the series of shocks is input as a `KeyedArray{Float64}` make sure to name the rows with valid shock names of type `Symbol`. Any shocks not part of the model will trigger a warning. `:none` in combination with an `initial_state` can be used for deterministic simulations." const DERIVATIVES = "`derivatives` [Default: `true`, Type: `Bool`]: calculate derivatives with respect to the parameters." const PERIODS = "`periods` [Default: `40`, Type: `Int`]: number of periods for which to calculate the IRFs. In case a matrix of shocks was provided, periods defines how many periods after the series of shocks the simulation continues." const NEGATIVE_SHOCK = "`negative_shock` [Default: `false`, Type: `Bool`]: calculate a negative shock. Relevant for generalised IRFs." diff --git a/src/get_functions.jl b/src/get_functions.jl index 8abbc382..aef5b1e8 100644 --- a/src/get_functions.jl +++ b/src/get_functions.jl @@ -71,7 +71,7 @@ function get_shock_decomposition(𝓂::ℳ, solve!(𝓂, parameters = parameters, verbose = verbose, dynamics = true) - reference_steady_state, solution_error = 𝓂.solution.outdated_NSSS ? 𝓂.SS_solve_func(𝓂.parameter_values, 𝓂, verbose) : (copy(𝓂.solution.non_stochastic_steady_state), eps()) + 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)) data = data(sort(axiskeys(data,1))) @@ -165,7 +165,7 @@ function get_estimated_shocks(𝓂::ℳ, solve!(𝓂, parameters = parameters, verbose = verbose, dynamics = true) - reference_steady_state, solution_error = 𝓂.solution.outdated_NSSS ? 𝓂.SS_solve_func(𝓂.parameter_values, 𝓂, verbose) : (copy(𝓂.solution.non_stochastic_steady_state), eps()) + 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)) data = data(sort(axiskeys(data,1))) @@ -259,7 +259,7 @@ function get_estimated_variables(𝓂::ℳ, solve!(𝓂, parameters = parameters, verbose = verbose, dynamics = true) - reference_steady_state, solution_error = 𝓂.solution.outdated_NSSS ? 𝓂.SS_solve_func(𝓂.parameter_values, 𝓂, verbose) : (copy(𝓂.solution.non_stochastic_steady_state), eps()) + 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)) data = data(sort(axiskeys(data,1))) @@ -347,7 +347,7 @@ function get_estimated_variable_standard_deviations(𝓂::ℳ, solve!(𝓂, parameters = parameters, verbose = verbose, dynamics = true) - reference_steady_state, solution_error = 𝓂.solution.outdated_NSSS ? 𝓂.SS_solve_func(𝓂.parameter_values, 𝓂, verbose) : (copy(𝓂.solution.non_stochastic_steady_state), eps()) + 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)) data = data(sort(axiskeys(data,1))) @@ -476,7 +476,7 @@ function get_conditional_forecast(𝓂::ℳ, initial_state::Vector{Float64} = [0.0], periods::Int = 40, parameters = nothing, - variables::Union{Symbol_input,String_input} = :all_including_auxilliary, + variables::Union{Symbol_input,String_input} = :all_excluding_obc, conditions_in_levels::Bool = true, levels::Bool = false, verbose::Bool = false) @@ -545,7 +545,7 @@ function get_conditional_forecast(𝓂::ℳ, state_update, pruning = parse_algorithm_to_state_update(:first_order, 𝓂) - reference_steady_state, solution_error = 𝓂.solution.outdated_NSSS ? 𝓂.SS_solve_func(𝓂.parameter_values, 𝓂, verbose) : (copy(𝓂.solution.non_stochastic_steady_state), eps()) + 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)) initial_state = initial_state == [0.0] ? zeros(𝓂.timings.nVars) : initial_state - reference_steady_state[1:length(𝓂.var)] @@ -672,7 +672,7 @@ get_irf(RBC, RBC.parameter_values) function get_irf(𝓂::ℳ, parameters::Vector; periods::Int = 40, - variables::Union{Symbol_input,String_input} = :all_including_auxilliary, + variables::Union{Symbol_input,String_input} = :all_excluding_obc, shocks::Union{Symbol_input,String_input,Matrix{Float64},KeyedArray{Float64}} = :all, negative_shock::Bool = false, initial_state::Vector{Float64} = [0.0], @@ -719,7 +719,7 @@ function get_irf(𝓂::ℳ, shock_idx = parse_shocks_input_to_index(shocks,𝓂.timings) end - reference_steady_state, solution_error = 𝓂.SS_solve_func(parameters, 𝓂, verbose) + reference_steady_state, (solution_error, iters) = 𝓂.SS_solve_func(parameters, 𝓂, verbose, false, 𝓂.solver_parameters) ∇₁ = calculate_jacobian(parameters, reference_steady_state, 𝓂) |> Matrix @@ -822,12 +822,13 @@ function get_irf(𝓂::ℳ; periods::Int = 40, algorithm::Symbol = :first_order, parameters = nothing, - variables::Union{Symbol_input,String_input} = :all_including_auxilliary, - shocks::Union{Symbol_input,String_input,Matrix{Float64},KeyedArray{Float64}} = :all, + variables::Union{Symbol_input,String_input} = :all_excluding_obc, + shocks::Union{Symbol_input,String_input,Matrix{Float64},KeyedArray{Float64}} = :all_excluding_obc, negative_shock::Bool = false, generalised_irf::Bool = false, initial_state::Vector{Float64} = [0.0], levels::Bool = false, + ignore_obc::Bool = false, verbose::Bool = false) solve!(𝓂, parameters = parameters, verbose = verbose, dynamics = true, algorithm = algorithm) @@ -840,9 +841,7 @@ function get_irf(𝓂::ℳ; @assert !(shocks == :none && generalised_irf) "Cannot compute generalised IRFs for model without shocks." - state_update, pruning = parse_algorithm_to_state_update(algorithm, 𝓂) - - reference_steady_state, solution_error = 𝓂.solution.outdated_NSSS ? 𝓂.SS_solve_func(𝓂.parameter_values, 𝓂, verbose) : (copy(𝓂.solution.non_stochastic_steady_state), eps()) + 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)) if algorithm == :second_order SSS_delta = reference_steady_state[1:length(𝓂.var)] - 𝓂.solution.perturbation.second_order.stochastic_steady_state @@ -871,6 +870,20 @@ function get_irf(𝓂::ℳ; unspecified_initial_state = initial_state == [0.0] initial_state = initial_state == [0.0] ? zeros(𝓂.timings.nVars) - SSS_delta : initial_state - reference_steady_state[1:𝓂.timings.nVars] + + if ignore_obc + occasionally_binding_constraints = false + else + occasionally_binding_constraints = length(𝓂.obc_violation_equations) > 0 + end + + if occasionally_binding_constraints #&& + @assert algorithm ∉ [:pruned_second_order, :second_order, :pruned_third_order, :third_order] "Occasionally binding constraints only compatible with first order perturbation solutions." + + solve!(𝓂, parameters = :activeᵒᵇᶜshocks => 1, verbose = false, dynamics = true, algorithm = algorithm) + end + + state_update, pruning = parse_algorithm_to_state_update(algorithm, 𝓂) if generalised_irf girfs = girf(state_update, @@ -886,17 +899,132 @@ function get_irf(𝓂::ℳ; negative_shock = negative_shock)#, warmup_periods::Int = 100, draws::Int = 50, iterations_to_steady_state::Int = 500) return girfs else - irfs = irf(state_update, - initial_state, - levels ? reference_steady_state : SSS_delta, - pruning, - unspecified_initial_state, - 𝓂.timings; - algorithm = algorithm, - periods = periods, - shocks = shocks, - variables = variables, - negative_shock = negative_shock) + if occasionally_binding_constraints + function obc_state_update(present_states::Vector{R}, present_shocks::Vector{R}, state_update::Function, algorithm::Symbol, model::JuMP.Model, x::Vector{JuMP.VariableRef}) where R <: Float64 + unconditional_forecast_horizon = 𝓂.max_obc_horizon + + reference_steady_state = 𝓂.solution.non_stochastic_steady_state + + obc_shock_idx = contains.(string.(𝓂.timings.exo),"ᵒᵇᶜ") + + periods_per_shock = 𝓂.max_obc_horizon + 1 + + num_shocks = sum(obc_shock_idx) ÷ periods_per_shock + + constraints_violated = any(JuMP.value.(𝓂.obc_violation_function(zeros(num_shocks*periods_per_shock), present_states, state_update, reference_steady_state, 𝓂, algorithm, unconditional_forecast_horizon, JuMP.AffExpr.(present_shocks))) .> eps(Float32)) + + if constraints_violated + # Now loop through obc_shock_bounds to set the bounds on these variables. + # maxmin_indicators = 𝓂.obc_violation_function(x, present_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 v + # # if 𝓂.obc_violation_function(x, present_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, present_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.@constraint(model, con, 𝓂.obc_violation_function(x, present_states, state_update, reference_steady_state, 𝓂, algorithm, unconditional_forecast_horizon, JuMP.AffExpr.(present_shocks)) .<= 0) + + JuMP.optimize!(model) + + solved = JuMP.termination_status(model) ∈ [JuMP.OPTIMAL,JuMP.LOCALLY_SOLVED] + + if !solved + for opt in [:LD_SLSQP, :LD_MMA, :LN_COBYLA] + # @info "Using $opt solver." + + JuMP.set_optimizer(model, NLopt.Optimizer) + + JuMP.set_attribute(model, "algorithm", opt) + + JuMP.optimize!(model) + + solved = JuMP.termination_status(model) ∈ [JuMP.OPTIMAL,JuMP.LOCALLY_SOLVED] && !(any(JuMP.value.(𝓂.obc_violation_function(JuMP.value.(x), present_states, state_update, reference_steady_state, 𝓂, algorithm, unconditional_forecast_horizon, JuMP.AffExpr.(present_shocks))) .> eps(Float32))) + + if solved break end + end + end + + present_shocks[contains.(string.(𝓂.timings.exo),"ᵒᵇᶜ")] .= JuMP.value.(x) + + JuMP.delete(model, con) + + JuMP.unregister(model, :con) + + JuMP.set_optimizer(model, MadNLP.Optimizer) + + # JuMP.set_attribute(model, "tol", 1e-12) + else + solved = true + end + + present_states = state_update(present_states,JuMP.value.(present_shocks)) + + return present_states, present_shocks, solved, model, x + end + + model = JuMP.Model() + + JuMP.set_optimizer(model, MadNLP.Optimizer) + + # JuMP.set_attribute(model, "tol", 1e-12) + + JuMP.set_silent(model) + + obc_shock_idx = contains.(string.(𝓂.timings.exo),"ᵒᵇᶜ") + + periods_per_shock = 𝓂.max_obc_horizon + 1 + + num_shocks = sum(obc_shock_idx) ÷ periods_per_shock + + JuMP.@variable(model, x[1:num_shocks*periods_per_shock]) + + JuMP.@objective(model, Min, x' * ℒ.I * x) + + irfs = irf(state_update, + obc_state_update, + model, + x, + initial_state, + levels ? reference_steady_state : SSS_delta, + pruning, + unspecified_initial_state, + 𝓂.timings; + algorithm = algorithm, + periods = periods, + shocks = shocks, + variables = variables, + negative_shock = negative_shock) + else + irfs = irf(state_update, + initial_state, + levels ? reference_steady_state : SSS_delta, + pruning, + unspecified_initial_state, + 𝓂.timings; + algorithm = algorithm, + periods = periods, + shocks = shocks, + variables = variables, + negative_shock = negative_shock) + end + + if occasionally_binding_constraints #&& algorithm ∈ [:pruned_second_order, :second_order, :pruned_third_order, :third_order] + solve!(𝓂, parameters = :activeᵒᵇᶜshocks => 0, verbose = false, dynamics = true, algorithm = algorithm) + end + return irfs end end @@ -938,6 +1066,11 @@ Wrapper for [`get_irf`](@ref) with `shocks = :simulate`. Function returns values """ get_simulation(args...; kwargs...) = get_irf(args...; levels = true, kwargs..., shocks = :simulate)#[:,:,1] +""" +Wrapper for [`get_irf`](@ref) with `shocks = :simulate`. Function returns values in levels by default. +""" +get_simulations(args...; kwargs...) = get_irf(args...; levels = true, kwargs..., shocks = :simulate)#[:,:,1] + """ Wrapper for [`get_irf`](@ref) with `shocks = :simulate`. """ @@ -1005,7 +1138,8 @@ function get_steady_state(𝓂::ℳ; algorithm::Symbol = :first_order, parameter_derivatives::Union{Symbol_input,String_input} = :all, verbose::Bool = false, - silent::Bool = true) + silent::Bool = true, + tol::AbstractFloat = eps()) solve!(𝓂, parameters = parameters, verbose = verbose) @@ -1031,7 +1165,12 @@ function get_steady_state(𝓂::ℳ; length_par = length(parameter_derivatives) end - SS, solution_error = 𝓂.solution.outdated_NSSS ? 𝓂.SS_solve_func(𝓂.parameter_values, 𝓂, verbose) : (copy(𝓂.solution.non_stochastic_steady_state), eps()) + SS, (solution_error, iters) = 𝓂.SS_solve_func(𝓂.parameter_values, 𝓂, verbose, false, 𝓂.solver_parameters, false, 𝓂.solver_parameters) + # SS, solution_error = 𝓂.solution.outdated_NSSS ? 𝓂.SS_solve_func(𝓂.parameter_values, 𝓂, verbose) : (copy(𝓂.solution.non_stochastic_steady_state), eps()) + + if solution_error > tol + @warn "Could not find non-stochastic steady state." + end if stochastic if algorithm == :third_order @@ -1386,7 +1525,7 @@ function get_solution(𝓂::ℳ, return -Inf end - SS_and_pars, solution_error = 𝓂.SS_solve_func(parameters, 𝓂, verbose) + SS_and_pars, (solution_error, iters) = 𝓂.SS_solve_func(parameters, 𝓂, verbose, false, 𝓂.solver_parameters) if solution_error > tol || isnan(solution_error) if algorithm == :second_order @@ -1524,7 +1663,7 @@ function get_conditional_variance_decomposition(𝓂::ℳ; # write_parameters_input!(𝓂,parameters, verbose = verbose) - SS_and_pars, _ = 𝓂.SS_solve_func(𝓂.parameter_values, 𝓂, verbose) + SS_and_pars, _ = 𝓂.SS_solve_func(𝓂.parameter_values, 𝓂, verbose, false, 𝓂.solver_parameters) ∇₁ = calculate_jacobian(𝓂.parameter_values, SS_and_pars, 𝓂) |> Matrix @@ -1666,7 +1805,7 @@ function get_variance_decomposition(𝓂::ℳ; solve!(𝓂, parameters = parameters, verbose = verbose) - SS_and_pars, solution_error = 𝓂.SS_solve_func(𝓂.parameter_values, 𝓂, verbose) + SS_and_pars, (solution_error, iters) = 𝓂.SS_solve_func(𝓂.parameter_values, 𝓂, verbose, false, 𝓂.solver_parameters) ∇₁ = calculate_jacobian(𝓂.parameter_values, SS_and_pars, 𝓂) |> Matrix @@ -1987,7 +2126,7 @@ function get_moments(𝓂::ℳ; standard_deviation::Bool = true, variance::Bool = false, covariance::Bool = false, - variables::Union{Symbol_input,String_input} = :all_including_auxilliary, + variables::Union{Symbol_input,String_input} = :all_excluding_obc, derivatives::Bool = true, parameter_derivatives::Union{Symbol_input,String_input} = :all, algorithm::Symbol = :first_order, @@ -2019,7 +2158,7 @@ function get_moments(𝓂::ℳ; length_par = length(parameter_derivatives) end - NSSS, solution_error = 𝓂.solution.outdated_NSSS ? 𝓂.SS_solve_func(𝓂.parameter_values, 𝓂, verbose) : (copy(𝓂.solution.non_stochastic_steady_state), eps()) + NSSS, (solution_error, iters) = 𝓂.solution.outdated_NSSS ? 𝓂.SS_solve_func(𝓂.parameter_values, 𝓂, verbose, false, 𝓂.solver_parameters) : (copy(𝓂.solution.non_stochastic_steady_state), (eps(), 0)) if length_par * length(NSSS) > 200 || (!variance && !standard_deviation && !non_stochastic_steady_state && !mean) derivatives = false diff --git a/src/inspect.jl b/src/inspect.jl index 13a9cdd3..ee9ab6d1 100644 --- a/src/inspect.jl +++ b/src/inspect.jl @@ -1,5 +1,9 @@ get_symbols(ex::Symbol) = [ex] +get_symbols(ex::Real) = [ex] + +get_symbols(ex::Int) = [ex] + function get_symbols(ex::Expr) par = Set{Symbol}() postwalk(x -> diff --git a/src/macros.jl b/src/macros.jl index af234c33..b36a5f7e 100644 --- a/src/macros.jl +++ b/src/macros.jl @@ -12,6 +12,9 @@ Parses the model equations and assigns them to an object. - `𝓂`: name of the object to be created containing the model information. - `ex`: equations +# Optional arguments to be placed between `𝓂` and `ex` +- `max_obc_horizon` [Default: `40`, Type: `Int`]: maximum length of anticipated shocks and corresponding unconditional forecast horizon over which the occasionally binding constraint is to be enforced. Increase this number if no solution is found to enforce the constraint. + Variables must be defined with their time subscript in squared brackets. Endogenous variables can have the following: - present: `c[0]` @@ -27,6 +30,8 @@ Exogenous variables (shocks) can have the following: Parameters enter the equations without squared brackets. +If an equation contains a `max` or `min` operator, then the default dynamic (first order) solution of the model will enforce the occasionally binding constraint. You can choose to ignore it by setting `ignore_obc = true` in the relevant function calls. + # Examples ```julia using MacroModelling @@ -52,6 +57,7 @@ macro model(𝓂,ex...) # parse options verbose = false precompile = false + max_obc_horizon = 40 for exp in ex[1:end-1] postwalk(x -> @@ -61,6 +67,8 @@ macro model(𝓂,ex...) verbose = x.args[2] : x.args[1] == :precompile && x.args[2] isa Bool ? precompile = x.args[2] : + x.args[1] == :max_obc_horizon && x.args[2] isa Int ? + max_obc_horizon = x.args[2] : begin @warn "Invalid options." x @@ -107,6 +115,10 @@ macro model(𝓂,ex...) model_ex = parse_for_loops(ex[end]) + model_ex = parse_occasionally_binding_constraints(model_ex, max_obc_horizon = max_obc_horizon) + + # obc_shock_bounds = Tuple{Symbol, Bool, Float64}[] + # write down dynamic equations and add auxilliary variables for leads and lags > 1 for (i,arg) in enumerate(model_ex.args) if isa(arg,Expr) @@ -772,7 +784,7 @@ macro model(𝓂,ex...) #assemble data container model_name = string(𝓂) quote - global $𝓂 = ℳ( + global $𝓂 = ℳ( $model_name, # $default_optimizer, sort(collect($exo)), @@ -847,6 +859,13 @@ macro model(𝓂,ex...) $T, + Expr[], + # $obc_shock_bounds, + $max_obc_horizon, + x->x, + + solver_parameters(eps(), eps(), 250, 2.9912988764832833, 0.8725, 0.0027, 0.028948770826150612, 8.04, 4.076413176215408, 0.06375413238034794, 0.24284340766769424, 0.5634017580097571, 0.009549630552246828, 0.6342888355132347, 0.5275522227754195, 1.0, 0.06178989216048817, 0.5234277812131813, 0.422, 0.011209254402846185, 0.5047, 0.6020757011698457, 1, 0.0, 2), + solution( perturbation( perturbation_solution(SparseMatrixCSC{Float64, Int64}(ℒ.I,0,0), x->x), perturbation_solution(SparseMatrixCSC{Float64, Int64}(ℒ.I,0,0), x->x), @@ -1340,6 +1359,11 @@ macro parameters(𝓂,ex...) return quote mod = @__MODULE__ + if any(contains.(string.(mod.$𝓂.var), "ᵒᵇᶜ")) + push!($calib_parameters, :activeᵒᵇᶜshocks) + push!($calib_values, 0) + end + calib_parameters, calib_values = expand_indices($calib_parameters, $calib_values, [mod.$𝓂.parameters_in_equations; mod.$𝓂.var]) calib_eq_parameters, calib_equations_list, ss_calib_list, par_calib_list = expand_calibration_equations($calib_eq_parameters, $calib_equations_list, $ss_calib_list, $par_calib_list, [mod.$𝓂.parameters_in_equations; mod.$𝓂.var]) calib_parameters_no_var, calib_equations_no_var_list = expand_indices($calib_parameters_no_var, $calib_equations_no_var_list, [mod.$𝓂.parameters_in_equations; mod.$𝓂.var]) @@ -1388,6 +1412,10 @@ macro parameters(𝓂,ex...) solve_steady_state!(mod.$𝓂, $symbolic, symbolics, verbose = $verbose) # 2nd argument is SS_symbolic + mod.$𝓂.obc_violation_equations = write_obc_violation_equations(mod.$𝓂) + + set_up_obc_violation_function!(mod.$𝓂) + if !$silent println("Set up non stochastic steady state problem:\t",round(time() - start_time, digits = 3), " seconds") end else start_time = time() @@ -1419,8 +1447,15 @@ macro parameters(𝓂,ex...) if !$precompile # time_SS_real_solve = @elapsed - SS_and_pars, solution_error = mod.$𝓂.SS_solve_func(mod.$𝓂.parameter_values, mod.$𝓂, $verbose) - if !$silent println("Find non stochastic steady state:\t",round(time() - start_time, digits = 3), " seconds") end + SS_and_pars, (solution_error, iters) = mod.$𝓂.SS_solve_func(mod.$𝓂.parameter_values, mod.$𝓂, $verbose, false, mod.$𝓂.solver_parameters) + + if !$silent + println("Find non stochastic steady state:\t",round(time() - start_time, digits = 3), " seconds") + + if solution_error > eps() + @warn "Could not find non-stochastic steady state. Consider setting bounds on variables or calibrated parameters in the `@parameters` section (e.g. `k > 10`)." + end + end mod.$𝓂.solution.non_stochastic_steady_state = SS_and_pars mod.$𝓂.solution.outdated_NSSS = false diff --git a/src/plotting.jl b/src/plotting.jl index 18b5d85a..f7bcb8f1 100644 --- a/src/plotting.jl +++ b/src/plotting.jl @@ -80,7 +80,7 @@ plot_model_estimates(RBC_CME, simulation([:k],:,:simulate)) function plot_model_estimates(𝓂::ℳ, data::KeyedArray{Float64}; parameters = nothing, - variables::Union{Symbol_input,String_input} = :all_including_auxilliary, + variables::Union{Symbol_input,String_input} = :all_excluding_obc, shocks::Union{Symbol_input,String_input} = :all, data_in_levels::Bool = true, shock_decomposition::Bool = false, @@ -107,7 +107,7 @@ function plot_model_estimates(𝓂::ℳ, solve!(𝓂, parameters = parameters, verbose = verbose, dynamics = true) - reference_steady_state, solution_error = 𝓂.solution.outdated_NSSS ? 𝓂.SS_solve_func(𝓂.parameter_values, 𝓂, verbose) : (copy(𝓂.solution.non_stochastic_steady_state), eps()) + 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)) data = data(sort(axiskeys(data,1))) @@ -351,8 +351,8 @@ plot_irf(RBC) """ function plot_irf(𝓂::ℳ; periods::Int = 40, - shocks::Union{Symbol_input,String_input,Matrix{Float64},KeyedArray{Float64}} = :all, - variables::Union{Symbol_input,String_input} = :all, + shocks::Union{Symbol_input,String_input,Matrix{Float64},KeyedArray{Float64}} = :all_excluding_obc, + variables::Union{Symbol_input,String_input} = :all_excluding_auxilliary_and_obc, parameters = nothing, show_plots::Bool = true, save_plots::Bool = false, @@ -363,6 +363,7 @@ function plot_irf(𝓂::ℳ; negative_shock::Bool = false, generalised_irf::Bool = false, initial_state::Vector{Float64} = [0.0], + ignore_obc::Bool = false, verbose::Bool = false) gr_back = StatsPlots.backend() == StatsPlots.Plots.GRBackend() @@ -377,9 +378,7 @@ function plot_irf(𝓂::ℳ; solve!(𝓂, parameters = parameters, verbose = verbose, dynamics = true, algorithm = algorithm) - state_update, pruning = parse_algorithm_to_state_update(algorithm, 𝓂) - - NSSS, solution_error = 𝓂.solution.outdated_NSSS ? 𝓂.SS_solve_func(𝓂.parameter_values, 𝓂, verbose) : (𝓂.solution.non_stochastic_steady_state, eps()) + 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) @@ -434,6 +433,20 @@ function plot_irf(𝓂::ℳ; var_idx = parse_variables_input_to_index(variables, 𝓂.timings) + if ignore_obc + occasionally_binding_constraints = false + else + occasionally_binding_constraints = length(𝓂.obc_violation_equations) > 0 + end + + if occasionally_binding_constraints #&& + @assert algorithm ∉ [:pruned_second_order, :second_order, :pruned_third_order, :third_order] "Occasionally binding constraints only compatible with first order perturbation solutions." + + solve!(𝓂, parameters = :activeᵒᵇᶜshocks => 1, verbose = false, dynamics = true, algorithm = algorithm) + end + + state_update, pruning = parse_algorithm_to_state_update(algorithm, 𝓂) + if generalised_irf Y = girf(state_update, SSS_delta, @@ -447,17 +460,132 @@ function plot_irf(𝓂::ℳ; variables = variables, negative_shock = negative_shock)#, warmup_periods::Int = 100, draws::Int = 50, iterations_to_steady_state::Int = 500) else - Y = irf(state_update, - initial_state, - zeros(𝓂.timings.nVars), - pruning, - unspecified_initial_state, - 𝓂.timings; - algorithm = algorithm, - periods = periods, - shocks = shocks, - variables = variables, - negative_shock = negative_shock) .+ SSS_delta[var_idx] + if occasionally_binding_constraints + function obc_state_update(present_states::Vector{R}, present_shocks::Vector{R}, state_update::Function, algorithm::Symbol, model::JuMP.Model, x::Vector{JuMP.VariableRef}) where R <: Float64 + # this function takes the previous state and shocks, updates it and calculates the shocks enforcing the constraint for the current period + unconditional_forecast_horizon = 𝓂.max_obc_horizon + + reference_steady_state = 𝓂.solution.non_stochastic_steady_state + + obc_shock_idx = contains.(string.(𝓂.timings.exo),"ᵒᵇᶜ") + + periods_per_shock = 𝓂.max_obc_horizon + 1 + + num_shocks = sum(obc_shock_idx) ÷ periods_per_shock + + constraints_violated = any(JuMP.value.(𝓂.obc_violation_function(zeros(num_shocks*periods_per_shock), present_states, state_update, reference_steady_state, 𝓂, algorithm, unconditional_forecast_horizon, JuMP.AffExpr.(present_shocks))) .> eps(Float32)) + + if constraints_violated + # Now loop through obc_shock_bounds to set the bounds on these variables. + # maxmin_indicators = 𝓂.obc_violation_function(x, present_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 v + # # if 𝓂.obc_violation_function(x, present_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, present_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.@constraint(model, con, 𝓂.obc_violation_function(x, present_states, state_update, reference_steady_state, 𝓂, algorithm, unconditional_forecast_horizon, JuMP.AffExpr.(present_shocks)) .<= 0) + + JuMP.optimize!(model) + + solved = JuMP.termination_status(model) ∈ [JuMP.OPTIMAL,JuMP.LOCALLY_SOLVED] + + if !solved + for opt in [:LD_SLSQP, :LD_MMA, :LN_COBYLA] + # @info "Using $opt solver." + + JuMP.set_optimizer(model, NLopt.Optimizer) + + JuMP.set_attribute(model, "algorithm", opt) + + JuMP.optimize!(model) + + solved = JuMP.termination_status(model) ∈ [JuMP.OPTIMAL,JuMP.LOCALLY_SOLVED] && !(any(JuMP.value.(𝓂.obc_violation_function(JuMP.value.(x), present_states, state_update, reference_steady_state, 𝓂, algorithm, unconditional_forecast_horizon, JuMP.AffExpr.(present_shocks))) .> eps(Float32))) + + if solved break end + end + end + + present_shocks[contains.(string.(𝓂.timings.exo),"ᵒᵇᶜ")] .= JuMP.value.(x) + + JuMP.delete(model, con) + + JuMP.unregister(model, :con) + + JuMP.set_optimizer(model, MadNLP.Optimizer) + + # JuMP.set_attribute(model, "tol", 1e-12) + else + solved = true + end + + present_states = state_update(present_states,JuMP.value.(present_shocks)) + + return present_states, present_shocks, solved, model, x + end + + model = JuMP.Model() + + JuMP.set_optimizer(model, MadNLP.Optimizer) + + # JuMP.set_attribute(model, "tol", 1e-12) + + JuMP.set_silent(model) + + obc_shock_idx = contains.(string.(𝓂.timings.exo),"ᵒᵇᶜ") + + periods_per_shock = 𝓂.max_obc_horizon + 1 + + num_shocks = sum(obc_shock_idx) ÷ periods_per_shock + + JuMP.@variable(model, x[1:num_shocks*periods_per_shock]) + + JuMP.@objective(model, Min, x' * ℒ.I * x) + + Y = irf(state_update, + obc_state_update, + model, + x, + initial_state, + zeros(𝓂.timings.nVars), + pruning, + unspecified_initial_state, + 𝓂.timings; + algorithm = algorithm, + periods = periods, + shocks = shocks, + variables = variables, + negative_shock = negative_shock) .+ SSS_delta[var_idx] + else + Y = irf(state_update, + initial_state, + zeros(𝓂.timings.nVars), + pruning, + unspecified_initial_state, + 𝓂.timings; + algorithm = algorithm, + periods = periods, + shocks = shocks, + variables = variables, + negative_shock = negative_shock) .+ SSS_delta[var_idx] + end + end + + if occasionally_binding_constraints #&& algorithm ∈ [:pruned_second_order, :second_order, :pruned_third_order, :third_order] + solve!(𝓂, parameters = :activeᵒᵇᶜshocks => 0, verbose = false, dynamics = true, algorithm = algorithm) end if shocks isa KeyedArray{Float64} || shocks isa Matrix{Float64} @@ -610,6 +738,11 @@ Wrapper for [`plot_irf`](@ref) with `shocks = :simulate` and `periods = 100`. """ plot_simulations(args...; kwargs...) = plot_irf(args...; kwargs..., shocks = :simulate, periods = 100) +""" +Wrapper for [`plot_irf`](@ref) with `shocks = :simulate` and `periods = 100`. +""" +plot_simulation(args...; kwargs...) = plot_irf(args...; kwargs..., shocks = :simulate, periods = 100) + """ Wrapper for [`plot_irf`](@ref) with `generalised_irf = true`. @@ -895,6 +1028,7 @@ function plot_solution(𝓂::ℳ, SS_and_std = get_moments(𝓂, derivatives = false, parameters = parameters, + variables = :all, verbose = verbose) SS_and_std[1] = SS_and_std[1] isa KeyedArray ? axiskeys(SS_and_std[1],1) isa Vector{String} ? rekey(SS_and_std[1], 1 => axiskeys(SS_and_std[1],1).|> x->Symbol.(replace.(x, "{" => "◖", "}" => "◗"))) : SS_and_std[1] : SS_and_std[1] @@ -1282,7 +1416,7 @@ function plot_conditional_forecast(𝓂::ℳ, initial_state::Vector{Float64} = [0.0], periods::Int = 40, parameters = nothing, - variables::Union{Symbol_input,String_input} = :all_including_auxilliary, + variables::Union{Symbol_input,String_input} = :all_excluding_obc, conditions_in_levels::Bool = true, levels::Bool = false, show_plots::Bool = true, @@ -1321,7 +1455,7 @@ function plot_conditional_forecast(𝓂::ℳ, full_SS = vcat(sort(union(𝓂.var,𝓂.aux,𝓂.exo_present)),map(x->Symbol(string(x) * "₍ₓ₎"),𝓂.timings.exo)) - NSSS, solution_error = 𝓂.solution.outdated_NSSS ? 𝓂.SS_solve_func(𝓂.parameter_values, 𝓂, verbose) : (𝓂.solution.non_stochastic_steady_state, eps()) + NSSS, (solution_error, iters) = 𝓂.solution.outdated_NSSS ? 𝓂.SS_solve_func(𝓂.parameter_values, 𝓂, verbose, false, 𝓂.solver_parameters) : (𝓂.solution.non_stochastic_steady_state, (eps(), 0)) var_names = axiskeys(Y,1) diff --git a/src/structures.jl b/src/structures.jl index 0e566a35..cc67102a 100644 --- a/src/structures.jl +++ b/src/structures.jl @@ -229,6 +229,34 @@ mutable struct solution end +mutable struct solver_parameters + xtol::Float64 + ftol::Float64 + iterations::Int + ϕ̄::Float64 + ϕ̂::Float64 + μ̄¹::Float64 + μ̄²::Float64 + p̄¹::Float64 + p̄²::Float64 + ρ::Float64 + ρ¹::Float64 + ρ²::Float64 + ρ³::Float64 + ν::Float64 + λ¹::Float64 + λ²::Float64 + λ̂¹::Float64 + λ̂²::Float64 + λ̅¹::Float64 + λ̅²::Float64 + λ̂̅¹::Float64 + λ̂̅²::Float64 + transformation_level::Int + shift::Float64 + backtracking_order::Int +end + mutable struct ℳ model_name::Any # SS_optimizer @@ -349,6 +377,14 @@ mutable struct ℳ model_third_order_derivatives::Vector{Function} timings::timings + + obc_violation_equations::Vector{Expr} + # obc_shock_bounds::Vector{Tuple{Symbol, Bool, Float64}} + max_obc_horizon::Int + obc_violation_function::Function + + solver_parameters::solver_parameters + solution::solution # symbolics::symbolics diff --git a/test/functionality_tests.jl b/test/functionality_tests.jl index c6355c49..f58af6cc 100644 --- a/test/functionality_tests.jl +++ b/test/functionality_tests.jl @@ -137,7 +137,7 @@ function functionality_test(m; algorithm = :first_order, plots = true, verbose = irfs_10 = get_irf(m, m.parameter_values, verbose = true, periods = 10) irfs_100 = get_irf(m, m.parameter_values, verbose = true, periods = 100) new_irfs1 = get_irf(m, m.parameter_values * 1.0001, verbose = true) - lvl_irfs = get_irf(m, old_par_vals, verbose = true, levels = true) + lvl_irfs = get_irf(m, old_par_vals, verbose = true, levels = true, variables = :all) lvlv_init_irfs = get_irf(m, old_par_vals, verbose = true, levels = true, initial_state = collect(lvl_irfs[:,5,1])) lvlv_init_neg_irfs = get_irf(m, old_par_vals, verbose = true, levels = true, initial_state = collect(lvl_irfs[:,5,1]), negative_shock = true) @@ -159,7 +159,7 @@ function functionality_test(m; algorithm = :first_order, plots = true, verbose = new_sub_irfs = get_irf(m, old_par_vals, verbose = true, shocks = KeyedArray(randn(m.timings.nExo,10),Shocks = string.(m.timings.exo), Periods = 1:10)) new_sub_irfs = get_irf(m, old_par_vals, verbose = true, shocks = KeyedArray(randn(1,10),Shocks = string.([m.timings.exo[1]]), Periods = 1:10)) new_sub_irfs = get_irf(m, old_par_vals, verbose = true, shocks = :none, initial_state = collect(lvl_irfs[:,5,1])) - new_sub_lvl_irfs = get_irf(m, old_par_vals, verbose = true, shocks = :none, initial_state = collect(lvl_irfs[:,5,1]), levels = true) + new_sub_lvl_irfs = get_irf(m, old_par_vals, verbose = true, shocks = :none, initial_state = collect(lvl_irfs[:,5,1]), levels = true, variables = :all) # new_sub_irfs = get_irf(m, old_par_vals, verbose = true, shocks = string.(:none), initial_state = collect(lvl_irfs[:,5,1])) # new_sub_lvl_irfs = get_irf(m, old_par_vals, verbose = true, shocks = string.(:none), initial_state = collect(lvl_irfs[:,5,1]), levels = true) @test isapprox(collect(new_sub_lvl_irfs[:,1,:]), collect(lvl_irfs[:,6,1]),rtol = eps(Float32)) @@ -171,7 +171,7 @@ function functionality_test(m; algorithm = :first_order, plots = true, verbose = new_sub_irfs = get_irf(m, old_par_vals, verbose = true, variables = reshape(m.timings.var,1,length(m.timings.var))) new_sub_irfs = get_irf(m, old_par_vals, verbose = true, variables = :all) - new_sub_irfs = get_irf(m, old_par_vals, verbose = true, variables = :all_including_auxilliary) + new_sub_irfs = get_irf(m, old_par_vals, verbose = true, variables = :all_excluding_obc) new_sub_irfs = get_irf(m, old_par_vals, verbose = true, variables = string.(m.timings.var[1])) @@ -181,7 +181,7 @@ function functionality_test(m; algorithm = :first_order, plots = true, verbose = new_sub_irfs = get_irf(m, old_par_vals, verbose = true, variables = reshape(string.(m.timings.var),1,length(m.timings.var))) # new_sub_irfs = get_irf(m, old_par_vals, verbose = true, variables = string.(:all)) - # new_sub_irfs = get_irf(m, old_par_vals, verbose = true, variables = string.(:all_including_auxilliary)) + # new_sub_irfs = get_irf(m, old_par_vals, verbose = true, variables = string.(:all_excluding_obc)) var_decomp_nv = get_variance_decomposition(m) var_decomp = get_variance_decomposition(m, verbose = true) new_var_decomp = get_variance_decomposition(m, verbose = true, parameters = m.parameter_values * 1.0001) @@ -220,7 +220,7 @@ function functionality_test(m; algorithm = :first_order, plots = true, verbose = # test conditional forecasting - new_sub_irfs_all = get_irf(m, verbose = true, variables = :all_including_auxilliary) + new_sub_irfs_all = get_irf(m, verbose = true, variables = :all, shocks = :all) varnames = axiskeys(new_sub_irfs_all,1) shocknames = axiskeys(new_sub_irfs_all,3) sol = get_solution(m) @@ -401,6 +401,82 @@ function functionality_test(m; algorithm = :first_order, plots = true, verbose = old_sols = get_solution(m, algorithm = algorithm, verbose = true, parameters = old_par_vals) GC.gc() + + if length(m.obc_violation_equations) > 0 && algorithm == :first_order + irfs_nv = get_irf(m, algorithm = algorithm, ignore_obc = true) + irfs = get_irf(m, verbose = true, algorithm = algorithm, ignore_obc = true) + irfs_10 = get_irf(m, verbose = true, algorithm = algorithm, periods = 10, ignore_obc = true) + irfs_100 = get_irf(m, verbose = true, algorithm = algorithm, periods = 100, ignore_obc = true) + new_irfs1 = get_irf(m, verbose = true, algorithm = algorithm, parameters = m.parameter_values * 1.0001, ignore_obc = true) + new_irfs2 = get_irf(m, verbose = true, algorithm = algorithm, parameters = (m.parameters[1] => m.parameter_values[1] * 1.0001), ignore_obc = true) + new_irfs3 = get_irf(m, verbose = true, algorithm = algorithm, parameters = Tuple(m.parameters[1:2] .=> m.parameter_values[1:2] * 1.0001), ignore_obc = true) + new_irfs4 = get_irf(m, verbose = true, algorithm = algorithm, parameters = (m.parameters[1:2] .=> m.parameter_values[1:2] / 1.0001), ignore_obc = true) + lvl_irfs = get_irf(m, verbose = true, algorithm = algorithm, parameters = old_par_vals, levels = true, ignore_obc = true) + + new_irfs2 = get_irf(m, verbose = true, algorithm = algorithm, parameters = (string.(m.parameters[1]) => m.parameter_values[1] * 1.0001), ignore_obc = true) + new_irfs3 = get_irf(m, verbose = true, algorithm = algorithm, parameters = Tuple(string.(m.parameters[1:2]) .=> m.parameter_values[1:2] * 1.0001), ignore_obc = true) + new_irfs4 = get_irf(m, verbose = true, algorithm = algorithm, parameters = (string.(m.parameters[1:2]) .=> m.parameter_values[1:2] / 1.0001), ignore_obc = true) + lvl_irfs = get_irf(m, verbose = true, algorithm = algorithm, parameters = old_par_vals, levels = true, variables = :all) + + lvl_irfs = axiskeys(lvl_irfs,3) isa Vector{String} ? rekey(lvl_irfs,3 => axiskeys(lvl_irfs,3) .|> Meta.parse .|> MacroModelling.replace_indices) : lvl_irfs + + lvlv_init_irfs = get_irf(m, verbose = true, algorithm = algorithm, parameters = old_par_vals, levels = true, initial_state = collect(lvl_irfs(:,5,m.exo[1])), ignore_obc = true) + lvlv_init_neg_irfs = get_irf(m, verbose = true, algorithm = algorithm, parameters = old_par_vals, levels = true, initial_state = collect(lvl_irfs(:,5,m.exo[1])), negative_shock = true, ignore_obc = true) + lvlv_init_neg_gen_irfs = get_irf(m, verbose = true, algorithm = algorithm, parameters = old_par_vals, levels = true, initial_state = collect(lvl_irfs(:,5,m.exo[1])), negative_shock = true, generalised_irf = true, ignore_obc = true) + init_neg_gen_irfs = get_irf(m, verbose = true, algorithm = algorithm, parameters = old_par_vals, initial_state = collect(lvl_irfs(:,5,m.exo[1])), negative_shock = true, generalised_irf = true, ignore_obc = true) + + new_sub_irfs = get_irf(m, verbose = true, algorithm = algorithm, shocks = m.exo[1], ignore_obc = true) + new_sub_irfs = get_irf(m, verbose = true, algorithm = algorithm, shocks = m.exo, ignore_obc = true) + new_sub_irfs = get_irf(m, verbose = true, algorithm = algorithm, shocks = Tuple(m.exo), ignore_obc = true) + new_sub_irfs = get_irf(m, verbose = true, algorithm = algorithm, shocks = reshape(m.exo,1,length(m.exo)), ignore_obc = true) + new_sub_irfs = get_irf(m, verbose = true, algorithm = algorithm, shocks = :all, ignore_obc = true) + + new_sub_irfs = get_irf(m, verbose = true, algorithm = algorithm, shocks = string.(m.exo[1]), ignore_obc = true) + new_sub_irfs = get_irf(m, verbose = true, algorithm = algorithm, shocks = string.(m.exo), ignore_obc = true) + new_sub_irfs = get_irf(m, verbose = true, algorithm = algorithm, shocks = Tuple(string.(m.exo)), ignore_obc = true) + new_sub_irfs = get_irf(m, verbose = true, algorithm = algorithm, shocks = reshape(string.(m.exo),1,length(m.exo)), ignore_obc = true) + # new_sub_irfs = get_irf(m, verbose = true, algorithm = algorithm, shocks = string.(:all)) + + new_sub_irfs = get_irf(m, verbose = true, algorithm = algorithm, shocks = randn(m.timings.nExo,10), ignore_obc = true) + new_sub_irfs = get_irf(m, verbose = true, algorithm = algorithm, shocks = KeyedArray(randn(m.timings.nExo,10),Shocks = m.timings.exo, Periods = 1:10), ignore_obc = true) + new_sub_irfs = get_irf(m, verbose = true, algorithm = algorithm, shocks = KeyedArray(randn(1,10),Shocks = [m.timings.exo[1]], Periods = 1:10), ignore_obc = true) + new_sub_irfs = get_irf(m, verbose = true, algorithm = algorithm, shocks = KeyedArray(randn(m.timings.nExo,10),Shocks = string.(m.timings.exo), Periods = 1:10), ignore_obc = true) + new_sub_irfs = get_irf(m, verbose = true, algorithm = algorithm, shocks = KeyedArray(randn(1,10),Shocks = string.([m.timings.exo[1]]), Periods = 1:10), ignore_obc = true) + new_sub_irfs = get_irf(m, verbose = true, algorithm = algorithm, generalised_irf = true, shocks = KeyedArray(randn(1,10),Shocks = [m.timings.exo[1]], Periods = 1:10), ignore_obc = true) + new_sub_irfs = get_irf(m, verbose = true, algorithm = algorithm, generalised_irf = true, shocks = KeyedArray(randn(1,10),Shocks = string.([m.timings.exo[1]]), Periods = 1:10), ignore_obc = true) + + new_sub_irfs = get_irf(m, verbose = true, algorithm = algorithm, shocks = :simulate, ignore_obc = true) + new_sub_irfs = get_irf(m, verbose = true, algorithm = algorithm, shocks = :none, initial_state = collect(lvl_irfs(:,5,m.exo[1])), ignore_obc = true) + new_sub_lvl_irfs = get_irf(m, verbose = true, algorithm = algorithm, shocks = :none, initial_state = collect(lvl_irfs(:,5,m.exo[1])), levels = true, ignore_obc = true, variables = :all) + + new_sub_lvl_irfs = axiskeys(new_sub_lvl_irfs,3) isa Vector{String} ? rekey(new_sub_lvl_irfs,3 => axiskeys(new_sub_lvl_irfs,3) .|> Meta.parse .|> MacroModelling.replace_indices) : new_sub_lvl_irfs + new_sub_irfs = axiskeys(new_sub_lvl_irfs,3) isa Vector{String} ? rekey(new_sub_irfs,3 => axiskeys(new_sub_irfs,3) .|> Meta.parse .|> MacroModelling.replace_indices) : new_sub_irfs + # new_sub_irfs = get_irf(m, verbose = true, algorithm = algorithm, shocks = string.(:simulate)) + # new_sub_irfs = get_irf(m, verbose = true, algorithm = algorithm, shocks = string.(:none), initial_state = collect(lvl_irfs(:,5,m.exo[1]))) + # new_sub_lvl_irfs = get_irf(m, verbose = true, algorithm = algorithm, shocks = string.(:none), initial_state = collect(lvl_irfs(:,5,m.exo[1])), levels = true) + + if algorithm ∈ setdiff(MacroModelling.all_available_algorithms, [:pruned_second_order,:pruned_third_order]) + @test isapprox(collect(new_sub_lvl_irfs(:,1,:)), collect(lvl_irfs(:,6,m.exo[1])),rtol = eps(Float32)) + end + + new_sub_irfs = get_irf(m, verbose = true, algorithm = algorithm, variables = m.timings.var[1], ignore_obc = true) + new_sub_irfs = get_irf(m, verbose = true, algorithm = algorithm, variables = m.timings.var[end-1:end], ignore_obc = true) + new_sub_irfs = get_irf(m, verbose = true, algorithm = algorithm, variables = m.timings.var, ignore_obc = true) + new_sub_irfs = get_irf(m, verbose = true, algorithm = algorithm, variables = Tuple(m.timings.var), ignore_obc = true) + new_sub_irfs = get_irf(m, verbose = true, algorithm = algorithm, variables = reshape(m.timings.var,1,length(m.timings.var)), ignore_obc = true) + new_sub_irfs = get_irf(m, verbose = true, algorithm = algorithm, variables = :all, ignore_obc = true) + + + new_sub_irfs = get_irf(m, verbose = true, algorithm = algorithm, variables = string.(m.timings.var[1]), ignore_obc = true) + new_sub_irfs = get_irf(m, verbose = true, algorithm = algorithm, variables = string.(m.timings.var[end-1:end]), ignore_obc = true) + new_sub_irfs = get_irf(m, verbose = true, algorithm = algorithm, variables = string.(m.timings.var), ignore_obc = true) + new_sub_irfs = get_irf(m, verbose = true, algorithm = algorithm, variables = Tuple(string.(m.timings.var)), ignore_obc = true) + new_sub_irfs = get_irf(m, verbose = true, algorithm = algorithm, variables = reshape(string.(m.timings.var),1,length(m.timings.var)), ignore_obc = true) + # new_sub_irfs = get_irf(m, verbose = true, algorithm = algorithm, variables = string.(:all)) + + sims = simulate(m, algorithm = algorithm, ignore_obc = true) + end + # irfs irfs_nv = get_irf(m, algorithm = algorithm) irfs = get_irf(m, verbose = true, algorithm = algorithm) @@ -415,7 +491,7 @@ function functionality_test(m; algorithm = :first_order, plots = true, verbose = new_irfs2 = get_irf(m, verbose = true, algorithm = algorithm, parameters = (string.(m.parameters[1]) => m.parameter_values[1] * 1.0001)) new_irfs3 = get_irf(m, verbose = true, algorithm = algorithm, parameters = Tuple(string.(m.parameters[1:2]) .=> m.parameter_values[1:2] * 1.0001)) new_irfs4 = get_irf(m, verbose = true, algorithm = algorithm, parameters = (string.(m.parameters[1:2]) .=> m.parameter_values[1:2] / 1.0001)) - lvl_irfs = get_irf(m, verbose = true, algorithm = algorithm, parameters = old_par_vals, levels = true) + lvl_irfs = get_irf(m, verbose = true, algorithm = algorithm, parameters = old_par_vals, levels = true, variables = :all) lvl_irfs = axiskeys(lvl_irfs,3) isa Vector{String} ? rekey(lvl_irfs,3 => axiskeys(lvl_irfs,3) .|> Meta.parse .|> MacroModelling.replace_indices) : lvl_irfs @@ -446,7 +522,7 @@ function functionality_test(m; algorithm = :first_order, plots = true, verbose = new_sub_irfs = get_irf(m, verbose = true, algorithm = algorithm, shocks = :simulate) new_sub_irfs = get_irf(m, verbose = true, algorithm = algorithm, shocks = :none, initial_state = collect(lvl_irfs(:,5,m.exo[1]))) - new_sub_lvl_irfs = get_irf(m, verbose = true, algorithm = algorithm, shocks = :none, initial_state = collect(lvl_irfs(:,5,m.exo[1])), levels = true) + new_sub_lvl_irfs = get_irf(m, verbose = true, algorithm = algorithm, shocks = :none, initial_state = collect(lvl_irfs(:,5,m.exo[1])), levels = true, variables = :all) new_sub_lvl_irfs = axiskeys(new_sub_lvl_irfs,3) isa Vector{String} ? rekey(new_sub_lvl_irfs,3 => axiskeys(new_sub_lvl_irfs,3) .|> Meta.parse .|> MacroModelling.replace_indices) : new_sub_lvl_irfs new_sub_irfs = axiskeys(new_sub_lvl_irfs,3) isa Vector{String} ? rekey(new_sub_irfs,3 => axiskeys(new_sub_irfs,3) .|> Meta.parse .|> MacroModelling.replace_indices) : new_sub_irfs @@ -498,6 +574,70 @@ function functionality_test(m; algorithm = :first_order, plots = true, verbose = if plots + if length(m.obc_violation_equations) > 0 + plot_irf(m, algorithm = algorithm, show_plots = true, ignore_obc = true) + plot_irf(m, verbose = true, algorithm = algorithm, show_plots = true, ignore_obc = true) + plot_irf(m, verbose = true, algorithm = algorithm, show_plots = false, save_plots = true, ignore_obc = true) + plot_irf(m, verbose = true, algorithm = algorithm, show_plots = false, save_plots = true, periods = 10, ignore_obc = true) + plot_irf(m, verbose = true, algorithm = algorithm, show_plots = false, save_plots = true, periods = 100, ignore_obc = true) + plot_irf(m, verbose = true, algorithm = algorithm, show_plots = false, save_plots = true, parameters = m.parameter_values * 1.0001, ignore_obc = true) + + plot_irf(m, verbose = true, algorithm = algorithm, show_plots = false, save_plots = true, parameters = (m.parameters[1] => m.parameter_values[1] * 1.0001), ignore_obc = true) + plot_irf(m, verbose = true, algorithm = algorithm, show_plots = false, save_plots = true, parameters = Tuple(m.parameters[1:2] .=> m.parameter_values[1:2] * 1.0001), ignore_obc = true) + plot_irf(m, verbose = true, algorithm = algorithm, show_plots = false, save_plots = true, parameters = (m.parameters[1:2] .=> m.parameter_values[1:2] / 1.0001), ignore_obc = true) + + plot_irf(m, verbose = true, algorithm = algorithm, show_plots = false, save_plots = true, parameters = (string.(m.parameters[1]) => m.parameter_values[1] * 1.0001), ignore_obc = true) + plot_irf(m, verbose = true, algorithm = algorithm, show_plots = false, save_plots = true, parameters = Tuple(string.(m.parameters[1:2]) .=> m.parameter_values[1:2] * 1.0001), ignore_obc = true) + plot_irf(m, verbose = true, algorithm = algorithm, show_plots = false, save_plots = true, parameters = (string.(m.parameters[1:2]) .=> m.parameter_values[1:2] / 1.0001), ignore_obc = true) + + plot_irf(m, verbose = true, algorithm = algorithm, show_plots = false, save_plots = true, parameters = old_par_vals, initial_state = collect(lvl_irfs(:,5,m.exo[1])), ignore_obc = true) + plot_irf(m, verbose = true, algorithm = algorithm, show_plots = false, save_plots = true, parameters = old_par_vals, initial_state = collect(lvl_irfs(:,5,m.exo[1])), negative_shock = true, ignore_obc = true) + plot_irf(m, verbose = true, algorithm = algorithm, show_plots = false, save_plots = true, parameters = old_par_vals, initial_state = collect(lvl_irfs(:,5,m.exo[1])), negative_shock = true, generalised_irf = true, ignore_obc = true) + + plot_irf(m, verbose = true, algorithm = algorithm, show_plots = false, save_plots = true, shocks = m.exo[1], ignore_obc = true) + plot_irf(m, verbose = true, algorithm = algorithm, show_plots = false, save_plots = true, shocks = m.exo, ignore_obc = true) + plot_irf(m, verbose = true, algorithm = algorithm, show_plots = false, save_plots = true, shocks = Tuple(m.exo), ignore_obc = true) + plot_irf(m, verbose = true, algorithm = algorithm, show_plots = false, save_plots = true, shocks = reshape(m.exo,1,length(m.exo)), ignore_obc = true) + plot_irf(m, verbose = true, algorithm = algorithm, show_plots = false, save_plots = true, shocks = :all, ignore_obc = true) + + + plot_irf(m, verbose = true, algorithm = algorithm, show_plots = false, save_plots = true, shocks = string.(m.exo[1]), ignore_obc = true) + plot_irf(m, verbose = true, algorithm = algorithm, show_plots = false, save_plots = true, shocks = string.(m.exo), ignore_obc = true) + plot_irf(m, verbose = true, algorithm = algorithm, show_plots = false, save_plots = true, shocks = Tuple(string.(m.exo)), ignore_obc = true) + plot_irf(m, verbose = true, algorithm = algorithm, show_plots = false, save_plots = true, shocks = reshape(string.(m.exo),1,length(m.exo)), ignore_obc = true) + # plot_irf(m, verbose = true, algorithm = algorithm, show_plots = false, save_plots = true, shocks = string.(:all)) + + plot_irf(m, verbose = true, algorithm = algorithm, show_plots = false, save_plots = true, shocks = randn(m.timings.nExo,10), ignore_obc = true) + plot_irf(m, verbose = true, algorithm = algorithm, show_plots = false, save_plots = true, shocks = KeyedArray(randn(m.timings.nExo,10),Shocks = m.timings.exo, Periods = 1:10), ignore_obc = true) + plot_irf(m, verbose = true, algorithm = algorithm, show_plots = false, save_plots = true, shocks = KeyedArray(randn(1,10),Shocks = [m.timings.exo[1]], Periods = 1:10), ignore_obc = true) + plot_irf(m, verbose = true, algorithm = algorithm, show_plots = false, save_plots = true, shocks = KeyedArray(randn(m.timings.nExo,10),Shocks = string.(m.timings.exo), Periods = 1:10), ignore_obc = true) + plot_irf(m, verbose = true, algorithm = algorithm, show_plots = false, save_plots = true, shocks = KeyedArray(randn(1,10),Shocks = string.([m.timings.exo[1]]), Periods = 1:10), ignore_obc = true) + + plot_irf(m, verbose = true, algorithm = algorithm, show_plots = false, save_plots = true, shocks = :simulate, ignore_obc = true) + plot_irf(m, verbose = true, algorithm = algorithm, show_plots = false, save_plots = true, shocks = :none, initial_state = collect(lvl_irfs(:,5,m.exo[1])), ignore_obc = true) + + # plot_irf(m, verbose = true, algorithm = algorithm, show_plots = false, save_plots = true, shocks = string.(:simulate)) + # plot_irf(m, verbose = true, algorithm = algorithm, show_plots = false, save_plots = true, shocks = string.(:none), initial_state = collect(lvl_irfs(:,5,m.exo[1]))) + + plot_irf(m, verbose = true, algorithm = algorithm, show_plots = false, save_plots = true, variables = m.timings.var[1], ignore_obc = true) + plot_irf(m, verbose = true, algorithm = algorithm, show_plots = false, save_plots = true, variables = m.timings.var[end-1:end], ignore_obc = true) + plot_irf(m, verbose = true, algorithm = algorithm, show_plots = false, save_plots = true, variables = m.timings.var, ignore_obc = true) + plot_irf(m, verbose = true, algorithm = algorithm, show_plots = false, save_plots = true, variables = Tuple(m.timings.var), ignore_obc = true) + plot_irf(m, verbose = true, algorithm = algorithm, show_plots = false, save_plots = true, variables = reshape(m.timings.var,1,length(m.timings.var)), ignore_obc = true) + plot_irf(m, verbose = true, algorithm = algorithm, show_plots = false, save_plots = true, variables = :all, ignore_obc = true) + + plot_irf(m, verbose = true, algorithm = algorithm, show_plots = false, save_plots = true, variables = string.(m.timings.var[1]), ignore_obc = true) + plot_irf(m, verbose = true, algorithm = algorithm, show_plots = false, save_plots = true, variables = string.(m.timings.var[end-1:end]), ignore_obc = true) + plot_irf(m, verbose = true, algorithm = algorithm, show_plots = false, save_plots = true, variables = string.(m.timings.var), ignore_obc = true) + plot_irf(m, verbose = true, algorithm = algorithm, show_plots = false, save_plots = true, variables = Tuple(string.(m.timings.var)), ignore_obc = true) + plot_irf(m, verbose = true, algorithm = algorithm, show_plots = false, save_plots = true, variables = reshape(string.(m.timings.var),1,length(m.timings.var)), ignore_obc = true) + # plot_irf(m, verbose = true, algorithm = algorithm, show_plots = false, save_plots = true, variables = string.(:all)) + + plot_irf(m, verbose = true, algorithm = algorithm, show_plots = false, save_plots = true, plots_per_page = 6, ignore_obc = true) + plot_irf(m, verbose = true, algorithm = algorithm, show_plots = false, save_plots = true, save_plots_format = :png, ignore_obc = true) + plot_irf(m, verbose = true, algorithm = algorithm, show_plots = false, save_plots = true, save_plots_format = :png, plots_per_page = 4, ignore_obc = true) + end + # plots plot_irf(m, algorithm = algorithm, show_plots = true) plot_irf(m, verbose = true, algorithm = algorithm, show_plots = true) diff --git a/test/models/Aguiar_Gopinath_2007.jl b/test/models/Aguiar_Gopinath_2007.jl deleted file mode 100644 index 7c6b0e16..00000000 --- a/test/models/Aguiar_Gopinath_2007.jl +++ /dev/null @@ -1,67 +0,0 @@ -@model Aguiar_Gopinath_2007 begin - y[0] = (exp(g[0]) * l[0]) ^ alpha * exp(z[0]) * k[-1] ^ (1 - alpha) - - z[0] = rho_z * z[-1] + σᶻ * eps_z[x] - - g[0] = (1 - rho_g) * mu_g + rho_g * g[-1] + σᵍ * eps_g[x] - - u[0] = (c[0] ^ gamma * (1 - l[0]) ^ (1 - gamma)) ^ (1 - sigma) / (1 - sigma) - - uc[0] = (1 - sigma) * u[0] * gamma / c[0] - - ul[0] = (1 - sigma) * u[0] * ( - (1 - gamma)) / (1 - l[0]) - - c[0] + k[0] * exp(g[0]) = y[0] + (1 - delta) * k[-1] - k[-1] * phi / 2 * (k[0] * exp(g[0]) / k[-1] - exp(mu_g)) ^ 2 - b[-1] + b[0] * exp(g[0]) * q[0] - - 1 / q[0] = 1 + r_star + psi * (exp(b[0] - b_star) - 1) - - exp(g[0]) * uc[0] * (1 + phi * (k[0] * exp(g[0]) / k[-1] - exp(mu_g))) = beta * exp(g[0] * gamma * (1 - sigma)) * uc[1] * (1 - delta + (1 - alpha) * y[1] / k[0] - phi / 2 * (k[1] * exp(g[1]) * ( - (2 * (k[1] * exp(g[1]) / k[0] - exp(mu_g)))) / k[0] + (k[1] * exp(g[1]) / k[0] - exp(mu_g)) ^ 2)) - - ul[0] + y[0] * alpha * uc[0] / l[0] = 0 - - q[0] * exp(g[0]) * uc[0] = beta * exp(g[0] * gamma * (1 - sigma)) * uc[1] - - invest[0] = k[-1] * phi / 2 * (k[0] * exp(g[0]) / k[-1] - exp(mu_g)) ^ 2 + k[0] * exp(g[0]) - (1 - delta) * k[-1] - - c_y[0] = c[0] / y[0] - - i_y[0] = invest[0] / y[0] - - nx[0] = (b[-1] - b[0] * exp(g[0]) * q[0]) / y[0] - - delta_y[0] = g[-1] + log(y[0]) - log(y[-1]) - -end - - -@parameters Aguiar_Gopinath_2007 verbose = true begin - beta = 1 / 1.02 - - gamma = 0.36 - - b_share = 0.1 - - b_share * y[ss] = b_star | b_star - - 1 + r_star = 1 / q[ss] | r_star - - psi = 0.001 - - alpha = 0.68 - - sigma = 2 - - delta = 0.05 - - phi = 4 - - mu_g = log(1.0066) - - rho_z = 0.95 - - rho_g = 0.01 - - σᶻ = .01 - - σᵍ = .0005 -end \ No newline at end of file diff --git a/test/models/Ascari_Sbordone_2014.jl b/test/models/Ascari_Sbordone_2014.jl deleted file mode 100644 index 78feefdd..00000000 --- a/test/models/Ascari_Sbordone_2014.jl +++ /dev/null @@ -1,84 +0,0 @@ -@model Ascari_Sbordone_2014 begin - 1 / y[0] ^ sigma = beta * (1 + i[0]) / (pi[1] * y[1] ^ sigma) - - w[0] = y[0] ^ sigma * d_n * exp(zeta[0]) * N[0] ^ phi_par - - p_star[0] = ((1 - theta * pi[-1] ^ ((1 - epsilon) * var_rho) * pi[0] ^ (epsilon - 1)) / (1 - theta)) ^ (1 / (1 - epsilon)) - - p_star[0] ^ (1 + epsilon * alpha / (1 - alpha)) = epsilon / ((epsilon - 1) * (1 - alpha)) * psi[0] / phi[0] - - psi[0] = w[0] * exp(A[0]) ^ (( - 1) / (1 - alpha)) * y[0] ^ (1 / (1 - alpha) - sigma) + beta * theta * pi[0] ^ (epsilon * ( - var_rho) / (1 - alpha)) * pi[1] ^ (epsilon / (1 - alpha)) * psi[1] - - phi[0] = y[0] ^ (1 - sigma) + beta * theta * pi[0] ^ ((1 - epsilon) * var_rho) * pi[1] ^ (epsilon - 1) * phi[1] - - N[0] = s[0] * (y[0] / exp(A[0])) ^ (1 / (1 - alpha)) - - s[0] = (1 - theta) * p_star[0] ^ (( - epsilon) / (1 - alpha)) + theta * pi[-1] ^ (var_rho * ( - epsilon) / (1 - alpha)) * pi[0] ^ (epsilon / (1 - alpha)) * s[-1] - - (1 + i[0]) / (1 + i_bar) = ((1 + i[-1]) / (1 + i_bar)) ^ rho_i * ((pi[0]/ Pi_bar) ^ phi_pi * (y[0] / Y_bar) ^ phi_y) ^ (1 - rho_i) * exp(v[0]) - - MC_real[0] = w[0] * 1 / (1 - alpha) * exp(A[0]) ^ (1 / (alpha - 1)) * y[0] ^ (alpha / (1 - alpha)) - - real_interest[0] = (1 + i[0]) / pi[1] - - Utility[0] = log(y[0]) - d_n * exp(zeta[0]) * N[0] ^ (1 + phi_par) / (1 + phi_par) + beta * Utility[1] - - v[0] = rho_v * v[-1] + σᵥ * e_v[x] - - A[0] = rho_a * A[-1] + σₐ * e_a[x] - - zeta[0] = rho_zeta * zeta[-1] + σ_zeta * e_zeta[x] - - A_tilde[0] = exp(A[0]) / s[0] - - Average_markup[0] = 1 / MC_real[0] - - Marginal_markup[0] = p_star[0] / MC_real[0] - - price_adjustment_gap[0] = 1 / p_star[0] -end - - -@parameters Ascari_Sbordone_2014 verbose = true begin - Pi_bar = (1+trend_inflation/100)^(1/4) - - N[ss] = 1/3 | d_n - - (1/3) ^ (1 - alpha) = y[ss] | Y_bar - - i_bar = Pi_bar / beta - 1 - - beta = 0.99 - - trend_inflation = 0 - - alpha = 0 - - theta = 0.75 - - epsilon = 10 - - sigma = 1 - - rho_v = 0 - - rho_a = 0 - - rho_zeta = 0 - - phi_par = 1 - - phi_pi = 2 - - phi_y = 0.125 - - rho_i = 0.8 - - var_rho = 0 - - σ_zeta = .01 - - σₐ = .01 - - σᵥ = .01 -end diff --git a/test/models/Baxter_and_King_1993.jl b/test/models/Baxter_and_King_1993.jl deleted file mode 100644 index ca461767..00000000 --- a/test/models/Baxter_and_King_1993.jl +++ /dev/null @@ -1,83 +0,0 @@ -@model Baxter_and_King_1993 begin - uc[0] = c[0]^-1 - - ul[0] = θ_l * l[0]^-1 - - y[0] = A * k[-1]^θ_k * n[0]^θ_n - - fk[0] = θ_k * A * k[-1]^(θ_k - 1) * n[0]^θ_n - - fn[0] = θ_n * A * k[-1]^θ_k * n[0]^(θ_n - 1) - - γ_x * k[0] = (1- δ_k) * k[-1] + iv[0] - - l[0] + n[0] = 1 - - c[0] + iv[0] = (1 - τ) * y[0] + tr[0] + check_walras[0] - - c[0] + iv[0] + gb[0] = y[0] - - τ * y[0] = gb[0] + tr[0] - - uc[0] = λ[0] - - ul[0] = λ[0] * (1 - τ) * fn[0] - - β * λ[1] * (q[1] + 1 - δ_k) = γ_x * λ[0] - - q[0] = (1 - τ) * fk[0] - - gb[0] = GB_BAR + e_gb[x] - - 1 + r[0] = γ_x * λ[0] / (λ[1] * β) - - w[0] = fn[0] -end - -@parameters Baxter_and_King_1993 begin - A = 1.0 - - γ_x = 1.016 - - θ_k = 0.42 - - θ_n = 1 - θ_k - - δ_k = 0.1 - - N = 0.2 - - L = 1 - N - - R = 0.065 - - β = γ_x / (1 + R) - - sG = 0.2 - - τBAR = 0.2 - - τ = 0.2 - - Q = γ_x / β - 1 + δ_k - - FK = Q / (1 - τBAR) - - K = (FK / ((θ_k * A * N^θ_n)))^(1 / (θ_k - 1)) - - FN = θ_n * A * K^θ_k * N^(θ_n - 1) - - IV = (γ_x - 1 + δ_k) * K - - Y = A * N^(1 - θ_k) * K^θ_k - - GB_BAR = sG * Y - - C = Y - IV - GB_BAR - - UC = C^(-1) - - UL = UC * (1 - τBAR) * FN - - θ_l = UL * L -end diff --git a/test/models/Caldara_et_al_2012.jl b/test/models/Caldara_et_al_2012.jl deleted file mode 100644 index 3b428576..00000000 --- a/test/models/Caldara_et_al_2012.jl +++ /dev/null @@ -1,51 +0,0 @@ - -@model Caldara_et_al_2012 begin - V[0] = ((1 - β) * (c[0] ^ ν * (1 - l[0]) ^ (1 - ν)) ^ (1 - 1 / ψ) + β * V[1] ^ (1 - 1 / ψ)) ^ (1 / (1 - 1 / ψ)) - - exp(s[0]) = V[1] ^ (1 - γ) - - 1 = (1 + ζ * exp(z[1]) * k[0] ^ (ζ - 1) * l[1] ^ (1 - ζ) - δ) * c[0] * β * (((1 - l[1]) / (1 - l[0])) ^ (1 - ν) * (c[1] / c[0]) ^ ν) ^ (1 - 1 / ψ) / c[1] - - Rᵏ[0] = ζ * exp(z[1]) * k[0] ^ (ζ - 1) * l[1] ^ (1 - ζ) - δ - - SDF⁺¹[0] = c[0] * β * (((1 - l[1]) / (1 - l[0])) ^ (1 - ν) * (c[1] / c[0]) ^ ν) ^ (1 - 1 / ψ) / c[1] - - 1 + Rᶠ[0] = 1 / SDF⁺¹[0] - - (1 - ν) / ν * c[0] / (1 - l[0]) = (1 - ζ) * exp(z[0]) * k[-1] ^ ζ * l[0] ^ (-ζ) - - c[0] + i[0] = exp(z[0]) * k[-1] ^ ζ * l[0] ^ (1 - ζ) - - k[0] = i[0] + k[-1] * (1 - δ) - - z[0] = λ * z[-1] + σ[0] * ϵᶻ[x] - - y[0] = exp(z[0]) * k[-1] ^ ζ * l[0] ^ (1 - ζ) - - log(σ[0]) = (1 - ρ) * log(σ̄) + ρ * log(σ[-1]) + η * ω[x] - -end - - -@parameters Caldara_et_al_2012 verbose = true begin - β = 0.991 - - l[ss] = 1/3 | ν - - ζ = 0.3 - - δ = 0.0196 - - λ = 0.95 - - ψ = 0.5 - - γ = 40 - - σ̄ = 0.021 - - η = 0.1 - - ρ = 0.9 - -end diff --git a/test/models/FS2000.jl b/test/models/FS2000.jl deleted file mode 100644 index 307d1aab..00000000 --- a/test/models/FS2000.jl +++ /dev/null @@ -1,68 +0,0 @@ -# Translated from: https://archives.dynare.org/documentation/examples.html -# be aware that dynare dynamics differ if c[2] or P[2] (not sure which one) are not declared explicitly as an auxilliary variable (c_lead(0) = c(+1);). The system in dynare has one less variable and the higher order solutions are different for the stochastic vol term. - -@model m begin - dA[0] = exp(gam + z_e_a * e_a[x]) - - log(m[0]) = (1 - rho) * log(mst) + rho * log(m[-1]) + z_e_m * e_m[x] - - - P[0] / (c[1] * P[1] * m[0]) + bet * P[1] * (alp * exp( - alp * (gam + log(e[1]))) * k[0] ^ (alp - 1) * n[1] ^ (1 - alp) + (1 - del) * exp( - (gam + log(e[1])))) / (c[2] * P[2] * m[1])=0 - - W[0] = l[0] / n[0] - - - (psi / (1 - psi)) * (c[0] * P[0] / (1 - n[0])) + l[0] / n[0] = 0 - - R[0] = P[0] * (1 - alp) * exp( - alp * (gam + z_e_a * e_a[x])) * k[-1] ^ alp * n[0] ^ ( - alp) / W[0] - - 1 / (c[0] * P[0]) - bet * P[0] * (1 - alp) * exp( - alp * (gam + z_e_a * e_a[x])) * k[-1] ^ alp * n[0] ^ (1 - alp) / (m[0] * l[0] * c[1] * P[1]) = 0 - - c[0] + k[0] = exp( - alp * (gam + z_e_a * e_a[x])) * k[-1] ^ alp * n[0] ^ (1 - alp) + (1 - del) * exp( - (gam + z_e_a * e_a[x])) * k[-1] - - P[0] * c[0] = m[0] - - m[0] - 1 + d[0] = l[0] - - e[0] = exp(z_e_a * e_a[x]) - - y[0] = k[-1] ^ alp * n[0] ^ (1 - alp) * exp( - alp * (gam + z_e_a * e_a[x])) - - gy_obs[0] = dA[0] * y[0] / y[-1] - - gp_obs[0] = (P[0] / P[-1]) * m[-1] / dA[0] - - log_gy_obs[0] = log(gy_obs[0]) - - log_gp_obs[0] = log(gp_obs[0]) -end - - -@parameters m verbose = true begin - alp = 0.356 - bet = 0.993 - gam = 0.0085 - mst = 1.0002 - rho = 0.129 - psi = 0.65 - del = 0.01 - z_e_a = 0.035449 - z_e_m = 0.008862 -end - - -# estimated_params; -# alp, beta_pdf, 0.356, 0.02; -# bet, beta_pdf, 0.993, 0.002; -# gam, normal_pdf, 0.0085, 0.003; -# mst, normal_pdf, 1.0002, 0.007; -# rho, beta_pdf, 0.129, 0.223; -# psi, beta_pdf, 0.65, 0.05; -# del, beta_pdf, 0.01, 0.005; -# stderr z_e_a * e_a[x], inv_gamma_pdf, 0.035449, inf; -# stderr z_e_m * e_m[x], inv_gamma_pdf, 0.008862, inf; -# end; - -# varobs gp_obs gy_obs; - -# // computes only the posterior mode for demonstration. -# //For full Metropolis simulation set mh_replic=20000. It will take several hours -# estimation(datafile=fsdat,nobs=192,loglinear,mh_replic=0,mh_nblocks=5,mh_jscale=0.8); diff --git a/test/models/GNSS_2010.jl b/test/models/GNSS_2010.jl deleted file mode 100644 index 29f1519e..00000000 --- a/test/models/GNSS_2010.jl +++ /dev/null @@ -1,291 +0,0 @@ -@model GNSS_2010 begin - (1 - a_i) * exp(ee_z[0]) * (c_p[0] - a_i * c_p[-1]) ^ (-1) = lam_p[0] - - j * exp(ee_j[0]) / h_p[0] - lam_p[0] * q_h[0] + beta_p * lam_p[1] * q_h[1] = 0 - - lam_p[0] = beta_p * lam_p[1] * (1 + r_d[0]) / pie[1] - - (1 - exp(eps_l[0])) * l_p[0] + exp(eps_l[0]) * l_p[0] ^ (1 + phi) / w_p[0] / lam_p[0] - pie_wp[0] * kappa_w * (pie_wp[0] - pie[-1] ^ ind_w * piss ^ (1 - ind_w)) + kappa_w * beta_p * lam_p[1] / lam_p[0] * (pie_wp[1] - piss ^ (1 - ind_w) * pie[0] ^ ind_w) * pie_wp[1] ^ 2 / pie[1] = 0 - - pie_wp[0] = pie[0] * w_p[0] / w_p[-1] - - c_p[0] + q_h[0] * (h_p[0] - h_p[-1]) + d_p[0] = l_p[0] * w_p[0] + (1 + r_d[-1]) * d_p[-1] / pie[0] + J_R[0] / gamma_p - - (1 - a_i) * exp(ee_z[0]) * (c_i[0] - a_i * c_i[-1]) ^ (-1) = lam_i[0] - - j * exp(ee_j[0]) / h_i[0] - q_h[0] * lam_i[0] + q_h[1] * beta_i * lam_i[1] + pie[1] * q_h[1] * s_i[0] * exp(m_i[0]) = 0 - - lam_i[0] - beta_i * lam_i[1] * (1 + r_bh[0]) / pie[1] = s_i[0] * (1 + r_bh[0]) - - (1 - exp(eps_l[0])) * l_i[0] + exp(eps_l[0]) * l_i[0] ^ (1 + phi) / w_i[0] / lam_i[0] - pie_wi[0] * kappa_w * (pie_wi[0] - pie[-1] ^ ind_w * piss ^ (1 - ind_w)) + kappa_w * beta_i * lam_i[1] / lam_i[0] * (pie_wi[1] - piss ^ (1 - ind_w) * pie[0] ^ ind_w) * pie_wi[1] ^ 2 / pie[1] = 0 - - pie_wi[0] = pie[0] * w_i[0] / w_i[-1] - - c_i[0] + q_h[0] * (h_i[0] - h_i[-1]) + (1 + r_bh[-1]) * b_i[-1] / pie[0] = l_i[0] * w_i[0] + b_i[0] - - (1 + r_bh[0]) * b_i[0] = pie[1] * h_i[0] * q_h[1] * exp(m_i[0]) - - K[0] = (1 - deltak) * K[-1] + I[0] * (1 - kappa_i / 2 * (I[0] * exp(ee_qk[0]) / I[-1] - 1) ^ 2) - - 1 = q_k[0] * (1 - kappa_i / 2 * (I[0] * exp(ee_qk[0]) / I[-1] - 1) ^ 2 - exp(ee_qk[0]) * I[0] * kappa_i * (I[0] * exp(ee_qk[0]) / I[-1] - 1) / I[-1]) + exp(ee_qk[1]) * kappa_i * beta_e * lam_e[1] / lam_e[0] * q_k[1] * (I[1] * exp(ee_qk[1]) / I[0] - 1) * (I[1] / I[0]) ^ 2 - - (1 - a_i) * (c_e[0] - a_i * c_e[-1]) ^ (-1) = lam_e[0] - - (1 - deltak) * pie[1] * q_k[1] * s_e[0] * exp(m_e[0]) + beta_e * lam_e[1] * ((1 - deltak) * q_k[1] + r_k[1] * u[1] - (eksi_1 * (u[1] - 1) + eksi_2 / 2 * (u[1] - 1) ^ 2)) = q_k[0] * lam_e[0] - - w_p[0] = ni * (1 - alpha) * y_e[0] / (l_pd[0] * x[0]) - - w_i[0] = y_e[0] * (1 - alpha) * (1 - ni) / (x[0] * l_id[0]) - - lam_e[0] - s_e[0] * (1 + r_be[0]) = beta_e * lam_e[1] * (1 + r_be[0]) / pie[1] - - r_k[0] = eksi_1 + eksi_2 * (u[0] - 1) - - c_e[0] + (1 + r_be[-1]) * b_ee[-1] / pie[0] + w_p[0] * l_pd[0] + w_i[0] * l_id[0] + q_k[0] * k_e[0] + (eksi_1 * (u[0] - 1) + eksi_2 / 2 * (u[0] - 1) ^ 2) * k_e[-1] = y_e[0] / x[0] + b_ee[0] + k_e[-1] * (1 - deltak) * q_k[0] - - y_e[0] = exp(A_e[0]) * (u[0] * k_e[-1]) ^ alpha * (l_pd[0] ^ ni * l_id[0] ^ (1 - ni)) ^ (1 - alpha) - - (1 + r_be[0]) * b_ee[0] = (1 - deltak) * k_e[0] * pie[1] * q_k[1] * exp(m_e[0]) - - r_k[0] = (l_pd[0] ^ ni * l_id[0] ^ (1 - ni)) ^ (1 - alpha) * alpha * exp(A_e[0]) * u[0] ^ (alpha - 1) * k_e[-1] ^ (alpha - 1) / x[0] - - R_b[0] = r_ib[0] + ( - kappa_kb) * (K_b[0] / B[0] - vi) * (K_b[0] / B[0]) ^ 2 - - pie[0] * K_b[0] = (1 - delta_kb) * K_b[-1] / exp(eps_K_b[0]) + j_B[-1] - - gamma_b * d_b[0] = d_p[0] * gamma_p - - gamma_b * b_h[0] = b_i[0] * gamma_i - - gamma_b * b_e[0] = b_ee[0] * gamma_e - - b_h[0] + b_e[0] = K_b[0] + d_b[0] - - kappa_d * beta_p * lam_p[1] / lam_p[0] * (r_d[1] / r_d[0] - (r_d[0] / r_d[-1]) ^ ind_d) * (r_d[1] / r_d[0]) ^ 2 * d_b[1] / d_b[0] + exp(mk_d[0]) / (exp(mk_d[0]) - 1) - 1 - r_ib[0] * exp(mk_d[0]) / (exp(mk_d[0]) - 1) / r_d[0] - r_d[0] * kappa_d * (r_d[0] / r_d[-1] - (r_d[-1] / r_d[-2]) ^ ind_d) / r_d[-1] = 0 - - beta_p * lam_p[1] / lam_p[0] * kappa_be * (r_be[1] / r_be[0] - (r_be[0] / r_be[-1]) ^ ind_be) * (r_be[1] / r_be[0]) ^ 2 * b_e[1] / b_e[0] + 1 - exp(mk_be[0]) / (exp(mk_be[0]) - 1) + R_b[0] * exp(mk_be[0]) / (exp(mk_be[0]) - 1) / r_be[0] - r_be[0] * kappa_be * (r_be[0] / r_be[-1] - (r_be[-1] / r_be[-2]) ^ ind_be) / r_be[-1] = 0 - - beta_p * lam_p[1] / lam_p[0] * kappa_bh * (r_bh[1] / r_bh[0] - (r_bh[0] / r_bh[-1]) ^ ind_bh) * (r_bh[1] / r_bh[0]) ^ 2 * b_h[1] / b_h[0] + 1 - exp(mk_bh[0]) / (exp(mk_bh[0]) - 1) + R_b[0] * exp(mk_bh[0]) / (exp(mk_bh[0]) - 1) / r_bh[0] - r_bh[0] * kappa_bh * (r_bh[0] / r_bh[-1] - (r_bh[-1] / r_bh[-2]) ^ ind_bh) / r_bh[-1] = 0 - - j_B[0] = r_bh[0] * b_h[0] + r_be[0] * b_e[0] - r_d[0] * d_b[0] - d_b[0] * r_d[0] * kappa_d / 2 * (r_d[0] / r_d[-1] - 1) ^ 2 - b_e[0] * r_be[0] * kappa_be / 2 * (r_be[0] / r_be[-1] - 1) ^ 2 - b_h[0] * r_bh[0] * kappa_bh / 2 * (r_bh[0] / r_bh[-1] - 1) ^ 2 - K_b[0] * kappa_kb / 2 * (K_b[0] / B[0] - vi) ^ 2 - - J_R[0] = Y[0] * (1 - 1 / x[0] - kappa_p / 2 * (pie[0] - pie[-1] ^ ind_p * piss ^ (1 - ind_p)) ^ 2) - - 1 - exp(eps_y[0]) + exp(eps_y[0]) / x[0] - pie[0] * kappa_p * (pie[0] - pie[-1] ^ ind_p * piss ^ (1 - ind_p)) + pie[1] * beta_p * lam_p[1] / lam_p[0] * kappa_p * (pie[1] - piss ^ (1 - ind_p) * pie[0] ^ ind_p) * Y[1] / Y[0] = 0 - - C[0] = c_p[0] * gamma_p + c_i[0] * gamma_i + c_e[0] * gamma_e - - BH[0] = gamma_b * b_h[0] - - BE[0] = gamma_b * b_e[0] - - B[0] = BH[0] + BE[0] - - D[0] = d_p[0] * gamma_p - - Y[0] = y_e[0] * gamma_e - - J_B[0] = gamma_b * j_B[0] - - l_pd[0] * gamma_e = l_p[0] * gamma_p - - l_id[0] * gamma_e = l_i[0] * gamma_i - - h = h_p[0] * gamma_p + h_i[0] * gamma_i - - K[0] = k_e[0] * gamma_e - - Y1[0] = C[0] + K[0] - (1 - deltak) * K[-1] - - PIW[0] = pie[0] * (w_p[0] + w_i[0]) / (w_p[-1] + w_i[-1]) - - 1 + r_ib[0] = (1 + r_ib_ss) ^ (1 - rho_ib) * (1 + r_ib[-1]) ^ rho_ib * ((pie[0] / piss) ^ phi_pie * (Y1[0] / Y1[-1]) ^ phi_y) ^ (1 - rho_ib) * (1 + σ_r_ib * e_r_ib[x]) - - exp(ee_z[0]) = 1 - rho_ee_z + rho_ee_z * exp(ee_z[-1]) + σ_z * e_z[x] - - exp(A_e[0]) = 1 - rho_A_e + rho_A_e * exp(A_e[-1]) + σ_A_e * e_A_e[x] - - exp(ee_j[0]) = 1 - rho_ee_j + rho_ee_j * exp(ee_j[-1]) - σ_j * e_j[x] - - exp(m_i[0]) = (1 - rho_mi) * m_i_ss + rho_mi * exp(m_i[-1]) + σ_mi * e_mi[x] - - exp(m_e[0]) = (1 - rho_me) * m_e_ss + rho_me * exp(m_e[-1]) + σ_me * e_me[x] - - exp(mk_d[0]) = (1 - rho_mk_d) * mk_d_ss + rho_mk_d * exp(mk_d[-1]) + σ_mk_d * e_mk_d[x] - - exp(mk_be[0]) = (1 - rho_mk_be) * mk_be_ss + rho_mk_be * exp(mk_be[-1]) + σ_mk_be * e_mk_be[x] - - exp(mk_bh[0]) = (1 - rho_mk_bh) * mk_bh_ss + rho_mk_bh * exp(mk_bh[-1]) + σ_mk_bh * e_mk_bh[x] - - exp(ee_qk[0]) = 1 - rho_ee_qk + rho_ee_qk * exp(ee_qk[-1]) + σ_qk * e_qk[x] - - exp(eps_y[0]) = (1 - rho_eps_y) * eps_y_ss + rho_eps_y * exp(eps_y[-1]) + σ_y * e_y[x] - - exp(eps_l[0]) = (1 - rho_eps_l) * eps_l_ss + rho_eps_l * exp(eps_l[-1]) + σ_l * e_l[x] - - exp(eps_K_b[0]) = 1 - rho_eps_K_b + rho_eps_K_b * exp(eps_K_b[-1]) + σ_eps_K_b * e_eps_K_b[x] - - rr_e[0] = lam_e[0] - beta_e * lam_e[1] * (1 + r_be[0]) / pie[1] - - bm[0] = r_bh[-1] * b_h[-1] / (b_h[-1] + b_e[-1]) + r_be[-1] * b_e[-1] / (b_h[-1] + b_e[-1]) - r_d[-1] - - spr_b[0] = r_bh[0] * 0.5 + r_be[0] * 0.5 - r_d[0] -end - -@parameters GNSS_2010 verbose = true begin - beta_p = 0.9943 - - beta_i = 0.975 - - beta_b = beta_p - - beta_e = beta_i - - j = 0.2 - - phi = 1.0 - - m_i_ss = 0.7 - - m_e_ss = 0.35 - - alpha = 0.250 - - eps_d = -1.46025 - - eps_bh = 2.932806 - - eps_be = 2.932806 - - mk_d_ss = eps_d/(eps_d-1) - - mk_bh_ss = eps_bh/(eps_bh-1) - - mk_be_ss = eps_be/(eps_be-1) - - book_ss = 0 - - eps_y_ss = 6 - - eps_l_ss = 5 - - gamma_p = 1 - - gamma_i = 1 - - ni = 0.8 - - gamma_b = 1 - - gamma_e = 1 - - deltak = 0.025 - - piss = 1 - - r_ib_ss = (eps_d-1)*(piss/beta_p-1)/eps_d - - r_be_ss = eps_be*r_ib_ss/(eps_be-1) - - r_bh_ss = eps_bh*r_ib_ss/(eps_bh-1) - - r_k_ss = (-(1-deltak))-piss*(1-deltak)*m_e_ss/beta_e*(1/(1+r_be_ss)-beta_e/piss)+1/beta_e - - h = 1 - - eksi_1 = r_k_ss - - eksi_2 = r_k_ss*0.1 - - vi = 0.09 - - eps_b = (eps_bh + eps_be) / 2 - - delta_kb = r_ib_ss/vi*(eps_d-eps_b+eps_d*vi*(eps_b-1))/((eps_d-1)*(eps_b-1)) - - ind_d = 0.0 - - ind_be = 0.0 - - ind_bh = 0.0 - - rho_ee_z = 3.9352753242570521e-001 - - rho_A_e = 9.3900015678945492e-001 - - rho_ee_j = 9.2117909414787280e-001 - - rho_me = 8.9386514435074682e-001 - - rho_mi = 9.2864864780617762e-001 - - rho_mk_d = 8.3804796415016769e-001 - - rho_mk_bh = 8.1946217303357627e-001 - - rho_mk_be = 8.3428100562221263e-001 - - rho_ee_qk = 5.4749146204441368e-001 - - rho_eps_y = 3.0473409634573673e-001 - - rho_eps_l = 6.3992225476484799e-001 - - rho_eps_K_b = 8.1297958524412761e-001 - - kappa_p = 2.8650196538695269e+001 - - kappa_w = 9.9898283585301883e+001 - - kappa_i = 1.0182155670839322e+001 - - kappa_d = 3.5029734165847466e+000 - - kappa_be = 9.3638233191517397e+000 - - kappa_bh = 1.0086654447226444e+001 - - kappa_kb = 1.1068335540791962e+001 - - phi_pie = 1.9816026561910398e+000 - - rho_ib = 7.6855514559469518e-001 - - phi_y = 3.4591496570352009e-001 - - ind_p = 1.6051347848216171e-001 - - ind_w = 2.7569624058316433e-001 - - a_i = 8.5595219718425664e-001 - - a_e = 0.0 - - a_p = 0.0 - - σ_z = 0.0144 - - σ_A_e = 0.0062 - - σ_j = 0.0658 - - σ_me = 0.0034 - - σ_mi = 0.0023 - - σ_mk_d = 0.0488 - - σ_mk_bh = 0.0051 - - σ_mk_be = 0.1454 - - σ_qk = 0.0128 - - σ_r_ib = 0.0018 - - σ_y = 1.0099 - - σ_l = 0.3721 - - σ_eps_K_b = 0.050 -end \ No newline at end of file diff --git a/test/models/Gali_Monacelli_2005_CITR.jl b/test/models/Gali_Monacelli_2005_CITR.jl deleted file mode 100644 index 63320541..00000000 --- a/test/models/Gali_Monacelli_2005_CITR.jl +++ /dev/null @@ -1,72 +0,0 @@ -@model Gali_Monacelli_2005_CITR begin - x[0] = x[1] - σᵃ ^ (-1) * (r[0] - pih[1] - rnat[0]) - - pih[0] = pih[1] * β + x[0] * κᵃ - - rnat[0] = ( - σᵃ) * Γ * (1 - ρᵃ) * a[0] + σᵃ * α * (Θ + Ψ) * (ystar[1] - ystar[0]) - - ynat[0] = Γ * a[0] + ystar[0] * α * Ψ - - x[0] = y[0] - ynat[0] - - y[0] = ystar[0] + σᵃ ^ (-1) * s[0] - - pi[0] = pih[0] + α * (s[0] - s[-1]) - - s[0] = s[-1] + deprec_rate[0] - pih[0] - - y[0] = a[0] + n[0] - - nx[0] = s[0] * α * (ω / σ - 1) - - y[0] = c[0] + s[0] * α * ω / σ - - real_wage[0] = σ * c[0] + n[0] * ϕ - - a[0] = ρᵃ * a[-1] + ϵ_a[x] - - ystar[0] = ρʸ * ystar[-1] + ϵ_star[x] - - r[0] = pi[0] * ϕᵖⁱ - -end - - -@parameters Gali_Monacelli_2005_CITR verbose = true begin - σ = 1 - - η = 1 - - γ = 1 - - ϕ = 3 - - θ = 0.75 - - β = 0.99 - - α = 0.4 - - ϕᵖⁱ = 1.5 - - ρᵃ = 0.9 - - ρʸ = 0.86 - - ρ = 1 / β - 1 - - ω = σ * γ + (1 - α) * (σ * η - 1) - - σᵃ = σ / (1 - α + α * ω) - - Θ = (1 - α) * (σ * η - 1) + σ * γ - 1 - - λ = (1 - β * θ) * (1 - θ) / θ - - κᵃ = λ * (σᵃ + ϕ) - - Γ = (1 + ϕ) / (σᵃ + ϕ) - - Ψ = -σᵃ * Θ / (σᵃ + ϕ) - -end \ No newline at end of file diff --git a/test/models/Ghironi_Melitz_2005.jl b/test/models/Ghironi_Melitz_2005.jl deleted file mode 100644 index e69d5829..00000000 --- a/test/models/Ghironi_Melitz_2005.jl +++ /dev/null @@ -1,115 +0,0 @@ -@model Ghironi_Melitz_2005 begin - 1 = Nd[0] * ρ̃d[0] ^ (1 - θ) + Nx̄[0] * ρ̃x̄[0] ^ (1 - θ) - - 1 = Nd̄[0] * ρ̃d̄[0] ^ (1 - θ) + Nx[0] * ρ̃x[0] ^ (1 - θ) - - ρ̃d[0] = θ / (θ - 1) * w[0] / (Z[0] * z̃d) - - ρ̃d̄[0] = θ / (θ - 1) * w̄[0] / (Z̄[0] * z̃d̄) - - ρ̃x[0] = θ / (θ - 1) * τ * w[0] / (Z[0] * z̃x[0]) / Q[0] - - ρ̃x̄[0] = Q[0] * θ / (θ - 1) * τ * w̄[0] / (Z̄[0] * z̃x̄[0]) - - d̃[0] = d̃d[0] + Nx[0] / Nd[0] * d̃x[0] - - d̃̄[0] = d̃d̄[0] + Nx̄[0] / Nd̄[0] * d̃x̄[0] - - d̃d[0] = ρ̃d[0] ^ (1 - θ) * 1 / θ * C[0] - - d̃d̄[0] = ρ̃d̄[0] ^ (1 - θ) * 1 / θ * C̄[0] - - ṽ[0] = w[0] * fe / Z[0] - - ṽ̄[0] = w̄[0] * fē / Z̄[0] - - d̃x[0] = w[0] * fx / Z[0] * (θ - 1) / (k - (θ - 1)) - - d̃x̄[0] = (θ - 1) / (k - (θ - 1)) * w̄[0] * fx̄ / Z̄[0] - - Nx[0] / Nd[0] = (zmin / z̃x[0]) ^ k * (k / (k - (θ - 1))) ^ (k / (θ - 1)) - - Nx̄[0] / Nd̄[0] = (k / (k - (θ - 1))) ^ (k / (θ - 1)) * (zmin̄ / z̃x̄[0]) ^ k - - Nd[0] = (1 - δ) * (Nd[-1] + Ne[-1]) - - Nd̄[0] = (1 - δ) * (Nd̄[-1] + Nē[-1]) - - C[0] ^ (-γ) = β * (1 + r[0]) * C[1] ^ (-γ) - - C̄[0] ^ (-γ) = β * (1 + r̄[0]) * C̄[1] ^ (-γ) - - ṽ[0] = (1 - δ) * β * (C[1] / C[0]) ^ (-γ) * (ṽ[1] + d̃[1]) - - ṽ̄[0] = (1 - δ) * β * (C̄[1] / C̄[0]) ^ (-γ) * (ṽ̄[1] + d̃̄[1]) - - C[0] = w[0] * L + Nd[0] * d̃[0] - ṽ[0] * Ne[0] - - C̄[0] = w̄[0] * L̄ + Nd̄[0] * d̃̄[0] - ṽ̄[0] * Nē[0] - - Q[0] = Nx̄[0] * ρ̃x̄[0] ^ (1 - θ) * C[0] / (Nx[0] * ρ̃x[0] ^ (1 - θ) * C̄[0]) - - Q̃[0] = ((Nd̄[0] / (Nd̄[0] + Nx[0]) * TOL[0] ^ (1 - θ) + Nx[0] / (Nd̄[0] + Nx[0]) * (τ * z̃d / z̃x[0]) ^ (1 - θ)) / (Nd[0] / (Nd[0] + Nx̄[0]) + Nx̄[0] / (Nd[0] + Nx̄[0]) * (τ * TOL[0] * z̃d̄ / z̃x̄[0]) ^ (1 - θ))) ^ (1 / (1 - θ)) - - Q̃[0] = Q[0] * ((Nd[0] + Nx̄[0]) / (Nd̄[0] + Nx[0])) ^ (( - 1) / (θ - 1)) - - Z[0] = (1 - ρZ) * 1.0 + ρZ * Z[-1] + σᶻ * ϵᶻ[x] - - Z̄[0] = 1.0 * (1 - ρZ̄) + ρZ̄ * Z̄[-1] + σᶻ̄ * ϵᶻ̄[x] - - z̃x[0] = (θ * fx * (w[0] / Z[0]) ^ θ * (1 + (θ - 1) / (k - (θ - 1))) * Q[0] ^ (-θ) * τ ^ (θ - 1) * (θ / (θ - 1)) ^ (θ - 1) * C̄[0] ^ (-1)) ^ (1 / (θ - 1)) - - z̃x̄[0] = ((θ / (θ - 1)) ^ (θ - 1) * θ * τ ^ (θ - 1) * (1 + (θ - 1) / (k - (θ - 1))) * fx̄ * (w̄[0] / Z̄[0]) ^ θ * Q[0] ^ θ * C[0] ^ (-1)) ^ (1 / (θ - 1)) - - zx[0] = z̃x[0] / (k / (k - (θ - 1))) ^ (1 / (θ - 1)) - - zx̄[0] = z̃x̄[0] / (k / (k - (θ - 1))) ^ (1 / (θ - 1)) - -end - - -@parameters Ghironi_Melitz_2005 verbose = true begin - σᶻ = .01 - - σᶻ̄ = .01 - - fx = fx_share * (1 - β * (1 - δ)) / (β * (1 - δ)) * fe - - fx̄ = fx_share * (1 - β * (1 - δ)) / (β * (1 - δ)) * fē - - β = 0.99 - - γ = 2.0 - - δ = 0.025 - - θ = 3.8 - - k = 3.4 - - τ = 1.3 - - zmin = 1.0 - - zmin̄ = 1.0 - - z̃d = (k / (k - (θ - 1))) ^ (1 / (θ - 1)) * zmin - - z̃d̄ = (k / (k - (θ - 1))) ^ (1 / (θ - 1)) * zmin̄ - - fe = 1.0 - - fē = 1.0 - - L = 1.0 - - L̄ = 1.0 - - ρZ = 0.9 - - ρZ̄ = 0.9 - - fx_share = 0.235 - -end - diff --git a/test/models/Ireland_2004.jl b/test/models/Ireland_2004.jl deleted file mode 100644 index 177ea1d3..00000000 --- a/test/models/Ireland_2004.jl +++ /dev/null @@ -1,46 +0,0 @@ -@model Ireland_2004 begin - a[0] = ρᵃ * a[-1] + σᵃ * ϵᵃ[x] - - e[0] = ρᵉ * e[-1] + σᵉ * ϵᵉ[x] - - x[0] = αˣ * x[-1] + (1 - αˣ) * x[1] - (r̂[0] - π̂[1]) + a[0] * (1 - ω) * (1 - ρᵃ) - - π̂[0] = β * (αᵖ * π̂[-1] + π̂[1] * (1 - αᵖ)) + x[0] * ψ - e[0] - - x[0] = ŷ[0] - a[0] * ω - - ĝ[0] = σᶻ * ϵᶻ[x] + ŷ[0] - ŷ[-1] - - r̂[0] - r̂[-1] = π̂[0] * ρᵖ + ĝ[0] * ρᵍ + x[0] * ρˣ + σʳ * ϵʳ[x] -end - - -@parameters Ireland_2004 verbose = true begin - β = 0.99 - - ψ = 0.1 - - ω = 0.0581 - - αˣ = 0.00001 - - αᵖ = 0.00001 - - ρᵖ = 0.3866 - - ρᵍ = 0.3960 - - ρˣ = 0.1654 - - ρᵃ = 0.9048 - - ρᵉ = 0.9907 - - σʳ = 0.0028 - - σᵃ = 0.0302 - - σᵉ = 0.0002 - - σᶻ = 0.0089 -end \ No newline at end of file diff --git a/test/models/JQ_2012_RBC.jl b/test/models/JQ_2012_RBC.jl deleted file mode 100644 index 73845bdd..00000000 --- a/test/models/JQ_2012_RBC.jl +++ /dev/null @@ -1,65 +0,0 @@ -@model JQ_2012_RBC begin - w[0] / c[0] ^ σ = α / (1 - n[0]) - - c[0] ^ (-σ) = β * (R[0] - τ) / (1 - τ) * c[1] ^ (-σ) - - w[0] * n[0] + b[-1] - b[0] / R[0] + d[0] = c[0] - - (1 - θ) * z[0] * k[-1] ^ θ * n[0] ^ (-θ) = w[0] / (1 - μ[0] * (1 + 2 * κ * (d[0] - d[ss]))) - - β * (c[0] / c[1]) ^ σ * (1 + 2 * κ * (d[0] - d[ss])) / (1 + 2 * κ * (d[1] - d[ss])) * (1 - δ + θ * (1 - (1 + 2 * κ * (d[1] - d[ss])) * μ[1]) * z[1] * k[0] ^ (θ - 1) * n[1] ^ (1 - θ)) + (1 + 2 * κ * (d[0] - d[ss])) * μ[0] * ξ[0] = 1 - - (1 + 2 * κ * (d[0] - d[ss])) / (1 + 2 * κ * (d[1] - d[ss])) * (c[0] / c[1]) ^ σ * β * R[0] + (1 + 2 * κ * (d[0] - d[ss])) * μ[0] * ξ[0] * R[0] * (1 - τ) / (R[0] - τ) = 1 - - b[0] / R[0] + k[-1] * (1 - δ) + z[0] * k[-1] ^ θ * n[0] ^ (1 - θ) - w[0] * n[0] - b[-1] - k[0] = (d[0] + κ * (d[0] - d[ss]) ^ 2) - - ξ[0] * (k[0] - b[0] * (1 - τ) / (R[0] - τ)) = z[0] * k[-1] ^ θ * n[0] ^ (1 - θ) - - log(z[0] / z̄) = A¹¹ * log(z[-1] / z̄) + A¹² * log(ξ[-1] / ξ̄) + σᶻ * ϵᶻ[x] - - log(ξ[0] / ξ̄) = log(z[-1] / z̄) * A²¹ + log(ξ[-1] / ξ̄) * A²² + σˣⁱ * ϵˣⁱ[x] - - y[0] = z[0] * k[-1] ^ θ * n[0] ^ (1 - θ) - - k[0] = k[-1] * (1 - δ) + i[0] - - v[0] = d[0] + c[0] * β / c[1] * v[1] - - 1 + r[0] = (R[0] - τ) / (1 - τ) -end - -@parameters JQ_2012_RBC verbose = true begin - b[ss] / (y[ss] * (1 + r[ss])) = BY_ratio | ξ̄ - - n[ss] = n̄ | α - - BY_ratio = 3.36 - - n̄ = .3 - - z̄ = 1 - - β = 0.9825 - - σ = 1 - - θ = 0.36 - - δ = 0.025 - - τ = 0.35 - - κ = 0.146 - - A¹¹ = 0.9457 - - A¹² = -0.0091 - - A²¹ = 0.0321 - - A²² = 0.9703 - - σᶻ = 0.0045 - - σˣⁱ = 0.0098 -end \ No newline at end of file diff --git a/test/models/NAWM_EAUS_2008.jl b/test/models/NAWM_EAUS_2008.jl deleted file mode 100644 index 1b88b555..00000000 --- a/test/models/NAWM_EAUS_2008.jl +++ /dev/null @@ -1,817 +0,0 @@ -@model NAWM_EAUS_2008 begin - EA_R[0] ^ 4 - 1 = EA_PHIRR * (EA_R[-1] ^ 4 - 1) + (1 - EA_PHIRR) * (EA_RRSTAR ^ 4 * EA_PI4TARGET - 1 + EA_PHIRPI * (EA_PIC4[0] - EA_PI4TARGET)) + EA_PHIRGY * (EA_Y[0] / EA_Y[-1] - 1) + EA_EPSR[x] - - US_R[0] ^ 4 - 1 = US_PHIRR * (US_R[-1] ^ 4 - 1) + (1 - US_PHIRR) * (US_RRSTAR ^ 4 * US_PI4TARGET - 1 + US_PHIRPI * (US_PIC4[0] - US_PI4TARGET)) + US_PHIRGY * (US_Y[0] / US_Y[-1] - 1) + US_EPSR[x] - - EA_UTILI[0] = 1 / (1 - EA_SIGMA) * (EA_CI[0] - EA_KAPPA * EA_CI[-1]) ^ (1 - EA_SIGMA) - 1 / (1 + EA_ZETA) * EA_NI[0] ^ (1 + EA_ZETA) + EA_BETA * EA_UTILI[1] - - EA_LAMBDAI[0] * (1 + EA_TAUC[0] + EA_GAMMAVI[0] + EA_VI[0] * EA_GAMMAVIDER[0]) = (EA_CI[0] - EA_KAPPA * EA_CI[-1]) ^ (-EA_SIGMA) - - EA_R[0] = EA_LAMBDAI[0] * EA_BETA ^ (-1) / EA_LAMBDAI[1] * EA_PIC[1] - - EA_GAMMAVIDER[0] * EA_VI[0] ^ 2 = 1 - EA_BETA * EA_LAMBDAI[1] / (EA_LAMBDAI[0] * EA_PIC[1]) - - EA_VI[0] = EA_CI[0] * (1 + EA_TAUC[0]) / EA_MI[0] - - EA_GAMMAVI[0] = EA_VI[0] * EA_GAMMAV1 + EA_GAMMAV2 / EA_VI[0] - 2 * (EA_GAMMAV1 * EA_GAMMAV2) ^ 0.5 - - EA_GAMMAVIDER[0] = EA_GAMMAV1 - EA_GAMMAV2 * EA_VI[0] ^ (-2) - - EA_KI[0] = (1 - EA_DELTA) * EA_KI[-1] + (1 - EA_GAMMAI[-1]) * EA_II[-1] - - EA_GAMMAI[0] = EA_GAMMAI1 / 2 * (EA_II[0] / EA_II[-1] - 1) ^ 2 - - EA_GAMMAIDER[0] = EA_GAMMAI1 * (EA_II[0] / EA_II[-1] - 1) / EA_II[-1] - - EA_GAMMAU[0] = ((EA_DELTA + EA_BETA ^ (-1) - 1) * EA_QBAR - EA_DELTA * EA_TAUKBAR * EA_PIBAR) / (EA_PIBAR * (1 - EA_TAUKBAR)) * (EA_U[0] - 1) + EA_GAMMAU2 / 2 * (EA_U[0] - 1) ^ 2 - - EA_GAMMAUDER[0] = ((EA_DELTA + EA_BETA ^ (-1) - 1) * EA_QBAR - EA_DELTA * EA_TAUKBAR * EA_PIBAR) / (EA_PIBAR * (1 - EA_TAUKBAR)) + (EA_U[0] - 1) * EA_GAMMAU2 - - EA_RK[0] = EA_GAMMAUDER[0] * EA_PI[0] - - EA_PI[0] = EA_Q[0] * (1 - EA_GAMMAI[0] - EA_II[0] * EA_GAMMAIDER[0]) + EA_BETA * EA_LAMBDAI[1] / EA_LAMBDAI[0] * EA_Q[1] * EA_GAMMAIDER[1] * EA_II[1] ^ 2 / EA_II[0] - - EA_Q[0] = EA_BETA * EA_LAMBDAI[1] / EA_LAMBDAI[0] * ((1 - EA_TAUK[1]) * (EA_RK[1] * EA_U[1] - EA_GAMMAU[1] * EA_PI[1]) + EA_PI[1] * EA_DELTA * EA_TAUK[1] + (1 - EA_DELTA) * EA_Q[1]) - - EA_WITILDE[0] ^ (1 + EA_ZETA * EA_ETAI) = EA_ETAI / (EA_ETAI - 1) * EA_FI[0] / EA_GI[0] - - EA_FI[0] = EA_WI[0] ^ ((1 + EA_ZETA) * EA_ETAI) * EA_NDI[0] ^ (1 + EA_ZETA) + EA_BETA * EA_XII * (EA_PIC[1] / (EA_PIC[0] ^ EA_CHII * EA_PI4TARGET ^ (0.25 * (1 - EA_CHII)))) ^ ((1 + EA_ZETA) * EA_ETAI) * EA_FI[1] - - EA_GI[0] = EA_NDI[0] * EA_LAMBDAI[0] * (1 - EA_TAUN[0] - EA_TAUWH[0]) * EA_WI[0] ^ EA_ETAI + EA_BETA * EA_XII * (EA_PIC[1] / (EA_PIC[0] ^ EA_CHII * EA_PI4TARGET ^ (0.25 * (1 - EA_CHII)))) ^ (EA_ETAI - 1) * EA_GI[1] - - EA_WI[0] ^ (1 - EA_ETAI) = (1 - EA_XII) * EA_WITILDE[0] ^ (1 - EA_ETAI) + EA_XII * EA_WI[-1] ^ (1 - EA_ETAI) * (EA_PI4TARGET ^ (0.25 * (1 - EA_CHII)) * EA_PIC[-1] ^ EA_CHII / EA_PIC[0]) ^ (1 - EA_ETAI) - - EA_UTILJ[0] = 1 / (1 - EA_SIGMA) * (EA_CJ[0] - EA_KAPPA * EA_CJ[-1]) ^ (1 - EA_SIGMA) - 1 / (1 + EA_ZETA) * EA_NJ[0] ^ (1 + EA_ZETA) + EA_BETA * EA_UTILJ[1] - - EA_CJ[0] * (1 + EA_TAUC[0] + EA_GAMMAVJ[0]) + EA_MJ[0] = EA_NJ[0] * (1 - EA_TAUN[0] - EA_TAUWH[0]) * EA_WJ[0] + EA_TRJ[0] - EA_TJ[0] + EA_MJ[-1] * EA_PIC[0] ^ (-1) - - EA_LAMBDAJ[0] * (1 + EA_TAUC[0] + EA_GAMMAVJ[0] + EA_VJ[0] * EA_GAMMAVJDER[0]) = (EA_CJ[0] - EA_KAPPA * EA_CJ[-1]) ^ (-EA_SIGMA) - - EA_GAMMAVJDER[0] * EA_VJ[0] ^ 2 = 1 - EA_BETA * EA_LAMBDAJ[1] / (EA_PIC[1] * EA_LAMBDAJ[0]) - - EA_VJ[0] = (1 + EA_TAUC[0]) * EA_CJ[0] / EA_MJ[0] - - EA_GAMMAVJ[0] = EA_GAMMAV1 * EA_VJ[0] + EA_GAMMAV2 / EA_VJ[0] - 2 * (EA_GAMMAV1 * EA_GAMMAV2) ^ 0.5 - - EA_GAMMAVJDER[0] = EA_GAMMAV1 - EA_GAMMAV2 * EA_VJ[0] ^ (-2) - - EA_WJTILDE[0] ^ (1 + EA_ZETA * EA_ETAJ) = EA_ETAJ / (EA_ETAJ - 1) * EA_FJ[0] / EA_GJ[0] - - EA_FJ[0] = EA_WJ[0] ^ ((1 + EA_ZETA) * EA_ETAJ) * EA_NDJ[0] ^ (1 + EA_ZETA) + EA_BETA * EA_XIJ * (EA_PIC[1] / (EA_PIC[0] ^ EA_CHIJ * EA_PI4TARGET ^ (0.25 * (1 - EA_CHIJ)))) ^ ((1 + EA_ZETA) * EA_ETAJ) * EA_FJ[1] - - EA_GJ[0] = EA_NDJ[0] * (1 - EA_TAUN[0] - EA_TAUWH[0]) * EA_LAMBDAJ[0] * EA_WJ[0] ^ EA_ETAJ + EA_BETA * EA_XIJ * (EA_PIC[1] / (EA_PIC[0] ^ EA_CHIJ * EA_PI4TARGET ^ (0.25 * (1 - EA_CHIJ)))) ^ (EA_ETAJ - 1) * EA_GJ[1] - - EA_WJ[0] ^ (1 - EA_ETAJ) = (1 - EA_XIJ) * EA_WJTILDE[0] ^ (1 - EA_ETAJ) + EA_XIJ * EA_WJ[-1] ^ (1 - EA_ETAJ) * (EA_PI4TARGET ^ (0.25 * (1 - EA_CHIJ)) * EA_PIC[-1] ^ EA_CHIJ / EA_PIC[0]) ^ (1 - EA_ETAJ) - - EA_YS[0] = EA_Z[0] * EA_KD[0] ^ EA_ALPHA * EA_ND[0] ^ (1 - EA_ALPHA) - EA_PSIBAR - - EA_RK[0] = EA_ALPHA * (EA_YS[0] + EA_PSIBAR) / EA_KD[0] * EA_MC[0] - - EA_MC[0] = 1 / (EA_Z[0] * EA_ALPHA ^ EA_ALPHA * (1 - EA_ALPHA) ^ (1 - EA_ALPHA)) * EA_RK[0] ^ EA_ALPHA * ((1 + EA_TAUWF[0]) * EA_W[0]) ^ (1 - EA_ALPHA) - - EA_NDI[0] = EA_ND[0] * (1 - EA_OMEGA) * (EA_WI[0] / EA_W[0]) ^ (-EA_ETA) - - EA_NDJ[0] = EA_ND[0] * EA_OMEGA * (EA_WJ[0] / EA_W[0]) ^ (-EA_ETA) - - EA_ND[0] ^ (1 - 1 / EA_ETA) = (1 - EA_OMEGA) ^ (1 / EA_ETA) * EA_NDI[0] ^ (1 - 1 / EA_ETA) + EA_OMEGA ^ (1 / EA_ETA) * EA_NDJ[0] ^ (1 - 1 / EA_ETA) - - EA_D[0] = EA_Y[0] * EA_PY[0] - EA_RK[0] * EA_KD[0] - EA_ND[0] * (1 + EA_TAUWF[0]) * EA_W[0] - - EA_PHTILDE[0] / EA_PH[0] = EA_THETA / (EA_THETA - 1) * EA_FH[0] / EA_GH[0] - - EA_FH[0] = EA_MC[0] * EA_H[0] + EA_LAMBDAI[1] * EA_BETA * EA_XIH / EA_LAMBDAI[0] * (EA_PIH[1] / (EA_PIH[0] ^ EA_CHIH * EA_PI4TARGET ^ (0.25 * (1 - EA_CHIH)))) ^ EA_THETA * EA_FH[1] - - EA_GH[0] = EA_PH[0] * EA_H[0] + EA_LAMBDAI[1] * EA_BETA * EA_XIH / EA_LAMBDAI[0] * (EA_PIH[1] / (EA_PIH[0] ^ EA_CHIH * EA_PI4TARGET ^ (0.25 * (1 - EA_CHIH)))) ^ (EA_THETA - 1) * EA_GH[1] - - EA_PH[0] ^ (1 - EA_THETA) = (1 - EA_XIH) * EA_PHTILDE[0] ^ (1 - EA_THETA) + EA_XIH * (EA_PH[-1] / EA_PIC[0]) ^ (1 - EA_THETA) * (EA_PI4TARGET ^ (0.25 * (1 - EA_CHIH)) * EA_PIH[-1] ^ EA_CHIH) ^ (1 - EA_THETA) - - EA_PIH[0] = EA_PIC[0] * EA_PH[0] / EA_PH[-1] - - US_PIMTILDE[0] / US_PIM[0] = EA_THETA / (EA_THETA - 1) * EA_FX[0] / EA_GX[0] - - EA_FX[0] = EA_MC[0] * US_SIZE / EA_SIZE * US_IM[0] + EA_LAMBDAI[1] * EA_BETA * EA_XIX / EA_LAMBDAI[0] * (US_PIIM[1] / (US_PIIM[0] ^ EA_CHIX * EA_PI4TARGET ^ (0.25 * (1 - EA_CHIX)))) ^ EA_THETA * EA_FX[1] - - EA_GX[0] = US_IM[0] * US_SIZE * US_PIM[0] * EAUS_RER[0] / EA_SIZE + EA_LAMBDAI[1] * EA_BETA * EA_XIX / EA_LAMBDAI[0] * (US_PIIM[1] / (US_PIIM[0] ^ EA_CHIX * EA_PI4TARGET ^ (0.25 * (1 - EA_CHIX)))) ^ (EA_THETA - 1) * EA_GX[1] - - US_PIM[0] ^ (1 - EA_THETA) = (1 - EA_XIX) * US_PIMTILDE[0] ^ (1 - EA_THETA) + EA_XIX * (US_PIM[-1] / US_PIC[0]) ^ (1 - EA_THETA) * (US_PIIM[-1] ^ EA_CHIX * US_PI4TARGET ^ (0.25 * (1 - EA_CHIH))) ^ (1 - EA_THETA) - - US_PIIM[0] = US_PIC[0] * US_PIM[0] / US_PIM[-1] - - EAUS_RER[0] = EA_RER[0] / US_RER - - EA_QC[0] ^ ((EA_MUC - 1) / EA_MUC) = EA_NUC ^ (1 / EA_MUC) * EA_HC[0] ^ (1 - 1 / EA_MUC) + (1 - EA_NUC) ^ (1 / EA_MUC) * ((1 - EA_GAMMAIMC[0]) * EA_IMC[0]) ^ (1 - 1 / EA_MUC) - - 1 = EA_NUC * EA_PH[0] ^ (1 - EA_MUC) + (1 - EA_NUC) * (EA_PIM[0] / EA_GAMMAIMCDAG[0]) ^ (1 - EA_MUC) - - EA_HC[0] = EA_QC[0] * EA_NUC * EA_PH[0] ^ (-EA_MUC) - - EA_GAMMAIMC[0] = EA_GAMMAIMC1 / 2 * (EA_IMC[0] / EA_QC[0] / (EA_IMC[-1] / EA_QC[-1]) - 1) ^ 2 - - EA_GAMMAIMCDAG[0] = 1 - EA_GAMMAIMC[0] - EA_IMC[0] * EA_GAMMAIMC1 * (EA_IMC[0] / EA_QC[0] / (EA_IMC[-1] / EA_QC[-1]) - 1) / EA_QC[0] / (EA_IMC[-1] / EA_QC[-1]) - - EA_QI[0] ^ ((EA_MUI - 1) / EA_MUI) = EA_NUI ^ (1 / EA_MUI) * EA_HI[0] ^ (1 - 1 / EA_MUI) + (1 - EA_NUI) ^ (1 / EA_MUI) * ((1 - EA_GAMMAIMI[0]) * EA_IMI[0]) ^ (1 - 1 / EA_MUI) - - EA_PI[0] ^ (1 - EA_MUI) = EA_NUI * EA_PH[0] ^ (1 - EA_MUI) + (1 - EA_NUI) * (EA_PIM[0] / EA_GAMMAIMIDAG[0]) ^ (1 - EA_MUI) - - EA_HI[0] = EA_QI[0] * EA_NUI * (EA_PH[0] / EA_PI[0]) ^ (-EA_MUI) - - EA_GAMMAIMI[0] = EA_GAMMAIMI1 / 2 * (EA_IMI[0] / EA_QI[0] / (EA_IMI[-1] / EA_QI[-1]) - 1) ^ 2 - - EA_GAMMAIMIDAG[0] = 1 - EA_GAMMAIMI[0] - EA_IMI[0] * EA_GAMMAIMI1 * (EA_IMI[0] / EA_QI[0] / (EA_IMI[-1] / EA_QI[0]) - 1) / EA_QI[0] / (EA_IMI[-1] / EA_QI[-1]) - - EA_PH[-1] * EA_G[-1] + EA_TR[-1] + EA_B[-1] * EA_PIC[-1] ^ (-1) + EA_PIC[-1] ^ (-1) * EA_M[-2] = EA_TAUC[-1] * EA_C[-1] + (EA_TAUN[-1] + EA_TAUWH[-1]) * (EA_WI[-1] * EA_NDI[-1] + EA_WJ[-1] * EA_NDJ[-1]) + EA_TAUWF[-1] * EA_W[-1] * EA_ND[-1] + EA_TAUK[-1] * (EA_RK[-1] * EA_U[-1] - (EA_DELTA + EA_GAMMAU[-1]) * EA_PI[-1]) * EA_K[-1] + EA_TAUD[-1] * EA_D[-1] + EA_T[-1] + EA_R[-1] ^ (-1) * EA_B[0] + EA_M[-1] - - EA_PH[0] * EA_G[0] = EA_GY[0] * EA_PYBAR * EA_YBAR - - EA_TR[0] = EA_YBAR * EA_PYBAR * EA_TRY[0] - - EA_T[0] / (EA_PYBAR * EA_YBAR) = EA_PHITB * (EA_B[0] / (EA_PYBAR * EA_YBAR) - EA_BYTARGET) - - EA_TI[0] = EA_T[0] * EA_UPSILONT - - EA_TRI[0] = EA_TR[0] * EA_UPSILONTR - - EA_PIC4[0] = EA_PIC[0] * EA_PIC[-1] * EA_PIC[-2] * EA_PIC[-3] - - EA_RR[0] - 1 = EA_R[0] / EA_PIC[1] - 1 - - EA_C[0] = EA_CI[0] * (1 - EA_OMEGA) + EA_CJ[0] * EA_OMEGA - - EA_M[0] = EA_MI[0] * (1 - EA_OMEGA) + EA_MJ[0] * EA_OMEGA - - EA_K[0] = EA_KI[0] * (1 - EA_OMEGA) - - EA_I[0] = EA_II[0] * (1 - EA_OMEGA) - - EA_TRJ[0] = EA_TR[0] * 1 / EA_OMEGA - EA_TRI[0] * (1 - EA_OMEGA) / EA_OMEGA - - EA_TJ[0] = EA_T[0] * 1 / EA_OMEGA - EA_TI[0] * (1 - EA_OMEGA) / EA_OMEGA - - EA_GAMMAV[0] = EA_GAMMAVI[0] * EA_CI[0] * (1 - EA_OMEGA) + EA_GAMMAVJ[0] * EA_CJ[0] * EA_OMEGA - - EA_NI[0] = EA_NDI[0] * EA_SI[0] - - EA_SI[0] = (1 - EA_XII) * (EA_WITILDE[0] / EA_WI[0]) ^ (-EA_ETAI) + EA_XII * (EA_WI[-1] / EA_WI[0]) ^ (-EA_ETAI) * (EA_PIC[0] / (EA_PI4TARGET ^ (0.25 * (1 - EA_CHII)) * EA_PIC[-1] ^ EA_CHII)) ^ EA_ETAI * EA_SI[-1] - - EA_NJ[0] = EA_NDJ[0] * EA_SJ[0] - - EA_SJ[0] = (1 - EA_XIJ) * (EA_WJTILDE[0] / EA_WJ[0]) ^ (-EA_ETAJ) + EA_XIJ * (EA_WJ[-1] / EA_WJ[0]) ^ (-EA_ETAJ) * (EA_PIC[0] / (EA_PI4TARGET ^ (0.25 * (1 - EA_CHIJ)) * EA_PIC[-1] ^ EA_CHIJ)) ^ EA_ETAJ * EA_SJ[-1] - - EA_U[0] * EA_K[0] = EA_KD[0] - - EA_YS[0] = EA_H[0] * EA_SH[0] + US_IM[0] * US_SIZE * EA_SX[0] / EA_SIZE - - EA_H[0] = EA_G[0] + EA_HC[0] + EA_HI[0] - - EA_IM[0] = EA_IMC[0] + EA_IMI[0] - - EA_SH[0] = (1 - EA_XIH) * (EA_PHTILDE[0] / EA_PH[0]) ^ (-EA_THETA) + EA_XIH * (EA_PIH[0] / (EA_PI4TARGET ^ (0.25 * (1 - EA_CHIH)) * EA_PIH[-1] ^ EA_CHIH)) ^ EA_THETA * EA_SH[-1] - - EA_SX[0] = (1 - EA_XIX) * (US_PIMTILDE[0] / US_PIM[0]) ^ (-EA_THETA) + EA_XIX * (US_PIIM[0] / (EA_PI4TARGET ^ (0.25 * (1 - EA_CHIH)) * US_PIIM[-1] ^ EA_CHIX)) ^ EA_THETA * EA_SX[-1] - - EA_QC[0] = EA_C[0] + EA_GAMMAV[0] - - EA_QI[0] = EA_I[0] + EA_GAMMAU[0] * EA_K[0] - - EA_Y[0] * EA_PY[0] = US_IM[0] * US_SIZE * US_PIM[0] * EAUS_RER[0] / EA_SIZE + EA_PH[0] * EA_G[0] + EA_QC[0] + EA_PI[0] * EA_QI[0] - EA_PIM[0] * ((1 - EA_GAMMAIMC[0]) * EA_IMC[0] / EA_GAMMAIMCDAG[0] + (1 - EA_GAMMAIMI[0]) * EA_IMI[0] / EA_GAMMAIMIDAG[0]) - - EA_Y[0] = EA_YS[0] - - log(EA_Z[0]) = (1 - EA_RHOZ) * log(EA_ZBAR) + EA_RHOZ * log(EA_Z[-1]) + EA_EPSZ[x] - - EA_GY[0] = (1 - EA_RHOG) * EA_GYBAR + EA_RHOG * EA_GY[-1] + EA_EPSG[x] - - EA_TRY[0] = (1 - EA_RHOTR) * EA_TRYBAR + EA_RHOTR * EA_TRY[-1] + EA_EPSTR[x] - - EA_TAUC[0] = (1 - EA_RHOTAUC) * EA_TAUCBAR + EA_TAUC[-1] * EA_RHOTAUC + EA_EPSTAUC[x] - - EA_TAUD[0] = (1 - EA_RHOTAUD) * EA_TAUDBAR + EA_TAUD[-1] * EA_RHOTAUD + EA_EPSTAUD[x] - - EA_TAUK[0] = EA_TAUKBAR * (1 - EA_RHOTAUK) + EA_TAUK[-1] * EA_RHOTAUK + EA_EPSTAUK[x] - - EA_TAUN[0] = (1 - EA_RHOTAUN) * EA_TAUNBAR + EA_TAUN[-1] * EA_RHOTAUN + EA_EPSTAUN[x] - - EA_TAUWH[0] = (1 - EA_RHOTAUWH) * EA_TAUWHBAR + EA_TAUWH[-1] * EA_RHOTAUWH + EA_EPSTAUWH[x] - - EA_TAUWF[0] = (1 - EA_RHOTAUWF) * EA_TAUWFBAR + EA_TAUWF[-1] * EA_RHOTAUWF + EA_EPSTAUWF[x] - - EA_CY[0] = EA_C[0] / (EA_Y[0] * EA_PY[0]) - - EA_IY[0] = EA_PI[0] * EA_I[0] / (EA_Y[0] * EA_PY[0]) - - EA_IMY[0] = EA_PIM[0] * EA_IM[0] / (EA_Y[0] * EA_PY[0]) - - EA_IMCY[0] = EA_IMC[0] * EA_PIM[0] / (EA_Y[0] * EA_PY[0]) - - EA_IMIY[0] = EA_PIM[0] * EA_IMI[0] / (EA_Y[0] * EA_PY[0]) - - EA_BY[0] = EA_B[0] / (EA_PYBAR * EA_YBAR) - - EA_TY[0] = EA_T[0] / (EA_PYBAR * EA_YBAR) - - EA_YGAP[0] = EA_Y[0] / EA_YBAR - 1 - - EA_YGROWTH[0] = EA_Y[0] / EA_Y[-1] - - EA_YSHARE[0] = EA_Y[0] * EA_PY[0] * EA_SIZE / EA_RER[0] / (EA_Y[0] * EA_PY[0] * EA_SIZE / EA_RER[0] + US_Y[0] * US_SIZE * US_PY[0] / US_RER) - - EA_EPSILONM[0] = ( - 0.125) / (EA_R[0] * (EA_R[0] + EA_R[0] * EA_GAMMAV2 - 1)) - - US_UTILI[0] = 1 / (1 - US_SIGMA) * (US_CI[0] - US_KAPPA * US_CI[-1]) ^ (1 - US_SIGMA) - 1 / (1 + US_ZETA) * US_NI[0] ^ (1 + US_ZETA) + US_BETA * US_UTILI[1] - - US_LAMBDAI[0] * (1 + US_TAUC[0] + US_GAMMAVI[0] + US_VI[0] * US_GAMMAVIDER[0]) = (US_CI[0] - US_KAPPA * US_CI[-1]) ^ (-US_SIGMA) - - US_R[0] = US_LAMBDAI[0] * US_BETA ^ (-1) / US_LAMBDAI[1] * US_PIC[1] - - US_GAMMAVIDER[0] * US_VI[0] ^ 2 = 1 - US_BETA * US_LAMBDAI[1] / (US_LAMBDAI[0] * US_PIC[1]) - - US_VI[0] = US_CI[0] * (1 + US_TAUC[0]) / US_MI[0] - - US_GAMMAVI[0] = US_VI[0] * US_GAMMAV1 + US_GAMMAV2 / US_VI[0] - 2 * (US_GAMMAV1 * US_GAMMAV2) ^ 0.5 - - US_GAMMAVIDER[0] = US_GAMMAV1 - US_GAMMAV2 * US_VI[0] ^ (-2) - - US_KI[0] = (1 - US_DELTA) * US_KI[-1] + (1 - US_GAMMAI[-1]) * US_II[-1] - - US_GAMMAI[0] = US_GAMMAI1 / 2 * (US_II[0] / US_II[-1] - 1) ^ 2 - - US_GAMMAIDER[0] = US_GAMMAI1 * (US_II[0] / US_II[-1] - 1) / US_II[-1] - - US_GAMMAU[0] = ((US_DELTA + US_BETA ^ (-1) - 1) * US_QBAR - US_DELTA * US_TAUKBAR * US_PIBAR) / (US_PIBAR * (1 - US_TAUKBAR)) * (US_U[0] - 1) + US_GAMMAU2 / 2 * (US_U[0] - 1) ^ 2 - - US_GAMMAUDER[0] = ((US_DELTA + US_BETA ^ (-1) - 1) * US_QBAR - US_DELTA * US_TAUKBAR * US_PIBAR) / (US_PIBAR * (1 - US_TAUKBAR)) + (US_U[0] - 1) * US_GAMMAU2 - - US_RK[0] = US_GAMMAUDER[0] * US_PI[0] - - US_PI[0] = US_Q[0] * (1 - US_GAMMAI[0] - US_II[0] * US_GAMMAIDER[0]) + US_BETA * US_LAMBDAI[1] / US_LAMBDAI[0] * US_Q[1] * US_GAMMAIDER[1] * US_II[1] ^ 2 / US_II[0] - - US_Q[0] = US_BETA * US_LAMBDAI[1] / US_LAMBDAI[0] * ((1 - US_TAUK[1]) * (US_RK[1] * US_U[1] - US_GAMMAU[1] * US_PI[1]) + US_PI[1] * US_DELTA * US_TAUK[1] + (1 - US_DELTA) * US_Q[1]) - - US_WITILDE[0] ^ (1 + US_ZETA * US_ETAI) = US_ETAI / (US_ETAI - 1) * US_FI[0] / US_GI[0] - - US_FI[0] = US_WI[0] ^ ((1 + US_ZETA) * US_ETAI) * US_NDI[0] ^ (1 + US_ZETA) + US_BETA * US_XII * (US_PIC[1] / (US_PIC[0] ^ US_CHII * US_PI4TARGET ^ (0.25 * (1 - US_CHII)))) ^ ((1 + US_ZETA) * US_ETAI) * US_FI[1] - - US_GI[0] = US_NDI[0] * US_LAMBDAI[0] * (1 - US_TAUN[0] - US_TAUWH[0]) * US_WI[0] ^ US_ETAI + US_BETA * US_XII * (US_PIC[1] / (US_PIC[0] ^ US_CHII * US_PI4TARGET ^ (0.25 * (1 - US_CHII)))) ^ (US_ETAI - 1) * US_GI[1] - - US_WI[0] ^ (1 - US_ETAI) = (1 - US_XII) * US_WITILDE[0] ^ (1 - US_ETAI) + US_XII * US_WI[-1] ^ (1 - US_ETAI) * (US_PI4TARGET ^ (0.25 * (1 - US_CHII)) * US_PIC[-1] ^ US_CHII / US_PIC[0]) ^ (1 - US_ETAI) - - US_UTILJ[0] = 1 / (1 - US_SIGMA) * (US_CJ[0] - US_KAPPA * US_CJ[-1]) ^ (1 - US_SIGMA) - 1 / (1 + US_ZETA) * US_NJ[0] ^ (1 + US_ZETA) + US_BETA * US_UTILJ[1] - - US_CJ[0] * (1 + US_TAUC[0] + US_GAMMAVJ[0]) + US_MJ[0] = US_NJ[0] * (1 - US_TAUN[0] - US_TAUWH[0]) * US_WJ[0] + US_TRJ[0] - US_TJ[0] + US_MJ[-1] * US_PIC[0] ^ (-1) - - US_LAMBDAJ[0] * (1 + US_TAUC[0] + US_GAMMAVJ[0] + US_VJ[0] * US_GAMMAVJDER[0]) = (US_CJ[0] - US_KAPPA * US_CJ[-1]) ^ (-US_SIGMA) - - US_GAMMAVJDER[0] * US_VJ[0] ^ 2 = 1 - US_BETA * US_LAMBDAJ[1] / (US_PIC[1] * US_LAMBDAJ[0]) - - US_VJ[0] = (1 + US_TAUC[0]) * US_CJ[0] / US_MJ[0] - - US_GAMMAVJ[0] = US_GAMMAV1 * US_VJ[0] + US_GAMMAV2 / US_VJ[0] - 2 * (US_GAMMAV1 * US_GAMMAV2) ^ 0.5 - - US_GAMMAVJDER[0] = US_GAMMAV1 - US_GAMMAV2 * US_VJ[0] ^ (-2) - - US_WJTILDE[0] ^ (1 + US_ZETA * US_ETAJ) = US_ETAJ / (US_ETAJ - 1) * US_FJ[0] / US_GJ[0] - - US_FJ[0] = US_WJ[0] ^ ((1 + US_ZETA) * US_ETAJ) * US_NDJ[0] ^ (1 + US_ZETA) + US_BETA * US_XIJ * (US_PIC[1] / (US_PIC[0] ^ US_CHIJ * US_PI4TARGET ^ (0.25 * (1 - US_CHIJ)))) ^ ((1 + US_ZETA) * US_ETAJ) * US_FJ[1] - - US_GJ[0] = US_NDJ[0] * (1 - US_TAUN[0] - US_TAUWH[0]) * US_LAMBDAJ[0] * US_WJ[0] ^ US_ETAJ + US_BETA * US_XIJ * (US_PIC[1] / (US_PIC[0] ^ US_CHIJ * US_PI4TARGET ^ (0.25 * (1 - US_CHIJ)))) ^ (US_ETAJ - 1) * US_GJ[1] - - US_WJ[0] ^ (1 - US_ETAJ) = (1 - US_XIJ) * US_WJTILDE[0] ^ (1 - US_ETAJ) + US_XIJ * US_WJ[-1] ^ (1 - US_ETAJ) * (US_PI4TARGET ^ (0.25 * (1 - US_CHIJ)) * US_PIC[-1] ^ US_CHIJ / US_PIC[0]) ^ (1 - US_ETAJ) - - US_YS[0] = US_Z[0] * US_KD[0] ^ US_ALPHA * US_ND[0] ^ (1 - US_ALPHA) - US_PSIBAR - - US_RK[0] = US_ALPHA * (US_YS[0] + US_PSIBAR) / US_KD[0] * US_MC[0] - - US_MC[0] = 1 / (US_Z[0] * US_ALPHA ^ US_ALPHA * (1 - US_ALPHA) ^ (1 - US_ALPHA)) * US_RK[0] ^ US_ALPHA * ((1 + US_TAUWF[0]) * US_W[0]) ^ (1 - US_ALPHA) - - US_NDI[0] = US_ND[0] * (1 - US_OMEGA) * (US_WI[0] / US_W[0]) ^ (-US_ETA) - - US_NDJ[0] = US_ND[0] * US_OMEGA * (US_WJ[0] / US_W[0]) ^ (-US_ETA) - - US_ND[0] ^ (1 - 1 / US_ETA) = (1 - US_OMEGA) ^ (1 / US_ETA) * US_NDI[0] ^ (1 - 1 / US_ETA) + US_OMEGA ^ (1 / US_ETA) * US_NDJ[0] ^ (1 - 1 / US_ETA) - - US_D[0] = US_Y[0] * US_PY[0] - US_RK[0] * US_KD[0] - US_ND[0] * (1 + US_TAUWF[0]) * US_W[0] - - US_PHTILDE[0] / US_PH[0] = US_THETA / (US_THETA - 1) * US_FH[0] / US_GH[0] - - US_FH[0] = US_MC[0] * US_H[0] + US_LAMBDAI[1] * US_BETA * US_XIH / US_LAMBDAI[0] * (US_PIH[1] / (US_PIH[0] ^ US_CHIH * US_PI4TARGET ^ (0.25 * (1 - US_CHIH)))) ^ US_THETA * US_FH[1] - - US_GH[0] = US_PH[0] * US_H[0] + US_LAMBDAI[1] * US_BETA * US_XIH / US_LAMBDAI[0] * (US_PIH[1] / (US_PIH[0] ^ US_CHIH * US_PI4TARGET ^ (0.25 * (1 - US_CHIH)))) ^ (US_THETA - 1) * US_GH[1] - - US_PH[0] ^ (1 - US_THETA) = (1 - US_XIH) * US_PHTILDE[0] ^ (1 - US_THETA) + US_XIH * (US_PH[-1] / US_PIC[0]) ^ (1 - US_THETA) * (US_PI4TARGET ^ (0.25 * (1 - US_CHIH)) * US_PIH[-1] ^ US_CHIH) ^ (1 - US_THETA) - - US_PIH[0] = US_PIC[0] * US_PH[0] / US_PH[-1] - - EA_PIMTILDE[0] / EA_PIM[0] = US_THETA / (US_THETA - 1) * US_FX[0] / US_GX[0] - - US_FX[0] = US_MC[0] * EA_IM[0] * EA_SIZE / US_SIZE + US_LAMBDAI[1] * US_BETA * US_XIX / US_LAMBDAI[0] * (EA_PIIM[1] / (EA_PIIM[0] ^ US_CHIX * US_PI4TARGET ^ (0.25 * (1 - US_CHIX)))) ^ US_THETA * US_FX[1] - - US_GX[0] = EA_IM[0] * EA_SIZE * EA_PIM[0] * USEA_RER[0] / US_SIZE + US_LAMBDAI[1] * US_BETA * US_XIX / US_LAMBDAI[0] * (EA_PIIM[1] / (EA_PIIM[0] ^ US_CHIX * US_PI4TARGET ^ (0.25 * (1 - US_CHIX)))) ^ (US_THETA - 1) * US_GX[1] - - EA_PIM[0] ^ (1 - US_THETA) = (1 - US_XIX) * EA_PIMTILDE[0] ^ (1 - US_THETA) + US_XIX * (EA_PIM[-1] / EA_PIC[0]) ^ (1 - US_THETA) * (EA_PIIM[-1] ^ US_CHIX * EA_PI4TARGET ^ (0.25 * (1 - US_CHIH))) ^ (1 - US_THETA) - - EA_PIIM[0] = EA_PIC[0] * EA_PIM[0] / EA_PIM[-1] - - USEA_RER[0] = US_RER / EA_RER[0] - - US_QC[0] ^ ((US_MUC - 1) / US_MUC) = US_NUC ^ (1 / US_MUC) * US_HC[0] ^ (1 - 1 / US_MUC) + (1 - US_NUC) ^ (1 / US_MUC) * ((1 - US_GAMMAIMC[0]) * US_IMC[0]) ^ (1 - 1 / US_MUC) - - 1 = US_NUC * US_PH[0] ^ (1 - US_MUC) + (1 - US_NUC) * (US_PIM[0] / US_GAMMAIMCDAG[0]) ^ (1 - US_MUC) - - US_HC[0] = US_QC[0] * US_NUC * US_PH[0] ^ (-US_MUC) - - US_GAMMAIMC[0] = US_GAMMAIMC1 / 2 * (US_IMC[0] / US_QC[0] / (US_IMC[-1] / US_QC[-1]) - 1) ^ 2 - - US_GAMMAIMCDAG[0] = 1 - US_GAMMAIMC[0] - US_IMC[0] * US_GAMMAIMC1 * (US_IMC[0] / US_QC[0] / (US_IMC[-1] / US_QC[-1]) - 1) / US_QC[0] / (US_IMC[-1] / US_QC[-1]) - - US_QI[0] ^ ((US_MUI - 1) / US_MUI) = US_NUI ^ (1 / US_MUI) * US_HI[0] ^ (1 - 1 / US_MUI) + (1 - US_NUI) ^ (1 / US_MUI) * ((1 - US_GAMMAIMI[0]) * US_IMI[0]) ^ (1 - 1 / US_MUI) - - US_PI[0] ^ (1 - US_MUI) = US_NUI * US_PH[0] ^ (1 - US_MUI) + (1 - US_NUI) * (US_PIM[0] / US_GAMMAIMIDAG[0]) ^ (1 - US_MUI) - - US_HI[0] = US_QI[0] * US_NUI * (US_PH[0] / US_PI[0]) ^ (-US_MUI) - - US_GAMMAIMI[0] = US_GAMMAIMI1 / 2 * (US_IMI[0] / US_QI[0] / (US_IMI[-1] / US_QI[-1]) - 1) ^ 2 - - US_GAMMAIMIDAG[0] = 1 - US_GAMMAIMI[0] - US_IMI[0] * US_GAMMAIMI1 * (US_IMI[0] / US_QI[0] / (US_IMI[-1] / US_QI[0]) - 1) / US_QI[0] / (US_IMI[-1] / US_QI[-1]) - - US_PH[-1] * US_G[-1] + US_TR[-1] + US_B[-1] * US_PIC[-1] ^ (-1) + US_PIC[-1] ^ (-1) * US_M[-2] = US_TAUC[-1] * US_C[-1] + (US_TAUN[-1] + US_TAUWH[-1]) * (US_WI[-1] * US_NDI[-1] + US_WJ[-1] * US_NDJ[-1]) + US_TAUWF[-1] * US_W[-1] * US_ND[-1] + US_TAUK[-1] * (US_RK[-1] * US_U[-1] - (US_DELTA + US_GAMMAU[-1]) * US_PI[-1]) * US_K[-1] + US_TAUD[-1] * US_D[-1] + US_T[-1] + US_R[-1] ^ (-1) * US_B[0] + US_M[-1] - - US_PH[0] * US_G[0] = US_GY[0] * US_PYBAR * US_YBAR - - US_TR[0] = US_YBAR * US_PYBAR * US_TRY[0] - - US_T[0] / (US_PYBAR * US_YBAR) = US_PHITB * (US_B[0] / (US_PYBAR * US_YBAR) - US_BYTARGET) - - US_TI[0] = US_T[0] * US_UPSILONT - - US_TRI[0] = US_TR[0] * US_UPSILONTR - - US_PIC4[0] = US_PIC[0] * US_PIC[-1] * US_PIC[-2] * US_PIC[-3] - - US_RR[0] - 1 = US_R[0] / US_PIC[1] - 1 - - US_C[0] = US_CI[0] * (1 - US_OMEGA) + US_CJ[0] * US_OMEGA - - US_M[0] = US_MI[0] * (1 - US_OMEGA) + US_MJ[0] * US_OMEGA - - US_K[0] = US_KI[0] * (1 - US_OMEGA) - - US_I[0] = US_II[0] * (1 - US_OMEGA) - - US_TRJ[0] = US_TR[0] * 1 / US_OMEGA - US_TRI[0] * (1 - US_OMEGA) / US_OMEGA - - US_TJ[0] = US_T[0] * 1 / US_OMEGA - US_TI[0] * (1 - US_OMEGA) / US_OMEGA - - US_GAMMAV[0] = US_GAMMAVI[0] * US_CI[0] * (1 - US_OMEGA) + US_GAMMAVJ[0] * US_CJ[0] * US_OMEGA - - US_NI[0] = US_NDI[0] * US_SI[0] - - US_SI[0] = (1 - US_XII) * (US_WITILDE[0] / US_WI[0]) ^ (-US_ETAI) + US_XII * (US_WI[-1] / US_WI[0]) ^ (-US_ETAI) * (US_PIC[0] / (US_PI4TARGET ^ (0.25 * (1 - US_CHII)) * US_PIC[-1] ^ US_CHII)) ^ US_ETAI * US_SI[-1] - - US_NJ[0] = US_NDJ[0] * US_SJ[0] - - US_SJ[0] = (1 - US_XIJ) * (US_WJTILDE[0] / US_WJ[0]) ^ (-US_ETAJ) + US_XIJ * (US_WJ[-1] / US_WJ[0]) ^ (-US_ETAJ) * (US_PIC[0] / (US_PI4TARGET ^ (0.25 * (1 - US_CHIJ)) * US_PIC[-1] ^ US_CHIJ)) ^ US_ETAJ * US_SJ[-1] - - US_U[0] * US_K[0] = US_KD[0] - - US_YS[0] = US_H[0] * US_SH[0] + EA_IM[0] * EA_SIZE * US_SX[0] / US_SIZE - - US_H[0] = US_G[0] + US_HC[0] + US_HI[0] - - US_IM[0] = US_IMC[0] + US_IMI[0] - - US_SH[0] = (1 - US_XIH) * (US_PHTILDE[0] / US_PH[0]) ^ (-US_THETA) + US_XIH * (US_PIH[0] / (US_PI4TARGET ^ (0.25 * (1 - US_CHIH)) * US_PIH[-1] ^ US_CHIH)) ^ US_THETA * US_SH[-1] - - US_SX[0] = (1 - US_XIX) * (EA_PIMTILDE[0] / EA_PIM[0]) ^ (-US_THETA) + US_XIX * (EA_PIIM[0] / (US_PI4TARGET ^ (0.25 * (1 - US_CHIH)) * EA_PIIM[-1] ^ US_CHIX)) ^ US_THETA * US_SX[-1] - - US_QC[0] = US_C[0] + US_GAMMAV[0] - - US_QI[0] = US_I[0] + US_GAMMAU[0] * US_K[0] - - US_Y[0] * US_PY[0] = EA_IM[0] * EA_SIZE * EA_PIM[0] * USEA_RER[0] / US_SIZE + US_PH[0] * US_G[0] + US_QC[0] + US_PI[0] * US_QI[0] - US_PIM[0] * ((1 - US_GAMMAIMC[0]) * US_IMC[0] / US_GAMMAIMCDAG[0] + (1 - US_GAMMAIMI[0]) * US_IMI[0] / US_GAMMAIMIDAG[0]) - - US_Y[0] = US_YS[0] - - log(US_Z[0]) = (1 - US_RHOZ) * log(US_ZBAR) + US_RHOZ * log(US_Z[-1]) + US_EPSZ[x] - - US_GY[0] = (1 - US_RHOG) * US_GYBAR + US_RHOG * US_GY[-1] + US_EPSG[x] - - US_TRY[0] = (1 - US_RHOTR) * US_TRYBAR + US_RHOTR * US_TRY[-1] + US_EPSTR[x] - - US_TAUC[0] = (1 - US_RHOTAUC) * US_TAUCBAR + US_TAUC[-1] * US_RHOTAUC + US_EPSTAUC[x] - - US_TAUD[0] = (1 - US_RHOTAUD) * US_TAUDBAR + US_TAUD[-1] * US_RHOTAUD + US_EPSTAUD[x] - - US_TAUK[0] = US_TAUKBAR * (1 - US_RHOTAUK) + US_TAUK[-1] * US_RHOTAUK + US_EPSTAUK[x] - - US_TAUN[0] = (1 - US_RHOTAUN) * US_TAUNBAR + US_TAUN[-1] * US_RHOTAUN + US_EPSTAUN[x] - - US_TAUWH[0] = (1 - US_RHOTAUWH) * US_TAUWHBAR + US_TAUWH[-1] * US_RHOTAUWH + US_EPSTAUWH[x] - - US_TAUWF[0] = (1 - US_RHOTAUWF) * US_TAUWFBAR + US_TAUWF[-1] * US_RHOTAUWF + US_EPSTAUWF[x] - - US_CY[0] = US_C[0] / (US_Y[0] * US_PY[0]) - - US_IY[0] = US_PI[0] * US_I[0] / (US_Y[0] * US_PY[0]) - - US_IMY[0] = US_PIM[0] * US_IM[0] / (US_Y[0] * US_PY[0]) - - US_IMCY[0] = US_PIM[0] * US_IMC[0] / (US_Y[0] * US_PY[0]) - - US_IMIY[0] = US_PIM[0] * US_IMI[0] / (US_Y[0] * US_PY[0]) - - US_BY[0] = US_B[0] / (US_PYBAR * US_YBAR) - - US_TY[0] = US_T[0] / (US_PYBAR * US_YBAR) - - US_YGAP[0] = US_Y[0] / US_YBAR - 1 - - US_YGROWTH[0] = US_Y[0] / US_Y[-1] - - US_YSHARE[0] = US_Y[0] * US_SIZE * US_PY[0] / US_RER / (EA_Y[0] * EA_PY[0] * EA_SIZE / EA_RER[0] + US_Y[0] * US_SIZE * US_PY[0] / US_RER) - - US_EPSILONM[0] = ( - 0.125) / (US_R[0] * (US_R[0] + US_R[0] * US_GAMMAV2 - 1)) - - 1 = EA_LAMBDAI[1] * EA_BETA * US_R[0] * (1 - EA_GAMMAB[0]) / EA_LAMBDAI[0] * EA_RERDEP[1] / US_PIC[1] - - EA_GAMMAB[0] = EA_GAMMAB1 * (exp(EA_RER[0] * EA_BF[0] / US_PIC[0] / (EA_Y[0] * EA_PY[0]) - EA_BFYTARGET) - 1) - EA_RP[0] - - EA_RP[0] = EA_RHORP * EA_RP[-1] + EA_EPSRP[x] - - EA_RERDEP[0] = EA_RER[0] / EA_RER[-1] - - EA_TOT[0] = EA_PIM[0] / (US_PIM[0] * EA_RER[0]) - - EA_TB[0] = US_IM[0] * US_SIZE * US_PIM[0] * EA_RER[0] / EA_SIZE - EA_PIM[0] * EA_IM[0] - - EA_BF[0] / US_R[-1] = EA_BF[-1] + EA_TB[-1] / EA_RER[-1] - - EA_SIZE * EA_BF[0] + US_SIZE * US_BF[0] = 0 - -end - - -@parameters NAWM_EAUS_2008 verbose = true begin - EA_RRSTAR = 1 / EA_BETA - - US_RRSTAR = 1 / US_BETA - - EA_SIZE = 0.4194 - - EA_OMEGA = 0.25 - - EA_BETA = 0.992638 - - EA_SIGMA = 2.00 - - EA_KAPPA = 0.60 - - EA_ZETA = 2.00 - - EA_DELTA = 0.025 - - EA_ETA = 6.00 - - EA_ETAI = 6.00 - - EA_ETAJ = 6.00 - - EA_XII = 0.75 - - EA_XIJ = 0.75 - - EA_CHII = 0.75 - - EA_CHIJ = 0.75 - - EA_ALPHA = 0.30 - - EA_PSI = 0.20 - - EA_THETA = 6.00 - - EA_XIH = 0.90 - - EA_XIX = 0.30 - - EA_CHIH = 0.50 - - EA_CHIX = 0.50 - - EA_NUC = 0.919622 - - EA_MUC = 1.5 - - EA_NUI = 0.418629 - - EA_MUI = 1.5 - - EA_GAMMAV1 = 0.289073 - - EA_GAMMAV2 = 0.150339 - - EA_GAMMAI1 = 3.00 - - EA_GAMMAU1 = 0.032765 - - EA_GAMMAU2 = 0.007 - - EA_GAMMAIMC1 = 2.50 - - EA_GAMMAIMI1 = 0.00 - - EA_GAMMAB1 = 0.01 - - EA_BYTARGET = 2.40 - - EA_PHITB = 0.10 - - EA_GYBAR = 0.18 - - EA_TRYBAR = 0.195161 - - EA_TAUCBAR = 0.183 - - EA_TAUKBAR = 0.184123 - - EA_TAUNBAR = 0.122 - - EA_TAUWHBAR = 0.118 - - EA_TAUWFBAR = 0.219 - - EA_UPSILONT = 1.20 - - EA_UPSILONTR = 0.6666666666666666 - - EA_PI4TARGET = 1.02 - - EA_PHIRR = 0.95 - - EA_PHIRPI = 2.00 - - EA_PHIRGY = 0.10 - - EA_interest_EXOG=EA_BETA^(-1)*EA_PI4TARGET^(1/4) - - EA_BFYTARGET = 0.00 - - EA_RHOZ = 0.90 - - EA_RHOR = 0.90 - - EA_RHOG = 0.90 - - EA_RHOTR = 0.90 - - EA_RHOTAUC = 0.90 - - EA_RHOTAUK = 0.90 - - EA_RHOTAUN = 0.90 - - EA_RHOTAUD = 0.90 - - EA_RHOTAUWH = 0.90 - - EA_RHOTAUWF = 0.90 - - EA_PYBAR = 1.00645740523434 - - EA_YBAR = 3.62698111871356 - - EA_RHORP = 0.9 - - EA_PIBAR = 0.961117319822928 - - EA_PSIBAR = 0.725396223742712 - - EA_QBAR = 0.961117319822928 - - EA_TAUDBAR = 0 - - EA_ZBAR = 1 - - US_SIZE = 0.5806 - - US_OMEGA = 0.25 - - US_BETA = 0.992638 - - US_SIGMA = 2.00 - - US_KAPPA = 0.60 - - US_ZETA = 2.00 - - US_DELTA = 0.025 - - US_ETA = 6.00 - - US_ETAI = 6.00 - - US_ETAJ = 6.00 - - US_XII = 0.75 - - US_XIJ = 0.75 - - US_CHII = 0.75 - - US_CHIJ = 0.75 - - US_ALPHA = 0.30 - - US_PSI = 0.20 - - US_THETA = 6.00 - - US_XIH = 0.90 - - US_XIX = 0.30 - - US_CHIH = 0.50 - - US_CHIX = 0.50 - - US_NUC = 0.899734 - - US_MUC = 1.5 - - US_NUI = 0.673228 - - US_MUI = 1.5 - - US_GAMMAV1 = 0.028706 - - US_GAMMAV2 = 0.150339 - - US_GAMMAI1 = 3.00 - - US_GAMMAU1 = 0.034697 - - US_GAMMAU2 = 0.007 - - US_GAMMAIMC1 = 2.50 - - US_GAMMAIMI1 = 0.00 - - US_GAMMAB1 = 0.01 - - US_BYTARGET = 2.40 - - US_PHITB = 0.10 - - US_GYBAR = 0.16 - - US_TRYBAR = 0.079732 - - US_TAUCBAR = 0.077 - - US_TAUKBAR = 0.184123 - - US_TAUNBAR = 0.154 - - US_TAUWHBAR = 0.071 - - US_TAUWFBAR = 0.071 - - US_UPSILONT = 1.20 - - US_UPSILONTR = 0.6666666666666666 - - US_PI4TARGET = 1.02 - - US_PHIRR = 0.95 - - US_PHIRPI = 2.00 - - US_PHIRGY = 0.10 - - US_interest_EXOG=US_BETA^(-1)*US_PI4TARGET^(1/4) - - US_RHOZ = 0.90 - - US_RHOR = 0.90 - - US_RHOG = 0.90 - - US_RHOTR = 0.90 - - US_RHOTAUC = 0.90 - - US_RHOTAUK = 0.90 - - US_RHOTAUN = 0.90 - - US_RHOTAUD = 0.90 - - US_RHOTAUWH = 0.90 - - US_RHOTAUWF = 0.90 - - US_PYBAR = 0.992282866960427 - - US_TAUDBAR = 0 - - US_YBAR = 3.92445610588497 - - US_PIBAR = 1.01776829477927 - - US_PSIBAR = 0.784891221176995 - - US_QBAR = 1.01776829477927 - - US_ZBAR = 1 - - US_RER = 1 - - # Help steady state solver - # EA_FI > 100 - - # US_FI > 100 - - # EA_FH > 20 - - # EA_GH > 20 - - # EA_K > 20 - - # EA_KD > 20 - - # EA_KI > 20 - - # US_FH > 20 - - # US_FJ > 20 - - # US_GH > 20 - - # US_K > 20 - - # US_KD > 20 - - # US_KI > 20 - - # US_GI > 10 - - # US_GJ > 10 -end - - -# Block: 7 - Solved using lm_ar, iterations: 112, transformer level: 2 and previous best non-converged solution; maximum residual = 9.38953803597542e-10 - -#lm_kyf is slow on NAWM -# Block: 1 - Solved using lm_kyf, iterations: 4, transformer level: 2 and previous best non-converged solution; maximum residual = 2.0763168961934753e-11 -# Block: 2 - Solved using lm_kyf, iterations: 4, transformer level: 2 and previous best non-converged solution; maximum residual = 2.0763168961934753e-11 -# Block: 3 - Solved using lm_kyf, iterations: 7, transformer level: 2 and previous best non-converged solution; maximum residual = 6.73594513500575e-12 -# Block: 4 - Solved using lm_kyf, iterations: 7, transformer level: 2 and previous best non-converged solution; maximum residual = 6.73594513500575e-12 -# Block: 5 - Solved using lm_kyf, iterations: 5, transformer level: 2 and previous best non-converged solution; maximum residual = 5.387754020702573e-9 -# Block: 6 - Solved using lm_kyf, iterations: 5, transformer level: 2 and previous best non-converged solution; maximum residual = 5.387754020702573e-9 -# Block: 7 - Solved using lm_kyf, iterations: 68092, transformer level: 2 and starting point: 1.5; maximum residual = 1.1652900866465643e-12 - - -# tr doesnt work NAWM -# Block: 1 - Solved using tr, iterations: 4, transformer level: 2 and previous best non-converged solution; maximum residual = 2.3722801500980495e-11 -# Block: 2 - Solved using tr, iterations: 4, transformer level: 2 and previous best non-converged solution; maximum residual = 2.3722801500980495e-11 -# Block: 3 - Solved using tr, iterations: 5, transformer level: 2 and previous best non-converged solution; maximum residual = 5.249277235108707e-9 -# Block: 4 - Solved using tr, iterations: 5, transformer level: 2 and previous best non-converged solution; maximum residual = 5.249277235108707e-9 -# Block: 5 - Solved using tr, iterations: 14, transformer level: 2 and previous best non-converged solution; maximum residual = 4.225908512012211e-11 -# Block: 6 - Solved using tr, iterations: 14, transformer level: 2 and previous best non-converged solution; maximum residual = 4.225908512012211e-11 - - -# dogleg also rather slow -# Block: 1 - Solved using dogleg, iterations: 4, transformer level: 3 and starting point: 1.1; maximum residual = 1.311661890213145e-11 -# Block: 2 - Solved using dogleg, iterations: 12, transformer level: 3 and starting point: 0.75; maximum residual = 1.885918301299666e-9 -# Block: 3 - Solved using dogleg, iterations: 9, transformer level: 3 and previous best non-converged solution; maximum residual = 3.1086244689504383e-15 -# Block: 4 - Solved using dogleg, iterations: 4, transformer level: 3 and starting point: 1.1; maximum residual = 1.311661890213145e-11 -# Block: 5 - Solved using dogleg, iterations: 11, transformer level: 3 and previous best non-converged solution; maximum residual = 3.5128150388530344e-14 -# Block: 6 - Solved using dogleg, iterations: 14, transformer level: 3 and starting point: -0.5; maximum residual = 2.0028423364237824e-12 - -# nr slow as well -# Block: 1 - Solved using nr, iterations: 4, transformer level: 3 and previous best non-converged solution; maximum residual = 7.199996154838573e-11 -# Block: 2 - Solved using nr, iterations: 9, transformer level: 3 and previous best non-converged solution; maximum residual = 2.220446049250313e-15 -# Block: 3 - Solved using nr, iterations: 9, transformer level: 3 and previous best non-converged solution; maximum residual = 2.220446049250313e-15 -# Block: 4 - Solved using nr, iterations: 4, transformer level: 3 and previous best non-converged solution; maximum residual = 7.199996154838573e-11 -# Block: 5 - Solved using nr, iterations: 6, transformer level: 3 and previous best non-converged solution; maximum residual = 3.1086244689504383e-15 -# Block: 6 - Solved using nr, iterations: 6, transformer level: 3 and previous best non-converged solution; maximum residual = 3.1086244689504383e-15 - -# lm_ar -# Block: 1 - Solved using lm_ar, iterations: 3, transformer level: 4 and previous best non-converged solution; maximum residual = 4.440892098500626e-16 -# Block: 2 - Solved using lm_ar, iterations: 3, transformer level: 4 and previous best non-converged solution; maximum residual = 4.440892098500626e-16 -# Block: 3 - Solved using lm_ar, iterations: 5, transformer level: 4 and previous best non-converged solution; maximum residual = 2.4158453015843406e-13 -# Block: 4 - Solved using lm_ar, iterations: 5, transformer level: 4 and previous best non-converged solution; maximum residual = 2.4158453015843406e-13 -# Block: 5 - Solved using lm_ar, iterations: 4, transformer level: 4 and previous best non-converged solution; maximum residual = 3.400058012914542e-16 -# Block: 6 - Solved using lm_ar, iterations: 4, transformer level: 4 and previous best non-converged solution; maximum residual = 3.400058012914542e-16 -# Block: 7 - Solved using lm_ar, iterations: 338, transformer level: 4 and previous best non-converged solution; maximum residual = 9.278267043555388e-11 - -# lm_ar no 10 lower bounds -# Block: 1 - Solved using lm_ar, iterations: 3, transformer level: 4 and previous best non-converged solution; maximum residual = 4.440892098500626e-16 -# Block: 2 - Solved using lm_ar, iterations: 3, transformer level: 4 and previous best non-converged solution; maximum residual = 4.440892098500626e-16 -# Block: 3 - Solved using lm_ar, iterations: 5, transformer level: 4 and previous best non-converged solution; maximum residual = 2.4158453015843406e-13 -# Block: 4 - Solved using lm_ar, iterations: 5, transformer level: 4 and previous best non-converged solution; maximum residual = 2.4158453015843406e-13 -# Block: 5 - Solved using lm_ar, iterations: 4, transformer level: 4 and previous best non-converged solution; maximum residual = 3.400058012914542e-16 -# Block: 6 - Solved using lm_ar, iterations: 4, transformer level: 4 and previous best non-converged solution; maximum residual = 3.400058012914542e-16 -# Block: 7 - Solved using lm_ar, iterations: 778, transformer level: 4 and previous best non-converged solution; maximum residual = 8.15703060652595e-12 - - -# lm_ar no 20 lower bounds \ No newline at end of file diff --git a/test/models/SGU_2003_debt_premium.jl b/test/models/SGU_2003_debt_premium.jl deleted file mode 100644 index 3f3efd64..00000000 --- a/test/models/SGU_2003_debt_premium.jl +++ /dev/null @@ -1,54 +0,0 @@ -@model SGU_2003_debt_premium begin - d[0] = (1 + r[-1]) * d[-1] - y[0] + c[0] + i[0] + ϕ / 2 * (k[0] - k[-1]) ^ 2 - - y[0] = exp(a[0]) * k[-1] ^ α * h[0] ^ (1 - α) - - k[0] = i[0] + k[-1] * (1 - δ) - - λ[0] = β * (1 + r[0]) * λ[1] - - (c[0] - h[0] ^ ω / ω) ^ (-γ) = λ[0] - - (c[0] - h[0] ^ ω / ω) ^ (-γ) * h[0] ^ (ω - 1) = y[0] * (1 - α) * λ[0] / h[0] - - λ[0] * (1 + ϕ * (k[0] - k[-1])) = β * λ[1] * (1 + α * y[1] / k[0] - δ + ϕ * (k[1] - k[0])) - - a[0] = ρ * a[-1] + σ_tfp * e[x] - - r[0] = r̄ + riskpremium[0] - - riskpremium[0] = ψ² * (exp(d[0] - d̄) - 1) - - tbʸ[0] = 1 - (ϕ / 2 * (k[0] - k[-1]) ^ 2 + c[0] + i[0]) / y[0] - - caʸ[0] = 1 / y[0] * (d[-1] - d[0]) - - util[0] = ((c[0] - h[0] ^ ω * ω ^ (-1)) ^ (1 - γ) - 1) / (1 - γ) - -end - - -@parameters SGU_2003_debt_premium verbose = true begin - β = 1 / (1 + r̄) - - γ = 2 - - ω = 1.455 - - α = 0.32 - - ϕ = 0.028 - - r̄ = 0.04 - - δ = 0.1 - - ρ = 0.42 - - σ_tfp = 0.0129 - - ψ² = 0.000742 - - d̄ = 0.7442 - -end diff --git a/test/models/SW03.jl b/test/models/SW03.jl deleted file mode 100644 index d2ca8ea3..00000000 --- a/test/models/SW03.jl +++ /dev/null @@ -1,118 +0,0 @@ -@model m begin - -q[0] + beta * ((1 - tau) * q[1] + epsilon_b[1] * (r_k[1] * z[1] - psi^-1 * r_k[ss] * (-1 + exp(psi * (-1 + z[1])))) * (C[1] - h * C[0])^(-sigma_c)) = 0 - -q_f[0] + beta * ((1 - tau) * q_f[1] + epsilon_b[1] * (r_k_f[1] * z_f[1] - psi^-1 * r_k_f[ss] * (-1 + exp(psi * (-1 + z_f[1])))) * (C_f[1] - h * C_f[0])^(-sigma_c)) = 0 - -r_k[0] + alpha * epsilon_a[0] * mc[0] * L[0]^(1 - alpha) * (K[-1] * z[0])^(-1 + alpha) = 0 - -r_k_f[0] + alpha * epsilon_a[0] * mc_f[0] * L_f[0]^(1 - alpha) * (K_f[-1] * z_f[0])^(-1 + alpha) = 0 - -G[0] + T[0] = 0 - -G[0] + G_bar * epsilon_G[0] = 0 - -G_f[0] + T_f[0] = 0 - -G_f[0] + G_bar * epsilon_G[0] = 0 - -L[0] + nu_w[0]^-1 * L_s[0] = 0 - -L_s_f[0] + L_f[0] * (W_i_f[0] * W_f[0]^-1)^(lambda_w^-1 * (-1 - lambda_w)) = 0 - L_s_f[0] - L_f[0] = 0 - L_s_f[0] + lambda_w^-1 * L_f[0] * W_f[0]^-1 * (-1 - lambda_w) * (-W_disutil_f[0] + W_i_f[0]) * (W_i_f[0] * W_f[0]^-1)^(-1 + lambda_w^-1 * (-1 - lambda_w)) = 0 - Pi_ws_f[0] - L_s_f[0] * (-W_disutil_f[0] + W_i_f[0]) = 0 - Pi_ps_f[0] - Y_f[0] * (-mc_f[0] + P_j_f[0]) * P_j_f[0]^(-lambda_p^-1 * (1 + lambda_p)) = 0 - -Q[0] + epsilon_b[0]^-1 * q[0] * (C[0] - h * C[-1])^(sigma_c) = 0 - -Q_f[0] + epsilon_b[0]^-1 * q_f[0] * (C_f[0] - h * C_f[-1])^(sigma_c) = 0 - -W[0] + epsilon_a[0] * mc[0] * (1 - alpha) * L[0]^(-alpha) * (K[-1] * z[0])^alpha = 0 - -W_f[0] + epsilon_a[0] * mc_f[0] * (1 - alpha) * L_f[0]^(-alpha) * (K_f[-1] * z_f[0])^alpha = 0 - -Y_f[0] + Y_s_f[0] = 0 - Y_s[0] - nu_p[0] * Y[0] = 0 - -Y_s_f[0] + Y_f[0] * P_j_f[0]^(-lambda_p^-1 * (1 + lambda_p)) = 0 - beta * epsilon_b[1] * (C_f[1] - h * C_f[0])^(-sigma_c) - epsilon_b[0] * R_f[0]^-1 * (C_f[0] - h * C_f[-1])^(-sigma_c) = 0 - beta * epsilon_b[1] * pi[1]^-1 * (C[1] - h * C[0])^(-sigma_c) - epsilon_b[0] * R[0]^-1 * (C[0] - h * C[-1])^(-sigma_c) = 0 - Y_f[0] * P_j_f[0]^(-lambda_p^-1 * (1 + lambda_p)) - lambda_p^-1 * Y_f[0] * (1 + lambda_p) * (-mc_f[0] + P_j_f[0]) * P_j_f[0]^(-1 - lambda_p^-1 * (1 + lambda_p)) = 0 - epsilon_b[0] * W_disutil_f[0] * (C_f[0] - h * C_f[-1])^(-sigma_c) - omega * epsilon_b[0] * epsilon_L[0] * L_s_f[0]^sigma_l = 0 - -1 + xi_p * (pi[0]^-1 * pi[-1]^gamma_p)^(-lambda_p^-1) + (1 - xi_p) * pi_star[0]^(-lambda_p^-1) = 0 - -1 + (1 - xi_w) * (w_star[0] * W[0]^-1)^(-lambda_w^-1) + xi_w * (W[-1] * W[0]^-1)^(-lambda_w^-1) * (pi[0]^-1 * pi[-1]^gamma_w)^(-lambda_w^-1) = 0 - -Phi - Y_s[0] + epsilon_a[0] * L[0]^(1 - alpha) * (K[-1] * z[0])^alpha = 0 - -Phi - Y_f[0] * P_j_f[0]^(-lambda_p^-1 * (1 + lambda_p)) + epsilon_a[0] * L_f[0]^(1 - alpha) * (K_f[-1] * z_f[0])^alpha = 0 - eta_b[exo] - log(epsilon_b[0]) + rho_b * log(epsilon_b[-1]) = 0 - -eta_L[exo] - log(epsilon_L[0]) + rho_L * log(epsilon_L[-1]) = 0 - eta_I[exo] - log(epsilon_I[0]) + rho_I * log(epsilon_I[-1]) = 0 - eta_w[exo] - f_1[0] + f_2[0] = 0 - eta_a[exo] - log(epsilon_a[0]) + rho_a * log(epsilon_a[-1]) = 0 - eta_p[exo] - g_1[0] + g_2[0] * (1 + lambda_p) = 0 - eta_G[exo] - log(epsilon_G[0]) + rho_G * log(epsilon_G[-1]) = 0 - -f_1[0] + beta * xi_w * f_1[1] * (w_star[0]^-1 * w_star[1])^(lambda_w^-1) * (pi[1]^-1 * pi[0]^gamma_w)^(-lambda_w^-1) + epsilon_b[0] * w_star[0] * L[0] * (1 + lambda_w)^-1 * (C[0] - h * C[-1])^(-sigma_c) * (w_star[0] * W[0]^-1)^(-lambda_w^-1 * (1 + lambda_w)) = 0 - -f_2[0] + beta * xi_w * f_2[1] * (w_star[0]^-1 * w_star[1])^(lambda_w^-1 * (1 + lambda_w) * (1 + sigma_l)) * (pi[1]^-1 * pi[0]^gamma_w)^(-lambda_w^-1 * (1 + lambda_w) * (1 + sigma_l)) + omega * epsilon_b[0] * epsilon_L[0] * (L[0] * (w_star[0] * W[0]^-1)^(-lambda_w^-1 * (1 + lambda_w)))^(1 + sigma_l) = 0 - -g_1[0] + beta * xi_p * pi_star[0] * g_1[1] * pi_star[1]^-1 * (pi[1]^-1 * pi[0]^gamma_p)^(-lambda_p^-1) + epsilon_b[0] * pi_star[0] * Y[0] * (C[0] - h * C[-1])^(-sigma_c) = 0 - -g_2[0] + beta * xi_p * g_2[1] * (pi[1]^-1 * pi[0]^gamma_p)^(-lambda_p^-1 * (1 + lambda_p)) + epsilon_b[0] * mc[0] * Y[0] * (C[0] - h * C[-1])^(-sigma_c) = 0 - -nu_w[0] + (1 - xi_w) * (w_star[0] * W[0]^-1)^(-lambda_w^-1 * (1 + lambda_w)) + xi_w * nu_w[-1] * (W[-1] * pi[0]^-1 * W[0]^-1 * pi[-1]^gamma_w)^(-lambda_w^-1 * (1 + lambda_w)) = 0 - -nu_p[0] + (1 - xi_p) * pi_star[0]^(-lambda_p^-1 * (1 + lambda_p)) + xi_p * nu_p[-1] * (pi[0]^-1 * pi[-1]^gamma_p)^(-lambda_p^-1 * (1 + lambda_p)) = 0 - -K[0] + K[-1] * (1 - tau) + I[0] * (1 - 0.5 * varphi * (-1 + I[-1]^-1 * epsilon_I[0] * I[0])^2) = 0 - -K_f[0] + K_f[-1] * (1 - tau) + I_f[0] * (1 - 0.5 * varphi * (-1 + I_f[-1]^-1 * epsilon_I[0] * I_f[0])^2) = 0 - U[0] - beta * U[1] - epsilon_b[0] * ((1 - sigma_c)^-1 * (C[0] - h * C[-1])^(1 - sigma_c) - omega * epsilon_L[0] * (1 + sigma_l)^-1 * L_s[0]^(1 + sigma_l)) = 0 - U_f[0] - beta * U_f[1] - epsilon_b[0] * ((1 - sigma_c)^-1 * (C_f[0] - h * C_f[-1])^(1 - sigma_c) - omega * epsilon_L[0] * (1 + sigma_l)^-1 * L_s_f[0]^(1 + sigma_l)) = 0 - -epsilon_b[0] * (C[0] - h * C[-1])^(-sigma_c) + q[0] * (1 - 0.5 * varphi * (-1 + I[-1]^-1 * epsilon_I[0] * I[0])^2 - varphi * I[-1]^-1 * epsilon_I[0] * I[0] * (-1 + I[-1]^-1 * epsilon_I[0] * I[0])) + beta * varphi * I[0]^-2 * epsilon_I[1] * q[1] * I[1]^2 * (-1 + I[0]^-1 * epsilon_I[1] * I[1]) = 0 - -epsilon_b[0] * (C_f[0] - h * C_f[-1])^(-sigma_c) + q_f[0] * (1 - 0.5 * varphi * (-1 + I_f[-1]^-1 * epsilon_I[0] * I_f[0])^2 - varphi * I_f[-1]^-1 * epsilon_I[0] * I_f[0] * (-1 + I_f[-1]^-1 * epsilon_I[0] * I_f[0])) + beta * varphi * I_f[0]^-2 * epsilon_I[1] * q_f[1] * I_f[1]^2 * (-1 + I_f[0]^-1 * epsilon_I[1] * I_f[1]) = 0 - eta_pi[exo] - log(pi_obj[0]) + rho_pi_bar * log(pi_obj[-1]) + log(calibr_pi_obj) * (1 - rho_pi_bar) = 0 - -C[0] - I[0] - T[0] + Y[0] - psi^-1 * r_k[ss] * K[-1] * (-1 + exp(psi * (-1 + z[0]))) = 0 - -calibr_pi + eta_R[exo] - log(R[ss]^-1 * R[0]) + r_Delta_pi * (-log(pi[ss]^-1 * pi[-1]) + log(pi[ss]^-1 * pi[0])) + r_Delta_y * (-log(Y[ss]^-1 * Y[-1]) + log(Y[ss]^-1 * Y[0]) + log(Y_f[ss]^-1 * Y_f[-1]) - log(Y_f[ss]^-1 * Y_f[0])) + rho * log(R[ss]^-1 * R[-1]) + (1 - rho) * (log(pi_obj[0]) + r_pi * (-log(pi_obj[0]) + log(pi[ss]^-1 * pi[-1])) + r_Y * (log(Y[ss]^-1 * Y[0]) - log(Y_f[ss]^-1 * Y_f[0]))) = 0 - -C_f[0] - I_f[0] + Pi_ws_f[0] - T_f[0] + Y_f[0] + L_s_f[0] * W_disutil_f[0] - L_f[0] * W_f[0] - psi^-1 * r_k_f[ss] * K_f[-1] * (-1 + exp(psi * (-1 + z_f[0]))) = 0 - epsilon_b[0] * (K[-1] * r_k[0] - r_k[ss] * K[-1] * exp(psi * (-1 + z[0]))) * (C[0] - h * C[-1])^(-sigma_c) = 0 - epsilon_b[0] * (K_f[-1] * r_k_f[0] - r_k_f[ss] * K_f[-1] * exp(psi * (-1 + z_f[0]))) * (C_f[0] - h * C_f[-1])^(-sigma_c) = 0 -end - - -@parameters m verbose = true begin - calibr_pi_obj | 1 = pi_obj[ss] - calibr_pi | pi[ss] = pi_obj[ss] - # Phi | Y_s[ss] * .408 = Phi - # Phi = .408 * Y_j[ss] - # (Y_j[ss] + Phi) / Y_j[ss] = 1.408 -> Phi; | this seems problematic because of the parameter - # lambda_p | .6 = C_f[ss] / Y_f[ss] - # lambda_w | L[ss] = .33 - # G_bar | .18 = G[ss] / Y[ss] - # calibr_pi_obj = 0 - # calibr_pi = 1 - lambda_p = .368 - G_bar = .362 - lambda_w = 0.5 - Phi = .819 - - alpha = 0.3 - beta = 0.99 - gamma_w = 0.763 - gamma_p = 0.469 - h = 0.573 - omega = 1 - psi = 0.169 - r_pi = 1.684 - r_Y = 0.099 - r_Delta_pi = 0.14 - r_Delta_y = 0.159 - rho = 0.961 - rho_b = 0.855 - rho_L = 0.889 - rho_I = 0.927 - rho_a = 0.823 - rho_G = 0.949 - rho_pi_bar = 0.924 - sigma_c = 1.353 - sigma_l = 2.4 - tau = 0.025 - varphi = 6.771 - xi_w = 0.737 - xi_p = 0.908 - - # Putting non-negative constraint on first block is enough - # 0 < K - # 0 < I - # 0 < Y_s - # 0 < q - # 0 < r_k - # 5 < f_1 - # 0 < L - # 0 < W - # 30 < g_1 - # 0 < z - # 0 < mc - # 0 < w_star - # 5 < f_2 - # 0 < Y - # 0 < g_2 - # 0 < C -end - diff --git a/test/models/SW07.jl b/test/models/SW07.jl deleted file mode 100644 index 52128347..00000000 --- a/test/models/SW07.jl +++ /dev/null @@ -1,161 +0,0 @@ -@model m begin - a[0] = calfa * rkf[0] + (1 - calfa) * (wf[0]) - - zcapf[0] = (1 / (czcap / (1 - czcap))) * rkf[0] - - rkf[0] = wf[0] + labf[0] - kf[0] - - kf[0] = kpf[-1] + zcapf[0] - - invef[0] = (1 / (1 + cbetabar * cgamma)) * (invef[-1] + cbetabar * cgamma * invef[1] + (1 / (cgamma ^ 2 * csadjcost)) * pkf[0]) + qs[0] - - pkf[0] = - rrf[0] + (1 / ((1 - chabb / cgamma) / (csigma * (1 + chabb / cgamma)))) * b[0] + (crk / (crk + (1 - ctou))) * rkf[1] + ((1 - ctou) / (crk + (1 - ctou))) * pkf[1] - - cf[0] = (chabb / cgamma) / (1 + chabb / cgamma) * cf[-1] + (1 / (1 + chabb / cgamma)) * cf[1] + ((csigma - 1) * cwhlc / (csigma * (1 + chabb / cgamma))) * (labf[0] - labf[1]) - (1 - chabb / cgamma) / (csigma * (1 + chabb / cgamma)) * (rrf[0]) + b[0] - - yf[0] = ccy * cf[0] + ciy * invef[0] + g[0] + crkky * zcapf[0] - - yf[0] = cfc * (calfa * kf[0] + (1 - calfa) * labf[0] + a[0]) - - wf[0] = csigl * labf[0] + (1 / (1 - chabb / cgamma)) * cf[0] - (chabb / cgamma) / (1 - chabb / cgamma) * cf[-1] - - kpf[0] = (1 - cikbar) * kpf[-1] + (cikbar) * invef[0] + (cikbar) * (cgamma ^ 2 * csadjcost) * qs[0] - - mc[0] = calfa * rk[0] + (1 - calfa) * (w[0]) - a[0] - - zcap[0] = (1 / (czcap / (1 - czcap))) * rk[0] - - rk[0] = w[0] + lab[0] - k[0] - - k[0] = kp[-1] + zcap[0] - - inve[0] = (1 / (1 + cbetabar * cgamma)) * (inve[-1] + cbetabar * cgamma * inve[1] + (1 / (cgamma ^ 2 * csadjcost)) * pk[0]) + qs[0] - - pk[0] = - r[0] + pinf[1] + (1 / ((1 - chabb / cgamma) / (csigma * (1 + chabb / cgamma)))) * b[0] + (crk / (crk + (1 - ctou))) * rk[1] + ((1 - ctou) / (crk + (1 - ctou))) * pk[1] - - c[0] = (chabb / cgamma) / (1 + chabb / cgamma) * c[-1] + (1 / (1 + chabb / cgamma)) * c[1] + ((csigma - 1) * cwhlc / (csigma * (1 + chabb / cgamma))) * (lab[0] - lab[1]) - (1 - chabb / cgamma) / (csigma * (1 + chabb / cgamma)) * (r[0] - pinf[1]) + b[0] - - y[0] = ccy * c[0] + ciy * inve[0] + g[0] + crkky * zcap[0] - - y[0] = cfc * (calfa * k[0] + (1 - calfa) * lab[0] + a[0]) - - pinf[0] = (1 / (1 + cbetabar * cgamma * cindp)) * (cbetabar * cgamma * pinf[1] + cindp * pinf[-1] + ((1 - cprobp) * (1 - cbetabar * cgamma * cprobp) / cprobp) / ((cfc - 1) * curvp + 1) * (mc[0])) + spinf[0] - - w[0] = (1 / (1 + cbetabar * cgamma)) * w[-1] + (cbetabar * cgamma / (1 + cbetabar * cgamma)) * w[1] + (cindw / (1 + cbetabar * cgamma)) * pinf[-1] - (1 + cbetabar * cgamma * cindw) / (1 + cbetabar * cgamma) * pinf[0] + (cbetabar * cgamma) / (1 + cbetabar * cgamma) * pinf[1] + (1 - cprobw) * (1 - cbetabar * cgamma * cprobw) / ((1 + cbetabar * cgamma) * cprobw) * (1 / ((clandaw - 1) * curvw + 1)) * (csigl * lab[0] + (1 / (1 - chabb / cgamma)) * c[0] - ((chabb / cgamma) / (1 - chabb / cgamma)) * c[-1] - w[0]) + sw[0] - - r[0] = crpi * (1 - crr) * pinf[0] + cry * (1 - crr) * (y[0] - yf[0]) + crdy * (y[0] - yf[0] - y[-1] + yf[-1]) + crr * r[-1] + ms[0] - - a[0] = crhoa * a[-1] + z_ea * ea[x] - - b[0] = crhob * b[-1] + z_eb * eb[x] - - g[0] = crhog * g[-1] + z_eg * eg[x] + cgy * z_ea * ea[x] - - qs[0] = crhoqs * qs[-1] + z_eqs * eqs[x] - - ms[0] = crhoms * ms[-1] + z_em * em[x] - - spinf[0] = crhopinf * spinf[-1] + epinfma[0] - cmap * epinfma[-1] - - epinfma[0] = z_epinf * epinf[x] - - sw[0] = crhow * sw[-1] + ewma[0] - cmaw * ewma[-1] - - ewma[0] = z_ew * ew[x] - - kp[0] = (1 - cikbar) * kp[-1] + cikbar * inve[0] + cikbar * cgamma ^ 2 * csadjcost * qs[0] - - dy[0] = y[0] - y[-1] + ctrend - - dc[0] = c[0] - c[-1] + ctrend - - dinve[0] = inve[0] - inve[-1] + ctrend - - dw[0] = w[0] - w[-1] + ctrend - - pinfobs[0] = (pinf[0]) + constepinf - - robs[0] = (r[0]) + conster - - labobs[0] = lab[0] + constelab - -end - - -@parameters m verbose = true begin - ctou=.025 - clandaw=1.5 - cg=0.18 - curvp=10 - curvw=10 - - calfa=.24 - # cgamma=1.004 - # cbeta=.9995 - csigma=1.5 - # cpie=1.005 - cfc=1.5 - cgy=0.51 - - csadjcost= 6.0144 - chabb= 0.6361 - cprobw= 0.8087 - csigl= 1.9423 - cprobp= 0.6 - cindw= 0.3243 - cindp= 0.47 - czcap= 0.2696 - crpi= 1.488 - crr= 0.8762 - cry= 0.0593 - crdy= 0.2347 - - crhoa= 0.9977 - crhob= 0.5799 - crhog= 0.9957 - crhols= 0.9928 - crhoqs= 0.7165 - crhoas=1 - crhoms=0 - crhopinf=0 - crhow=0 - cmap = 0 - cmaw = 0 - - clandap=cfc - cbetabar=cbeta*cgamma^(-csigma) - cr=cpie/(cbeta*cgamma^(-csigma)) - crk=(cbeta^(-1))*(cgamma^csigma) - (1-ctou) - cw = (calfa^calfa*(1-calfa)^(1-calfa)/(clandap*crk^calfa))^(1/(1-calfa)) - cikbar=(1-(1-ctou)/cgamma) - cik=(1-(1-ctou)/cgamma)*cgamma - clk=((1-calfa)/calfa)*(crk/cw) - cky=cfc*(clk)^(calfa-1) - ciy=cik*cky - ccy=1-cg-cik*cky - crkky=crk*cky - cwhlc=(1/clandaw)*(1-calfa)/calfa*crk*cky/ccy - cwly=1-crk*cky - - conster=(cr-1)*100 - # ctrend=(cgamma-1)*100 - ctrend=(1.004-1)*100 - # constepinf=(cpie-1)*100 - constepinf=(1.005-1)*100 - - cpie=1+constepinf/100 - cgamma=1+ctrend/100 - - cbeta=1/(1+constebeta/100) - constebeta = 100 / .9995 - 100 - - constelab=0 - - z_ea = 0.4618 - z_eb = 1.8513 - z_eg = 0.6090 - z_eqs = 0.6017 - z_em = 0.2397 - z_epinf = 0.1455 - z_ew = 0.2089 -end \ No newline at end of file diff --git a/test/runtests.jl b/test/runtests.jl index 0c1f8865..65eb38bc 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -6,2131 +6,2143 @@ import StatsPlots, Turing # has to come before Aqua, otherwise exports are not r using Aqua using JET -if Sys.islinux() || Sys.iswindows() - test_higher_order = false -else - test_higher_order = true -end - -if Sys.iswindows() - selected_plots_only = true -else - selected_plots_only = false -end +test_set = ENV["TEST_SET"] +println("Running test set: $test_set") println("Threads used: ", Threads.nthreads()) include("functionality_tests.jl") -@testset verbose = true "Code quality (Aqua.jl)" begin - # Aqua.test_all(MacroModelling) - @testset "Compare Project.toml and test/Project.toml" Aqua.test_project_extras(MacroModelling) - @testset "Project.toml formatting" Aqua.test_project_toml_formatting(MacroModelling) - @testset "Stale dependencies" Aqua.test_stale_deps(MacroModelling)#; ignore = [:Aqua, :JET]) - @testset "Unbound type parameters" Aqua.test_unbound_args(MacroModelling) - @testset "Undefined exports" Aqua.test_undefined_exports(MacroModelling) - @testset "Piracy" Aqua.test_piracy(MacroModelling) - @testset "Method ambiguity" Aqua.test_ambiguities(MacroModelling, recursive = false) - @testset "Compat" Aqua.test_deps_compat(MacroModelling)#; ignore = [:Aqua, :JET]) -end -GC.gc() - -@testset verbose = true "Static checking (JET.jl)" begin - if VERSION >= v"1.9" - JET.test_package(MacroModelling; target_defined_modules = true, toplevel_logger = nothing) - end -end +# @testset verbose = true "Code formatting (JuliaFormatter.jl)" begin +# @test format(MacroModelling; verbose=true, overwrite=true) +# end -@testset verbose = true "Standalone functions" begin - include("test_standalone_function.jl") -end -GC.gc() -@testset verbose = true "Backus_Kehoe_Kydland_1992" begin - include("models/Backus_Kehoe_Kydland_1992.jl") - functionality_test(Backus_Kehoe_Kydland_1992, plots = true) +if test_set == "estimation" + include("test_estimation.jl") end -Backus_Kehoe_Kydland_1992 = nothing -GC.gc() - +if test_set == "higher_order" + plots = true + test_higher_order = true -@testset verbose = true "FS2000" begin - include("models/FS2000.jl") - functionality_test(m, plots = false) -end -m = nothing -GC.gc() - + @testset verbose = true "Test various models: NSSS and 1st order solution" begin + include("test_models.jl") + end + GC.gc() -if test_higher_order @testset verbose = true "FS2000 second order" begin - include("models/FS2000.jl") - functionality_test(m, algorithm = :second_order, plots = true) + include("../models/FS2000.jl") + functionality_test(FS2000, algorithm = :second_order, plots = plots) end - m = nothing + # FS2000 = nothing GC.gc() @testset verbose = true "FS2000 pruned second order" begin - include("models/FS2000.jl") - functionality_test(m, algorithm = :pruned_second_order, plots = selected_plots_only) + # include("../models/FS2000.jl") + functionality_test(FS2000, algorithm = :pruned_second_order, plots = plots) end - m = nothing + # FS2000 = nothing GC.gc() @testset verbose = true "FS2000 third order" begin - include("models/FS2000.jl") - functionality_test(m, algorithm = :third_order, plots = true) + # include("../models/FS2000.jl") + functionality_test(FS2000, algorithm = :third_order, plots = plots) end - m = nothing + # FS2000 = nothing GC.gc() @testset verbose = true "FS2000 pruned third order" begin - include("models/FS2000.jl") - functionality_test(m, algorithm = :pruned_third_order, plots = selected_plots_only) + # include("../models/FS2000.jl") + functionality_test(FS2000, algorithm = :pruned_third_order, plots = plots) end - m = nothing + FS2000 = nothing GC.gc() -end - -# @testset verbose = true "Code formatting (JuliaFormatter.jl)" begin -# @test format(MacroModelling; verbose=true, overwrite=true) -# end - -@testset verbose = true "Test various models: NSSS and 1st order solution" begin - include("test_models.jl") -end -GC.gc() - -@testset verbose = true "SW07 with calibration equations" begin - include("models/SW07.jl") - functionality_test(m, plots = selected_plots_only) -end -m = nothing -GC.gc() - - -@testset verbose = true "RBC_CME with calibration equations, parameter definitions, special functions, variables in steady state, and leads/lag > 1 on endogenous and exogenous variables" begin - include("models/RBC_CME_calibration_equations_and_parameter_definitions_lead_lags.jl") - functionality_test(m) -end -m = nothing -GC.gc() - -if test_higher_order - @testset verbose = true "RBC_CME with calibration equations, parameter definitions, special functions, variables in steady state, and leads/lag > 1 on endogenous and exogenous variables pruned second order" begin - include("models/RBC_CME_calibration_equations_and_parameter_definitions_lead_lags.jl") - functionality_test(m, algorithm = :pruned_second_order, plots = false) + @testset verbose = true "RBC_CME with calibration equations and parameter definitions second order" begin + include("models/RBC_CME_calibration_equations_and_parameter_definitions.jl") + functionality_test(m, algorithm = :second_order, plots = plots) end - m = nothing + # m = nothing GC.gc() - @testset verbose = true "RBC_CME with calibration equations, parameter definitions, special functions, variables in steady state, and leads/lag > 1 on endogenous and exogenous variables pruned third order" begin - include("models/RBC_CME_calibration_equations_and_parameter_definitions_lead_lags.jl") - functionality_test(m, algorithm = :pruned_third_order, plots = false) + @testset verbose = true "RBC_CME with calibration equations and parameter definitions third order" begin + # include("models/RBC_CME_calibration_equations_and_parameter_definitions.jl") + functionality_test(m, algorithm = :third_order, plots = plots) end m = nothing GC.gc() -end -@testset verbose = true "RBC_CME with calibration equations, parameter definitions, special functions, variables in steady state, and leads/lag > 1 on endogenous and exogenous variables numerical SS" begin - include("models/RBC_CME_calibration_equations_and_parameter_definitions_lead_lags_numsolve.jl") - functionality_test(m) -end -m = nothing -GC.gc() - -@testset verbose = true "RBC_CME with calibration equations, parameter definitions, and special functions" begin - include("models/RBC_CME_calibration_equations_and_parameter_definitions_and_specfuns.jl") - functionality_test(m, plots = false) -end -m = nothing -GC.gc() - -@testset verbose = true "RBC_CME with calibration equations and parameter definitions" begin - include("models/RBC_CME_calibration_equations_and_parameter_definitions.jl") - functionality_test(m, plots = false) -end -m = nothing -GC.gc() - - -if test_higher_order - @testset verbose = true "RBC_CME with calibration equations and parameter definitions second order" begin - include("models/RBC_CME_calibration_equations_and_parameter_definitions.jl") - functionality_test(m, algorithm = :second_order, plots = false) + @testset verbose = true "RBC_CME with calibration equations, parameter definitions, special functions, variables in steady state, and leads/lag > 1 on endogenous and exogenous variables pruned second order" begin + include("models/RBC_CME_calibration_equations_and_parameter_definitions_lead_lags.jl") + functionality_test(m, algorithm = :pruned_second_order, plots = plots) end - m = nothing + # m = nothing GC.gc() - @testset verbose = true "RBC_CME with calibration equations and parameter definitions third order" begin - include("models/RBC_CME_calibration_equations_and_parameter_definitions.jl") - functionality_test(m, algorithm = :third_order, plots = false) + @testset verbose = true "RBC_CME with calibration equations, parameter definitions, special functions, variables in steady state, and leads/lag > 1 on endogenous and exogenous variables pruned third order" begin + # include("models/RBC_CME_calibration_equations_and_parameter_definitions_lead_lags.jl") + functionality_test(m, algorithm = :pruned_third_order, plots = plots) end m = nothing GC.gc() -end - - - -@testset verbose = true "RBC_CME with calibration equations" begin - include("models/RBC_CME_calibration_equations.jl") - functionality_test(m, plots = false) -end -m = nothing -GC.gc() - -if test_higher_order @testset verbose = true "RBC_CME with calibration equations second order" begin include("models/RBC_CME_calibration_equations.jl") - functionality_test(m, algorithm = :second_order, plots = false) + functionality_test(m, algorithm = :second_order, plots = plots) end - m = nothing + # m = nothing GC.gc() @testset verbose = true "RBC_CME with calibration equations third order" begin - include("models/RBC_CME_calibration_equations.jl") - functionality_test(m, algorithm = :third_order, plots = false) + # include("models/RBC_CME_calibration_equations.jl") + functionality_test(m, algorithm = :third_order, plots = plots) end m = nothing GC.gc() -end -@testset verbose = true "RBC_CME" begin - include("models/RBC_CME.jl") - functionality_test(m, plots = false) -end -m = nothing -GC.gc() - - -if test_higher_order @testset verbose = true "RBC_CME second order" begin include("models/RBC_CME.jl") - functionality_test(m, algorithm = :second_order, plots = false) + functionality_test(m, algorithm = :second_order, plots = plots) end - m = nothing + # m = nothing GC.gc() - @testset verbose = true "RBC_CME third order" begin - include("models/RBC_CME.jl") - functionality_test(m, algorithm = :third_order, plots = false) + # include("models/RBC_CME.jl") + functionality_test(m, algorithm = :third_order, plots = plots) end m = nothing GC.gc() end -@testset verbose = true "SW03 with calibration equations" begin - include("models/SW03.jl") - functionality_test(m) -end -m = nothing -GC.gc() - -@testset verbose = true "Model without shocks" begin - @model m begin - K[0] = (1 - δ) * K[-1] + I[0] - Z[0] = (1 - ρ) * μ + ρ * Z[-1] - I[1] = ((ρ + δ - Z[0])/(1 - δ)) + ((1 + ρ)/(1 - δ)) * I[0] - end - - @parameters m verbose = true begin - ρ = 0.05 - δ = 0.10 - μ = .17 - σ = .2 - end - - m_ss = get_steady_state(m) - @test isapprox(m_ss(:,:Steady_state),[1/7.5,1/.75,.17],rtol = eps(Float32)) - m_sol = get_solution(m) - @test isapprox(m_sol(:,:K),[1/.75,.9,.04975124378109454],rtol = eps(Float32)) - init = m_ss(:,:Steady_state) |> collect - init[2] *= 1.5 - get_irf(m, initial_state = init, shocks = :none) - plot_irf(m, initial_state = init, shocks = :none) - @test true -end -m = nothing +if test_set == "plots" + plots = true -@testset verbose = true "Distribution functions, general and SS" begin - - @model RBC_CME begin - y[0]=A[0]*k[-1]^alpha - 1/c[0]=beta*1/c[1]*(alpha*A[1]*k[0]^(alpha-1)+(1-delta)) - 1/c[0]=beta*1/c[1]*(R[0]/Pi[+1]) - R[0] * beta =(Pi[0]/Pibar)^phi_pi - # A[0]*k[-1]^alpha=c[0]+k[0]-(1-delta)*k[-1] - A[0]*k[-1]^alpha=c[0]+k[0]-(1-delta*z_delta[0])*k[-1] - z_delta[0] = 1 - rho_z_delta + rho_z_delta * z_delta[-1] + std_z_delta * delta_eps[x] - c_normcdf[0]= normcdf(c[0]) - c_normpdf[0]= normpdf(c[0]) - c_norminvcdf[0]= norminvcdf(c[0]-1) - c_norminv[0]= norminv(c[0]-1) - c_qnorm[0]= qnorm(c[0]-1) - c_dnorm[0]= dnorm(c[0]) - c_pnorm[0]= pnorm(c[0]) - c_normlogpdf[0]= normlogpdf(c[0]) - # c_norm[0]= cdf(Normal(),c[0]) - c_inv[0] = erfcinv(c[0]) - # c_binomlogpdf[0]= binomlogpdf(c[0]) - # A[0]=exp(z[0]) - A[0] = 1 - rhoz + rhoz * A[-1] + std_eps * eps_z[x] - # ZZ_avg[0] = (A[0] + A[-1] + A[-2] + A[-3]) / 4 - # A_annual[0] = (A[0] + A[-4] + A[-8] + A[-12]) / 4 - # y_avg[0] = log(y[0] / y[-4]) - # y_growth[0] = log(y[1] / y[2]) - # y_growthl[0] = log(y[0] / y[1]) - # y_growthl1[0] = log(y[-1] / y[0]) - # log(A[0]) = rhoz * log(A[-1]) + std_eps * eps_z[x] + @testset verbose = true "Backus_Kehoe_Kydland_1992" begin + include("../models/Backus_Kehoe_Kydland_1992.jl") + functionality_test(Backus_Kehoe_Kydland_1992, plots = plots) end + Backus_Kehoe_Kydland_1992 = nothing + GC.gc() - - @parameters RBC_CME verbose = true begin - # alpha | k[ss] / (4 * y[ss]) = cap_share - # cap_share = 1.66 - alpha = .157 - - # beta | R[ss] = R_ss - # R_ss = 1.0035 - beta = .999 - - # delta | c[ss]/y[ss] = 1 - I_K_ratio - # delta | delta * k[ss]/y[ss] = I_K_ratio #check why this doesnt solve for y - # I_K_ratio = .15 - delta = .0226 - - # Pibar | Pi[ss] = Pi_ss - # Pi_ss = 1.0025 - Pibar = 1.0008 - - phi_pi = 1.5 - rhoz = .9 - std_eps = .0068 - rho_z_delta = .9 - std_z_delta = .005 - end - - get_solution(RBC_CME) - - - @model finacc begin - R[0] * beta = C[1] / C[0] - C[0] = w[0] * L[0] - B[0] + R[-1] * B[-1] + (1-v) * (Rk[-1] * Q[-1] * K[-1] - (R[-1] + mu * G[0] * Rk[-1] * Q[-1] * K[-1] / (Q[-1] * K[-1] - N[-1])) * (Q[-1] * K[-1] - N[-1])) - We - w[0] = C[0] / (1-L[0]) - K[0] = (1-delta) * K[-1] + I[0] - Q[0] = 1 + chi * (I[0] / K[-1] - delta) - Y[0] = A[0] * K[-1]^alpha * L[0]^(1-alpha) - Rk[-1] = (alpha * Y[0] / K[-1] + Q[0] * (1-delta))/Q[-1] - w[0] = (1-alpha) * Y[0] / L[0] - N[0] = v * (Rk[-1] * Q[-1] * K[-1] - (R[-1] + mu * G[0] * Rk[-1] * Q[-1] * K[-1] / (Q[-1] * K[-1] - N[-1])) * (Q[-1] * K[-1] - N[-1])) + We - 0 = (omegabar[0] * (1 - F[0]) + (1 - mu) * G[0]) * Rk[0] / R[0] * Q[0] * K[0] / N[0] - (Q[0] * K[0] / N[0] - 1) - 0 = (1 - (omegabar[0] * (1 - F[0]) + G[0])) * Rk[0] / R[0] + (1 - F[0]) / (1 - F[0] - omegabar[0] * mu * (normpdf((log(omegabar[0]) + sigma^2/2) / sigma)/ omegabar[0] / sigma)) * ((omegabar[0] * (1 - F[0]) + (1 - mu) * G[0]) * Rk[0] / R[0] - 1) - G[0] = normcdf(((log(omegabar[0])+sigma^2/2)/sigma) - sigma) - F[0] = normcdf((log(omegabar[0])+sigma^2/2)/sigma) - EFP[0] = (mu * G[0] * Rk[-1] * Q[-1] * K[-1] / (Q[-1] * K[-1] - N[-1])) - Y[0] + walras[0] = C[0] + I[0] + EFP[0] * (Q[-1] * K[-1] - N[-1]) - B[0] = Q[0] * K[0] - N[0] - A[0] = 1 - rhoz + rhoz * A[-1] + std_eps * eps_z[x] - end - - - @parameters finacc verbose = true begin - beta = 0.99 - delta = 0.02 - We = 1e-12 - alpha = 0.36 - chi = 0 - v = 0.978 - mu = 0.94 - sigma = 0.2449489742783178 - rhoz = .9 - std_eps = .0068 - - .5 > omegabar > .44 - K > 15 - 0 < L < .45 + @testset verbose = true "Gali 2015 ELB" begin + include("../models/Gali_2015_chapter_3_obc.jl") + functionality_test(Gali_2015_chapter_3_obc, plots = plots) end + Gali_2015_chapter_3_obc = nothing + GC.gc() - # solve!(finacc) - @test isapprox(get_steady_state(finacc,derivatives = false)[:,1],[1.0, 7.004987166460695, 1.2762549358842095, 0.0008293608419033882, 0.0009318065746306208, 0.0003952537570055814, 0.30743973601435376, 15.371986800781423, 0.4435430773517457, 8.366999635233856, 1.0000000000593001, 1.0101010101010102, 1.0172249577970442, 1.5895043340984303, 0.4529051354389826, 2.2935377097663356, -1.4597012487627126e-10], rtol = 1e-6) -end -RBC_CME = nothing -finacc = nothing - -@testset verbose = true "Lead and lag > 1" begin - - @model RBC_CME begin - y[0]=A[0]*k[-1]^alpha - 1/c[0]=beta*1/c[1]*(alpha*A[1]*k[0]^(alpha-1)+(1-delta)) - 1/c[0]=beta*1/c[1]*(R[0]/Pi[+1]) - R[0] * beta =(Pi[0]/Pibar)^phi_pi - # A[0]*k[-1]^alpha=c[0]+k[0]-(1-delta)*k[-1] - A[0]*k[-1]^alpha=c[0]+k[0]-(1-delta*z_delta[0])*k[-1] - z_delta[0] = 1 - rho_z_delta + rho_z_delta * z_delta[-1] + std_z_delta * delta_eps[x] - # z[0]=rhoz*z[-1]+std_eps*eps_z[x] - # A[0]=exp(z[0]) - A[0] = 1 - rhoz + rhoz * A[-1] + std_eps * eps_z[x] - # ZZ_avg[0] = (A[0] + A[-1] + A[-2] + A[-3]) / 4 - # A_annual[0] = (A[0] + A[-4] + A[-8] + A[-12]) / 4 - # y_avg[0] = log(y[0] / y[-4]) - # y_growth[0] = log(y[1] / y[2]) - # y_growthl[0] = log(y[0] / y[1]) - # y_growthl1[0] = log(y[-1] / y[0]) - # log(A[0]) = rhoz * log(A[-1]) + std_eps * eps_z[x] + @testset verbose = true "FS2000" begin + include("../models/FS2000.jl") + functionality_test(FS2000, plots = plots) end + FS2000 = nothing + GC.gc() - @parameters RBC_CME verbose = true begin - # alpha | k[ss] / (4 * y[ss]) = cap_share - # cap_share = 1.66 - alpha = .157 - - # beta | R[ss] = R_ss - # R_ss = 1.0035 - beta = .999 - - # delta | c[ss]/y[ss] = 1 - I_K_ratio - # delta | delta * k[ss]/y[ss] = I_K_ratio #check why this doesnt solve for y - # I_K_ratio = .15 - delta = .0226 - - # Pibar | Pi[ss] = Pi_ss - # Pi_ss = 1.0025 - Pibar = 1.0008 - - phi_pi = 1.5 - rhoz = .9 - std_eps = .0068 - rho_z_delta = .9 - std_z_delta = .005 + @testset verbose = true "SW07 with calibration equations" begin + include("../models/SW07.jl") + functionality_test(SW07, plots = plots) end - - get_solution(RBC_CME) - - get_solution(RBC_CME, algorithm = :linear_time_iteration) - - @test isapprox(RBC_CME.solution.perturbation.first_order.solution_matrix, RBC_CME.solution.perturbation.linear_time_iteration.solution_matrix, atol = 1e-4) - - get_solution(RBC_CME, algorithm = :quadratic_iteration) - - @test isapprox(RBC_CME.solution.perturbation.first_order.solution_matrix, RBC_CME.solution.perturbation.quadratic_iteration.solution_matrix, atol = 1e-4) - - # @test isapprox(RBC_CME.solution.perturbation.first_order.C, RBC_CME.solution.perturbation.linear_time_iteration.C, atol = 1e-4) - - - + SW07 = nothing + GC.gc() - # exo multi lead/lag >> 1 - @model RBC_CME_exo_mult begin - y[0]=A[0]*k[-1]^alpha - 1/c[0]=beta*1/c[1]*(alpha*A[1]*k[0]^(alpha-1)+(1-delta)) - 1/c[0]=beta*1/c[1]*(R[0]/Pi[+1]) - R[0] * beta =(Pi[0]/Pibar)^phi_pi - # A[0]*k[-1]^alpha=c[0]+k[0]-(1-delta)*k[-1] - A[0]*k[-1]^alpha=c[0]+k[0]-(1-delta*z_delta[0])*k[-1] - z_delta[0] = 1 - rho_z_delta + rho_z_delta * z_delta[-1] + std_z_delta * delta_eps[x] - # z[0]=rhoz*z[-1]+std_eps*eps_z[x] - # A[0]=exp(z[0]) - A[0] = 1 - rhoz + rhoz * A[-1] + std_eps * (eps_z[x-8] + eps_z[x-4] + eps_z[x+4] + eps_z_s[x]) - # ZZ_avg[0] = (A[0] + A[-1] + A[-2] + A[-3]) / 4 - # A_annual[0] = (A[0] + A[-4] + A[-8] + A[-12]) / 4 - # y_avg[0] = log(y[0] / y[-4]) - # y_growth[0] = log(y[1] / y[2]) - # y_growthl[0] = log(y[0] / y[1]) - # y_growthl1[0] = log(y[-1] / y[0]) - # log(A[0]) = rhoz * log(A[-1]) + std_eps * eps_z[x] + @testset verbose = true "RBC_CME with calibration equations, parameter definitions, special functions, variables in steady state, and leads/lag > 1 on endogenous and exogenous variables" begin + include("models/RBC_CME_calibration_equations_and_parameter_definitions_lead_lags.jl") + functionality_test(m, plots = plots) end + m = nothing + GC.gc() - @parameters RBC_CME_exo_mult verbose = true begin - # alpha | k[ss] / (4 * y[ss]) = cap_share - # cap_share = 1.66 - alpha = .157 - - # beta | R[ss] = R_ss - # R_ss = 1.0035 - beta = .999 - - # delta | c[ss]/y[ss] = 1 - I_K_ratio - # delta | delta * k[ss]/y[ss] = I_K_ratio #check why this doesnt solve for y - # I_K_ratio = .15 - delta = .0226 - - # Pibar | Pi[ss] = Pi_ss - # Pi_ss = 1.0025 - Pibar = 1.0008 - phi_pi = 1.5 - rhoz = .9 - std_eps = .0068 - rho_z_delta = .9 - std_z_delta = .005 - end - - get_solution(RBC_CME_exo_mult) - - get_solution(RBC_CME_exo_mult, algorithm = :linear_time_iteration) - - # @test isapprox(RBC_CME.solution.perturbation.first_order.C[:,2], RBC_CME_exo_mult.solution.perturbation.first_order.solution_matrix[[1:4...,16:end...],15], atol = 1e-4) - @test isapprox(RBC_CME.solution.perturbation.first_order.solution_matrix, RBC_CME_exo_mult.solution.perturbation.first_order.solution_matrix[[1:4...,16:end...],[1,10:12...,14]], atol = 1e-4) - - @test isapprox(RBC_CME_exo_mult.solution.perturbation.first_order.solution_matrix, RBC_CME_exo_mult.solution.perturbation.linear_time_iteration.solution_matrix, atol = 1e-4) - - - get_solution(RBC_CME_exo_mult, algorithm = :quadratic_iteration) - - @test isapprox(RBC_CME.solution.perturbation.first_order.solution_matrix, RBC_CME_exo_mult.solution.perturbation.quadratic_iteration.solution_matrix[[1:4...,16:end...],[1,10:12...,14]], atol = 1e-4) - - # @test isapprox(RBC_CME_exo_mult.solution.perturbation.first_order.solution_matrix, RBC_CME_exo_mult.solution.perturbation.linear_time_iteration.solution_matrix, atol = 1e-4) - # @test isapprox(RBC_CME_exo_mult.solution.perturbation.first_order.C, RBC_CME_exo_mult.solution.perturbation.linear_time_iteration.C, atol = 1e-4) - - # endo/exo multi lead/lag >> 1 - @model RBC_CME_all_mult begin - y[0]=A[0]*k[-1]^alpha - 1/c[0]=beta*1/c[1]*(alpha*A[1]*k[0]^(alpha-1)+(1-delta)) - 1/c[0]=beta*1/c[1]*(R[0]/Pi[+1]) - R[0] * beta =(Pi[0]/Pibar)^phi_pi - # A[0]*k[-1]^alpha=c[0]+k[0]-(1-delta)*k[-1] - A[0]*k[-1]^alpha=c[0]+k[0]-(1-delta*z_delta[0])*k[-1] - z_delta[0] = 1 - rho_z_delta + rho_z_delta * z_delta[-1] + std_z_delta * delta_eps[x] - # z[0]=rhoz*z[-1]+std_eps*eps_z[x] - # A[0]=exp(z[0]) - A[0] = 1 - rhoz + rhoz * A[-1] + std_eps * (eps_z[x-8] + eps_z[x-4] + eps_z[x+4] + eps_z_s[x]) - ZZ_avg[0] = (A[0] + A[-1] + A[-2] + A[-3]) / 4 - ZZ_avg_fut[0] = (A[0] + A[1] + A[2] + A[3]) / 4 - # A_annual[0] = (A[0] + A[-4] + A[-8] + A[-12]) / 4 - # y_avg[0] = log(y[0] / y[-4]) - # y_growth[0] = log(y[1] / y[2]) - # y_growthl[0] = log(y[0] / y[1]) - # y_growthl1[0] = log(y[-1] / y[0]) - # log(A[0]) = rhoz * log(A[-1]) + std_eps * eps_z[x] + @testset verbose = true "RBC_CME with calibration equations, parameter definitions, special functions, variables in steady state, and leads/lag > 1 on endogenous and exogenous variables numerical SS" begin + include("models/RBC_CME_calibration_equations_and_parameter_definitions_lead_lags_numsolve.jl") + functionality_test(m, plots = plots) end + m = nothing + GC.gc() - - @parameters RBC_CME_all_mult verbose = true begin - # alpha | k[ss] / (4 * y[ss]) = cap_share - # cap_share = 1.66 - alpha = .157 - - # beta | R[ss] = R_ss - # R_ss = 1.0035 - beta = .999 - - # delta | c[ss]/y[ss] = 1 - I_K_ratio - # delta | delta * k[ss]/y[ss] = I_K_ratio #check why this doesnt solve for y - # I_K_ratio = .15 - delta = .0226 - - # Pibar | Pi[ss] = Pi_ss - # Pi_ss = 1.0025 - Pibar = 1.0008 - - phi_pi = 1.5 - rhoz = .9 - std_eps = .0068 - rho_z_delta = .9 - std_z_delta = .005 - end - - get_solution(RBC_CME_all_mult) - - get_solution(RBC_CME_all_mult, algorithm = :linear_time_iteration) - - # @test isapprox(RBC_CME.solution.perturbation.first_order.C[:,2], RBC_CME_all_mult.solution.perturbation.first_order.solution_matrix[[1,6,7,10,22:end...],21], atol = 1e-4) - @test isapprox(RBC_CME.solution.perturbation.first_order.solution_matrix, RBC_CME_all_mult.solution.perturbation.first_order.solution_matrix[[1,6,7,10,22:end...],[1,12:14...,16]], atol = 1e-4) - - @test isapprox(RBC_CME_all_mult.solution.perturbation.first_order.solution_matrix, RBC_CME_all_mult.solution.perturbation.linear_time_iteration.solution_matrix, atol = 1e-4) - - get_solution(RBC_CME_all_mult, algorithm = :quadratic_iteration) - - # @test isapprox(RBC_CME.solution.perturbation.first_order.C[:,2], RBC_CME_all_mult.solution.perturbation.first_order.solution_matrix[[1,6,7,10,22:end...],21], atol = 1e-4) - @test isapprox(RBC_CME.solution.perturbation.first_order.solution_matrix, RBC_CME_all_mult.solution.perturbation.quadratic_iteration.solution_matrix[[1,6,7,10,22:end...],[1,12:14...,16]], atol = 1e-4) - # [[1:4...,16:end...],[1,10:12...,14]] - # @test isapprox(RBC_CME_all_mult.solution.perturbation.first_order.solution_matrix, RBC_CME_all_mult.solution.perturbation.linear_time_iteration.solution_matrix, atol = 1e-4) - # @test isapprox(RBC_CME_all_mult.solution.perturbation.first_order.C, RBC_CME_all_mult.solution.perturbation.linear_time_iteration.C, atol = 1e-4) - - RBC_CME_exo_mult = nothing - - - # exo lead >> 1 - @model RBC_CME_exo_lead1 begin - y[0]=A[0]*k[-1]^alpha - 1/c[0]=beta*1/c[1]*(alpha*A[1]*k[0]^(alpha-1)+(1-delta)) - 1/c[0]=beta*1/c[1]*(R[0]/Pi[+1]) - R[0] * beta =(Pi[0]/Pibar)^phi_pi - # A[0]*k[-1]^alpha=c[0]+k[0]-(1-delta)*k[-1] - A[0]*k[-1]^alpha=c[0]+k[0]-(1-delta*z_delta[0])*k[-1] - z_delta[0] = 1 - rho_z_delta + rho_z_delta * z_delta[-1] + std_z_delta * delta_eps[x] - # z[0]=rhoz*z[-1]+std_eps*eps_z[x] - # A[0]=exp(z[0]) - A[0] = 1 - rhoz + rhoz * A[-1] + std_eps * eps_z[x+8] - # ZZ_avg[0] = (A[0] + A[-1] + A[-2] + A[-3]) / 4 - # A_annual[0] = (A[0] + A[-4] + A[-8] + A[-12]) / 4 - # y_avg[0] = log(y[0] / y[-4]) - # y_growth[0] = log(y[1] / y[2]) - # y_growthl[0] = log(y[0] / y[1]) - # y_growthl1[0] = log(y[-1] / y[0]) - # log(A[0]) = rhoz * log(A[-1]) + std_eps * eps_z[x] + @testset verbose = true "RBC_CME with calibration equations, parameter definitions, and special functions" begin + include("models/RBC_CME_calibration_equations_and_parameter_definitions_and_specfuns.jl") + functionality_test(m, plots = plots) end + m = nothing + GC.gc() - - @parameters RBC_CME_exo_lead1 verbose = true begin - # alpha | k[ss] / (4 * y[ss]) = cap_share - # cap_share = 1.66 - alpha = .157 - - # beta | R[ss] = R_ss - # R_ss = 1.0035 - beta = .999 - - # delta | c[ss]/y[ss] = 1 - I_K_ratio - # delta | delta * k[ss]/y[ss] = I_K_ratio #check why this doesnt solve for y - # I_K_ratio = .15 - delta = .0226 - - # Pibar | Pi[ss] = Pi_ss - # Pi_ss = 1.0025 - Pibar = 1.0008 - - phi_pi = 1.5 - rhoz = .9 - std_eps = .0068 - rho_z_delta = .9 - std_z_delta = .005 + @testset verbose = true "RBC_CME with calibration equations and parameter definitions" begin + include("models/RBC_CME_calibration_equations_and_parameter_definitions.jl") + functionality_test(m, plots = plots) end - - get_solution(RBC_CME_exo_lead1) - - get_solution(RBC_CME_exo_lead1, algorithm = :linear_time_iteration) - - # @test isapprox(RBC_CME.solution.perturbation.first_order.C[:,2], RBC_CME_exo_lead1.solution.perturbation.first_order.solution_matrix[[1:4...,13:end...],12], atol = 1e-4) - @test isapprox(RBC_CME.solution.perturbation.first_order.solution_matrix[:,[1:4...]], RBC_CME_exo_lead1.solution.perturbation.first_order.solution_matrix[[1:4...,13:15...],[1:4...]], atol = 1e-4) - - @test isapprox(RBC_CME_exo_lead1.solution.perturbation.first_order.solution_matrix, RBC_CME_exo_lead1.solution.perturbation.linear_time_iteration.solution_matrix, atol = 1e-4) - - get_solution(RBC_CME_exo_lead1, algorithm = :quadratic_iteration) - - # @test isapprox(RBC_CME.solution.perturbation.first_order.C[:,2], RBC_CME_exo_lead1.solution.perturbation.first_order.solution_matrix[[1:4...,13:end...],12], atol = 1e-4) - @test isapprox(RBC_CME.solution.perturbation.first_order.solution_matrix[:,[1:4...]], RBC_CME_exo_lead1.solution.perturbation.quadratic_iteration.solution_matrix[[1:4...,13:15...],[1:4...]], atol = 1e-4) - - # @test isapprox(RBC_CME_exo_lead1.solution.perturbation.first_order.solution_matrix, RBC_CME_exo_lead1.solution.perturbation.linear_time_iteration.solution_matrix, atol = 1e-4) - # @test isapprox(RBC_CME_exo_lead1.solution.perturbation.first_order.C, RBC_CME_exo_lead1.solution.perturbation.linear_time_iteration.C, atol = 1e-4) - - RBC_CME_exo_lead1 = nothing - + m = nothing + GC.gc() - # exo multi lag >> 1 - @model RBC_CME_exo_lag_mult begin - y[0]=A[0]*k[-1]^alpha - 1/c[0]=beta*1/c[1]*(alpha*A[1]*k[0]^(alpha-1)+(1-delta)) - 1/c[0]=beta*1/c[1]*(R[0]/Pi[+1]) - R[0] * beta =(Pi[0]/Pibar)^phi_pi - # A[0]*k[-1]^alpha=c[0]+k[0]-(1-delta)*k[-1] - A[0]*k[-1]^alpha=c[0]+k[0]-(1-delta*z_delta[0])*k[-1] - z_delta[0] = 1 - rho_z_delta + rho_z_delta * z_delta[-1] + std_z_delta * delta_eps[x] - # z[0]=rhoz*z[-1]+std_eps*eps_z[x] - # A[0]=exp(z[0]) - A[0] = 1 - rhoz + rhoz * A[-1] + std_eps * (eps_z[x-8] + eps_z[x-4] + eps_z_s[x]) - # ZZ_avg[0] = (A[0] + A[-1] + A[-2] + A[-3]) / 4 - # A_annual[0] = (A[0] + A[-4] + A[-8] + A[-12]) / 4 - # y_avg[0] = log(y[0] / y[-4]) - # y_growth[0] = log(y[1] / y[2]) - # y_growthl[0] = log(y[0] / y[1]) - # y_growthl1[0] = log(y[-1] / y[0]) - # log(A[0]) = rhoz * log(A[-1]) + std_eps * eps_z[x] + @testset verbose = true "RBC_CME with calibration equations" begin + include("models/RBC_CME_calibration_equations.jl") + functionality_test(m, plots = plots) end + m = nothing + GC.gc() - @parameters RBC_CME_exo_lag_mult verbose = true begin - # alpha | k[ss] / (4 * y[ss]) = cap_share - # cap_share = 1.66 - alpha = .157 - - # beta | R[ss] = R_ss - # R_ss = 1.0035 - beta = .999 - - # delta | c[ss]/y[ss] = 1 - I_K_ratio - # delta | delta * k[ss]/y[ss] = I_K_ratio #check why this doesnt solve for y - # I_K_ratio = .15 - delta = .0226 - - # Pibar | Pi[ss] = Pi_ss - # Pi_ss = 1.0025 - Pibar = 1.0008 - phi_pi = 1.5 - rhoz = .9 - std_eps = .0068 - rho_z_delta = .9 - std_z_delta = .005 + @testset verbose = true "RBC_CME" begin + include("models/RBC_CME.jl") + functionality_test(m, plots = plots) end - - get_solution(RBC_CME_exo_lag_mult) - - get_solution(RBC_CME_exo_lag_mult, algorithm = :linear_time_iteration) - - # @test isapprox(RBC_CME.solution.perturbation.first_order.C[:,2], RBC_CME_exo_lag_mult.solution.perturbation.first_order.solution_matrix[[1:4...,13:end...],12], atol = 1e-4) - @test isapprox(RBC_CME.solution.perturbation.first_order.solution_matrix, RBC_CME_exo_lag_mult.solution.perturbation.first_order.solution_matrix[[1:4...,13:15...],[1,10:12...,14]], atol = 1e-4) - - @test isapprox(RBC_CME_exo_lag_mult.solution.perturbation.first_order.solution_matrix, RBC_CME_exo_lag_mult.solution.perturbation.linear_time_iteration.solution_matrix, atol = 1e-4) - - get_solution(RBC_CME_exo_lag_mult, algorithm = :quadratic_iteration) - - @test isapprox(RBC_CME_exo_lag_mult.solution.perturbation.first_order.solution_matrix, RBC_CME_exo_lag_mult.solution.perturbation.quadratic_iteration.solution_matrix, atol = 1e-4) - # @test isapprox(RBC_CME_exo_lag_mult.solution.perturbation.first_order.C, RBC_CME_exo_lag_mult.solution.perturbation.linear_time_iteration.C, atol = 1e-4) - - # irf(RBC_CME_exo_lag_mult) - - # irf(RBC_CME) - - # irf(RBC_CME_exo_lag1) + m = nothing + GC.gc() - RBC_CME_exo_lag_mult = nothing - # exo lag >> 1 - @model RBC_CME_exo_lag1 begin - y[0]=A[0]*k[-1]^alpha - 1/c[0]=beta*1/c[1]*(alpha*A[1]*k[0]^(alpha-1)+(1-delta)) - 1/c[0]=beta*1/c[1]*(R[0]/Pi[+1]) - R[0] * beta =(Pi[0]/Pibar)^phi_pi - # A[0]*k[-1]^alpha=c[0]+k[0]-(1-delta)*k[-1] - A[0]*k[-1]^alpha=c[0]+k[0]-(1-delta*z_delta[0])*k[-1] - z_delta[0] = 1 - rho_z_delta + rho_z_delta * z_delta[-1] + std_z_delta * delta_eps[x] - # z[0]=rhoz*z[-1]+std_eps*eps_z[x] - # A[0]=exp(z[0]) - A[0] = 1 - rhoz + rhoz * A[-1] + std_eps * eps_z[x-8] - # ZZ_avg[0] = (A[0] + A[-1] + A[-2] + A[-3]) / 4 - # A_annual[0] = (A[0] + A[-4] + A[-8] + A[-12]) / 4 - # y_avg[0] = log(y[0] / y[-4]) - # y_growth[0] = log(y[1] / y[2]) - # y_growthl[0] = log(y[0] / y[1]) - # y_growthl1[0] = log(y[-1] / y[0]) - # log(A[0]) = rhoz * log(A[-1]) + std_eps * eps_z[x] + @testset verbose = true "SW03 with calibration equations" begin + include("../models/SW03.jl") + functionality_test(SW03, plots = plots) end + SW03 = nothing + GC.gc() +end - @parameters RBC_CME_exo_lag1 verbose = true begin - # alpha | k[ss] / (4 * y[ss]) = cap_share - # cap_share = 1.66 - alpha = .157 - - # beta | R[ss] = R_ss - # R_ss = 1.0035 - beta = .999 - - # delta | c[ss]/y[ss] = 1 - I_K_ratio - # delta | delta * k[ss]/y[ss] = I_K_ratio #check why this doesnt solve for y - # I_K_ratio = .15 - delta = .0226 - # Pibar | Pi[ss] = Pi_ss - # Pi_ss = 1.0025 - Pibar = 1.0008 +if test_set == "basic" + plots = false + test_higher_order = false - phi_pi = 1.5 - rhoz = .9 - std_eps = .0068 - rho_z_delta = .9 - std_z_delta = .005 + @testset verbose = true "Code quality (Aqua.jl)" begin + # Aqua.test_all(MacroModelling) + @testset "Compare Project.toml and test/Project.toml" Aqua.test_project_extras(MacroModelling) + @testset "Stale dependencies" Aqua.test_stale_deps(MacroModelling)#; ignore = [:Aqua, :JET]) + @testset "Unbound type parameters" Aqua.test_unbound_args(MacroModelling) + @testset "Undefined exports" Aqua.test_undefined_exports(MacroModelling) + @testset "Piracy" Aqua.test_piracies(MacroModelling) + @testset "Method ambiguity" Aqua.test_ambiguities(MacroModelling, recursive = false) + @testset "Compat" Aqua.test_deps_compat(MacroModelling)#; ignore = [:Aqua, :JET]) + # @testset "Persistent tasks" Aqua.test_persistent_tasks(MacroModelling) end + GC.gc() - get_solution(RBC_CME_exo_lag1) - - get_solution(RBC_CME_exo_lag1, algorithm = :linear_time_iteration) - - # @test isapprox(RBC_CME.solution.perturbation.first_order.C[:,2], RBC_CME_exo_lag1.solution.perturbation.first_order.solution_matrix[[1:4...,13:end...],12], atol = 1e-4) - @test isapprox(RBC_CME.solution.perturbation.first_order.solution_matrix, RBC_CME_exo_lag1.solution.perturbation.first_order.solution_matrix[[1:4...,13:end...],[1,10:12...,9]], atol = 1e-4) - - @test isapprox(RBC_CME_exo_lag1.solution.perturbation.first_order.solution_matrix, RBC_CME_exo_lag1.solution.perturbation.linear_time_iteration.solution_matrix, atol = 1e-4) - # @test isapprox(RBC_CME_exo_lag1.solution.perturbation.first_order.C, RBC_CME_exo_lag1.solution.perturbation.linear_time_iteration.C, atol = 1e-4) - - get_solution(RBC_CME_exo_lag1, algorithm = :quadratic_iteration) - - @test isapprox(RBC_CME_exo_lag1.solution.perturbation.first_order.solution_matrix, RBC_CME_exo_lag1.solution.perturbation.quadratic_iteration.solution_matrix, atol = 1e-4) - - RBC_CME_exo_lag1 = nothing - - - # exo lead > 1 - @model RBC_CME_exo_lead begin - y[0]=A[0]*k[-1]^alpha - 1/c[0]=beta*1/c[1]*(alpha*A[1]*k[0]^(alpha-1)+(1-delta)) - 1/c[0]=beta*1/c[1]*(R[0]/Pi[+1]) - R[0] * beta =(Pi[0]/Pibar)^phi_pi - # A[0]*k[-1]^alpha=c[0]+k[0]-(1-delta)*k[-1] - A[0]*k[-1]^alpha=c[0]+k[0]-(1-delta*z_delta[0])*k[-1] - z_delta[0] = 1 - rho_z_delta + rho_z_delta * z_delta[-1] + std_z_delta * delta_eps[x] - # z[0]=rhoz*z[-1]+std_eps*eps_z[x] - # A[0]=exp(z[0]) - A[0] = 1 - rhoz + rhoz * A[-1] + std_eps * eps_z[x+1] - # ZZ_avg[0] = (A[0] + A[-1] + A[-2] + A[-3]) / 4 - # A_annual[0] = (A[0] + A[-4] + A[-8] + A[-12]) / 4 - # y_avg[0] = log(y[0] / y[-4]) - # y_growth[0] = log(y[1] / y[2]) - # y_growthl[0] = log(y[0] / y[1]) - # y_growthl1[0] = log(y[-1] / y[0]) - # log(A[0]) = rhoz * log(A[-1]) + std_eps * eps_z[x] + @testset verbose = true "Static checking (JET.jl)" begin + if VERSION >= v"1.9" + JET.test_package(MacroModelling; target_defined_modules = true, toplevel_logger = nothing) + end end - - @parameters RBC_CME_exo_lead verbose = true begin - # alpha | k[ss] / (4 * y[ss]) = cap_share - # cap_share = 1.66 - alpha = .157 - - # beta | R[ss] = R_ss - # R_ss = 1.0035 - beta = .999 - - # delta | c[ss]/y[ss] = 1 - I_K_ratio - # delta | delta * k[ss]/y[ss] = I_K_ratio #check why this doesnt solve for y - # I_K_ratio = .15 - delta = .0226 - - # Pibar | Pi[ss] = Pi_ss - # Pi_ss = 1.0025 - Pibar = 1.0008 - - phi_pi = 1.5 - rhoz = .9 - std_eps = .0068 - rho_z_delta = .9 - std_z_delta = .005 - end - - get_solution(RBC_CME_exo_lead) - - get_solution(RBC_CME_exo_lead, algorithm = :linear_time_iteration) - - # @test isapprox(RBC_CME.solution.perturbation.first_order.C[:,2], RBC_CME_exo_lead.solution.perturbation.first_order.solution_matrix[[1:4...,6:8...],5], atol = 1e-4) - @test isapprox(RBC_CME.solution.perturbation.first_order.solution_matrix[:,[1:(end-1)...]], RBC_CME_exo_lead.solution.perturbation.first_order.solution_matrix[[1:4...,6:end...],[1:(end-1)...]], atol = 1e-4) - - @test isapprox(RBC_CME_exo_lead.solution.perturbation.first_order.solution_matrix, RBC_CME_exo_lead.solution.perturbation.linear_time_iteration.solution_matrix, atol = 1e-4) - # @test isapprox(RBC_CME_exo_lead.solution.perturbation.first_order.C, RBC_CME_exo_lead.solution.perturbation.linear_time_iteration.C, atol = 1e-4) - - get_solution(RBC_CME_exo_lead, algorithm = :quadratic_iteration) - - @test isapprox(RBC_CME_exo_lead.solution.perturbation.first_order.solution_matrix, RBC_CME_exo_lead.solution.perturbation.quadratic_iteration.solution_matrix, atol = 1e-4) - - RBC_CME_exo_lead = nothing - - - # exo lag > 1 - @model RBC_CME_exo_lag begin - y[0]=A[0]*k[-1]^alpha - 1/c[0]=beta*1/c[1]*(alpha*A[1]*k[0]^(alpha-1)+(1-delta)) - 1/c[0]=beta*1/c[1]*(R[0]/Pi[+1]) - R[0] * beta =(Pi[0]/Pibar)^phi_pi - # A[0]*k[-1]^alpha=c[0]+k[0]-(1-delta)*k[-1] - A[0]*k[-1]^alpha=c[0]+k[0]-(1-delta*z_delta[0])*k[-1] - z_delta[0] = 1 - rho_z_delta + rho_z_delta * z_delta[-1] + std_z_delta * delta_eps[x] - # z[0]=rhoz*z[-1]+std_eps*eps_z[x] - # A[0]=exp(z[0]) - A[0] = 1 - rhoz + rhoz * A[-1] + std_eps * eps_z[x-1] - # ZZ_avg[0] = (A[0] + A[-1] + A[-2] + A[-3]) / 4 - # A_annual[0] = (A[0] + A[-4] + A[-8] + A[-12]) / 4 - # y_avg[0] = log(y[0] / y[-4]) - # y_growth[0] = log(y[1] / y[2]) - # y_growthl[0] = log(y[0] / y[1]) - # y_growthl1[0] = log(y[-1] / y[0]) - # log(A[0]) = rhoz * log(A[-1]) + std_eps * eps_z[x] + @testset verbose = true "Test various models: NSSS and 1st order solution" begin + include("test_models.jl") end + GC.gc() - - @parameters RBC_CME_exo_lag verbose = true begin - # alpha | k[ss] / (4 * y[ss]) = cap_share - # cap_share = 1.66 - alpha = .157 - - # beta | R[ss] = R_ss - # R_ss = 1.0035 - beta = .999 - - # delta | c[ss]/y[ss] = 1 - I_K_ratio - # delta | delta * k[ss]/y[ss] = I_K_ratio #check why this doesnt solve for y - # I_K_ratio = .15 - delta = .0226 - - # Pibar | Pi[ss] = Pi_ss - # Pi_ss = 1.0025 - Pibar = 1.0008 - - phi_pi = 1.5 - rhoz = .9 - std_eps = .0068 - rho_z_delta = .9 - std_z_delta = .005 - end - - get_solution(RBC_CME_exo_lag) - - get_solution(RBC_CME_exo_lag, algorithm = :linear_time_iteration) - - # @test isapprox(RBC_CME.solution.perturbation.first_order.C[:,2], RBC_CME_exo_lag.solution.perturbation.first_order.solution_matrix[[1:4...,6:8...],5], atol = 1e-4) - @test isapprox(RBC_CME.solution.perturbation.first_order.solution_matrix, RBC_CME_exo_lag.solution.perturbation.first_order.solution_matrix[[1:4...,6:end...],[1,3,4,5,2]], atol = 1e-4) - - @test isapprox(RBC_CME_exo_lag.solution.perturbation.first_order.solution_matrix, RBC_CME_exo_lag.solution.perturbation.linear_time_iteration.solution_matrix, atol = 1e-4) - # @test isapprox(RBC_CME_exo_lag.solution.perturbation.first_order.C, RBC_CME_exo_lag.solution.perturbation.linear_time_iteration.C, atol = 1e-4) - - get_solution(RBC_CME_exo_lag, algorithm = :quadratic_iteration) - - @test isapprox(RBC_CME_exo_lag.solution.perturbation.first_order.solution_matrix, RBC_CME_exo_lag.solution.perturbation.quadratic_iteration.solution_matrix, atol = 1e-4) - - RBC_CME_exo_lag = nothing - - # Lags > 1 - @model RBC_CME_lag begin - y[0]=A[0]*k[-1]^alpha - 1/c[0]=beta*1/c[1]*(alpha*A[1]*k[0]^(alpha-1)+(1-delta)) - 1/c[0]=beta*1/c[1]*(R[0]/Pi[+1]) - R[0] * beta =(Pi[0]/Pibar)^phi_pi - # A[0]*k[-1]^alpha=c[0]+k[0]-(1-delta)*k[-1] - A[0]*k[-1]^alpha=c[0]+k[0]-(1-delta*z_delta[0])*k[-1] - z_delta[0] = 1 - rho_z_delta + rho_z_delta * z_delta[-1] + std_z_delta * delta_eps[x] - # z[0]=rhoz*z[-1]+std_eps*eps_z[x] - # A[0]=exp(z[0]) - A[0] = 1 - rhoz + rhoz * A[-1] + std_eps * eps_z[x] - ZZ_avg[0] = (A[0] + A[-1] + A[-2] + A[-3]) / 4 - ZZ_dev[0] = log(c[0]/c[ss]) - # A_annual[0] = (A[0] + A[-4] + A[-8] + A[-12]) / 4 - # y_avg[0] = log(y[0] / y[-4]) - # y_growth[0] = log(y[1] / y[2]) - # y_growthl[0] = log(y[0] / y[1]) - # y_growthl1[0] = log(y[-1] / y[0]) - # log(A[0]) = rhoz * log(A[-1]) + std_eps * eps_z[x] + @testset verbose = true "Standalone functions" begin + include("test_standalone_function.jl") end + GC.gc() - @parameters RBC_CME_lag verbose = true begin - # alpha | k[ss] / (4 * y[ss]) = cap_share - # cap_share = 1.66 - alpha = .157 + @testset verbose = true "Model without shocks" begin + @model m begin + K[0] = (1 - δ) * K[-1] + I[0] + Z[0] = (1 - ρ) * μ + ρ * Z[-1] + I[1] = ((ρ + δ - Z[0])/(1 - δ)) + ((1 + ρ)/(1 - δ)) * I[0] + end - # beta | R[ss] = R_ss - # R_ss = 1.0035 - beta = .999 + @parameters m verbose = true begin + ρ = 0.05 + δ = 0.10 + μ = .17 + σ = .2 + end - # delta | c[ss]/y[ss] = 1 - I_K_ratio - # delta | delta * k[ss]/y[ss] = I_K_ratio #check why this doesnt solve for y - # I_K_ratio = .15 - delta = .0226 + m_ss = get_steady_state(m) + @test isapprox(m_ss(:,:Steady_state),[1/7.5,1/.75,.17],rtol = eps(Float32)) - # Pibar | Pi[ss] = Pi_ss - # Pi_ss = 1.0025 - Pibar = 1.0008 + m_sol = get_solution(m) + @test isapprox(m_sol(:,:K),[1/.75,.9,.04975124378109454],rtol = eps(Float32)) - phi_pi = 1.5 - rhoz = .9 - std_eps = .0068 - rho_z_delta = .9 - std_z_delta = .005 - end - - get_solution(RBC_CME_lag) - - @test RBC_CME.solution.perturbation.first_order.solution_matrix ≈ RBC_CME_lag.solution.perturbation.first_order.solution_matrix[[1,4,5,8:11...],[1,4:end...]] - # @test RBC_CME.solution.perturbation.first_order.C ≈ RBC_CME_lag.solution.perturbation.first_order.C[[1,4,5,8:11...],:] - - get_solution(RBC_CME_lag, algorithm = :linear_time_iteration) - - @test isapprox(RBC_CME_lag.solution.perturbation.first_order.solution_matrix, RBC_CME_lag.solution.perturbation.linear_time_iteration.solution_matrix, atol = 1e-4) - # @test isapprox(RBC_CME_lag.solution.perturbation.first_order.C, RBC_CME_lag.solution.perturbation.linear_time_iteration.C, atol = 1e-4) - - get_solution(RBC_CME_lag, algorithm = :quadratic_iteration) - - @test isapprox(RBC_CME_lag.solution.perturbation.first_order.solution_matrix, RBC_CME_lag.solution.perturbation.quadratic_iteration.solution_matrix, atol = 1e-4) - - RBC_CME_lag = nothing - - # Leads > 1 - @model RBC_CME_lead begin - y[0]=A[0]*k[-1]^alpha - 1/c[0]=beta*1/c[1]*(alpha*A[1]*k[0]^(alpha-1)+(1-delta)) - 1/c[0]=beta*1/c[1]*(R[0]/Pi[+1]) - R[0] * beta =(Pi[0]/Pibar)^phi_pi - # A[0]*k[-1]^alpha=c[0]+k[0]-(1-delta)*k[-1] - A[0]*k[-1]^alpha=c[0]+k[0]-(1-delta*z_delta[0])*k[-1] - z_delta[0] = 1 - rho_z_delta + rho_z_delta * z_delta[-1] + std_z_delta * delta_eps[x] - # z[0]=rhoz*z[-1]+std_eps*eps_z[x] - # A[0]=exp(z[0]) - A[0] = 1 - rhoz + rhoz * A[-1] + std_eps * eps_z[x] - ZZ_avg[0] = (A[0] + A[1] + A[2] + A[3]) / 4 - ZZ_dev[0] = log(c[0]/c[ss]) - # A_annual[0] = (A[0] + A[-4] + A[-8] + A[-12]) / 4 - # y_avg[0] = log(y[0] / y[-4]) - # y_growth[0] = log(y[1] / y[2]) - # y_growthl[0] = log(y[0] / y[1]) - # y_growthl1[0] = log(y[-1] / y[0]) - # log(A[0]) = rhoz * log(A[-1]) + std_eps * eps_z[x] - end - - @parameters RBC_CME_lead verbose = true begin - # alpha | k[ss] / (4 * y[ss]) = cap_share - # cap_share = 1.66 - alpha = .157 - - # beta | R[ss] = R_ss - # R_ss = 1.0035 - beta = .999 - - # delta | c[ss]/y[ss] = 1 - I_K_ratio - # delta | delta * k[ss]/y[ss] = I_K_ratio #check why this doesnt solve for y - # I_K_ratio = .15 - delta = .0226 - - # Pibar | Pi[ss] = Pi_ss - # Pi_ss = 1.0025 - Pibar = 1.0008 - - phi_pi = 1.5 - rhoz = .9 - std_eps = .0068 - rho_z_delta = .9 - std_z_delta = .005 - end - - get_solution(RBC_CME_lead) - - @test RBC_CME.solution.perturbation.first_order.solution_matrix ≈ RBC_CME_lead.solution.perturbation.first_order.solution_matrix[[1,4,5,8:11...],:] - # @test RBC_CME.solution.perturbation.first_order.C ≈ RBC_CME_lead.solution.perturbation.first_order.C[[1,4,5,8:11...],:] - - get_solution(RBC_CME_lead, algorithm = :linear_time_iteration) - - @test isapprox(RBC_CME_lead.solution.perturbation.first_order.solution_matrix, RBC_CME_lead.solution.perturbation.linear_time_iteration.solution_matrix, atol = 1e-4) - # @test isapprox(RBC_CME_lead.solution.perturbation.first_order.C, RBC_CME_lead.solution.perturbation.linear_time_iteration.C, atol = 1e-4) - - get_solution(RBC_CME_lead, algorithm = :quadratic_iteration) - - @test isapprox(RBC_CME_lead.solution.perturbation.first_order.solution_matrix, RBC_CME_lead.solution.perturbation.quadratic_iteration.solution_matrix, atol = 1e-4) - - RBC_CME_lead = nothing - - - # Leads and lags > 1 - @model RBC_CME_lead_lag begin - y[0]=A[0]*k[-1]^alpha - 1/c[0]=beta*1/c[1]*(alpha*A[1]*k[0]^(alpha-1)+(1-delta)) - 1/c[0]=beta*1/c[1]*(R[0]/Pi[+1]) - R[0] * beta =(Pi[0]/Pibar)^phi_pi - # A[0]*k[-1]^alpha=c[0]+k[0]-(1-delta)*k[-1] - A[0]*k[-1]^alpha=c[0]+k[0]-(1-delta*z_delta[0])*k[-1] - z_delta[0] = 1 - rho_z_delta + rho_z_delta * z_delta[-1] + std_z_delta * delta_eps[x] - # z[0]=rhoz*z[-1]+std_eps*eps_z[x] - # A[0]=exp(z[0]) - A[0] = 1 - rhoz + rhoz * A[-1] + std_eps * eps_z[x] - ZZ_avg_f[0] = (A[0] + A[1] + A[2] + A[3]) / 4 - ZZ_avg_b[0] = (A[0] + A[-1] + A[-2] + A[-3]) / 4 - # A_annual[0] = (A[0] + A[-4] + A[-8] + A[-12]) / 4 - # y_avg[0] = log(y[0] / y[-4]) - # y_growth[0] = log(y[1] / y[2]) - # y_growthl[0] = log(y[0] / y[1]) - # y_growthl1[0] = log(y[-1] / y[0]) - # log(A[0]) = rhoz * log(A[-1]) + std_eps * eps_z[x] - end - - - @parameters RBC_CME_lead_lag verbose = true begin - # alpha | k[ss] / (4 * y[ss]) = cap_share - # cap_share = 1.66 - alpha = .157 - - # beta | R[ss] = R_ss - # R_ss = 1.0035 - beta = .999 + init = m_ss(:,:Steady_state) |> collect + init[2] *= 1.5 + get_irf(m, initial_state = init, shocks = :none) - # delta | c[ss]/y[ss] = 1 - I_K_ratio - # delta | delta * k[ss]/y[ss] = I_K_ratio #check why this doesnt solve for y - # I_K_ratio = .15 - delta = .0226 - - # Pibar | Pi[ss] = Pi_ss - # Pi_ss = 1.0025 - Pibar = 1.0008 - - phi_pi = 1.5 - rhoz = .9 - std_eps = .0068 - rho_z_delta = .9 - std_z_delta = .005 - end - - get_solution(RBC_CME_lead_lag) - - @test RBC_CME.solution.perturbation.first_order.solution_matrix ≈ RBC_CME_lead_lag.solution.perturbation.first_order.solution_matrix[[1,6,7,10:13...],[1,4:end...]] - # @test RBC_CME.solution.perturbation.first_order.C ≈ RBC_CME_lead_lag.solution.perturbation.first_order.C[[1,6,7,(10:13)...],:] - - get_solution(RBC_CME_lead_lag, algorithm = :linear_time_iteration) - - @test isapprox(RBC_CME_lead_lag.solution.perturbation.first_order.solution_matrix, RBC_CME_lead_lag.solution.perturbation.linear_time_iteration.solution_matrix, atol = 1e-4) - # @test isapprox(RBC_CME_lead_lag.solution.perturbation.first_order.C, RBC_CME_lead_lag.solution.perturbation.linear_time_iteration.C, atol = 1e-4) - - get_solution(RBC_CME_lead_lag, algorithm = :quadratic_iteration) - - @test isapprox(RBC_CME_lead_lag.solution.perturbation.first_order.solution_matrix, RBC_CME_lead_lag.solution.perturbation.quadratic_iteration.solution_matrix, atol = 1e-4) - - RBC_CME_lead_lag = nothing - - - # Leads and lags > 10 - @model RBC_CME_lead_lag10 begin - y[0]=A[0]*k[-1]^alpha - 1/c[0]=beta*1/c[1]*(alpha*A[1]*k[0]^(alpha-1)+(1-delta)) - 1/c[0]=beta*1/c[1]*(R[0]/Pi[+1]) - R[0] * beta =(Pi[0]/Pibar)^phi_pi - # A[0]*k[-1]^alpha=c[0]+k[0]-(1-delta)*k[-1] - A[0]*k[-1]^alpha=c[0]+k[0]-(1-delta*z_delta[0])*k[-1] - z_delta[0] = 1 - rho_z_delta + rho_z_delta * z_delta[-1] + std_z_delta * delta_eps[x] - # z[0]=rhoz*z[-1]+std_eps*eps_z[x] - # A[0]=exp(z[0]) - A[0] = 1 - rhoz + rhoz * A[-1] + std_eps * eps_z[x] - ZZ_avg_f[0] = (A[0] + A[1] + A[2] + A[3]) / 4 - ZZ_avg_b[0] = (A[0] + A[-1] + A[-2] + A[-3]) / 4 - ZZ_avg_f10[0] = (A[0] + A[10]) / 2 - # ZZ_avg_b10[0] = (A[0] + A[-10]) / 2 - # A_annual[0] = (A[0] + A[-4] + A[-8] + A[-12]) / 4 - # y_avg[0] = log(y[0] / y[-4]) - # y_growth[0] = log(y[1] / y[2]) - # y_growthl[0] = log(y[0] / y[1]) - # y_growthl1[0] = log(y[-1] / y[0]) - # log(A[0]) = rhoz * log(A[-1]) + std_eps * eps_z[x] + plot_irf(m, initial_state = init, shocks = :none) + @test true end + m = nothing - - @parameters RBC_CME_lead_lag10 verbose = true begin - # alpha | k[ss] / (4 * y[ss]) = cap_share - # cap_share = 1.66 - alpha = .157 - - # beta | R[ss] = R_ss - # R_ss = 1.0035 - beta = .999 - - # delta | c[ss]/y[ss] = 1 - I_K_ratio - # delta | delta * k[ss]/y[ss] = I_K_ratio #check why this doesnt solve for y - # I_K_ratio = .15 - delta = .0226 - - # Pibar | Pi[ss] = Pi_ss - # Pi_ss = 1.0025 - Pibar = 1.0008 - - phi_pi = 1.5 - rhoz = .9 - std_eps = .0068 - rho_z_delta = .9 - std_z_delta = .005 - end - - get_solution(RBC_CME_lead_lag10) - - @test RBC_CME.solution.perturbation.first_order.solution_matrix ≈ RBC_CME_lead_lag10.solution.perturbation.first_order.solution_matrix[[1,13,14,18:21...],[1,4:end...]] - # @test RBC_CME.solution.perturbation.first_order.C ≈ RBC_CME_lead_lag10.solution.perturbation.first_order.C[[1,13,14,(18:21)...],:] - - get_solution(RBC_CME_lead_lag10, algorithm = :linear_time_iteration) - - @test isapprox(RBC_CME_lead_lag10.solution.perturbation.first_order.solution_matrix, RBC_CME_lead_lag10.solution.perturbation.linear_time_iteration.solution_matrix, atol = 1e-4) - # @test isapprox(RBC_CME_lead_lag10.solution.perturbation.first_order.C, RBC_CME_lead_lag10.solution.perturbation.linear_time_iteration.C, atol = 1e-4) - - get_solution(RBC_CME_lead_lag10, algorithm = :quadratic_iteration) - - @test isapprox(RBC_CME_lead_lag10.solution.perturbation.first_order.solution_matrix, RBC_CME_lead_lag10.solution.perturbation.quadratic_iteration.solution_matrix, atol = 1e-4) - - RBC_CME_lead_lag10 = nothing - - - # Leads and lags > 10 - @model RBC_CME_lead_lag20 begin - y[0]=A[0]*k[-1]^alpha - 1/c[0]=beta*1/c[1]*(alpha*A[1]*k[0]^(alpha-1)+(1-delta)) - 1/c[0]=beta*1/c[1]*(R[0]/Pi[+1]) - R[0] * beta =(Pi[0]/Pibar)^phi_pi - # A[0]*k[-1]^alpha=c[0]+k[0]-(1-delta)*k[-1] - A[0]*k[-1]^alpha=c[0]+k[0]-(1-delta*z_delta[0])*k[-1] - z_delta[0] = 1 - rho_z_delta + rho_z_delta * z_delta[-1] + std_z_delta * delta_eps[x] - # z[0]=rhoz*z[-1]+std_eps*eps_z[x] - # A[0]=exp(z[0]) - A[0] = 1 - rhoz + rhoz * A[-1] + std_eps * eps_z[x] - ZZ_avg_f[0] = (A[0] + A[1] + A[2] + A[3]) / 4 - ZZ_avg_b[0] = (A[0] + A[-1] + A[-2] + A[-3]) / 4 - ZZ_avg_ff[0] = (A[0] + A[10]) / 2 - ZZ_avg_bb[0] = (A[0] + A[-10]) / 2 - # A_annual[0] = (A[0] + A[-4] + A[-8] + A[-12]) / 4 - # y_avg[0] = log(y[0] / y[-4]) - # y_growth[0] = log(y[1] / y[2]) - # y_growthl[0] = log(y[0] / y[1]) - # y_growthl1[0] = log(y[-1] / y[0]) - # log(A[0]) = rhoz * log(A[-1]) + std_eps * eps_z[x] + @testset verbose = true "Distribution functions, general and SS" begin + + @model RBC_CME begin + y[0]=A[0]*k[-1]^alpha + 1/c[0]=beta*1/c[1]*(alpha*A[1]*k[0]^(alpha-1)+(1-delta)) + 1/c[0]=beta*1/c[1]*(R[0]/Pi[+1]) + R[0] * beta =(Pi[0]/Pibar)^phi_pi + # A[0]*k[-1]^alpha=c[0]+k[0]-(1-delta)*k[-1] + A[0]*k[-1]^alpha=c[0]+k[0]-(1-delta*z_delta[0])*k[-1] + z_delta[0] = 1 - rho_z_delta + rho_z_delta * z_delta[-1] + std_z_delta * delta_eps[x] + c_normcdf[0]= normcdf(c[0]) + c_normpdf[0]= normpdf(c[0]) + c_norminvcdf[0]= norminvcdf(c[0]-1) + c_norminv[0]= norminv(c[0]-1) + c_qnorm[0]= qnorm(c[0]-1) + c_dnorm[0]= dnorm(c[0]) + c_pnorm[0]= pnorm(c[0]) + c_normlogpdf[0]= normlogpdf(c[0]) + # c_norm[0]= cdf(Normal(),c[0]) + c_inv[0] = erfcinv(c[0]) + # c_binomlogpdf[0]= binomlogpdf(c[0]) + # A[0]=exp(z[0]) + A[0] = 1 - rhoz + rhoz * A[-1] + std_eps * eps_z[x] + # ZZ_avg[0] = (A[0] + A[-1] + A[-2] + A[-3]) / 4 + # A_annual[0] = (A[0] + A[-4] + A[-8] + A[-12]) / 4 + # y_avg[0] = log(y[0] / y[-4]) + # y_growth[0] = log(y[1] / y[2]) + # y_growthl[0] = log(y[0] / y[1]) + # y_growthl1[0] = log(y[-1] / y[0]) + # log(A[0]) = rhoz * log(A[-1]) + std_eps * eps_z[x] + end + + + @parameters RBC_CME verbose = true begin + # alpha | k[ss] / (4 * y[ss]) = cap_share + # cap_share = 1.66 + alpha = .157 + + # beta | R[ss] = R_ss + # R_ss = 1.0035 + beta = .999 + + # delta | c[ss]/y[ss] = 1 - I_K_ratio + # delta | delta * k[ss]/y[ss] = I_K_ratio #check why this doesnt solve for y + # I_K_ratio = .15 + delta = .0226 + + # Pibar | Pi[ss] = Pi_ss + # Pi_ss = 1.0025 + Pibar = 1.0008 + + phi_pi = 1.5 + rhoz = .9 + std_eps = .0068 + rho_z_delta = .9 + std_z_delta = .005 + end + + get_solution(RBC_CME) + + + @model finacc begin + R[0] * beta = C[1] / C[0] + C[0] = w[0] * L[0] - B[0] + R[-1] * B[-1] + (1-v) * (Rk[-1] * Q[-1] * K[-1] - (R[-1] + mu * G[0] * Rk[-1] * Q[-1] * K[-1] / (Q[-1] * K[-1] - N[-1])) * (Q[-1] * K[-1] - N[-1])) - We + w[0] = C[0] / (1-L[0]) + K[0] = (1-delta) * K[-1] + I[0] + Q[0] = 1 + chi * (I[0] / K[-1] - delta) + Y[0] = A[0] * K[-1]^alpha * L[0]^(1-alpha) + Rk[-1] = (alpha * Y[0] / K[-1] + Q[0] * (1-delta))/Q[-1] + w[0] = (1-alpha) * Y[0] / L[0] + N[0] = v * (Rk[-1] * Q[-1] * K[-1] - (R[-1] + mu * G[0] * Rk[-1] * Q[-1] * K[-1] / (Q[-1] * K[-1] - N[-1])) * (Q[-1] * K[-1] - N[-1])) + We + 0 = (omegabar[0] * (1 - F[0]) + (1 - mu) * G[0]) * Rk[0] / R[0] * Q[0] * K[0] / N[0] - (Q[0] * K[0] / N[0] - 1) + 0 = (1 - (omegabar[0] * (1 - F[0]) + G[0])) * Rk[0] / R[0] + (1 - F[0]) / (1 - F[0] - omegabar[0] * mu * (normpdf((log(omegabar[0]) + sigma^2/2) / sigma)/ omegabar[0] / sigma)) * ((omegabar[0] * (1 - F[0]) + (1 - mu) * G[0]) * Rk[0] / R[0] - 1) + G[0] = normcdf(((log(omegabar[0])+sigma^2/2)/sigma) - sigma) + F[0] = normcdf((log(omegabar[0])+sigma^2/2)/sigma) + EFP[0] = (mu * G[0] * Rk[-1] * Q[-1] * K[-1] / (Q[-1] * K[-1] - N[-1])) + Y[0] + walras[0] = C[0] + I[0] + EFP[0] * (Q[-1] * K[-1] - N[-1]) + B[0] = Q[0] * K[0] - N[0] + A[0] = 1 - rhoz + rhoz * A[-1] + std_eps * eps_z[x] + end + + + @parameters finacc verbose = true begin + beta = 0.99 + delta = 0.02 + We = 1e-12 + alpha = 0.36 + chi = 0 + v = 0.978 + mu = 0.94 + sigma = 0.2449489742783178 + rhoz = .9 + std_eps = .0068 + + .5 > omegabar > .44 + K > 15 + 0 < L < .45 + end + + # solve!(finacc) + @test isapprox(get_steady_state(finacc,derivatives = false)[:,1],[1.0, 7.004987166460695, 1.2762549358842095, 0.0008293608419033882, 0.0009318065746306208, 0.0003952537570055814, 0.30743973601435376, 15.371986800781423, 0.4435430773517457, 8.366999635233856, 1.0000000000593001, 1.0101010101010102, 1.0172249577970442, 1.5895043340984303, 0.4529051354389826, 2.2935377097663356, -1.4597012487627126e-10], rtol = 1e-6) end + RBC_CME = nothing + finacc = nothing + @testset verbose = true "Lead and lag > 1" begin + + @model RBC_CME begin + y[0]=A[0]*k[-1]^alpha + 1/c[0]=beta*1/c[1]*(alpha*A[1]*k[0]^(alpha-1)+(1-delta)) + 1/c[0]=beta*1/c[1]*(R[0]/Pi[+1]) + R[0] * beta =(Pi[0]/Pibar)^phi_pi + # A[0]*k[-1]^alpha=c[0]+k[0]-(1-delta)*k[-1] + A[0]*k[-1]^alpha=c[0]+k[0]-(1-delta*z_delta[0])*k[-1] + z_delta[0] = 1 - rho_z_delta + rho_z_delta * z_delta[-1] + std_z_delta * delta_eps[x] + # z[0]=rhoz*z[-1]+std_eps*eps_z[x] + # A[0]=exp(z[0]) + A[0] = 1 - rhoz + rhoz * A[-1] + std_eps * eps_z[x] + # ZZ_avg[0] = (A[0] + A[-1] + A[-2] + A[-3]) / 4 + # A_annual[0] = (A[0] + A[-4] + A[-8] + A[-12]) / 4 + # y_avg[0] = log(y[0] / y[-4]) + # y_growth[0] = log(y[1] / y[2]) + # y_growthl[0] = log(y[0] / y[1]) + # y_growthl1[0] = log(y[-1] / y[0]) + # log(A[0]) = rhoz * log(A[-1]) + std_eps * eps_z[x] + end + + + @parameters RBC_CME verbose = true begin + # alpha | k[ss] / (4 * y[ss]) = cap_share + # cap_share = 1.66 + alpha = .157 + + # beta | R[ss] = R_ss + # R_ss = 1.0035 + beta = .999 + + # delta | c[ss]/y[ss] = 1 - I_K_ratio + # delta | delta * k[ss]/y[ss] = I_K_ratio #check why this doesnt solve for y + # I_K_ratio = .15 + delta = .0226 + + # Pibar | Pi[ss] = Pi_ss + # Pi_ss = 1.0025 + Pibar = 1.0008 + + phi_pi = 1.5 + rhoz = .9 + std_eps = .0068 + rho_z_delta = .9 + std_z_delta = .005 + end + + get_solution(RBC_CME) + + get_solution(RBC_CME, algorithm = :linear_time_iteration) + + @test isapprox(RBC_CME.solution.perturbation.first_order.solution_matrix, RBC_CME.solution.perturbation.linear_time_iteration.solution_matrix, atol = 1e-4) + + get_solution(RBC_CME, algorithm = :quadratic_iteration) + + @test isapprox(RBC_CME.solution.perturbation.first_order.solution_matrix, RBC_CME.solution.perturbation.quadratic_iteration.solution_matrix, atol = 1e-4) + + # @test isapprox(RBC_CME.solution.perturbation.first_order.C, RBC_CME.solution.perturbation.linear_time_iteration.C, atol = 1e-4) + + + + + + # exo multi lead/lag >> 1 + @model RBC_CME_exo_mult begin + y[0]=A[0]*k[-1]^alpha + 1/c[0]=beta*1/c[1]*(alpha*A[1]*k[0]^(alpha-1)+(1-delta)) + 1/c[0]=beta*1/c[1]*(R[0]/Pi[+1]) + R[0] * beta =(Pi[0]/Pibar)^phi_pi + # A[0]*k[-1]^alpha=c[0]+k[0]-(1-delta)*k[-1] + A[0]*k[-1]^alpha=c[0]+k[0]-(1-delta*z_delta[0])*k[-1] + z_delta[0] = 1 - rho_z_delta + rho_z_delta * z_delta[-1] + std_z_delta * delta_eps[x] + # z[0]=rhoz*z[-1]+std_eps*eps_z[x] + # A[0]=exp(z[0]) + A[0] = 1 - rhoz + rhoz * A[-1] + std_eps * (eps_z[x-8] + eps_z[x-4] + eps_z[x+4] + eps_z_s[x]) + # ZZ_avg[0] = (A[0] + A[-1] + A[-2] + A[-3]) / 4 + # A_annual[0] = (A[0] + A[-4] + A[-8] + A[-12]) / 4 + # y_avg[0] = log(y[0] / y[-4]) + # y_growth[0] = log(y[1] / y[2]) + # y_growthl[0] = log(y[0] / y[1]) + # y_growthl1[0] = log(y[-1] / y[0]) + # log(A[0]) = rhoz * log(A[-1]) + std_eps * eps_z[x] + end + + + @parameters RBC_CME_exo_mult verbose = true begin + # alpha | k[ss] / (4 * y[ss]) = cap_share + # cap_share = 1.66 + alpha = .157 + + # beta | R[ss] = R_ss + # R_ss = 1.0035 + beta = .999 + + # delta | c[ss]/y[ss] = 1 - I_K_ratio + # delta | delta * k[ss]/y[ss] = I_K_ratio #check why this doesnt solve for y + # I_K_ratio = .15 + delta = .0226 + + # Pibar | Pi[ss] = Pi_ss + # Pi_ss = 1.0025 + Pibar = 1.0008 + + phi_pi = 1.5 + rhoz = .9 + std_eps = .0068 + rho_z_delta = .9 + std_z_delta = .005 + end + + get_solution(RBC_CME_exo_mult) + + get_solution(RBC_CME_exo_mult, algorithm = :linear_time_iteration) + + # @test isapprox(RBC_CME.solution.perturbation.first_order.C[:,2], RBC_CME_exo_mult.solution.perturbation.first_order.solution_matrix[[1:4...,16:end...],15], atol = 1e-4) + @test isapprox(RBC_CME.solution.perturbation.first_order.solution_matrix, RBC_CME_exo_mult.solution.perturbation.first_order.solution_matrix[[1:4...,16:end...],[1,10:12...,14]], atol = 1e-4) + + @test isapprox(RBC_CME_exo_mult.solution.perturbation.first_order.solution_matrix, RBC_CME_exo_mult.solution.perturbation.linear_time_iteration.solution_matrix, atol = 1e-4) + + + get_solution(RBC_CME_exo_mult, algorithm = :quadratic_iteration) + + @test isapprox(RBC_CME.solution.perturbation.first_order.solution_matrix, RBC_CME_exo_mult.solution.perturbation.quadratic_iteration.solution_matrix[[1:4...,16:end...],[1,10:12...,14]], atol = 1e-4) + + # @test isapprox(RBC_CME_exo_mult.solution.perturbation.first_order.solution_matrix, RBC_CME_exo_mult.solution.perturbation.linear_time_iteration.solution_matrix, atol = 1e-4) + # @test isapprox(RBC_CME_exo_mult.solution.perturbation.first_order.C, RBC_CME_exo_mult.solution.perturbation.linear_time_iteration.C, atol = 1e-4) + + # endo/exo multi lead/lag >> 1 + @model RBC_CME_all_mult begin + y[0]=A[0]*k[-1]^alpha + 1/c[0]=beta*1/c[1]*(alpha*A[1]*k[0]^(alpha-1)+(1-delta)) + 1/c[0]=beta*1/c[1]*(R[0]/Pi[+1]) + R[0] * beta =(Pi[0]/Pibar)^phi_pi + # A[0]*k[-1]^alpha=c[0]+k[0]-(1-delta)*k[-1] + A[0]*k[-1]^alpha=c[0]+k[0]-(1-delta*z_delta[0])*k[-1] + z_delta[0] = 1 - rho_z_delta + rho_z_delta * z_delta[-1] + std_z_delta * delta_eps[x] + # z[0]=rhoz*z[-1]+std_eps*eps_z[x] + # A[0]=exp(z[0]) + A[0] = 1 - rhoz + rhoz * A[-1] + std_eps * (eps_z[x-8] + eps_z[x-4] + eps_z[x+4] + eps_z_s[x]) + ZZ_avg[0] = (A[0] + A[-1] + A[-2] + A[-3]) / 4 + ZZ_avg_fut[0] = (A[0] + A[1] + A[2] + A[3]) / 4 + # A_annual[0] = (A[0] + A[-4] + A[-8] + A[-12]) / 4 + # y_avg[0] = log(y[0] / y[-4]) + # y_growth[0] = log(y[1] / y[2]) + # y_growthl[0] = log(y[0] / y[1]) + # y_growthl1[0] = log(y[-1] / y[0]) + # log(A[0]) = rhoz * log(A[-1]) + std_eps * eps_z[x] + end + + + @parameters RBC_CME_all_mult verbose = true begin + # alpha | k[ss] / (4 * y[ss]) = cap_share + # cap_share = 1.66 + alpha = .157 + + # beta | R[ss] = R_ss + # R_ss = 1.0035 + beta = .999 + + # delta | c[ss]/y[ss] = 1 - I_K_ratio + # delta | delta * k[ss]/y[ss] = I_K_ratio #check why this doesnt solve for y + # I_K_ratio = .15 + delta = .0226 + + # Pibar | Pi[ss] = Pi_ss + # Pi_ss = 1.0025 + Pibar = 1.0008 + + phi_pi = 1.5 + rhoz = .9 + std_eps = .0068 + rho_z_delta = .9 + std_z_delta = .005 + end + + get_solution(RBC_CME_all_mult) + + get_solution(RBC_CME_all_mult, algorithm = :linear_time_iteration) + + # @test isapprox(RBC_CME.solution.perturbation.first_order.C[:,2], RBC_CME_all_mult.solution.perturbation.first_order.solution_matrix[[1,6,7,10,22:end...],21], atol = 1e-4) + @test isapprox(RBC_CME.solution.perturbation.first_order.solution_matrix, RBC_CME_all_mult.solution.perturbation.first_order.solution_matrix[[1,6,7,10,22:end...],[1,12:14...,16]], atol = 1e-4) + + @test isapprox(RBC_CME_all_mult.solution.perturbation.first_order.solution_matrix, RBC_CME_all_mult.solution.perturbation.linear_time_iteration.solution_matrix, atol = 1e-4) + + get_solution(RBC_CME_all_mult, algorithm = :quadratic_iteration) + + # @test isapprox(RBC_CME.solution.perturbation.first_order.C[:,2], RBC_CME_all_mult.solution.perturbation.first_order.solution_matrix[[1,6,7,10,22:end...],21], atol = 1e-4) + @test isapprox(RBC_CME.solution.perturbation.first_order.solution_matrix, RBC_CME_all_mult.solution.perturbation.quadratic_iteration.solution_matrix[[1,6,7,10,22:end...],[1,12:14...,16]], atol = 1e-4) + # [[1:4...,16:end...],[1,10:12...,14]] + # @test isapprox(RBC_CME_all_mult.solution.perturbation.first_order.solution_matrix, RBC_CME_all_mult.solution.perturbation.linear_time_iteration.solution_matrix, atol = 1e-4) + # @test isapprox(RBC_CME_all_mult.solution.perturbation.first_order.C, RBC_CME_all_mult.solution.perturbation.linear_time_iteration.C, atol = 1e-4) + + RBC_CME_exo_mult = nothing + + + # exo lead >> 1 + @model RBC_CME_exo_lead1 begin + y[0]=A[0]*k[-1]^alpha + 1/c[0]=beta*1/c[1]*(alpha*A[1]*k[0]^(alpha-1)+(1-delta)) + 1/c[0]=beta*1/c[1]*(R[0]/Pi[+1]) + R[0] * beta =(Pi[0]/Pibar)^phi_pi + # A[0]*k[-1]^alpha=c[0]+k[0]-(1-delta)*k[-1] + A[0]*k[-1]^alpha=c[0]+k[0]-(1-delta*z_delta[0])*k[-1] + z_delta[0] = 1 - rho_z_delta + rho_z_delta * z_delta[-1] + std_z_delta * delta_eps[x] + # z[0]=rhoz*z[-1]+std_eps*eps_z[x] + # A[0]=exp(z[0]) + A[0] = 1 - rhoz + rhoz * A[-1] + std_eps * eps_z[x+8] + # ZZ_avg[0] = (A[0] + A[-1] + A[-2] + A[-3]) / 4 + # A_annual[0] = (A[0] + A[-4] + A[-8] + A[-12]) / 4 + # y_avg[0] = log(y[0] / y[-4]) + # y_growth[0] = log(y[1] / y[2]) + # y_growthl[0] = log(y[0] / y[1]) + # y_growthl1[0] = log(y[-1] / y[0]) + # log(A[0]) = rhoz * log(A[-1]) + std_eps * eps_z[x] + end + + + @parameters RBC_CME_exo_lead1 verbose = true begin + # alpha | k[ss] / (4 * y[ss]) = cap_share + # cap_share = 1.66 + alpha = .157 + + # beta | R[ss] = R_ss + # R_ss = 1.0035 + beta = .999 + + # delta | c[ss]/y[ss] = 1 - I_K_ratio + # delta | delta * k[ss]/y[ss] = I_K_ratio #check why this doesnt solve for y + # I_K_ratio = .15 + delta = .0226 + + # Pibar | Pi[ss] = Pi_ss + # Pi_ss = 1.0025 + Pibar = 1.0008 + + phi_pi = 1.5 + rhoz = .9 + std_eps = .0068 + rho_z_delta = .9 + std_z_delta = .005 + end + + get_solution(RBC_CME_exo_lead1) - @parameters RBC_CME_lead_lag20 verbose = true begin - # alpha | k[ss] / (4 * y[ss]) = cap_share - # cap_share = 1.66 - alpha = .157 - - # beta | R[ss] = R_ss - # R_ss = 1.0035 - beta = .999 + get_solution(RBC_CME_exo_lead1, algorithm = :linear_time_iteration) - # delta | c[ss]/y[ss] = 1 - I_K_ratio - # delta | delta * k[ss]/y[ss] = I_K_ratio #check why this doesnt solve for y - # I_K_ratio = .15 - delta = .0226 + # @test isapprox(RBC_CME.solution.perturbation.first_order.C[:,2], RBC_CME_exo_lead1.solution.perturbation.first_order.solution_matrix[[1:4...,13:end...],12], atol = 1e-4) + @test isapprox(RBC_CME.solution.perturbation.first_order.solution_matrix[:,[1:4...]], RBC_CME_exo_lead1.solution.perturbation.first_order.solution_matrix[[1:4...,13:15...],[1:4...]], atol = 1e-4) - # Pibar | Pi[ss] = Pi_ss - # Pi_ss = 1.0025 - Pibar = 1.0008 + @test isapprox(RBC_CME_exo_lead1.solution.perturbation.first_order.solution_matrix, RBC_CME_exo_lead1.solution.perturbation.linear_time_iteration.solution_matrix, atol = 1e-4) - phi_pi = 1.5 - rhoz = .9 - std_eps = .0068 - rho_z_delta = .9 - std_z_delta = .005 - end - - get_solution(RBC_CME_lead_lag20) + get_solution(RBC_CME_exo_lead1, algorithm = :quadratic_iteration) - @test RBC_CME.solution.perturbation.first_order.solution_matrix ≈ RBC_CME_lead_lag20.solution.perturbation.first_order.solution_matrix[[1,20,21,(26:29)...],[1,11:end...]] - # @test RBC_CME.solution.perturbation.first_order.C ≈ RBC_CME_lead_lag20.solution.perturbation.first_order.C[[1,20,21,(26:29)...],:] + # @test isapprox(RBC_CME.solution.perturbation.first_order.C[:,2], RBC_CME_exo_lead1.solution.perturbation.first_order.solution_matrix[[1:4...,13:end...],12], atol = 1e-4) + @test isapprox(RBC_CME.solution.perturbation.first_order.solution_matrix[:,[1:4...]], RBC_CME_exo_lead1.solution.perturbation.quadratic_iteration.solution_matrix[[1:4...,13:15...],[1:4...]], atol = 1e-4) - get_solution(RBC_CME_lead_lag20, algorithm = :linear_time_iteration) + # @test isapprox(RBC_CME_exo_lead1.solution.perturbation.first_order.solution_matrix, RBC_CME_exo_lead1.solution.perturbation.linear_time_iteration.solution_matrix, atol = 1e-4) + # @test isapprox(RBC_CME_exo_lead1.solution.perturbation.first_order.C, RBC_CME_exo_lead1.solution.perturbation.linear_time_iteration.C, atol = 1e-4) - @test isapprox(RBC_CME_lead_lag20.solution.perturbation.first_order.solution_matrix, RBC_CME_lead_lag20.solution.perturbation.linear_time_iteration.solution_matrix, atol = 1e-4) - # @test isapprox(RBC_CME_lead_lag20.solution.perturbation.first_order.C, RBC_CME_lead_lag20.solution.perturbation.linear_time_iteration.C, atol = 1e-4) + RBC_CME_exo_lead1 = nothing - get_solution(RBC_CME_lead_lag20, algorithm = :quadratic_iteration) - @test isapprox(RBC_CME_lead_lag20.solution.perturbation.first_order.solution_matrix, RBC_CME_lead_lag20.solution.perturbation.quadratic_iteration.solution_matrix, atol = 1e-4) - RBC_CME_lead_lag20 = nothing -end + # exo multi lag >> 1 + @model RBC_CME_exo_lag_mult begin + y[0]=A[0]*k[-1]^alpha + 1/c[0]=beta*1/c[1]*(alpha*A[1]*k[0]^(alpha-1)+(1-delta)) + 1/c[0]=beta*1/c[1]*(R[0]/Pi[+1]) + R[0] * beta =(Pi[0]/Pibar)^phi_pi + # A[0]*k[-1]^alpha=c[0]+k[0]-(1-delta)*k[-1] + A[0]*k[-1]^alpha=c[0]+k[0]-(1-delta*z_delta[0])*k[-1] + z_delta[0] = 1 - rho_z_delta + rho_z_delta * z_delta[-1] + std_z_delta * delta_eps[x] + # z[0]=rhoz*z[-1]+std_eps*eps_z[x] + # A[0]=exp(z[0]) + A[0] = 1 - rhoz + rhoz * A[-1] + std_eps * (eps_z[x-8] + eps_z[x-4] + eps_z_s[x]) + # ZZ_avg[0] = (A[0] + A[-1] + A[-2] + A[-3]) / 4 + # A_annual[0] = (A[0] + A[-4] + A[-8] + A[-12]) / 4 + # y_avg[0] = log(y[0] / y[-4]) + # y_growth[0] = log(y[1] / y[2]) + # y_growthl[0] = log(y[0] / y[1]) + # y_growthl1[0] = log(y[-1] / y[0]) + # log(A[0]) = rhoz * log(A[-1]) + std_eps * eps_z[x] + end -@testset verbose = true "Steady state RBC CME model" begin - # Basic test - @model RBC_CME begin - y[0]=A[0]*k[-1]^alpha - 1/c[0]=beta*1/c[1]*(alpha*A[1]*k[0]^(alpha-1)+(1-delta)) - 1/c[0]=beta*1/c[1]*(R[0]/Pi[+1]) - R[0] * beta =(Pi[0]/Pibar)^phi_pi - # A[0]*k[-1]^alpha=c[0]+k[0]-(1-delta)*k[-1] - A[0]*k[-1]^alpha=c[0]+k[0]-(1-delta*z_delta[0])*k[-1] - z_delta[0] = 1 - rho_z_delta + rho_z_delta * z_delta[-1] + std_z_delta * delta_eps[x] - # z[0]=rhoz*z[-1]+std_eps*eps_z[x] - # A[0]=exp(z[0]) - A[0] = 1 - rhoz + rhoz * A[-1] + std_eps * eps_z[x] - # A_avg[0] = (A[0] + A[-1] + A[-2] + A[-3]) / 4 - # A_annual[0] = (A[0] + A[-4] + A[-8] + A[-12]) / 4 - # y_avg[0] = log(y[0] / y[-4]) - # y_growth[0] = log(y[1] / y[2]) - # y_growthl[0] = log(y[0] / y[1]) - # y_growthl1[0] = log(y[-1] / y[0]) - # log(A[0]) = rhoz * log(A[-1]) + std_eps * eps_z[x] - end + @parameters RBC_CME_exo_lag_mult verbose = true begin + # alpha | k[ss] / (4 * y[ss]) = cap_share + # cap_share = 1.66 + alpha = .157 + # beta | R[ss] = R_ss + # R_ss = 1.0035 + beta = .999 - @parameters RBC_CME verbose = true begin - # alpha | k[ss] / (4 * y[ss]) = cap_share - # cap_share = 1.66 - alpha = .157 + # delta | c[ss]/y[ss] = 1 - I_K_ratio + # delta | delta * k[ss]/y[ss] = I_K_ratio #check why this doesnt solve for y + # I_K_ratio = .15 + delta = .0226 - # beta | R[ss] = R_ss - # R_ss = 1.0035 - beta = .999 + # Pibar | Pi[ss] = Pi_ss + # Pi_ss = 1.0025 + Pibar = 1.0008 - # delta | c[ss]/y[ss] = 1 - I_K_ratio - # delta | delta * k[ss]/y[ss] = I_K_ratio #check why this doesnt solve for y - # I_K_ratio = .15 - delta = .0226 + phi_pi = 1.5 + rhoz = .9 + std_eps = .0068 + rho_z_delta = .9 + std_z_delta = .005 + end + + get_solution(RBC_CME_exo_lag_mult) - # Pibar | Pi[ss] = Pi_ss - # Pi_ss = 1.0025 - Pibar = 1.0008 + get_solution(RBC_CME_exo_lag_mult, algorithm = :linear_time_iteration) - phi_pi = 1.5 - rhoz = .9 - std_eps = .0068 - rho_z_delta = .9 - std_z_delta = .005 - end - # get_steady_state(RBC_CME)[1] - # using NLopt - # RBC_CME.SS_optimizer = NLopt.LD_LBFGS - # solve!(RBC_CME) - @test get_steady_state(RBC_CME)(RBC_CME.var,:Steady_state) ≈ [1.0, 1.0024019205374952, 1.003405325870413, 1.2092444352939415, 9.467573947982233, 1.42321160651834, 1.0] - # get_moments(RBC_CME)[1] - # irf(RBC_CME) - - RBC_CME = nothing + # @test isapprox(RBC_CME.solution.perturbation.first_order.C[:,2], RBC_CME_exo_lag_mult.solution.perturbation.first_order.solution_matrix[[1:4...,13:end...],12], atol = 1e-4) + @test isapprox(RBC_CME.solution.perturbation.first_order.solution_matrix, RBC_CME_exo_lag_mult.solution.perturbation.first_order.solution_matrix[[1:4...,13:15...],[1,10:12...,14]], atol = 1e-4) - - # Symbolic test - @model RBC_CME begin - y[0]=A[0]*k[-1]^alpha - 1/c[0]=beta*1/c[1]*(alpha*A[1]*k[0]^(alpha-1)+(1-delta)) - 1/c[0]=beta*1/c[1]*(R[0]/Pi[+1]) - R[0] * beta =(Pi[0]/Pibar)^phi_pi - # A[0]*k[-1]^alpha=c[0]+k[0]-(1-delta)*k[-1] - A[0]*k[-1]^alpha=c[0]+k[0]-(1-delta*z_delta[0])*k[-1] - z_delta[0] = 1 - rho_z_delta + rho_z_delta * z_delta[-1] + std_z_delta * delta_eps[x] - # z[0]=rhoz*z[-1]+std_eps*eps_z[x] - # A[0]=exp(z[0]) - A[0] = 1 - rhoz + rhoz * A[-1] + std_eps * eps_z[x] - # log(A[0]) = rhoz * log(A[-1]) + std_eps * eps_z[x] - end + @test isapprox(RBC_CME_exo_lag_mult.solution.perturbation.first_order.solution_matrix, RBC_CME_exo_lag_mult.solution.perturbation.linear_time_iteration.solution_matrix, atol = 1e-4) + get_solution(RBC_CME_exo_lag_mult, algorithm = :quadratic_iteration) - @parameters RBC_CME symbolic = true verbose = true begin - # alpha | k[ss] / (4 * y[ss]) = cap_share - # cap_share = 1.66 - alpha = .157 - - # beta | R[ss] = R_ss - # R_ss = 1.0035 - beta = .999 - - # delta | c[ss]/y[ss] = 1 - I_K_ratio - # delta | delta * k[ss]/y[ss] = I_K_ratio #check why this doesnt solve for y - # I_K_ratio = .15 - delta = .0226 - - # Pibar | Pi[ss] = Pi_ss - # Pi_ss = 1.0025 - Pibar = 1.0008 - - phi_pi = 1.5 - rhoz = .9 - std_eps = .0068 - rho_z_delta = .9 - std_z_delta = .005 - - # cap_share > 0 - # R_ss > 0 - # Pi_ss > 0 - # I_K_ratio > 0 - - # 0 < alpha < 1 - 0 < beta < 1 - # 0 < delta < 1 - 0 < Pibar - # 0 <= rhoz < 1 - phi_pi > 0 - - # 0 < A < 1 - # 0 < k < 50 - 0 < Pi - 0 < R - end - # get_steady_state(RBC_CME)[1] - # using NLopt - # RBC_CME.SS_optimizer = NLopt.LD_LBFGS - # solve!(RBC_CME,symbolic_SS = true) - @test get_steady_state(RBC_CME)(RBC_CME.var,:Steady_state) ≈ [1.0, 1.0024019205374952, 1.003405325870413, 1.2092444352939415, 9.467573947982233, 1.42321160651834, 1.0] - # get_moments(RBC_CME)[1] + @test isapprox(RBC_CME_exo_lag_mult.solution.perturbation.first_order.solution_matrix, RBC_CME_exo_lag_mult.solution.perturbation.quadratic_iteration.solution_matrix, atol = 1e-4) + # @test isapprox(RBC_CME_exo_lag_mult.solution.perturbation.first_order.C, RBC_CME_exo_lag_mult.solution.perturbation.linear_time_iteration.C, atol = 1e-4) - RBC_CME = nothing + # irf(RBC_CME_exo_lag_mult) + # irf(RBC_CME) + # irf(RBC_CME_exo_lag1) + RBC_CME_exo_lag_mult = nothing - # Numerical test with calibration targets - @model RBC_CME begin - y[0]=A[0]*k[-1]^alpha - 1/c[0]=beta*1/c[1]*(alpha*A[1]*k[0]^(alpha-1)+(1-delta)) - 1/c[0]=beta*1/c[1]*(R[0]/Pi[+1]) - R[0] * beta =(Pi[0]/Pibar)^phi_pi - # A[0]*k[-1]^alpha=c[0]+k[0]-(1-delta)*k[-1] - A[0]*k[-1]^alpha=c[0]+k[0]-(1-delta*z_delta[0])*k[-1] - z_delta[0] = 1 - rho_z_delta + rho_z_delta * z_delta[-1] + std_z_delta * delta_eps[x] - # z[0]=rhoz*z[-1]+std_eps*eps_z[x] - # A[0]=exp(z[0]) - A[0] = 1 - rhoz + rhoz * A[-1] + std_eps * eps_z[x] - # log(A[0]) = rhoz * log(A[-1]) + std_eps * eps_z[x] - end + # exo lag >> 1 + @model RBC_CME_exo_lag1 begin + y[0]=A[0]*k[-1]^alpha + 1/c[0]=beta*1/c[1]*(alpha*A[1]*k[0]^(alpha-1)+(1-delta)) + 1/c[0]=beta*1/c[1]*(R[0]/Pi[+1]) + R[0] * beta =(Pi[0]/Pibar)^phi_pi + # A[0]*k[-1]^alpha=c[0]+k[0]-(1-delta)*k[-1] + A[0]*k[-1]^alpha=c[0]+k[0]-(1-delta*z_delta[0])*k[-1] + z_delta[0] = 1 - rho_z_delta + rho_z_delta * z_delta[-1] + std_z_delta * delta_eps[x] + # z[0]=rhoz*z[-1]+std_eps*eps_z[x] + # A[0]=exp(z[0]) + A[0] = 1 - rhoz + rhoz * A[-1] + std_eps * eps_z[x-8] + # ZZ_avg[0] = (A[0] + A[-1] + A[-2] + A[-3]) / 4 + # A_annual[0] = (A[0] + A[-4] + A[-8] + A[-12]) / 4 + # y_avg[0] = log(y[0] / y[-4]) + # y_growth[0] = log(y[1] / y[2]) + # y_growthl[0] = log(y[0] / y[1]) + # y_growthl1[0] = log(y[-1] / y[0]) + # log(A[0]) = rhoz * log(A[-1]) + std_eps * eps_z[x] + end - @parameters RBC_CME verbose = true begin - alpha | k[ss] / (4 * y[ss]) = cap_share - cap_share = 1.66 - # alpha = .157 - beta | R[ss] = R_ss # beta needs to enter into function: block in order to solve - R_ss = 1.0035 - # beta = .999 + @parameters RBC_CME_exo_lag1 verbose = true begin + # alpha | k[ss] / (4 * y[ss]) = cap_share + # cap_share = 1.66 + alpha = .157 - # delta | c[ss]/y[ss] = 1 - I_K_ratio - delta | delta * k[ss] / y[ss] = I_K_ratio #check why this doesnt solve for y; because delta is not recognised as a free parameter here. - I_K_ratio = .15 - # delta = .0226 + # beta | R[ss] = R_ss + # R_ss = 1.0035 + beta = .999 - Pibar | Pi[ss] = Pi_ss - Pi_ss = 1.0025 - # Pibar = 1.0008 + # delta | c[ss]/y[ss] = 1 - I_K_ratio + # delta | delta * k[ss]/y[ss] = I_K_ratio #check why this doesnt solve for y + # I_K_ratio = .15 + delta = .0226 - phi_pi = 1.5 - rhoz = .9 - std_eps = .0068 - rho_z_delta = .9 - std_z_delta = .005 + # Pibar | Pi[ss] = Pi_ss + # Pi_ss = 1.0025 + Pibar = 1.0008 + phi_pi = 1.5 + rhoz = .9 + std_eps = .0068 + rho_z_delta = .9 + std_z_delta = .005 + end - # cap_share > 0 - # R_ss > 0 - # Pi_ss > 0 - # I_K_ratio > 0 - - # 0 < alpha < 1 - # 0 < beta < 1 - # 0 < delta < 1 - # 0 < Pibar - # 0 <= rhoz < 1 - # phi_pi > 0 - - # 0 < A < 1 - # 0 < k < 50 - # 0 < y < 10 - # 0 < c < 10 - end - # get_steady_state(RBC_CME)[1] - # using NLopt - # RBC_CME.SS_optimizer = NLopt.LD_LBFGS - # solve!(RBC_CME, verbose = true) - # RBC_CME.SS_init_guess[1:7] = [1.0, 1.0025, 1.0035, 1.2081023828249515, 9.437411555244328, 1.4212969209705313, 1.0] - # get_steady_state(RBC_CME) - @test get_steady_state(RBC_CME, verbose = true)(RBC_CME.var,:Steady_state) ≈ [1.0, 1.0025, 1.0035, 1.2081023824176236, 9.437411552284384, 1.4212969205027686, 1.0] - # get_moments(RBC_CME)[1] - - # RBC_CME.ss_solve_blocks[1]([0.15662344139650963, 1.2081023828249515, 0.02259036144578319, 9.437411555244328, 1.4212969209705313],RBC_CME) - - RBC_CME = nothing - - - # Symbolic test with calibration targets - @model RBC_CME begin - y[0]=A[0]*k[-1]^alpha - 1/c[0]=beta*1/c[1]*(alpha*A[1]*k[0]^(alpha-1)+(1-delta)) - 1/c[0]=beta*1/c[1]*(R[0]/Pi[+1]) - R[0] * beta =(Pi[0]/Pibar)^phi_pi - # A[0]*k[-1]^alpha=c[0]+k[0]-(1-delta)*k[-1] - A[0]*k[-1]^alpha=c[0]+k[0]-(1-delta*z_delta[0])*k[-1] - z_delta[0] = 1 - rho_z_delta + rho_z_delta * z_delta[-1] + std_z_delta * delta_eps[x] - # z[0]=rhoz*z[-1]+std_eps*eps_z[x] - # A[0]=exp(z[0]) - A[0] = 1 - rhoz + rhoz * A[-1] + std_eps * eps_z[x] - # log(A[0]) = rhoz * log(A[-1]) + std_eps * eps_z[x] - end + get_solution(RBC_CME_exo_lag1) + + get_solution(RBC_CME_exo_lag1, algorithm = :linear_time_iteration) + + # @test isapprox(RBC_CME.solution.perturbation.first_order.C[:,2], RBC_CME_exo_lag1.solution.perturbation.first_order.solution_matrix[[1:4...,13:end...],12], atol = 1e-4) + @test isapprox(RBC_CME.solution.perturbation.first_order.solution_matrix, RBC_CME_exo_lag1.solution.perturbation.first_order.solution_matrix[[1:4...,13:end...],[1,10:12...,9]], atol = 1e-4) + + @test isapprox(RBC_CME_exo_lag1.solution.perturbation.first_order.solution_matrix, RBC_CME_exo_lag1.solution.perturbation.linear_time_iteration.solution_matrix, atol = 1e-4) + # @test isapprox(RBC_CME_exo_lag1.solution.perturbation.first_order.C, RBC_CME_exo_lag1.solution.perturbation.linear_time_iteration.C, atol = 1e-4) + + get_solution(RBC_CME_exo_lag1, algorithm = :quadratic_iteration) + + @test isapprox(RBC_CME_exo_lag1.solution.perturbation.first_order.solution_matrix, RBC_CME_exo_lag1.solution.perturbation.quadratic_iteration.solution_matrix, atol = 1e-4) + + RBC_CME_exo_lag1 = nothing + + + # exo lead > 1 + @model RBC_CME_exo_lead begin + y[0]=A[0]*k[-1]^alpha + 1/c[0]=beta*1/c[1]*(alpha*A[1]*k[0]^(alpha-1)+(1-delta)) + 1/c[0]=beta*1/c[1]*(R[0]/Pi[+1]) + R[0] * beta =(Pi[0]/Pibar)^phi_pi + # A[0]*k[-1]^alpha=c[0]+k[0]-(1-delta)*k[-1] + A[0]*k[-1]^alpha=c[0]+k[0]-(1-delta*z_delta[0])*k[-1] + z_delta[0] = 1 - rho_z_delta + rho_z_delta * z_delta[-1] + std_z_delta * delta_eps[x] + # z[0]=rhoz*z[-1]+std_eps*eps_z[x] + # A[0]=exp(z[0]) + A[0] = 1 - rhoz + rhoz * A[-1] + std_eps * eps_z[x+1] + # ZZ_avg[0] = (A[0] + A[-1] + A[-2] + A[-3]) / 4 + # A_annual[0] = (A[0] + A[-4] + A[-8] + A[-12]) / 4 + # y_avg[0] = log(y[0] / y[-4]) + # y_growth[0] = log(y[1] / y[2]) + # y_growthl[0] = log(y[0] / y[1]) + # y_growthl1[0] = log(y[-1] / y[0]) + # log(A[0]) = rhoz * log(A[-1]) + std_eps * eps_z[x] + end + + + @parameters RBC_CME_exo_lead verbose = true begin + # alpha | k[ss] / (4 * y[ss]) = cap_share + # cap_share = 1.66 + alpha = .157 + + # beta | R[ss] = R_ss + # R_ss = 1.0035 + beta = .999 + + # delta | c[ss]/y[ss] = 1 - I_K_ratio + # delta | delta * k[ss]/y[ss] = I_K_ratio #check why this doesnt solve for y + # I_K_ratio = .15 + delta = .0226 + + # Pibar | Pi[ss] = Pi_ss + # Pi_ss = 1.0025 + Pibar = 1.0008 + + phi_pi = 1.5 + rhoz = .9 + std_eps = .0068 + rho_z_delta = .9 + std_z_delta = .005 + end + + get_solution(RBC_CME_exo_lead) + + get_solution(RBC_CME_exo_lead, algorithm = :linear_time_iteration) + + # @test isapprox(RBC_CME.solution.perturbation.first_order.C[:,2], RBC_CME_exo_lead.solution.perturbation.first_order.solution_matrix[[1:4...,6:8...],5], atol = 1e-4) + @test isapprox(RBC_CME.solution.perturbation.first_order.solution_matrix[:,[1:(end-1)...]], RBC_CME_exo_lead.solution.perturbation.first_order.solution_matrix[[1:4...,6:end...],[1:(end-1)...]], atol = 1e-4) + + @test isapprox(RBC_CME_exo_lead.solution.perturbation.first_order.solution_matrix, RBC_CME_exo_lead.solution.perturbation.linear_time_iteration.solution_matrix, atol = 1e-4) + # @test isapprox(RBC_CME_exo_lead.solution.perturbation.first_order.C, RBC_CME_exo_lead.solution.perturbation.linear_time_iteration.C, atol = 1e-4) + + get_solution(RBC_CME_exo_lead, algorithm = :quadratic_iteration) + + @test isapprox(RBC_CME_exo_lead.solution.perturbation.first_order.solution_matrix, RBC_CME_exo_lead.solution.perturbation.quadratic_iteration.solution_matrix, atol = 1e-4) + + RBC_CME_exo_lead = nothing + + + # exo lag > 1 + @model RBC_CME_exo_lag begin + y[0]=A[0]*k[-1]^alpha + 1/c[0]=beta*1/c[1]*(alpha*A[1]*k[0]^(alpha-1)+(1-delta)) + 1/c[0]=beta*1/c[1]*(R[0]/Pi[+1]) + R[0] * beta =(Pi[0]/Pibar)^phi_pi + # A[0]*k[-1]^alpha=c[0]+k[0]-(1-delta)*k[-1] + A[0]*k[-1]^alpha=c[0]+k[0]-(1-delta*z_delta[0])*k[-1] + z_delta[0] = 1 - rho_z_delta + rho_z_delta * z_delta[-1] + std_z_delta * delta_eps[x] + # z[0]=rhoz*z[-1]+std_eps*eps_z[x] + # A[0]=exp(z[0]) + A[0] = 1 - rhoz + rhoz * A[-1] + std_eps * eps_z[x-1] + # ZZ_avg[0] = (A[0] + A[-1] + A[-2] + A[-3]) / 4 + # A_annual[0] = (A[0] + A[-4] + A[-8] + A[-12]) / 4 + # y_avg[0] = log(y[0] / y[-4]) + # y_growth[0] = log(y[1] / y[2]) + # y_growthl[0] = log(y[0] / y[1]) + # y_growthl1[0] = log(y[-1] / y[0]) + # log(A[0]) = rhoz * log(A[-1]) + std_eps * eps_z[x] + end + + + @parameters RBC_CME_exo_lag verbose = true begin + # alpha | k[ss] / (4 * y[ss]) = cap_share + # cap_share = 1.66 + alpha = .157 + + # beta | R[ss] = R_ss + # R_ss = 1.0035 + beta = .999 + + # delta | c[ss]/y[ss] = 1 - I_K_ratio + # delta | delta * k[ss]/y[ss] = I_K_ratio #check why this doesnt solve for y + # I_K_ratio = .15 + delta = .0226 + + # Pibar | Pi[ss] = Pi_ss + # Pi_ss = 1.0025 + Pibar = 1.0008 + + phi_pi = 1.5 + rhoz = .9 + std_eps = .0068 + rho_z_delta = .9 + std_z_delta = .005 + end + + get_solution(RBC_CME_exo_lag) + + get_solution(RBC_CME_exo_lag, algorithm = :linear_time_iteration) + + # @test isapprox(RBC_CME.solution.perturbation.first_order.C[:,2], RBC_CME_exo_lag.solution.perturbation.first_order.solution_matrix[[1:4...,6:8...],5], atol = 1e-4) + @test isapprox(RBC_CME.solution.perturbation.first_order.solution_matrix, RBC_CME_exo_lag.solution.perturbation.first_order.solution_matrix[[1:4...,6:end...],[1,3,4,5,2]], atol = 1e-4) + + @test isapprox(RBC_CME_exo_lag.solution.perturbation.first_order.solution_matrix, RBC_CME_exo_lag.solution.perturbation.linear_time_iteration.solution_matrix, atol = 1e-4) + # @test isapprox(RBC_CME_exo_lag.solution.perturbation.first_order.C, RBC_CME_exo_lag.solution.perturbation.linear_time_iteration.C, atol = 1e-4) + + get_solution(RBC_CME_exo_lag, algorithm = :quadratic_iteration) + + @test isapprox(RBC_CME_exo_lag.solution.perturbation.first_order.solution_matrix, RBC_CME_exo_lag.solution.perturbation.quadratic_iteration.solution_matrix, atol = 1e-4) + + RBC_CME_exo_lag = nothing + + # Lags > 1 + @model RBC_CME_lag begin + y[0]=A[0]*k[-1]^alpha + 1/c[0]=beta*1/c[1]*(alpha*A[1]*k[0]^(alpha-1)+(1-delta)) + 1/c[0]=beta*1/c[1]*(R[0]/Pi[+1]) + R[0] * beta =(Pi[0]/Pibar)^phi_pi + # A[0]*k[-1]^alpha=c[0]+k[0]-(1-delta)*k[-1] + A[0]*k[-1]^alpha=c[0]+k[0]-(1-delta*z_delta[0])*k[-1] + z_delta[0] = 1 - rho_z_delta + rho_z_delta * z_delta[-1] + std_z_delta * delta_eps[x] + # z[0]=rhoz*z[-1]+std_eps*eps_z[x] + # A[0]=exp(z[0]) + A[0] = 1 - rhoz + rhoz * A[-1] + std_eps * eps_z[x] + ZZ_avg[0] = (A[0] + A[-1] + A[-2] + A[-3]) / 4 + ZZ_dev[0] = log(c[0]/c[ss]) + # A_annual[0] = (A[0] + A[-4] + A[-8] + A[-12]) / 4 + # y_avg[0] = log(y[0] / y[-4]) + # y_growth[0] = log(y[1] / y[2]) + # y_growthl[0] = log(y[0] / y[1]) + # y_growthl1[0] = log(y[-1] / y[0]) + # log(A[0]) = rhoz * log(A[-1]) + std_eps * eps_z[x] + end + + + @parameters RBC_CME_lag verbose = true begin + # alpha | k[ss] / (4 * y[ss]) = cap_share + # cap_share = 1.66 + alpha = .157 + + # beta | R[ss] = R_ss + # R_ss = 1.0035 + beta = .999 + + # delta | c[ss]/y[ss] = 1 - I_K_ratio + # delta | delta * k[ss]/y[ss] = I_K_ratio #check why this doesnt solve for y + # I_K_ratio = .15 + delta = .0226 + + # Pibar | Pi[ss] = Pi_ss + # Pi_ss = 1.0025 + Pibar = 1.0008 + + phi_pi = 1.5 + rhoz = .9 + std_eps = .0068 + rho_z_delta = .9 + std_z_delta = .005 + end + + get_solution(RBC_CME_lag) + + @test RBC_CME.solution.perturbation.first_order.solution_matrix ≈ RBC_CME_lag.solution.perturbation.first_order.solution_matrix[[1,4,5,8:11...],[1,4:end...]] + # @test RBC_CME.solution.perturbation.first_order.C ≈ RBC_CME_lag.solution.perturbation.first_order.C[[1,4,5,8:11...],:] + + get_solution(RBC_CME_lag, algorithm = :linear_time_iteration) + + @test isapprox(RBC_CME_lag.solution.perturbation.first_order.solution_matrix, RBC_CME_lag.solution.perturbation.linear_time_iteration.solution_matrix, atol = 1e-4) + # @test isapprox(RBC_CME_lag.solution.perturbation.first_order.C, RBC_CME_lag.solution.perturbation.linear_time_iteration.C, atol = 1e-4) + + get_solution(RBC_CME_lag, algorithm = :quadratic_iteration) + + @test isapprox(RBC_CME_lag.solution.perturbation.first_order.solution_matrix, RBC_CME_lag.solution.perturbation.quadratic_iteration.solution_matrix, atol = 1e-4) + + RBC_CME_lag = nothing + + # Leads > 1 + @model RBC_CME_lead begin + y[0]=A[0]*k[-1]^alpha + 1/c[0]=beta*1/c[1]*(alpha*A[1]*k[0]^(alpha-1)+(1-delta)) + 1/c[0]=beta*1/c[1]*(R[0]/Pi[+1]) + R[0] * beta =(Pi[0]/Pibar)^phi_pi + # A[0]*k[-1]^alpha=c[0]+k[0]-(1-delta)*k[-1] + A[0]*k[-1]^alpha=c[0]+k[0]-(1-delta*z_delta[0])*k[-1] + z_delta[0] = 1 - rho_z_delta + rho_z_delta * z_delta[-1] + std_z_delta * delta_eps[x] + # z[0]=rhoz*z[-1]+std_eps*eps_z[x] + # A[0]=exp(z[0]) + A[0] = 1 - rhoz + rhoz * A[-1] + std_eps * eps_z[x] + ZZ_avg[0] = (A[0] + A[1] + A[2] + A[3]) / 4 + ZZ_dev[0] = log(c[0]/c[ss]) + # A_annual[0] = (A[0] + A[-4] + A[-8] + A[-12]) / 4 + # y_avg[0] = log(y[0] / y[-4]) + # y_growth[0] = log(y[1] / y[2]) + # y_growthl[0] = log(y[0] / y[1]) + # y_growthl1[0] = log(y[-1] / y[0]) + # log(A[0]) = rhoz * log(A[-1]) + std_eps * eps_z[x] + end + + @parameters RBC_CME_lead verbose = true begin + # alpha | k[ss] / (4 * y[ss]) = cap_share + # cap_share = 1.66 + alpha = .157 + + # beta | R[ss] = R_ss + # R_ss = 1.0035 + beta = .999 + + # delta | c[ss]/y[ss] = 1 - I_K_ratio + # delta | delta * k[ss]/y[ss] = I_K_ratio #check why this doesnt solve for y + # I_K_ratio = .15 + delta = .0226 + + # Pibar | Pi[ss] = Pi_ss + # Pi_ss = 1.0025 + Pibar = 1.0008 + + phi_pi = 1.5 + rhoz = .9 + std_eps = .0068 + rho_z_delta = .9 + std_z_delta = .005 + end + + get_solution(RBC_CME_lead) + + @test RBC_CME.solution.perturbation.first_order.solution_matrix ≈ RBC_CME_lead.solution.perturbation.first_order.solution_matrix[[1,4,5,8:11...],:] + # @test RBC_CME.solution.perturbation.first_order.C ≈ RBC_CME_lead.solution.perturbation.first_order.C[[1,4,5,8:11...],:] + + get_solution(RBC_CME_lead, algorithm = :linear_time_iteration) + + @test isapprox(RBC_CME_lead.solution.perturbation.first_order.solution_matrix, RBC_CME_lead.solution.perturbation.linear_time_iteration.solution_matrix, atol = 1e-4) + # @test isapprox(RBC_CME_lead.solution.perturbation.first_order.C, RBC_CME_lead.solution.perturbation.linear_time_iteration.C, atol = 1e-4) + + get_solution(RBC_CME_lead, algorithm = :quadratic_iteration) + + @test isapprox(RBC_CME_lead.solution.perturbation.first_order.solution_matrix, RBC_CME_lead.solution.perturbation.quadratic_iteration.solution_matrix, atol = 1e-4) + + RBC_CME_lead = nothing + + + # Leads and lags > 1 + @model RBC_CME_lead_lag begin + y[0]=A[0]*k[-1]^alpha + 1/c[0]=beta*1/c[1]*(alpha*A[1]*k[0]^(alpha-1)+(1-delta)) + 1/c[0]=beta*1/c[1]*(R[0]/Pi[+1]) + R[0] * beta =(Pi[0]/Pibar)^phi_pi + # A[0]*k[-1]^alpha=c[0]+k[0]-(1-delta)*k[-1] + A[0]*k[-1]^alpha=c[0]+k[0]-(1-delta*z_delta[0])*k[-1] + z_delta[0] = 1 - rho_z_delta + rho_z_delta * z_delta[-1] + std_z_delta * delta_eps[x] + # z[0]=rhoz*z[-1]+std_eps*eps_z[x] + # A[0]=exp(z[0]) + A[0] = 1 - rhoz + rhoz * A[-1] + std_eps * eps_z[x] + ZZ_avg_f[0] = (A[0] + A[1] + A[2] + A[3]) / 4 + ZZ_avg_b[0] = (A[0] + A[-1] + A[-2] + A[-3]) / 4 + # A_annual[0] = (A[0] + A[-4] + A[-8] + A[-12]) / 4 + # y_avg[0] = log(y[0] / y[-4]) + # y_growth[0] = log(y[1] / y[2]) + # y_growthl[0] = log(y[0] / y[1]) + # y_growthl1[0] = log(y[-1] / y[0]) + # log(A[0]) = rhoz * log(A[-1]) + std_eps * eps_z[x] + end + + + @parameters RBC_CME_lead_lag verbose = true begin + # alpha | k[ss] / (4 * y[ss]) = cap_share + # cap_share = 1.66 + alpha = .157 + + # beta | R[ss] = R_ss + # R_ss = 1.0035 + beta = .999 + + # delta | c[ss]/y[ss] = 1 - I_K_ratio + # delta | delta * k[ss]/y[ss] = I_K_ratio #check why this doesnt solve for y + # I_K_ratio = .15 + delta = .0226 + + # Pibar | Pi[ss] = Pi_ss + # Pi_ss = 1.0025 + Pibar = 1.0008 + + phi_pi = 1.5 + rhoz = .9 + std_eps = .0068 + rho_z_delta = .9 + std_z_delta = .005 + end + + get_solution(RBC_CME_lead_lag) + + @test RBC_CME.solution.perturbation.first_order.solution_matrix ≈ RBC_CME_lead_lag.solution.perturbation.first_order.solution_matrix[[1,6,7,10:13...],[1,4:end...]] + # @test RBC_CME.solution.perturbation.first_order.C ≈ RBC_CME_lead_lag.solution.perturbation.first_order.C[[1,6,7,(10:13)...],:] + + get_solution(RBC_CME_lead_lag, algorithm = :linear_time_iteration) + + @test isapprox(RBC_CME_lead_lag.solution.perturbation.first_order.solution_matrix, RBC_CME_lead_lag.solution.perturbation.linear_time_iteration.solution_matrix, atol = 1e-4) + # @test isapprox(RBC_CME_lead_lag.solution.perturbation.first_order.C, RBC_CME_lead_lag.solution.perturbation.linear_time_iteration.C, atol = 1e-4) + + get_solution(RBC_CME_lead_lag, algorithm = :quadratic_iteration) + + @test isapprox(RBC_CME_lead_lag.solution.perturbation.first_order.solution_matrix, RBC_CME_lead_lag.solution.perturbation.quadratic_iteration.solution_matrix, atol = 1e-4) + + RBC_CME_lead_lag = nothing + + + # Leads and lags > 10 + @model RBC_CME_lead_lag10 begin + y[0]=A[0]*k[-1]^alpha + 1/c[0]=beta*1/c[1]*(alpha*A[1]*k[0]^(alpha-1)+(1-delta)) + 1/c[0]=beta*1/c[1]*(R[0]/Pi[+1]) + R[0] * beta =(Pi[0]/Pibar)^phi_pi + # A[0]*k[-1]^alpha=c[0]+k[0]-(1-delta)*k[-1] + A[0]*k[-1]^alpha=c[0]+k[0]-(1-delta*z_delta[0])*k[-1] + z_delta[0] = 1 - rho_z_delta + rho_z_delta * z_delta[-1] + std_z_delta * delta_eps[x] + # z[0]=rhoz*z[-1]+std_eps*eps_z[x] + # A[0]=exp(z[0]) + A[0] = 1 - rhoz + rhoz * A[-1] + std_eps * eps_z[x] + ZZ_avg_f[0] = (A[0] + A[1] + A[2] + A[3]) / 4 + ZZ_avg_b[0] = (A[0] + A[-1] + A[-2] + A[-3]) / 4 + ZZ_avg_f10[0] = (A[0] + A[10]) / 2 + # ZZ_avg_b10[0] = (A[0] + A[-10]) / 2 + # A_annual[0] = (A[0] + A[-4] + A[-8] + A[-12]) / 4 + # y_avg[0] = log(y[0] / y[-4]) + # y_growth[0] = log(y[1] / y[2]) + # y_growthl[0] = log(y[0] / y[1]) + # y_growthl1[0] = log(y[-1] / y[0]) + # log(A[0]) = rhoz * log(A[-1]) + std_eps * eps_z[x] + end + + + @parameters RBC_CME_lead_lag10 verbose = true begin + # alpha | k[ss] / (4 * y[ss]) = cap_share + # cap_share = 1.66 + alpha = .157 + + # beta | R[ss] = R_ss + # R_ss = 1.0035 + beta = .999 + + # delta | c[ss]/y[ss] = 1 - I_K_ratio + # delta | delta * k[ss]/y[ss] = I_K_ratio #check why this doesnt solve for y + # I_K_ratio = .15 + delta = .0226 + + # Pibar | Pi[ss] = Pi_ss + # Pi_ss = 1.0025 + Pibar = 1.0008 + + phi_pi = 1.5 + rhoz = .9 + std_eps = .0068 + rho_z_delta = .9 + std_z_delta = .005 + end + + get_solution(RBC_CME_lead_lag10) + + @test RBC_CME.solution.perturbation.first_order.solution_matrix ≈ RBC_CME_lead_lag10.solution.perturbation.first_order.solution_matrix[[1,13,14,18:21...],[1,4:end...]] + # @test RBC_CME.solution.perturbation.first_order.C ≈ RBC_CME_lead_lag10.solution.perturbation.first_order.C[[1,13,14,(18:21)...],:] + + get_solution(RBC_CME_lead_lag10, algorithm = :linear_time_iteration) + + @test isapprox(RBC_CME_lead_lag10.solution.perturbation.first_order.solution_matrix, RBC_CME_lead_lag10.solution.perturbation.linear_time_iteration.solution_matrix, atol = 1e-4) + # @test isapprox(RBC_CME_lead_lag10.solution.perturbation.first_order.C, RBC_CME_lead_lag10.solution.perturbation.linear_time_iteration.C, atol = 1e-4) + + get_solution(RBC_CME_lead_lag10, algorithm = :quadratic_iteration) + + @test isapprox(RBC_CME_lead_lag10.solution.perturbation.first_order.solution_matrix, RBC_CME_lead_lag10.solution.perturbation.quadratic_iteration.solution_matrix, atol = 1e-4) + + RBC_CME_lead_lag10 = nothing + + + # Leads and lags > 10 + @model RBC_CME_lead_lag20 begin + y[0]=A[0]*k[-1]^alpha + 1/c[0]=beta*1/c[1]*(alpha*A[1]*k[0]^(alpha-1)+(1-delta)) + 1/c[0]=beta*1/c[1]*(R[0]/Pi[+1]) + R[0] * beta =(Pi[0]/Pibar)^phi_pi + # A[0]*k[-1]^alpha=c[0]+k[0]-(1-delta)*k[-1] + A[0]*k[-1]^alpha=c[0]+k[0]-(1-delta*z_delta[0])*k[-1] + z_delta[0] = 1 - rho_z_delta + rho_z_delta * z_delta[-1] + std_z_delta * delta_eps[x] + # z[0]=rhoz*z[-1]+std_eps*eps_z[x] + # A[0]=exp(z[0]) + A[0] = 1 - rhoz + rhoz * A[-1] + std_eps * eps_z[x] + ZZ_avg_f[0] = (A[0] + A[1] + A[2] + A[3]) / 4 + ZZ_avg_b[0] = (A[0] + A[-1] + A[-2] + A[-3]) / 4 + ZZ_avg_ff[0] = (A[0] + A[10]) / 2 + ZZ_avg_bb[0] = (A[0] + A[-10]) / 2 + # A_annual[0] = (A[0] + A[-4] + A[-8] + A[-12]) / 4 + # y_avg[0] = log(y[0] / y[-4]) + # y_growth[0] = log(y[1] / y[2]) + # y_growthl[0] = log(y[0] / y[1]) + # y_growthl1[0] = log(y[-1] / y[0]) + # log(A[0]) = rhoz * log(A[-1]) + std_eps * eps_z[x] + end + + + @parameters RBC_CME_lead_lag20 verbose = true begin + # alpha | k[ss] / (4 * y[ss]) = cap_share + # cap_share = 1.66 + alpha = .157 + + # beta | R[ss] = R_ss + # R_ss = 1.0035 + beta = .999 + + # delta | c[ss]/y[ss] = 1 - I_K_ratio + # delta | delta * k[ss]/y[ss] = I_K_ratio #check why this doesnt solve for y + # I_K_ratio = .15 + delta = .0226 + + # Pibar | Pi[ss] = Pi_ss + # Pi_ss = 1.0025 + Pibar = 1.0008 + + phi_pi = 1.5 + rhoz = .9 + std_eps = .0068 + rho_z_delta = .9 + std_z_delta = .005 + end + + get_solution(RBC_CME_lead_lag20) + @test RBC_CME.solution.perturbation.first_order.solution_matrix ≈ RBC_CME_lead_lag20.solution.perturbation.first_order.solution_matrix[[1,20,21,(26:29)...],[1,11:end...]] + # @test RBC_CME.solution.perturbation.first_order.C ≈ RBC_CME_lead_lag20.solution.perturbation.first_order.C[[1,20,21,(26:29)...],:] - @parameters RBC_CME symbolic = true verbose = true begin - alpha | k[ss] / (4 * y[ss]) = cap_share - cap_share = 1.66 - # alpha = .157 + get_solution(RBC_CME_lead_lag20, algorithm = :linear_time_iteration) - beta | R[ss] = R_ss - R_ss = 1.0035 - # beta = .999 + @test isapprox(RBC_CME_lead_lag20.solution.perturbation.first_order.solution_matrix, RBC_CME_lead_lag20.solution.perturbation.linear_time_iteration.solution_matrix, atol = 1e-4) + # @test isapprox(RBC_CME_lead_lag20.solution.perturbation.first_order.C, RBC_CME_lead_lag20.solution.perturbation.linear_time_iteration.C, atol = 1e-4) - delta | c[ss]/y[ss] = 1 - I_K_ratio - # delta | delta * k[ss] / y[ss] = I_K_ratio # this doesnt solve symbolically - I_K_ratio = .15 - # delta = .0226 + get_solution(RBC_CME_lead_lag20, algorithm = :quadratic_iteration) - Pibar | Pi[ss] = Pi_ss - Pi_ss = 1.0025 - # Pibar = 1.0008 + @test isapprox(RBC_CME_lead_lag20.solution.perturbation.first_order.solution_matrix, RBC_CME_lead_lag20.solution.perturbation.quadratic_iteration.solution_matrix, atol = 1e-4) - phi_pi = 1.5 - rhoz = .9 - std_eps = .0068 - rho_z_delta = .9 - std_z_delta = .005 - - # cap_share > 0 - # R_ss > 0 - # Pi_ss > 0 - # I_K_ratio > 0 - - # 0 < alpha < .5 - # 0 < beta < 1 - # 0 < delta < 1 - # 0 < Pibar - # 0 <= rhoz < 1 - # phi_pi > 0 - - # 0 < A < 1 - # 0 < k < 50 - # 0 < y < 10 - # 0 < c < 10 + RBC_CME_lead_lag20 = nothing end - # # get_steady_state(RBC_CME)[1] - # # using NLopt - # # RBC_CME.SS_optimizer = NLopt.LD_LBFGS - # # get_steady_state(RBC_CME) - @test isapprox(get_steady_state(RBC_CME, verbose = true)(RBC_CME.var,:Steady_state), [1.0, 1.0025, 1.0035, 1.2081023828249515, 9.437411555244328, 1.4212969209705313, 1.0],rtol = eps(Float32)) - # get_moments(RBC_CME)[1] - - RBC_CME = nothing -end - - -# using MacroModelling: @model, @parameters, get_steady_state, solve! - -@testset verbose = true "Steady state SW03 model" begin - - @model SW03 begin - -q[0] + beta * ((1 - tau) * q[1] + epsilon_b[1] * (r_k[1] * z[1] - psi^-1 * r_k[ss] * (-1 + exp(psi * (-1 + z[1])))) * (C[1] - h * C[0])^(-sigma_c)) = 0 - -q_f[0] + beta * ((1 - tau) * q_f[1] + epsilon_b[1] * (r_k_f[1] * z_f[1] - psi^-1 * r_k_f[ss] * (-1 + exp(psi * (-1 + z_f[1])))) * (C_f[1] - h * C_f[0])^(-sigma_c)) = 0 - -r_k[0] + alpha * epsilon_a[0] * mc[0] * L[0]^(1 - alpha) * (K[-1] * z[0])^(-1 + alpha) = 0 - -r_k_f[0] + alpha * epsilon_a[0] * mc_f[0] * L_f[0]^(1 - alpha) * (K_f[-1] * z_f[0])^(-1 + alpha) = 0 - -G[0] + T[0] = 0 - -G[0] + G_bar * epsilon_G[0] = 0 - -G_f[0] + T_f[0] = 0 - -G_f[0] + G_bar * epsilon_G[0] = 0 - -L[0] + nu_w[0]^-1 * L_s[0] = 0 - -L_s_f[0] + L_f[0] * (W_i_f[0] * W_f[0]^-1)^(lambda_w^-1 * (-1 - lambda_w)) = 0 - L_s_f[0] - L_f[0] = 0 - L_s_f[0] + lambda_w^-1 * L_f[0] * W_f[0]^-1 * (-1 - lambda_w) * (-W_disutil_f[0] + W_i_f[0]) * (W_i_f[0] * W_f[0]^-1)^(-1 + lambda_w^-1 * (-1 - lambda_w)) = 0 - Pi_ws_f[0] - L_s_f[0] * (-W_disutil_f[0] + W_i_f[0]) = 0 - Pi_ps_f[0] - Y_f[0] * (-mc_f[0] + P_j_f[0]) * P_j_f[0]^(-lambda_p^-1 * (1 + lambda_p)) = 0 - -Q[0] + epsilon_b[0]^-1 * q[0] * (C[0] - h * C[-1])^(sigma_c) = 0 - -Q_f[0] + epsilon_b[0]^-1 * q_f[0] * (C_f[0] - h * C_f[-1])^(sigma_c) = 0 - -W[0] + epsilon_a[0] * mc[0] * (1 - alpha) * L[0]^(-alpha) * (K[-1] * z[0])^alpha = 0 - -W_f[0] + epsilon_a[0] * mc_f[0] * (1 - alpha) * L_f[0]^(-alpha) * (K_f[-1] * z_f[0])^alpha = 0 - -Y_f[0] + Y_s_f[0] = 0 - Y_s[0] - nu_p[0] * Y[0] = 0 - -Y_s_f[0] + Y_f[0] * P_j_f[0]^(-lambda_p^-1 * (1 + lambda_p)) = 0 - beta * epsilon_b[1] * (C_f[1] - h * C_f[0])^(-sigma_c) - epsilon_b[0] * R_f[0]^-1 * (C_f[0] - h * C_f[-1])^(-sigma_c) = 0 - beta * epsilon_b[1] * pi[1]^-1 * (C[1] - h * C[0])^(-sigma_c) - epsilon_b[0] * R[0]^-1 * (C[0] - h * C[-1])^(-sigma_c) = 0 - Y_f[0] * P_j_f[0]^(-lambda_p^-1 * (1 + lambda_p)) - lambda_p^-1 * Y_f[0] * (1 + lambda_p) * (-mc_f[0] + P_j_f[0]) * P_j_f[0]^(-1 - lambda_p^-1 * (1 + lambda_p)) = 0 - epsilon_b[0] * W_disutil_f[0] * (C_f[0] - h * C_f[-1])^(-sigma_c) - omega * epsilon_b[0] * epsilon_L[0] * L_s_f[0]^sigma_l = 0 - -1 + xi_p * (pi[0]^-1 * pi[-1]^gamma_p)^(-lambda_p^-1) + (1 - xi_p) * pi_star[0]^(-lambda_p^-1) = 0 - -1 + (1 - xi_w) * (w_star[0] * W[0]^-1)^(-lambda_w^-1) + xi_w * (W[-1] * W[0]^-1)^(-lambda_w^-1) * (pi[0]^-1 * pi[-1]^gamma_w)^(-lambda_w^-1) = 0 - -Phi - Y_s[0] + epsilon_a[0] * L[0]^(1 - alpha) * (K[-1] * z[0])^alpha = 0 - -Phi - Y_f[0] * P_j_f[0]^(-lambda_p^-1 * (1 + lambda_p)) + epsilon_a[0] * L_f[0]^(1 - alpha) * (K_f[-1] * z_f[0])^alpha = 0 - eta_b[exo] - log(epsilon_b[0]) + rho_b * log(epsilon_b[-1]) = 0 - -eta_L[exo] - log(epsilon_L[0]) + rho_L * log(epsilon_L[-1]) = 0 - eta_I[exo] - log(epsilon_I[0]) + rho_I * log(epsilon_I[-1]) = 0 - eta_w[exo] - f_1[0] + f_2[0] = 0 - eta_a[exo] - log(epsilon_a[0]) + rho_a * log(epsilon_a[-1]) = 0 - eta_p[exo] - g_1[0] + g_2[0] * (1 + lambda_p) = 0 - eta_G[exo] - log(epsilon_G[0]) + rho_G * log(epsilon_G[-1]) = 0 - -f_1[0] + beta * xi_w * f_1[1] * (w_star[0]^-1 * w_star[1])^(lambda_w^-1) * (pi[1]^-1 * pi[0]^gamma_w)^(-lambda_w^-1) + epsilon_b[0] * w_star[0] * L[0] * (1 + lambda_w)^-1 * (C[0] - h * C[-1])^(-sigma_c) * (w_star[0] * W[0]^-1)^(-lambda_w^-1 * (1 + lambda_w)) = 0 - -f_2[0] + beta * xi_w * f_2[1] * (w_star[0]^-1 * w_star[1])^(lambda_w^-1 * (1 + lambda_w) * (1 + sigma_l)) * (pi[1]^-1 * pi[0]^gamma_w)^(-lambda_w^-1 * (1 + lambda_w) * (1 + sigma_l)) + omega * epsilon_b[0] * epsilon_L[0] * (L[0] * (w_star[0] * W[0]^-1)^(-lambda_w^-1 * (1 + lambda_w)))^(1 + sigma_l) = 0 - -g_1[0] + beta * xi_p * pi_star[0] * g_1[1] * pi_star[1]^-1 * (pi[1]^-1 * pi[0]^gamma_p)^(-lambda_p^-1) + epsilon_b[0] * pi_star[0] * Y[0] * (C[0] - h * C[-1])^(-sigma_c) = 0 - -g_2[0] + beta * xi_p * g_2[1] * (pi[1]^-1 * pi[0]^gamma_p)^(-lambda_p^-1 * (1 + lambda_p)) + epsilon_b[0] * mc[0] * Y[0] * (C[0] - h * C[-1])^(-sigma_c) = 0 - -nu_w[0] + (1 - xi_w) * (w_star[0] * W[0]^-1)^(-lambda_w^-1 * (1 + lambda_w)) + xi_w * nu_w[-1] * (W[-1] * pi[0]^-1 * W[0]^-1 * pi[-1]^gamma_w)^(-lambda_w^-1 * (1 + lambda_w)) = 0 - -nu_p[0] + (1 - xi_p) * pi_star[0]^(-lambda_p^-1 * (1 + lambda_p)) + xi_p * nu_p[-1] * (pi[0]^-1 * pi[-1]^gamma_p)^(-lambda_p^-1 * (1 + lambda_p)) = 0 - -K[0] + K[-1] * (1 - tau) + I[0] * (1 - 0.5 * varphi * (-1 + I[-1]^-1 * epsilon_I[0] * I[0])^2) = 0 - -K_f[0] + K_f[-1] * (1 - tau) + I_f[0] * (1 - 0.5 * varphi * (-1 + I_f[-1]^-1 * epsilon_I[0] * I_f[0])^2) = 0 - U[0] - beta * U[1] - epsilon_b[0] * ((1 - sigma_c)^-1 * (C[0] - h * C[-1])^(1 - sigma_c) - omega * epsilon_L[0] * (1 + sigma_l)^-1 * L_s[0]^(1 + sigma_l)) = 0 - U_f[0] - beta * U_f[1] - epsilon_b[0] * ((1 - sigma_c)^-1 * (C_f[0] - h * C_f[-1])^(1 - sigma_c) - omega * epsilon_L[0] * (1 + sigma_l)^-1 * L_s_f[0]^(1 + sigma_l)) = 0 - -epsilon_b[0] * (C[0] - h * C[-1])^(-sigma_c) + q[0] * (1 - 0.5 * varphi * (-1 + I[-1]^-1 * epsilon_I[0] * I[0])^2 - varphi * I[-1]^-1 * epsilon_I[0] * I[0] * (-1 + I[-1]^-1 * epsilon_I[0] * I[0])) + beta * varphi * I[0]^-2 * epsilon_I[1] * q[1] * I[1]^2 * (-1 + I[0]^-1 * epsilon_I[1] * I[1]) = 0 - -epsilon_b[0] * (C_f[0] - h * C_f[-1])^(-sigma_c) + q_f[0] * (1 - 0.5 * varphi * (-1 + I_f[-1]^-1 * epsilon_I[0] * I_f[0])^2 - varphi * I_f[-1]^-1 * epsilon_I[0] * I_f[0] * (-1 + I_f[-1]^-1 * epsilon_I[0] * I_f[0])) + beta * varphi * I_f[0]^-2 * epsilon_I[1] * q_f[1] * I_f[1]^2 * (-1 + I_f[0]^-1 * epsilon_I[1] * I_f[1]) = 0 - eta_pi[exo] - log(pi_obj[0]) + rho_pi_bar * log(pi_obj[-1]) + log(calibr_pi_obj) * (1 - rho_pi_bar) = 0 - -C[0] - I[0] - T[0] + Y[0] - psi^-1 * r_k[ss] * K[-1] * (-1 + exp(psi * (-1 + z[0]))) = 0 - -calibr_pi + eta_R[exo] - log(R[ss]^-1 * R[0]) + r_Delta_pi * (-log(pi[ss]^-1 * pi[-1]) + log(pi[ss]^-1 * pi[0])) + r_Delta_y * (-log(Y[ss]^-1 * Y[-1]) + log(Y[ss]^-1 * Y[0]) + log(Y_f[ss]^-1 * Y_f[-1]) - log(Y_f[ss]^-1 * Y_f[0])) + rho * log(R[ss]^-1 * R[-1]) + (1 - rho) * (log(pi_obj[0]) + r_pi * (-log(pi_obj[0]) + log(pi[ss]^-1 * pi[-1])) + r_Y * (log(Y[ss]^-1 * Y[0]) - log(Y_f[ss]^-1 * Y_f[0]))) = 0 - -C_f[0] - I_f[0] + Pi_ws_f[0] - T_f[0] + Y_f[0] + L_s_f[0] * W_disutil_f[0] - L_f[0] * W_f[0] - psi^-1 * r_k_f[ss] * K_f[-1] * (-1 + exp(psi * (-1 + z_f[0]))) = 0 - epsilon_b[0] * (K[-1] * r_k[0] - r_k[ss] * K[-1] * exp(psi * (-1 + z[0]))) * (C[0] - h * C[-1])^(-sigma_c) = 0 - epsilon_b[0] * (K_f[-1] * r_k_f[0] - r_k_f[ss] * K_f[-1] * exp(psi * (-1 + z_f[0]))) * (C_f[0] - h * C_f[-1])^(-sigma_c) = 0 - end - + @testset verbose = true "Steady state RBC CME model" begin + # Basic test + @model RBC_CME begin + y[0]=A[0]*k[-1]^alpha + 1/c[0]=beta*1/c[1]*(alpha*A[1]*k[0]^(alpha-1)+(1-delta)) + 1/c[0]=beta*1/c[1]*(R[0]/Pi[+1]) + R[0] * beta =(Pi[0]/Pibar)^phi_pi + # A[0]*k[-1]^alpha=c[0]+k[0]-(1-delta)*k[-1] + A[0]*k[-1]^alpha=c[0]+k[0]-(1-delta*z_delta[0])*k[-1] + z_delta[0] = 1 - rho_z_delta + rho_z_delta * z_delta[-1] + std_z_delta * delta_eps[x] + # z[0]=rhoz*z[-1]+std_eps*eps_z[x] + # A[0]=exp(z[0]) + A[0] = 1 - rhoz + rhoz * A[-1] + std_eps * eps_z[x] + # A_avg[0] = (A[0] + A[-1] + A[-2] + A[-3]) / 4 + # A_annual[0] = (A[0] + A[-4] + A[-8] + A[-12]) / 4 + # y_avg[0] = log(y[0] / y[-4]) + # y_growth[0] = log(y[1] / y[2]) + # y_growthl[0] = log(y[0] / y[1]) + # y_growthl1[0] = log(y[-1] / y[0]) + # log(A[0]) = rhoz * log(A[-1]) + std_eps * eps_z[x] + end + + + @parameters RBC_CME verbose = true begin + # alpha | k[ss] / (4 * y[ss]) = cap_share + # cap_share = 1.66 + alpha = .157 + + # beta | R[ss] = R_ss + # R_ss = 1.0035 + beta = .999 + + # delta | c[ss]/y[ss] = 1 - I_K_ratio + # delta | delta * k[ss]/y[ss] = I_K_ratio #check why this doesnt solve for y + # I_K_ratio = .15 + delta = .0226 + + # Pibar | Pi[ss] = Pi_ss + # Pi_ss = 1.0025 + Pibar = 1.0008 + + phi_pi = 1.5 + rhoz = .9 + std_eps = .0068 + rho_z_delta = .9 + std_z_delta = .005 + end + # get_steady_state(RBC_CME)[1] + # using NLopt + # RBC_CME.SS_optimizer = NLopt.LD_LBFGS + # solve!(RBC_CME) + @test get_steady_state(RBC_CME)(RBC_CME.var,:Steady_state) ≈ [1.0, 1.0024019205374952, 1.003405325870413, 1.2092444352939415, 9.467573947982233, 1.42321160651834, 1.0] + # get_moments(RBC_CME)[1] + # irf(RBC_CME) + + RBC_CME = nothing - @parameters SW03 verbose = true begin - calibr_pi_obj | 1 = pi_obj[ss] - calibr_pi | pi[ss] = pi_obj[ss] - # Phi | Y_s[ss] * .408 = Phi - # Phi = .408 * Y_j[ss] - # (Y_j[ss] + Phi) / Y_j[ss] = 1.408 -> Phi; | this seems problematic because of the parameter - # lambda_p | .6 = C_f[ss] / Y_f[ss] - # lambda_w | L[ss] = .33 - # G_bar | .18 = G[ss] / Y[ss] - # calibr_pi_obj = 0 - # calibr_pi = 1 - lambda_p = .368 - G_bar = .362 - lambda_w = 0.5 - Phi = .819 - - alpha = 0.3 - beta = 0.99 - gamma_w = 0.763 - gamma_p = 0.469 - h = 0.573 - omega = 1 - psi = 0.169 - r_pi = 1.684 - r_Y = 0.099 - r_Delta_pi = 0.14 - r_Delta_y = 0.159 - rho = 0.961 - rho_b = 0.855 - rho_L = 0.889 - rho_I = 0.927 - rho_a = 0.823 - rho_G = 0.949 - rho_pi_bar = 0.924 - sigma_c = 1.353 - sigma_l = 2.4 - tau = 0.025 - varphi = 6.771 - xi_w = 0.737 - xi_p = 0.908 - - # Putting non-negative constraint on first block is enough - # 0 < K - # 0 < I - # 0 < Y_s - # 0 < q - # 0 < r_k - # 5 < f_1 - # 0 < L - # 0 < W - # 30 < g_1 - # 0 < z - # 0 < mc - # 0 < w_star - # 5 < f_2 - # 0 < Y - # 0 < g_2 - # 0 < C + + # Symbolic test + @model RBC_CME begin + y[0]=A[0]*k[-1]^alpha + 1/c[0]=beta*1/c[1]*(alpha*A[1]*k[0]^(alpha-1)+(1-delta)) + 1/c[0]=beta*1/c[1]*(R[0]/Pi[+1]) + R[0] * beta =(Pi[0]/Pibar)^phi_pi + # A[0]*k[-1]^alpha=c[0]+k[0]-(1-delta)*k[-1] + A[0]*k[-1]^alpha=c[0]+k[0]-(1-delta*z_delta[0])*k[-1] + z_delta[0] = 1 - rho_z_delta + rho_z_delta * z_delta[-1] + std_z_delta * delta_eps[x] + # z[0]=rhoz*z[-1]+std_eps*eps_z[x] + # A[0]=exp(z[0]) + A[0] = 1 - rhoz + rhoz * A[-1] + std_eps * eps_z[x] + # log(A[0]) = rhoz * log(A[-1]) + std_eps * eps_z[x] + end + + + @parameters RBC_CME symbolic = true verbose = true begin + # alpha | k[ss] / (4 * y[ss]) = cap_share + # cap_share = 1.66 + alpha = .157 + + # beta | R[ss] = R_ss + # R_ss = 1.0035 + beta = .999 + + # delta | c[ss]/y[ss] = 1 - I_K_ratio + # delta | delta * k[ss]/y[ss] = I_K_ratio #check why this doesnt solve for y + # I_K_ratio = .15 + delta = .0226 + + # Pibar | Pi[ss] = Pi_ss + # Pi_ss = 1.0025 + Pibar = 1.0008 + + phi_pi = 1.5 + rhoz = .9 + std_eps = .0068 + rho_z_delta = .9 + std_z_delta = .005 + + # cap_share > 0 + # R_ss > 0 + # Pi_ss > 0 + # I_K_ratio > 0 + + # 0 < alpha < 1 + 0 < beta < 1 + # 0 < delta < 1 + 0 < Pibar + # 0 <= rhoz < 1 + phi_pi > 0 + + # 0 < A < 1 + # 0 < k < 50 + 0 < Pi + 0 < R + end + # get_steady_state(RBC_CME)[1] + # using NLopt + # RBC_CME.SS_optimizer = NLopt.LD_LBFGS + # solve!(RBC_CME,symbolic_SS = true) + @test get_steady_state(RBC_CME)(RBC_CME.var,:Steady_state) ≈ [1.0, 1.0024019205374952, 1.003405325870413, 1.2092444352939415, 9.467573947982233, 1.42321160651834, 1.0] + # get_moments(RBC_CME)[1] + + RBC_CME = nothing + + + + + # Numerical test with calibration targets + @model RBC_CME begin + y[0]=A[0]*k[-1]^alpha + 1/c[0]=beta*1/c[1]*(alpha*A[1]*k[0]^(alpha-1)+(1-delta)) + 1/c[0]=beta*1/c[1]*(R[0]/Pi[+1]) + R[0] * beta =(Pi[0]/Pibar)^phi_pi + # A[0]*k[-1]^alpha=c[0]+k[0]-(1-delta)*k[-1] + A[0]*k[-1]^alpha=c[0]+k[0]-(1-delta*z_delta[0])*k[-1] + z_delta[0] = 1 - rho_z_delta + rho_z_delta * z_delta[-1] + std_z_delta * delta_eps[x] + # z[0]=rhoz*z[-1]+std_eps*eps_z[x] + # A[0]=exp(z[0]) + A[0] = 1 - rhoz + rhoz * A[-1] + std_eps * eps_z[x] + # log(A[0]) = rhoz * log(A[-1]) + std_eps * eps_z[x] + end + + + @parameters RBC_CME verbose = true begin + alpha | k[ss] / (4 * y[ss]) = cap_share + cap_share = 1.66 + # alpha = .157 + + beta | R[ss] = R_ss # beta needs to enter into function: block in order to solve + R_ss = 1.0035 + # beta = .999 + + # delta | c[ss]/y[ss] = 1 - I_K_ratio + delta | delta * k[ss] / y[ss] = I_K_ratio #check why this doesnt solve for y; because delta is not recognised as a free parameter here. + I_K_ratio = .15 + # delta = .0226 + + Pibar | Pi[ss] = Pi_ss + Pi_ss = 1.0025 + # Pibar = 1.0008 + + phi_pi = 1.5 + rhoz = .9 + std_eps = .0068 + rho_z_delta = .9 + std_z_delta = .005 + + + # cap_share > 0 + # R_ss > 0 + # Pi_ss > 0 + # I_K_ratio > 0 + + # 0 < alpha < 1 + # 0 < beta < 1 + # 0 < delta < 1 + # 0 < Pibar + # 0 <= rhoz < 1 + # phi_pi > 0 + + # 0 < A < 1 + # 0 < k < 50 + # 0 < y < 10 + # 0 < c < 10 + end + # get_steady_state(RBC_CME)[1] + # using NLopt + # RBC_CME.SS_optimizer = NLopt.LD_LBFGS + # solve!(RBC_CME, verbose = true) + # RBC_CME.SS_init_guess[1:7] = [1.0, 1.0025, 1.0035, 1.2081023828249515, 9.437411555244328, 1.4212969209705313, 1.0] + # get_steady_state(RBC_CME) + @test get_steady_state(RBC_CME, verbose = true)(RBC_CME.var,:Steady_state) ≈ [1.0, 1.0025, 1.0035, 1.2081023824176236, 9.437411552284384, 1.4212969205027686, 1.0] + # get_moments(RBC_CME)[1] + + # RBC_CME.ss_solve_blocks[1]([0.15662344139650963, 1.2081023828249515, 0.02259036144578319, 9.437411555244328, 1.4212969209705313],RBC_CME) + + RBC_CME = nothing + + + # Symbolic test with calibration targets + @model RBC_CME begin + y[0]=A[0]*k[-1]^alpha + 1/c[0]=beta*1/c[1]*(alpha*A[1]*k[0]^(alpha-1)+(1-delta)) + 1/c[0]=beta*1/c[1]*(R[0]/Pi[+1]) + R[0] * beta =(Pi[0]/Pibar)^phi_pi + # A[0]*k[-1]^alpha=c[0]+k[0]-(1-delta)*k[-1] + A[0]*k[-1]^alpha=c[0]+k[0]-(1-delta*z_delta[0])*k[-1] + z_delta[0] = 1 - rho_z_delta + rho_z_delta * z_delta[-1] + std_z_delta * delta_eps[x] + # z[0]=rhoz*z[-1]+std_eps*eps_z[x] + # A[0]=exp(z[0]) + A[0] = 1 - rhoz + rhoz * A[-1] + std_eps * eps_z[x] + # log(A[0]) = rhoz * log(A[-1]) + std_eps * eps_z[x] + end + + + @parameters RBC_CME symbolic = true verbose = true begin + alpha | k[ss] / (4 * y[ss]) = cap_share + cap_share = 1.66 + # alpha = .157 + + beta | R[ss] = R_ss + R_ss = 1.0035 + # beta = .999 + + delta | c[ss]/y[ss] = 1 - I_K_ratio + # delta | delta * k[ss] / y[ss] = I_K_ratio # this doesnt solve symbolically + I_K_ratio = .15 + # delta = .0226 + + Pibar | Pi[ss] = Pi_ss + Pi_ss = 1.0025 + # Pibar = 1.0008 + + phi_pi = 1.5 + rhoz = .9 + std_eps = .0068 + rho_z_delta = .9 + std_z_delta = .005 + + # cap_share > 0 + # R_ss > 0 + # Pi_ss > 0 + # I_K_ratio > 0 + + # 0 < alpha < .5 + # 0 < beta < 1 + # 0 < delta < 1 + # 0 < Pibar + # 0 <= rhoz < 1 + # phi_pi > 0 + + # 0 < A < 1 + # 0 < k < 50 + # 0 < y < 10 + # 0 < c < 10 + end + # # get_steady_state(RBC_CME)[1] + # # using NLopt + # # RBC_CME.SS_optimizer = NLopt.LD_LBFGS + # # get_steady_state(RBC_CME) + @test isapprox(get_steady_state(RBC_CME, verbose = true)(RBC_CME.var,:Steady_state), [1.0, 1.0025, 1.0035, 1.2081023828249515, 9.437411555244328, 1.4212969209705313, 1.0],rtol = eps(Float32)) + # get_moments(RBC_CME)[1] + + RBC_CME = nothing end - # solve!(SW03, verbose = true) - - - @test isapprox(get_steady_state(SW03, verbose = true)(SW03.timings.var), - [ 1.2043777509278788 - 1.2043777484127967 - 0.362 - 0.362 - 0.44153840098985714 - 0.44153839784516097 - 17.66153603957938 - 17.66153591381742 - 1.2891159430437658 - 1.2891159432893282 - 1.289115942962812 - 1.289115943290125 - 0.9999999999999677 - 0.5401411855429173 - 0.482173806623137 - 0.999999999999352 - 1.0000000000002556 - 1.0101010101010102 - 1.0101010101010102 - 0.362 - 0.362 - -427.9858908413812 - -427.98589116567274 - 1.122103431093411 - 0.7480689524203904 - 1.1221034286309022 - 1.122103428630708 - 2.0079161519182205 - 2.0079161462568305 - 2.0079161519185624 - 2.007916146256947 - 1.0 - 1.0 - 1.0 - 1.0 - 1.0 - 8.770699454739315 - 8.770699454739393 - 48.84717584575426 - 35.70699988724729 - 0.7309941520471651 - 0.730994152046712 - 1.0 - 0.9999999999372022 - 1.0 - 1.0 - 1.0 - 2.4590033452182944 - 2.459003352168301 - 0.035101010082054955 - 0.03510101010809239 - 1.1221034311168996 - 0.9999999999999698 - 1.0000000000000089], - rtol = eps(Float32) - ) - SW03 = nothing -# # x = 1 - - -# # SW03 = nothing - -# # @model SW03 begin -# # -q[0] + beta * ((1 - tau) * q[1] + epsilon_b[1] * (r_k[1] * z[1] - psi^-1 * r_k[ss] * (-1 + exp(psi * (-1 + z[1])))) * (C[1] - h * C[0])^(-sigma_c)) = 0 -# # -q_f[0] + beta * ((1 - tau) * q_f[1] + epsilon_b[1] * (r_k_f[1] * z_f[1] - psi^-1 * r_k_f[ss] * (-1 + exp(psi * (-1 + z_f[1])))) * (C_f[1] - h * C_f[0])^(-sigma_c)) = 0 -# # -r_k[0] + alpha * epsilon_a[0] * mc[0] * L[0]^(1 - alpha) * (K[-1] * z[0])^(-1 + alpha) = 0 -# # -r_k_f[0] + alpha * epsilon_a[0] * mc_f[0] * L_f[0]^(1 - alpha) * (K_f[-1] * z_f[0])^(-1 + alpha) = 0 -# # -G[0] + T[0] = 0 -# # -G[0] + G_bar * epsilon_G[0] = 0 -# # -G_f[0] + T_f[0] = 0 -# # -G_f[0] + G_bar * epsilon_G[0] = 0 -# # -L[0] + nu_w[0]^-1 * L_s[0] = 0 -# # -L_s_f[0] + L_f[0] * (W_i_f[0] * W_f[0]^-1)^(lambda_w^-1 * (-1 - lambda_w)) = 0 -# # L_s_f[0] - L_f[0] = 0 -# # L_s_f[0] + lambda_w^-1 * L_f[0] * W_f[0]^-1 * (-1 - lambda_w) * (-W_disutil_f[0] + W_i_f[0]) * (W_i_f[0] * W_f[0]^-1)^(-1 + lambda_w^-1 * (-1 - lambda_w)) = 0 -# # Pi_ws_f[0] - L_s_f[0] * (-W_disutil_f[0] + W_i_f[0]) = 0 -# # Pi_ps_f[0] - Y_f[0] * (-mc_f[0] + P_j_f[0]) * P_j_f[0]^(-lambda_p^-1 * (1 + lambda_p)) = 0 -# # -Q[0] + epsilon_b[0]^-1 * q[0] * (C[0] - h * C[-1])^(sigma_c) = 0 -# # -Q_f[0] + epsilon_b[0]^-1 * q_f[0] * (C_f[0] - h * C_f[-1])^(sigma_c) = 0 -# # -W[0] + epsilon_a[0] * mc[0] * (1 - alpha) * L[0]^(-alpha) * (K[-1] * z[0])^alpha = 0 -# # -W_f[0] + epsilon_a[0] * mc_f[0] * (1 - alpha) * L_f[0]^(-alpha) * (K_f[-1] * z_f[0])^alpha = 0 -# # -Y_f[0] + Y_s_f[0] = 0 -# # Y_s[0] - nu_p[0] * Y[0] = 0 -# # -Y_s_f[0] + Y_f[0] * P_j_f[0]^(-lambda_p^-1 * (1 + lambda_p)) = 0 -# # beta * epsilon_b[1] * (C_f[1] - h * C_f[0])^(-sigma_c) - epsilon_b[0] * R_f[0]^-1 * (C_f[0] - h * C_f[-1])^(-sigma_c) = 0 -# # beta * epsilon_b[1] * pi[1]^-1 * (C[1] - h * C[0])^(-sigma_c) - epsilon_b[0] * R[0]^-1 * (C[0] - h * C[-1])^(-sigma_c) = 0 -# # Y_f[0] * P_j_f[0]^(-lambda_p^-1 * (1 + lambda_p)) - lambda_p^-1 * Y_f[0] * (1 + lambda_p) * (-mc_f[0] + P_j_f[0]) * P_j_f[0]^(-1 - lambda_p^-1 * (1 + lambda_p)) = 0 -# # epsilon_b[0] * W_disutil_f[0] * (C_f[0] - h * C_f[-1])^(-sigma_c) - omega * epsilon_b[0] * epsilon_L[0] * L_s_f[0]^sigma_l = 0 -# # -1 + xi_p * (pi[0]^-1 * pi[-1]^gamma_p)^(-lambda_p^-1) + (1 - xi_p) * pi_star[0]^(-lambda_p^-1) = 0 -# # -1 + (1 - xi_w) * (w_star[0] * W[0]^-1)^(-lambda_w^-1) + xi_w * (W[-1] * W[0]^-1)^(-lambda_w^-1) * (pi[0]^-1 * pi[-1]^gamma_w)^(-lambda_w^-1) = 0 -# # -Phi - Y_s[0] + epsilon_a[0] * L[0]^(1 - alpha) * (K[-1] * z[0])^alpha = 0 -# # -Phi - Y_f[0] * P_j_f[0]^(-lambda_p^-1 * (1 + lambda_p)) + epsilon_a[0] * L_f[0]^(1 - alpha) * (K_f[-1] * z_f[0])^alpha = 0 -# # eta_b[exo] - log(epsilon_b[0]) + rho_b * log(epsilon_b[-1]) = 0 -# # -eta_L[exo] - log(epsilon_L[0]) + rho_L * log(epsilon_L[-1]) = 0 -# # eta_I[exo] - log(epsilon_I[0]) + rho_I * log(epsilon_I[-1]) = 0 -# # eta_w[exo] - f_1[0] + f_2[0] = 0 -# # eta_a[exo] - log(epsilon_a[0]) + rho_a * log(epsilon_a[-1]) = 0 -# # eta_p[exo] - g_1[0] + g_2[0] * (1 + lambda_p) = 0 -# # eta_G[exo] - log(epsilon_G[0]) + rho_G * log(epsilon_G[-1]) = 0 -# # -f_1[0] + beta * xi_w * f_1[1] * (w_star[0]^-1 * w_star[1])^(lambda_w^-1) * (pi[1]^-1 * pi[0]^gamma_w)^(-lambda_w^-1) + epsilon_b[0] * w_star[0] * L[0] * (1 + lambda_w)^-1 * (C[0] - h * C[-1])^(-sigma_c) * (w_star[0] * W[0]^-1)^(-lambda_w^-1 * (1 + lambda_w)) = 0 -# # -f_2[0] + beta * xi_w * f_2[1] * (w_star[0]^-1 * w_star[1])^(lambda_w^-1 * (1 + lambda_w) * (1 + sigma_l)) * (pi[1]^-1 * pi[0]^gamma_w)^(-lambda_w^-1 * (1 + lambda_w) * (1 + sigma_l)) + omega * epsilon_b[0] * epsilon_L[0] * (L[0] * (w_star[0] * W[0]^-1)^(-lambda_w^-1 * (1 + lambda_w)))^(1 + sigma_l) = 0 -# # -g_1[0] + beta * xi_p * pi_star[0] * g_1[1] * pi_star[1]^-1 * (pi[1]^-1 * pi[0]^gamma_p)^(-lambda_p^-1) + epsilon_b[0] * pi_star[0] * Y[0] * (C[0] - h * C[-1])^(-sigma_c) = 0 -# # -g_2[0] + beta * xi_p * g_2[1] * (pi[1]^-1 * pi[0]^gamma_p)^(-lambda_p^-1 * (1 + lambda_p)) + epsilon_b[0] * mc[0] * Y[0] * (C[0] - h * C[-1])^(-sigma_c) = 0 -# # -nu_w[0] + (1 - xi_w) * (w_star[0] * W[0]^-1)^(-lambda_w^-1 * (1 + lambda_w)) + xi_w * nu_w[-1] * (W[-1] * pi[0]^-1 * W[0]^-1 * pi[-1]^gamma_w)^(-lambda_w^-1 * (1 + lambda_w)) = 0 -# # -nu_p[0] + (1 - xi_p) * pi_star[0]^(-lambda_p^-1 * (1 + lambda_p)) + xi_p * nu_p[-1] * (pi[0]^-1 * pi[-1]^gamma_p)^(-lambda_p^-1 * (1 + lambda_p)) = 0 -# # -K[0] + K[-1] * (1 - tau) + I[0] * (1 - 0.5 * varphi * (-1 + I[-1]^-1 * epsilon_I[0] * I[0])^2) = 0 -# # -K_f[0] + K_f[-1] * (1 - tau) + I_f[0] * (1 - 0.5 * varphi * (-1 + I_f[-1]^-1 * epsilon_I[0] * I_f[0])^2) = 0 -# # U[0] - beta * U[1] - epsilon_b[0] * ((1 - sigma_c)^-1 * (C[0] - h * C[-1])^(1 - sigma_c) - omega * epsilon_L[0] * (1 + sigma_l)^-1 * L_s[0]^(1 + sigma_l)) = 0 -# # U_f[0] - beta * U_f[1] - epsilon_b[0] * ((1 - sigma_c)^-1 * (C_f[0] - h * C_f[-1])^(1 - sigma_c) - omega * epsilon_L[0] * (1 + sigma_l)^-1 * L_s_f[0]^(1 + sigma_l)) = 0 -# # -epsilon_b[0] * (C[0] - h * C[-1])^(-sigma_c) + q[0] * (1 - 0.5 * varphi * (-1 + I[-1]^-1 * epsilon_I[0] * I[0])^2 - varphi * I[-1]^-1 * epsilon_I[0] * I[0] * (-1 + I[-1]^-1 * epsilon_I[0] * I[0])) + beta * varphi * I[0]^-2 * epsilon_I[1] * q[1] * I[1]^2 * (-1 + I[0]^-1 * epsilon_I[1] * I[1]) = 0 -# # -epsilon_b[0] * (C_f[0] - h * C_f[-1])^(-sigma_c) + q_f[0] * (1 - 0.5 * varphi * (-1 + I_f[-1]^-1 * epsilon_I[0] * I_f[0])^2 - varphi * I_f[-1]^-1 * epsilon_I[0] * I_f[0] * (-1 + I_f[-1]^-1 * epsilon_I[0] * I_f[0])) + beta * varphi * I_f[0]^-2 * epsilon_I[1] * q_f[1] * I_f[1]^2 * (-1 + I_f[0]^-1 * epsilon_I[1] * I_f[1]) = 0 -# # eta_pi[exo] - log(pi_obj[0]) + rho_pi_bar * log(pi_obj[-1]) + log(calibr_pi_obj) * (1 - rho_pi_bar) = 0 -# # -C[0] - I[0] - T[0] + Y[0] - psi^-1 * r_k[ss] * K[-1] * (-1 + exp(psi * (-1 + z[0]))) = 0 -# # -calibr_pi + eta_R[exo] - log(R[ss]^-1 * R[0]) + r_Delta_pi * (-log(pi[ss]^-1 * pi[-1]) + log(pi[ss]^-1 * pi[0])) + r_Delta_y * (-log(Y[ss]^-1 * Y[-1]) + log(Y[ss]^-1 * Y[0]) + log(Y_f[ss]^-1 * Y_f[-1]) - log(Y_f[ss]^-1 * Y_f[0])) + rho * log(R[ss]^-1 * R[-1]) + (1 - rho) * (log(pi_obj[0]) + r_pi * (-log(pi_obj[0]) + log(pi[ss]^-1 * pi[-1])) + r_Y * (log(Y[ss]^-1 * Y[0]) - log(Y_f[ss]^-1 * Y_f[0]))) = 0 -# # -C_f[0] - I_f[0] + Pi_ws_f[0] - T_f[0] + Y_f[0] + L_s_f[0] * W_disutil_f[0] - L_f[0] * W_f[0] - psi^-1 * r_k_f[ss] * K_f[-1] * (-1 + exp(psi * (-1 + z_f[0]))) = 0 -# # epsilon_b[0] * (K[-1] * r_k[0] - r_k[ss] * K[-1] * exp(psi * (-1 + z[0]))) * (C[0] - h * C[-1])^(-sigma_c) = 0 -# # epsilon_b[0] * (K_f[-1] * r_k_f[0] - r_k_f[ss] * K_f[-1] * exp(psi * (-1 + z_f[0]))) * (C_f[0] - h * C_f[-1])^(-sigma_c) = 0 -# # end - - -# # @parameters SW03 begin -# # calibr_pi_obj | 1 = pi_obj[ss] -# # calibr_pi | pi[ss] = pi_obj[ss] -# # Phi | (Y_s[ss] + Phi) / Y_s[ss] = 1.408 -# # # lambda_p | .6 = C_f[ss] / Y_f[ss] -# # # lambda_w | L[ss] = .33 -# # G_bar | .18 = G[ss] / Y[ss] - -# # lambda_p = .368 -# # # G_bar = .362 -# # lambda_w = 0.5 -# # # Phi = .819 - -# # alpha = 0.3 -# # beta = 0.99 -# # gamma_w = 0.763 -# # gamma_p = 0.469 -# # h = 0.573 -# # omega = 1 -# # psi = 0.169 -# # r_pi = 1.684 -# # r_Y = 0.099 -# # r_Delta_pi = 0.14 -# # r_Delta_y = 0.159 -# # rho = 0.961 -# # rho_b = 0.855 -# # rho_L = 0.889 -# # rho_I = 0.927 -# # rho_a = 0.823 -# # rho_G = 0.949 -# # rho_pi_bar = 0.924 -# # sigma_c = 1.353 -# # sigma_l = 2.4 -# # tau = 0.025 -# # varphi = 6.771 -# # xi_w = 0.737 -# # xi_p = 0.908 - -# # end - - -# # solve!(SW03, symbolic_SS = false) - -# # # get_steady_state(SW03) - -# # @test get_steady_state(SW03)[1] ≈ [ 1.20465991441435 -# # 1.204659917151701 -# # 0.3613478048030788 -# # 0.3613478048030788 -# # 0.4414800855444218 -# # 0.4414800896382151 -# # 17.659203422264238 -# # 17.65920357698873 -# # 1.2889457095271066 -# # 1.2889457096070582 -# # 1.2889457095307755 -# # 1.2889457098239414 -# # 1.0000000000366498 -# # 0.5400259611608715 -# # 0.48211013259048446 -# # 1.00000000000172 -# # 1.000000000127065 -# # 1.0101010101010102 -# # 1.0101010101010102 -# # 0.3613478047907606 -# # 0.3613478048030788 -# # -427.92495898028676 -# # -427.9249587468684 -# # 1.1221034247496608 -# # 0.7480689524616317 -# # 1.122103428477167 -# # 1.1221034282377538 -# # 2.0074878047372287 -# # 2.00748781245403 -# # 2.007487804732286 -# # 2.0074878121606647 -# # 1.0 -# # 1.0 -# # 1.0 -# # 1.0 -# # 1.0 -# # 8.766762166589194 -# # 8.766762166588967 -# # 48.8212791635492 -# # 35.68806956399776 -# # 0.730994152045567 -# # 0.7309941520886629 -# # 1.0 -# # 1.0000000000028464 -# # 1.0 -# # 1.0 -# # 1.0 -# # 2.4582240979093846 -# # 2.4582240906598867 -# # 0.03510101014899653 -# # 0.035101010136073356 -# # 1.1221034247485961 -# # 1.0000000000000178 -# # 0.9999999999583465] + # using MacroModelling: @model, @parameters, get_steady_state, solve! -end + @testset verbose = true "Steady state SW03 model" begin + + @model SW03 begin + -q[0] + beta * ((1 - tau) * q[1] + epsilon_b[1] * (r_k[1] * z[1] - psi^-1 * r_k[ss] * (-1 + exp(psi * (-1 + z[1])))) * (C[1] - h * C[0])^(-sigma_c)) = 0 + -q_f[0] + beta * ((1 - tau) * q_f[1] + epsilon_b[1] * (r_k_f[1] * z_f[1] - psi^-1 * r_k_f[ss] * (-1 + exp(psi * (-1 + z_f[1])))) * (C_f[1] - h * C_f[0])^(-sigma_c)) = 0 + -r_k[0] + alpha * epsilon_a[0] * mc[0] * L[0]^(1 - alpha) * (K[-1] * z[0])^(-1 + alpha) = 0 + -r_k_f[0] + alpha * epsilon_a[0] * mc_f[0] * L_f[0]^(1 - alpha) * (K_f[-1] * z_f[0])^(-1 + alpha) = 0 + -G[0] + T[0] = 0 + -G[0] + G_bar * epsilon_G[0] = 0 + -G_f[0] + T_f[0] = 0 + -G_f[0] + G_bar * epsilon_G[0] = 0 + -L[0] + nu_w[0]^-1 * L_s[0] = 0 + -L_s_f[0] + L_f[0] * (W_i_f[0] * W_f[0]^-1)^(lambda_w^-1 * (-1 - lambda_w)) = 0 + L_s_f[0] - L_f[0] = 0 + L_s_f[0] + lambda_w^-1 * L_f[0] * W_f[0]^-1 * (-1 - lambda_w) * (-W_disutil_f[0] + W_i_f[0]) * (W_i_f[0] * W_f[0]^-1)^(-1 + lambda_w^-1 * (-1 - lambda_w)) = 0 + Pi_ws_f[0] - L_s_f[0] * (-W_disutil_f[0] + W_i_f[0]) = 0 + Pi_ps_f[0] - Y_f[0] * (-mc_f[0] + P_j_f[0]) * P_j_f[0]^(-lambda_p^-1 * (1 + lambda_p)) = 0 + -Q[0] + epsilon_b[0]^-1 * q[0] * (C[0] - h * C[-1])^(sigma_c) = 0 + -Q_f[0] + epsilon_b[0]^-1 * q_f[0] * (C_f[0] - h * C_f[-1])^(sigma_c) = 0 + -W[0] + epsilon_a[0] * mc[0] * (1 - alpha) * L[0]^(-alpha) * (K[-1] * z[0])^alpha = 0 + -W_f[0] + epsilon_a[0] * mc_f[0] * (1 - alpha) * L_f[0]^(-alpha) * (K_f[-1] * z_f[0])^alpha = 0 + -Y_f[0] + Y_s_f[0] = 0 + Y_s[0] - nu_p[0] * Y[0] = 0 + -Y_s_f[0] + Y_f[0] * P_j_f[0]^(-lambda_p^-1 * (1 + lambda_p)) = 0 + beta * epsilon_b[1] * (C_f[1] - h * C_f[0])^(-sigma_c) - epsilon_b[0] * R_f[0]^-1 * (C_f[0] - h * C_f[-1])^(-sigma_c) = 0 + beta * epsilon_b[1] * pi[1]^-1 * (C[1] - h * C[0])^(-sigma_c) - epsilon_b[0] * R[0]^-1 * (C[0] - h * C[-1])^(-sigma_c) = 0 + Y_f[0] * P_j_f[0]^(-lambda_p^-1 * (1 + lambda_p)) - lambda_p^-1 * Y_f[0] * (1 + lambda_p) * (-mc_f[0] + P_j_f[0]) * P_j_f[0]^(-1 - lambda_p^-1 * (1 + lambda_p)) = 0 + epsilon_b[0] * W_disutil_f[0] * (C_f[0] - h * C_f[-1])^(-sigma_c) - omega * epsilon_b[0] * epsilon_L[0] * L_s_f[0]^sigma_l = 0 + -1 + xi_p * (pi[0]^-1 * pi[-1]^gamma_p)^(-lambda_p^-1) + (1 - xi_p) * pi_star[0]^(-lambda_p^-1) = 0 + -1 + (1 - xi_w) * (w_star[0] * W[0]^-1)^(-lambda_w^-1) + xi_w * (W[-1] * W[0]^-1)^(-lambda_w^-1) * (pi[0]^-1 * pi[-1]^gamma_w)^(-lambda_w^-1) = 0 + -Phi - Y_s[0] + epsilon_a[0] * L[0]^(1 - alpha) * (K[-1] * z[0])^alpha = 0 + -Phi - Y_f[0] * P_j_f[0]^(-lambda_p^-1 * (1 + lambda_p)) + epsilon_a[0] * L_f[0]^(1 - alpha) * (K_f[-1] * z_f[0])^alpha = 0 + eta_b[exo] - log(epsilon_b[0]) + rho_b * log(epsilon_b[-1]) = 0 + -eta_L[exo] - log(epsilon_L[0]) + rho_L * log(epsilon_L[-1]) = 0 + eta_I[exo] - log(epsilon_I[0]) + rho_I * log(epsilon_I[-1]) = 0 + eta_w[exo] - f_1[0] + f_2[0] = 0 + eta_a[exo] - log(epsilon_a[0]) + rho_a * log(epsilon_a[-1]) = 0 + eta_p[exo] - g_1[0] + g_2[0] * (1 + lambda_p) = 0 + eta_G[exo] - log(epsilon_G[0]) + rho_G * log(epsilon_G[-1]) = 0 + -f_1[0] + beta * xi_w * f_1[1] * (w_star[0]^-1 * w_star[1])^(lambda_w^-1) * (pi[1]^-1 * pi[0]^gamma_w)^(-lambda_w^-1) + epsilon_b[0] * w_star[0] * L[0] * (1 + lambda_w)^-1 * (C[0] - h * C[-1])^(-sigma_c) * (w_star[0] * W[0]^-1)^(-lambda_w^-1 * (1 + lambda_w)) = 0 + -f_2[0] + beta * xi_w * f_2[1] * (w_star[0]^-1 * w_star[1])^(lambda_w^-1 * (1 + lambda_w) * (1 + sigma_l)) * (pi[1]^-1 * pi[0]^gamma_w)^(-lambda_w^-1 * (1 + lambda_w) * (1 + sigma_l)) + omega * epsilon_b[0] * epsilon_L[0] * (L[0] * (w_star[0] * W[0]^-1)^(-lambda_w^-1 * (1 + lambda_w)))^(1 + sigma_l) = 0 + -g_1[0] + beta * xi_p * pi_star[0] * g_1[1] * pi_star[1]^-1 * (pi[1]^-1 * pi[0]^gamma_p)^(-lambda_p^-1) + epsilon_b[0] * pi_star[0] * Y[0] * (C[0] - h * C[-1])^(-sigma_c) = 0 + -g_2[0] + beta * xi_p * g_2[1] * (pi[1]^-1 * pi[0]^gamma_p)^(-lambda_p^-1 * (1 + lambda_p)) + epsilon_b[0] * mc[0] * Y[0] * (C[0] - h * C[-1])^(-sigma_c) = 0 + -nu_w[0] + (1 - xi_w) * (w_star[0] * W[0]^-1)^(-lambda_w^-1 * (1 + lambda_w)) + xi_w * nu_w[-1] * (W[-1] * pi[0]^-1 * W[0]^-1 * pi[-1]^gamma_w)^(-lambda_w^-1 * (1 + lambda_w)) = 0 + -nu_p[0] + (1 - xi_p) * pi_star[0]^(-lambda_p^-1 * (1 + lambda_p)) + xi_p * nu_p[-1] * (pi[0]^-1 * pi[-1]^gamma_p)^(-lambda_p^-1 * (1 + lambda_p)) = 0 + -K[0] + K[-1] * (1 - tau) + I[0] * (1 - 0.5 * varphi * (-1 + I[-1]^-1 * epsilon_I[0] * I[0])^2) = 0 + -K_f[0] + K_f[-1] * (1 - tau) + I_f[0] * (1 - 0.5 * varphi * (-1 + I_f[-1]^-1 * epsilon_I[0] * I_f[0])^2) = 0 + U[0] - beta * U[1] - epsilon_b[0] * ((1 - sigma_c)^-1 * (C[0] - h * C[-1])^(1 - sigma_c) - omega * epsilon_L[0] * (1 + sigma_l)^-1 * L_s[0]^(1 + sigma_l)) = 0 + U_f[0] - beta * U_f[1] - epsilon_b[0] * ((1 - sigma_c)^-1 * (C_f[0] - h * C_f[-1])^(1 - sigma_c) - omega * epsilon_L[0] * (1 + sigma_l)^-1 * L_s_f[0]^(1 + sigma_l)) = 0 + -epsilon_b[0] * (C[0] - h * C[-1])^(-sigma_c) + q[0] * (1 - 0.5 * varphi * (-1 + I[-1]^-1 * epsilon_I[0] * I[0])^2 - varphi * I[-1]^-1 * epsilon_I[0] * I[0] * (-1 + I[-1]^-1 * epsilon_I[0] * I[0])) + beta * varphi * I[0]^-2 * epsilon_I[1] * q[1] * I[1]^2 * (-1 + I[0]^-1 * epsilon_I[1] * I[1]) = 0 + -epsilon_b[0] * (C_f[0] - h * C_f[-1])^(-sigma_c) + q_f[0] * (1 - 0.5 * varphi * (-1 + I_f[-1]^-1 * epsilon_I[0] * I_f[0])^2 - varphi * I_f[-1]^-1 * epsilon_I[0] * I_f[0] * (-1 + I_f[-1]^-1 * epsilon_I[0] * I_f[0])) + beta * varphi * I_f[0]^-2 * epsilon_I[1] * q_f[1] * I_f[1]^2 * (-1 + I_f[0]^-1 * epsilon_I[1] * I_f[1]) = 0 + eta_pi[exo] - log(pi_obj[0]) + rho_pi_bar * log(pi_obj[-1]) + log(calibr_pi_obj) * (1 - rho_pi_bar) = 0 + -C[0] - I[0] - T[0] + Y[0] - psi^-1 * r_k[ss] * K[-1] * (-1 + exp(psi * (-1 + z[0]))) = 0 + -calibr_pi + eta_R[exo] - log(R[ss]^-1 * R[0]) + r_Delta_pi * (-log(pi[ss]^-1 * pi[-1]) + log(pi[ss]^-1 * pi[0])) + r_Delta_y * (-log(Y[ss]^-1 * Y[-1]) + log(Y[ss]^-1 * Y[0]) + log(Y_f[ss]^-1 * Y_f[-1]) - log(Y_f[ss]^-1 * Y_f[0])) + rho * log(R[ss]^-1 * R[-1]) + (1 - rho) * (log(pi_obj[0]) + r_pi * (-log(pi_obj[0]) + log(pi[ss]^-1 * pi[-1])) + r_Y * (log(Y[ss]^-1 * Y[0]) - log(Y_f[ss]^-1 * Y_f[0]))) = 0 + -C_f[0] - I_f[0] + Pi_ws_f[0] - T_f[0] + Y_f[0] + L_s_f[0] * W_disutil_f[0] - L_f[0] * W_f[0] - psi^-1 * r_k_f[ss] * K_f[-1] * (-1 + exp(psi * (-1 + z_f[0]))) = 0 + epsilon_b[0] * (K[-1] * r_k[0] - r_k[ss] * K[-1] * exp(psi * (-1 + z[0]))) * (C[0] - h * C[-1])^(-sigma_c) = 0 + epsilon_b[0] * (K_f[-1] * r_k_f[0] - r_k_f[ss] * K_f[-1] * exp(psi * (-1 + z_f[0]))) * (C_f[0] - h * C_f[-1])^(-sigma_c) = 0 + end + + + @parameters SW03 verbose = true begin + calibr_pi_obj | 1 = pi_obj[ss] + calibr_pi | pi[ss] = pi_obj[ss] + # Phi | Y_s[ss] * .408 = Phi + # Phi = .408 * Y_j[ss] + # (Y_j[ss] + Phi) / Y_j[ss] = 1.408 -> Phi; | this seems problematic because of the parameter + # lambda_p | .6 = C_f[ss] / Y_f[ss] + # lambda_w | L[ss] = .33 + # G_bar | .18 = G[ss] / Y[ss] + # calibr_pi_obj = 0 + # calibr_pi = 1 + lambda_p = .368 + G_bar = .362 + lambda_w = 0.5 + Phi = .819 + + alpha = 0.3 + beta = 0.99 + gamma_w = 0.763 + gamma_p = 0.469 + h = 0.573 + omega = 1 + psi = 0.169 + r_pi = 1.684 + r_Y = 0.099 + r_Delta_pi = 0.14 + r_Delta_y = 0.159 + rho = 0.961 + rho_b = 0.855 + rho_L = 0.889 + rho_I = 0.927 + rho_a = 0.823 + rho_G = 0.949 + rho_pi_bar = 0.924 + sigma_c = 1.353 + sigma_l = 2.4 + tau = 0.025 + varphi = 6.771 + xi_w = 0.737 + xi_p = 0.908 + + # Putting non-negative constraint on first block is enough + # 0 < K + # 0 < I + # 0 < Y_s + # 0 < q + # 0 < r_k + # 5 < f_1 + # 0 < L + # 0 < W + # 30 < g_1 + # 0 < z + # 0 < mc + # 0 < w_star + # 5 < f_2 + # 0 < Y + # 0 < g_2 + # 0 < C + end + + + # solve!(SW03, verbose = true) + + + @test isapprox(get_steady_state(SW03, verbose = true)(SW03.timings.var), + [ 1.2043777509278788 + 1.2043777484127967 + 0.362 + 0.362 + 0.44153840098985714 + 0.44153839784516097 + 17.66153603957938 + 17.66153591381742 + 1.2891159430437658 + 1.2891159432893282 + 1.289115942962812 + 1.289115943290125 + 0.9999999999999677 + 0.5401411855429173 + 0.482173806623137 + 0.999999999999352 + 1.0000000000002556 + 1.0101010101010102 + 1.0101010101010102 + 0.362 + 0.362 + -427.9858908413812 + -427.98589116567274 + 1.122103431093411 + 0.7480689524203904 + 1.1221034286309022 + 1.122103428630708 + 2.0079161519182205 + 2.0079161462568305 + 2.0079161519185624 + 2.007916146256947 + 1.0 + 1.0 + 1.0 + 1.0 + 1.0 + 8.770699454739315 + 8.770699454739393 + 48.84717584575426 + 35.70699988724729 + 0.7309941520471651 + 0.730994152046712 + 1.0 + 0.9999999999372022 + 1.0 + 1.0 + 1.0 + 2.4590033452182944 + 2.459003352168301 + 0.035101010082054955 + 0.03510101010809239 + 1.1221034311168996 + 0.9999999999999698 + 1.0000000000000089], + rtol = eps(Float32) + ) + + SW03 = nothing + # # x = 1 + + + # # SW03 = nothing + + # # @model SW03 begin + # # -q[0] + beta * ((1 - tau) * q[1] + epsilon_b[1] * (r_k[1] * z[1] - psi^-1 * r_k[ss] * (-1 + exp(psi * (-1 + z[1])))) * (C[1] - h * C[0])^(-sigma_c)) = 0 + # # -q_f[0] + beta * ((1 - tau) * q_f[1] + epsilon_b[1] * (r_k_f[1] * z_f[1] - psi^-1 * r_k_f[ss] * (-1 + exp(psi * (-1 + z_f[1])))) * (C_f[1] - h * C_f[0])^(-sigma_c)) = 0 + # # -r_k[0] + alpha * epsilon_a[0] * mc[0] * L[0]^(1 - alpha) * (K[-1] * z[0])^(-1 + alpha) = 0 + # # -r_k_f[0] + alpha * epsilon_a[0] * mc_f[0] * L_f[0]^(1 - alpha) * (K_f[-1] * z_f[0])^(-1 + alpha) = 0 + # # -G[0] + T[0] = 0 + # # -G[0] + G_bar * epsilon_G[0] = 0 + # # -G_f[0] + T_f[0] = 0 + # # -G_f[0] + G_bar * epsilon_G[0] = 0 + # # -L[0] + nu_w[0]^-1 * L_s[0] = 0 + # # -L_s_f[0] + L_f[0] * (W_i_f[0] * W_f[0]^-1)^(lambda_w^-1 * (-1 - lambda_w)) = 0 + # # L_s_f[0] - L_f[0] = 0 + # # L_s_f[0] + lambda_w^-1 * L_f[0] * W_f[0]^-1 * (-1 - lambda_w) * (-W_disutil_f[0] + W_i_f[0]) * (W_i_f[0] * W_f[0]^-1)^(-1 + lambda_w^-1 * (-1 - lambda_w)) = 0 + # # Pi_ws_f[0] - L_s_f[0] * (-W_disutil_f[0] + W_i_f[0]) = 0 + # # Pi_ps_f[0] - Y_f[0] * (-mc_f[0] + P_j_f[0]) * P_j_f[0]^(-lambda_p^-1 * (1 + lambda_p)) = 0 + # # -Q[0] + epsilon_b[0]^-1 * q[0] * (C[0] - h * C[-1])^(sigma_c) = 0 + # # -Q_f[0] + epsilon_b[0]^-1 * q_f[0] * (C_f[0] - h * C_f[-1])^(sigma_c) = 0 + # # -W[0] + epsilon_a[0] * mc[0] * (1 - alpha) * L[0]^(-alpha) * (K[-1] * z[0])^alpha = 0 + # # -W_f[0] + epsilon_a[0] * mc_f[0] * (1 - alpha) * L_f[0]^(-alpha) * (K_f[-1] * z_f[0])^alpha = 0 + # # -Y_f[0] + Y_s_f[0] = 0 + # # Y_s[0] - nu_p[0] * Y[0] = 0 + # # -Y_s_f[0] + Y_f[0] * P_j_f[0]^(-lambda_p^-1 * (1 + lambda_p)) = 0 + # # beta * epsilon_b[1] * (C_f[1] - h * C_f[0])^(-sigma_c) - epsilon_b[0] * R_f[0]^-1 * (C_f[0] - h * C_f[-1])^(-sigma_c) = 0 + # # beta * epsilon_b[1] * pi[1]^-1 * (C[1] - h * C[0])^(-sigma_c) - epsilon_b[0] * R[0]^-1 * (C[0] - h * C[-1])^(-sigma_c) = 0 + # # Y_f[0] * P_j_f[0]^(-lambda_p^-1 * (1 + lambda_p)) - lambda_p^-1 * Y_f[0] * (1 + lambda_p) * (-mc_f[0] + P_j_f[0]) * P_j_f[0]^(-1 - lambda_p^-1 * (1 + lambda_p)) = 0 + # # epsilon_b[0] * W_disutil_f[0] * (C_f[0] - h * C_f[-1])^(-sigma_c) - omega * epsilon_b[0] * epsilon_L[0] * L_s_f[0]^sigma_l = 0 + # # -1 + xi_p * (pi[0]^-1 * pi[-1]^gamma_p)^(-lambda_p^-1) + (1 - xi_p) * pi_star[0]^(-lambda_p^-1) = 0 + # # -1 + (1 - xi_w) * (w_star[0] * W[0]^-1)^(-lambda_w^-1) + xi_w * (W[-1] * W[0]^-1)^(-lambda_w^-1) * (pi[0]^-1 * pi[-1]^gamma_w)^(-lambda_w^-1) = 0 + # # -Phi - Y_s[0] + epsilon_a[0] * L[0]^(1 - alpha) * (K[-1] * z[0])^alpha = 0 + # # -Phi - Y_f[0] * P_j_f[0]^(-lambda_p^-1 * (1 + lambda_p)) + epsilon_a[0] * L_f[0]^(1 - alpha) * (K_f[-1] * z_f[0])^alpha = 0 + # # eta_b[exo] - log(epsilon_b[0]) + rho_b * log(epsilon_b[-1]) = 0 + # # -eta_L[exo] - log(epsilon_L[0]) + rho_L * log(epsilon_L[-1]) = 0 + # # eta_I[exo] - log(epsilon_I[0]) + rho_I * log(epsilon_I[-1]) = 0 + # # eta_w[exo] - f_1[0] + f_2[0] = 0 + # # eta_a[exo] - log(epsilon_a[0]) + rho_a * log(epsilon_a[-1]) = 0 + # # eta_p[exo] - g_1[0] + g_2[0] * (1 + lambda_p) = 0 + # # eta_G[exo] - log(epsilon_G[0]) + rho_G * log(epsilon_G[-1]) = 0 + # # -f_1[0] + beta * xi_w * f_1[1] * (w_star[0]^-1 * w_star[1])^(lambda_w^-1) * (pi[1]^-1 * pi[0]^gamma_w)^(-lambda_w^-1) + epsilon_b[0] * w_star[0] * L[0] * (1 + lambda_w)^-1 * (C[0] - h * C[-1])^(-sigma_c) * (w_star[0] * W[0]^-1)^(-lambda_w^-1 * (1 + lambda_w)) = 0 + # # -f_2[0] + beta * xi_w * f_2[1] * (w_star[0]^-1 * w_star[1])^(lambda_w^-1 * (1 + lambda_w) * (1 + sigma_l)) * (pi[1]^-1 * pi[0]^gamma_w)^(-lambda_w^-1 * (1 + lambda_w) * (1 + sigma_l)) + omega * epsilon_b[0] * epsilon_L[0] * (L[0] * (w_star[0] * W[0]^-1)^(-lambda_w^-1 * (1 + lambda_w)))^(1 + sigma_l) = 0 + # # -g_1[0] + beta * xi_p * pi_star[0] * g_1[1] * pi_star[1]^-1 * (pi[1]^-1 * pi[0]^gamma_p)^(-lambda_p^-1) + epsilon_b[0] * pi_star[0] * Y[0] * (C[0] - h * C[-1])^(-sigma_c) = 0 + # # -g_2[0] + beta * xi_p * g_2[1] * (pi[1]^-1 * pi[0]^gamma_p)^(-lambda_p^-1 * (1 + lambda_p)) + epsilon_b[0] * mc[0] * Y[0] * (C[0] - h * C[-1])^(-sigma_c) = 0 + # # -nu_w[0] + (1 - xi_w) * (w_star[0] * W[0]^-1)^(-lambda_w^-1 * (1 + lambda_w)) + xi_w * nu_w[-1] * (W[-1] * pi[0]^-1 * W[0]^-1 * pi[-1]^gamma_w)^(-lambda_w^-1 * (1 + lambda_w)) = 0 + # # -nu_p[0] + (1 - xi_p) * pi_star[0]^(-lambda_p^-1 * (1 + lambda_p)) + xi_p * nu_p[-1] * (pi[0]^-1 * pi[-1]^gamma_p)^(-lambda_p^-1 * (1 + lambda_p)) = 0 + # # -K[0] + K[-1] * (1 - tau) + I[0] * (1 - 0.5 * varphi * (-1 + I[-1]^-1 * epsilon_I[0] * I[0])^2) = 0 + # # -K_f[0] + K_f[-1] * (1 - tau) + I_f[0] * (1 - 0.5 * varphi * (-1 + I_f[-1]^-1 * epsilon_I[0] * I_f[0])^2) = 0 + # # U[0] - beta * U[1] - epsilon_b[0] * ((1 - sigma_c)^-1 * (C[0] - h * C[-1])^(1 - sigma_c) - omega * epsilon_L[0] * (1 + sigma_l)^-1 * L_s[0]^(1 + sigma_l)) = 0 + # # U_f[0] - beta * U_f[1] - epsilon_b[0] * ((1 - sigma_c)^-1 * (C_f[0] - h * C_f[-1])^(1 - sigma_c) - omega * epsilon_L[0] * (1 + sigma_l)^-1 * L_s_f[0]^(1 + sigma_l)) = 0 + # # -epsilon_b[0] * (C[0] - h * C[-1])^(-sigma_c) + q[0] * (1 - 0.5 * varphi * (-1 + I[-1]^-1 * epsilon_I[0] * I[0])^2 - varphi * I[-1]^-1 * epsilon_I[0] * I[0] * (-1 + I[-1]^-1 * epsilon_I[0] * I[0])) + beta * varphi * I[0]^-2 * epsilon_I[1] * q[1] * I[1]^2 * (-1 + I[0]^-1 * epsilon_I[1] * I[1]) = 0 + # # -epsilon_b[0] * (C_f[0] - h * C_f[-1])^(-sigma_c) + q_f[0] * (1 - 0.5 * varphi * (-1 + I_f[-1]^-1 * epsilon_I[0] * I_f[0])^2 - varphi * I_f[-1]^-1 * epsilon_I[0] * I_f[0] * (-1 + I_f[-1]^-1 * epsilon_I[0] * I_f[0])) + beta * varphi * I_f[0]^-2 * epsilon_I[1] * q_f[1] * I_f[1]^2 * (-1 + I_f[0]^-1 * epsilon_I[1] * I_f[1]) = 0 + # # eta_pi[exo] - log(pi_obj[0]) + rho_pi_bar * log(pi_obj[-1]) + log(calibr_pi_obj) * (1 - rho_pi_bar) = 0 + # # -C[0] - I[0] - T[0] + Y[0] - psi^-1 * r_k[ss] * K[-1] * (-1 + exp(psi * (-1 + z[0]))) = 0 + # # -calibr_pi + eta_R[exo] - log(R[ss]^-1 * R[0]) + r_Delta_pi * (-log(pi[ss]^-1 * pi[-1]) + log(pi[ss]^-1 * pi[0])) + r_Delta_y * (-log(Y[ss]^-1 * Y[-1]) + log(Y[ss]^-1 * Y[0]) + log(Y_f[ss]^-1 * Y_f[-1]) - log(Y_f[ss]^-1 * Y_f[0])) + rho * log(R[ss]^-1 * R[-1]) + (1 - rho) * (log(pi_obj[0]) + r_pi * (-log(pi_obj[0]) + log(pi[ss]^-1 * pi[-1])) + r_Y * (log(Y[ss]^-1 * Y[0]) - log(Y_f[ss]^-1 * Y_f[0]))) = 0 + # # -C_f[0] - I_f[0] + Pi_ws_f[0] - T_f[0] + Y_f[0] + L_s_f[0] * W_disutil_f[0] - L_f[0] * W_f[0] - psi^-1 * r_k_f[ss] * K_f[-1] * (-1 + exp(psi * (-1 + z_f[0]))) = 0 + # # epsilon_b[0] * (K[-1] * r_k[0] - r_k[ss] * K[-1] * exp(psi * (-1 + z[0]))) * (C[0] - h * C[-1])^(-sigma_c) = 0 + # # epsilon_b[0] * (K_f[-1] * r_k_f[0] - r_k_f[ss] * K_f[-1] * exp(psi * (-1 + z_f[0]))) * (C_f[0] - h * C_f[-1])^(-sigma_c) = 0 + # # end + + + # # @parameters SW03 begin + # # calibr_pi_obj | 1 = pi_obj[ss] + # # calibr_pi | pi[ss] = pi_obj[ss] + # # Phi | (Y_s[ss] + Phi) / Y_s[ss] = 1.408 + # # # lambda_p | .6 = C_f[ss] / Y_f[ss] + # # # lambda_w | L[ss] = .33 + # # G_bar | .18 = G[ss] / Y[ss] + + # # lambda_p = .368 + # # # G_bar = .362 + # # lambda_w = 0.5 + # # # Phi = .819 + + # # alpha = 0.3 + # # beta = 0.99 + # # gamma_w = 0.763 + # # gamma_p = 0.469 + # # h = 0.573 + # # omega = 1 + # # psi = 0.169 + # # r_pi = 1.684 + # # r_Y = 0.099 + # # r_Delta_pi = 0.14 + # # r_Delta_y = 0.159 + # # rho = 0.961 + # # rho_b = 0.855 + # # rho_L = 0.889 + # # rho_I = 0.927 + # # rho_a = 0.823 + # # rho_G = 0.949 + # # rho_pi_bar = 0.924 + # # sigma_c = 1.353 + # # sigma_l = 2.4 + # # tau = 0.025 + # # varphi = 6.771 + # # xi_w = 0.737 + # # xi_p = 0.908 + + # # end + + + # # solve!(SW03, symbolic_SS = false) + + # # # get_steady_state(SW03) + + # # @test get_steady_state(SW03)[1] ≈ [ 1.20465991441435 + # # 1.204659917151701 + # # 0.3613478048030788 + # # 0.3613478048030788 + # # 0.4414800855444218 + # # 0.4414800896382151 + # # 17.659203422264238 + # # 17.65920357698873 + # # 1.2889457095271066 + # # 1.2889457096070582 + # # 1.2889457095307755 + # # 1.2889457098239414 + # # 1.0000000000366498 + # # 0.5400259611608715 + # # 0.48211013259048446 + # # 1.00000000000172 + # # 1.000000000127065 + # # 1.0101010101010102 + # # 1.0101010101010102 + # # 0.3613478047907606 + # # 0.3613478048030788 + # # -427.92495898028676 + # # -427.9249587468684 + # # 1.1221034247496608 + # # 0.7480689524616317 + # # 1.122103428477167 + # # 1.1221034282377538 + # # 2.0074878047372287 + # # 2.00748781245403 + # # 2.007487804732286 + # # 2.0074878121606647 + # # 1.0 + # # 1.0 + # # 1.0 + # # 1.0 + # # 1.0 + # # 8.766762166589194 + # # 8.766762166588967 + # # 48.8212791635492 + # # 35.68806956399776 + # # 0.730994152045567 + # # 0.7309941520886629 + # # 1.0 + # # 1.0000000000028464 + # # 1.0 + # # 1.0 + # # 1.0 + # # 2.4582240979093846 + # # 2.4582240906598867 + # # 0.03510101014899653 + # # 0.035101010136073356 + # # 1.1221034247485961 + # # 1.0000000000000178 + # # 0.9999999999583465] -@testset verbose = true "First order perturbation" begin - # Numerical test with calibration targets - @model RBC_CME begin - y[0]=A[0]*k[-1]^alpha - 1/c[0]=beta*1/c[1]*(alpha*A[1]*k[0]^(alpha-1)+(1-delta)) - 1/c[0]=beta*1/c[1]*(R[0]/Pi[+1]) - R[0] * beta =(Pi[0]/Pibar)^phi_pi - A[0]*k[-1]^alpha=c[0]+k[0]-(1-delta*z_delta[0])*k[-1] - z_delta[0] = 1 - rho_z_delta + rho_z_delta * z_delta[-1] + std_z_delta * delta_eps[x] - A[0] = 1 - rhoz + rhoz * A[-1] + std_eps * eps_z[x] end - @parameters RBC_CME verbose = true begin - alpha | k[ss] / (4 * y[ss]) = cap_share - cap_share = 1.66 - # alpha = .157 - - beta | R[ss] = R_ss # beta needs to enter into function: block in order to solve - R_ss = 1.0035 - # beta = .999 - - # delta | c[ss]/y[ss] = 1 - I_K_ratio - delta | delta * k[ss] / y[ss] = I_K_ratio #check why this doesnt solve for y; because delta is not recognised as a free parameter here. - I_K_ratio = .15 - # delta = .0226 - - Pibar | Pi[ss] = Pi_ss - Pi_ss = 1.0025 - # Pibar = 1.0008 - - phi_pi = 1.5 - rhoz = .9 - std_eps = .0068 - rho_z_delta = .9 - std_z_delta = .005 - end - - get_solution(RBC_CME) - @test isapprox(RBC_CME.solution.perturbation.first_order.solution_matrix[:,[(end-RBC_CME.timings.nExo+1):end...]], [ 0.0 0.0068 - 6.73489e-6 0.000168887 - 1.01124e-5 0.000253583 - -0.000365783 0.00217203 - -0.00070019 0.00749279 - 0.0 0.00966482 - 0.005 0.0], atol = 1e-6) - - get_solution(RBC_CME, parameters = :I_K_ratio => .1) - @test isapprox(RBC_CME.solution.perturbation.first_order.solution_matrix[:,[(end-RBC_CME.timings.nExo+1):end...]],[ 0.0 0.0068 - 3.42408e-6 0.000111417 - 5.14124e-6 0.000167292 - -0.000196196 0.00190741 - -0.000430554 0.0066164 - 0.0 0.00852381 + @testset verbose = true "First order perturbation" begin + # Numerical test with calibration targets + @model RBC_CME begin + y[0]=A[0]*k[-1]^alpha + 1/c[0]=beta*1/c[1]*(alpha*A[1]*k[0]^(alpha-1)+(1-delta)) + 1/c[0]=beta*1/c[1]*(R[0]/Pi[+1]) + R[0] * beta =(Pi[0]/Pibar)^phi_pi + A[0]*k[-1]^alpha=c[0]+k[0]-(1-delta*z_delta[0])*k[-1] + z_delta[0] = 1 - rho_z_delta + rho_z_delta * z_delta[-1] + std_z_delta * delta_eps[x] + A[0] = 1 - rhoz + rhoz * A[-1] + std_eps * eps_z[x] + end + + + @parameters RBC_CME verbose = true begin + alpha | k[ss] / (4 * y[ss]) = cap_share + cap_share = 1.66 + # alpha = .157 + + beta | R[ss] = R_ss # beta needs to enter into function: block in order to solve + R_ss = 1.0035 + # beta = .999 + + # delta | c[ss]/y[ss] = 1 - I_K_ratio + delta | delta * k[ss] / y[ss] = I_K_ratio #check why this doesnt solve for y; because delta is not recognised as a free parameter here. + I_K_ratio = .15 + # delta = .0226 + + Pibar | Pi[ss] = Pi_ss + Pi_ss = 1.0025 + # Pibar = 1.0008 + + phi_pi = 1.5 + rhoz = .9 + std_eps = .0068 + rho_z_delta = .9 + std_z_delta = .005 + end + + get_solution(RBC_CME) + @test isapprox(RBC_CME.solution.perturbation.first_order.solution_matrix[:,[(end-RBC_CME.timings.nExo+1):end...]], [ 0.0 0.0068 + 6.73489e-6 0.000168887 + 1.01124e-5 0.000253583 + -0.000365783 0.00217203 + -0.00070019 0.00749279 + 0.0 0.00966482 + 0.005 0.0], atol = 1e-6) + + get_solution(RBC_CME, parameters = :I_K_ratio => .1) + @test isapprox(RBC_CME.solution.perturbation.first_order.solution_matrix[:,[(end-RBC_CME.timings.nExo+1):end...]],[ 0.0 0.0068 + 3.42408e-6 0.000111417 + 5.14124e-6 0.000167292 + -0.000196196 0.00190741 + -0.000430554 0.0066164 + 0.0 0.00852381 + 0.005 0.0], atol = 1e-6) + + get_solution(RBC_CME, parameters = :cap_share => 1.5) + @test isapprox(RBC_CME.solution.perturbation.first_order.solution_matrix[:,[(end-RBC_CME.timings.nExo+1):end...]],[ 0.0 0.0068 + 4.00629e-6 0.000118171 + 6.01543e-6 0.000177434 + -0.000207089 0.00201698 + -0.00041124 0.00639229 + 0.0 0.00840927 0.005 0.0], atol = 1e-6) - get_solution(RBC_CME, parameters = :cap_share => 1.5) - @test isapprox(RBC_CME.solution.perturbation.first_order.solution_matrix[:,[(end-RBC_CME.timings.nExo+1):end...]],[ 0.0 0.0068 - 4.00629e-6 0.000118171 - 6.01543e-6 0.000177434 - -0.000207089 0.00201698 - -0.00041124 0.00639229 - 0.0 0.00840927 - 0.005 0.0], atol = 1e-6) - - RBC_CME = nothing -end - - - - - -@testset verbose = true "First order: linear time iteration" begin - # Numerical test with calibration targets - @model RBC_CME begin - y[0]=A[0]*k[-1]^alpha - 1/c[0]=beta*1/c[1]*(alpha*A[1]*k[0]^(alpha-1)+(1-delta)) - 1/c[0]=beta*1/c[1]*(R[0]/Pi[+1]) - R[0] * beta =(Pi[0]/Pibar)^phi_pi - A[0]*k[-1]^alpha=c[0]+k[0]-(1-delta*z_delta[0])*k[-1] - z_delta[0] = 1 - rho_z_delta + rho_z_delta * z_delta[-1] + std_z_delta * delta_eps[x] - A[0] = 1 - rhoz + rhoz * A[-1] + std_eps * eps_z[x] + RBC_CME = nothing end - @parameters RBC_CME verbose = true begin - alpha | k[ss] / (4 * y[ss]) = cap_share - cap_share = 1.66 - # alpha = .157 - beta | R[ss] = R_ss # beta needs to enter into function: block in order to solve - R_ss = 1.0035 - # beta = .999 - # delta | c[ss]/y[ss] = 1 - I_K_ratio - delta | delta * k[ss] / y[ss] = I_K_ratio #check why this doesnt solve for y; because delta is not recognised as a free parameter here. - I_K_ratio = .15 - # delta = .0226 - Pibar | Pi[ss] = Pi_ss - Pi_ss = 1.0025 - # Pibar = 1.0008 + @testset verbose = true "First order: linear time iteration" begin + # Numerical test with calibration targets + @model RBC_CME begin + y[0]=A[0]*k[-1]^alpha + 1/c[0]=beta*1/c[1]*(alpha*A[1]*k[0]^(alpha-1)+(1-delta)) + 1/c[0]=beta*1/c[1]*(R[0]/Pi[+1]) + R[0] * beta =(Pi[0]/Pibar)^phi_pi + A[0]*k[-1]^alpha=c[0]+k[0]-(1-delta*z_delta[0])*k[-1] + z_delta[0] = 1 - rho_z_delta + rho_z_delta * z_delta[-1] + std_z_delta * delta_eps[x] + A[0] = 1 - rhoz + rhoz * A[-1] + std_eps * eps_z[x] + end - phi_pi = 1.5 - rhoz = .9 - std_eps = .0068 - rho_z_delta = .9 - std_z_delta = .005 - end - get_solution(RBC_CME, algorithm = :linear_time_iteration) + @parameters RBC_CME verbose = true begin + alpha | k[ss] / (4 * y[ss]) = cap_share + cap_share = 1.66 + # alpha = .157 - @test isapprox(RBC_CME.solution.perturbation.linear_time_iteration.solution_matrix[:,[(end-RBC_CME.timings.nExo+1):end...]], [ 0.0 0.0068 - 6.73489e-6 0.000168887 - 1.01124e-5 0.000253583 - -0.000365783 0.00217203 - -0.00070019 0.00749279 - 0.0 0.00966482 - 0.005 0.0], atol = 1e-6) + beta | R[ss] = R_ss # beta needs to enter into function: block in order to solve + R_ss = 1.0035 + # beta = .999 + # delta | c[ss]/y[ss] = 1 - I_K_ratio + delta | delta * k[ss] / y[ss] = I_K_ratio #check why this doesnt solve for y; because delta is not recognised as a free parameter here. + I_K_ratio = .15 + # delta = .0226 - get_solution(RBC_CME, algorithm = :linear_time_iteration, parameters = :I_K_ratio => .1) + Pibar | Pi[ss] = Pi_ss + Pi_ss = 1.0025 + # Pibar = 1.0008 - @test isapprox(RBC_CME.solution.perturbation.linear_time_iteration.solution_matrix[:,[(end-RBC_CME.timings.nExo+1):end...]],[ 0.0 0.0068 - 3.42408e-6 0.000111417 - 5.14124e-6 0.000167292 - -0.000196196 0.00190741 - -0.000430554 0.0066164 - 0.0 0.00852381 - 0.005 0.0], atol = 1e-6) + phi_pi = 1.5 + rhoz = .9 + std_eps = .0068 + rho_z_delta = .9 + std_z_delta = .005 + end + get_solution(RBC_CME, algorithm = :linear_time_iteration) - get_solution(RBC_CME, algorithm = :linear_time_iteration, parameters = :cap_share => 1.5) + @test isapprox(RBC_CME.solution.perturbation.linear_time_iteration.solution_matrix[:,[(end-RBC_CME.timings.nExo+1):end...]], [ 0.0 0.0068 + 6.73489e-6 0.000168887 + 1.01124e-5 0.000253583 + -0.000365783 0.00217203 + -0.00070019 0.00749279 + 0.0 0.00966482 + 0.005 0.0], atol = 1e-6) - @test isapprox(RBC_CME.solution.perturbation.linear_time_iteration.solution_matrix[:,[(end-RBC_CME.timings.nExo+1):end...]],[ 0.0 0.0068 - 4.00629e-6 0.000118171 - 6.01543e-6 0.000177434 - -0.000207089 0.00201698 - -0.00041124 0.00639229 - 0.0 0.00840927 - 0.005 0.0], atol = 1e-6) - RBC_CME = nothing -end + get_solution(RBC_CME, algorithm = :linear_time_iteration, parameters = :I_K_ratio => .1) + @test isapprox(RBC_CME.solution.perturbation.linear_time_iteration.solution_matrix[:,[(end-RBC_CME.timings.nExo+1):end...]],[ 0.0 0.0068 + 3.42408e-6 0.000111417 + 5.14124e-6 0.000167292 + -0.000196196 0.00190741 + -0.000430554 0.0066164 + 0.0 0.00852381 + 0.005 0.0], atol = 1e-6) + get_solution(RBC_CME, algorithm = :linear_time_iteration, parameters = :cap_share => 1.5) + @test isapprox(RBC_CME.solution.perturbation.linear_time_iteration.solution_matrix[:,[(end-RBC_CME.timings.nExo+1):end...]],[ 0.0 0.0068 + 4.00629e-6 0.000118171 + 6.01543e-6 0.000177434 + -0.000207089 0.00201698 + -0.00041124 0.00639229 + 0.0 0.00840927 + 0.005 0.0], atol = 1e-6) -@testset verbose = true "First order: quadratic iteration" begin - # Numerical test with calibration targets - @model RBC_CME begin - y[0]=A[0]*k[-1]^alpha - 1/c[0]=beta*1/c[1]*(alpha*A[1]*k[0]^(alpha-1)+(1-delta)) - 1/c[0]=beta*1/c[1]*(R[0]/Pi[+1]) - R[0] * beta =(Pi[0]/Pibar)^phi_pi - A[0]*k[-1]^alpha=c[0]+k[0]-(1-delta*z_delta[0])*k[-1] - z_delta[0] = 1 - rho_z_delta + rho_z_delta * z_delta[-1] + std_z_delta * delta_eps[x] - A[0] = 1 - rhoz + rhoz * A[-1] + std_eps * eps_z[x] + RBC_CME = nothing end - @parameters RBC_CME verbose = true begin - alpha | k[ss] / (4 * y[ss]) = cap_share - cap_share = 1.66 - # alpha = .157 - beta | R[ss] = R_ss # beta needs to enter into function: block in order to solve - R_ss = 1.0035 - # beta = .999 - # delta | c[ss]/y[ss] = 1 - I_K_ratio - delta | delta * k[ss] / y[ss] = I_K_ratio #check why this doesnt solve for y; because delta is not recognised as a free parameter here. - I_K_ratio = .15 - # delta = .0226 - Pibar | Pi[ss] = Pi_ss - Pi_ss = 1.0025 - # Pibar = 1.0008 + @testset verbose = true "First order: quadratic iteration" begin + # Numerical test with calibration targets + @model RBC_CME begin + y[0]=A[0]*k[-1]^alpha + 1/c[0]=beta*1/c[1]*(alpha*A[1]*k[0]^(alpha-1)+(1-delta)) + 1/c[0]=beta*1/c[1]*(R[0]/Pi[+1]) + R[0] * beta =(Pi[0]/Pibar)^phi_pi + A[0]*k[-1]^alpha=c[0]+k[0]-(1-delta*z_delta[0])*k[-1] + z_delta[0] = 1 - rho_z_delta + rho_z_delta * z_delta[-1] + std_z_delta * delta_eps[x] + A[0] = 1 - rhoz + rhoz * A[-1] + std_eps * eps_z[x] + end - phi_pi = 1.5 - rhoz = .9 - std_eps = .0068 - rho_z_delta = .9 - std_z_delta = .005 - end - get_solution(RBC_CME, algorithm = :quadratic_iteration) + @parameters RBC_CME verbose = true begin + alpha | k[ss] / (4 * y[ss]) = cap_share + cap_share = 1.66 + # alpha = .157 - @test isapprox(RBC_CME.solution.perturbation.quadratic_iteration.solution_matrix[:,[(end-RBC_CME.timings.nExo+1):end...]], [ 0.0 0.0068 - 6.73489e-6 0.000168887 - 1.01124e-5 0.000253583 - -0.000365783 0.00217203 - -0.00070019 0.00749279 - 0.0 0.00966482 - 0.005 0.0], atol = 1e-6) + beta | R[ss] = R_ss # beta needs to enter into function: block in order to solve + R_ss = 1.0035 + # beta = .999 + # delta | c[ss]/y[ss] = 1 - I_K_ratio + delta | delta * k[ss] / y[ss] = I_K_ratio #check why this doesnt solve for y; because delta is not recognised as a free parameter here. + I_K_ratio = .15 + # delta = .0226 - get_solution(RBC_CME, algorithm = :quadratic_iteration, parameters = :I_K_ratio => .1) + Pibar | Pi[ss] = Pi_ss + Pi_ss = 1.0025 + # Pibar = 1.0008 - @test isapprox(RBC_CME.solution.perturbation.quadratic_iteration.solution_matrix[:,[(end-RBC_CME.timings.nExo+1):end...]],[ 0.0 0.0068 - 3.42408e-6 0.000111417 - 5.14124e-6 0.000167292 - -0.000196196 0.00190741 - -0.000430554 0.0066164 - 0.0 0.00852381 - 0.005 0.0], atol = 1e-6) + phi_pi = 1.5 + rhoz = .9 + std_eps = .0068 + rho_z_delta = .9 + std_z_delta = .005 + end + get_solution(RBC_CME, algorithm = :quadratic_iteration) - get_solution(RBC_CME, algorithm = :quadratic_iteration, parameters = :cap_share => 1.5) + @test isapprox(RBC_CME.solution.perturbation.quadratic_iteration.solution_matrix[:,[(end-RBC_CME.timings.nExo+1):end...]], [ 0.0 0.0068 + 6.73489e-6 0.000168887 + 1.01124e-5 0.000253583 + -0.000365783 0.00217203 + -0.00070019 0.00749279 + 0.0 0.00966482 + 0.005 0.0], atol = 1e-6) - @test isapprox(RBC_CME.solution.perturbation.quadratic_iteration.solution_matrix[:,[(end-RBC_CME.timings.nExo+1):end...]],[ 0.0 0.0068 - 4.00629e-6 0.000118171 - 6.01543e-6 0.000177434 - -0.000207089 0.00201698 - -0.00041124 0.00639229 - 0.0 0.00840927 - 0.005 0.0], atol = 1e-6) - RBC_CME = nothing -end + get_solution(RBC_CME, algorithm = :quadratic_iteration, parameters = :I_K_ratio => .1) + @test isapprox(RBC_CME.solution.perturbation.quadratic_iteration.solution_matrix[:,[(end-RBC_CME.timings.nExo+1):end...]],[ 0.0 0.0068 + 3.42408e-6 0.000111417 + 5.14124e-6 0.000167292 + -0.000196196 0.00190741 + -0.000430554 0.0066164 + 0.0 0.00852381 + 0.005 0.0], atol = 1e-6) + get_solution(RBC_CME, algorithm = :quadratic_iteration, parameters = :cap_share => 1.5) + @test isapprox(RBC_CME.solution.perturbation.quadratic_iteration.solution_matrix[:,[(end-RBC_CME.timings.nExo+1):end...]],[ 0.0 0.0068 + 4.00629e-6 0.000118171 + 6.01543e-6 0.000177434 + -0.000207089 0.00201698 + -0.00041124 0.00639229 + 0.0 0.00840927 + 0.005 0.0], atol = 1e-6) -@testset verbose = true "Plotting" begin - # Symbolic test with calibration targets - @model RBC_CME begin - y[0]=A[0]*k[-1]^alpha - 1/c[0]=beta*1/c[1]*(alpha*A[1]*k[0]^(alpha-1)+(1-delta)) - 1/c[0]=beta*1/c[1]*(R[0]/Pi[+1]) - R[0] * beta =(Pi[0]/Pibar)^phi_pi - # A[0]*k[-1]^alpha=c[0]+k[0]-(1-delta)*k[-1] - A[0]*k[-1]^alpha=c[0]+k[0]-(1-delta*z_delta[0])*k[-1] - z_delta[0] = 1 - rho_z_delta + rho_z_delta * z_delta[-1] + std_z_delta * delta_eps[x] - # z[0]=rhoz*z[-1]+std_eps*eps_z[x] - # A[0]=exp(z[0]) - A[0] = 1 - rhoz + rhoz * A[-1] + std_eps * eps_z[x] - # log(A[0]) = rhoz * log(A[-1]) + std_eps * eps_z[x] + RBC_CME = nothing end - @parameters RBC_CME verbose = true begin - alpha | k[ss] / (4 * y[ss]) = cap_share - cap_share = 1.66 - # alpha = .157 - beta | R[ss] = R_ss - R_ss = 1.0035 - # beta = .999 - delta | c[ss]/y[ss] = 1 - I_K_ratio - # delta | delta * k[ss] / y[ss] = I_K_ratio # this doesnt solve symbolically - I_K_ratio = .15 - # delta = .0226 - Pibar | Pi[ss] = Pi_ss - Pi_ss = 1.0025 - # Pibar = 1.0008 - - phi_pi = 1.5 - rhoz = .9 - std_eps = .0068 - rho_z_delta = .9 - std_z_delta = .005 - - # cap_share > 0 - # R_ss > 0 - # Pi_ss > 0 - # I_K_ratio > 0 - - # 0 < alpha < 1 - # 0 < beta < 1 - # 0 < delta < 1 - # 0 < Pibar - # 0 <= rhoz < 1 - # phi_pi > 0 - - # 0 < A < 1 - # 0 < k < 50 - # 0 < y < 10 - # 0 < c < 10 + @testset verbose = true "Plotting" begin + # Symbolic test with calibration targets + @model RBC_CME begin + y[0]=A[0]*k[-1]^alpha + 1/c[0]=beta*1/c[1]*(alpha*A[1]*k[0]^(alpha-1)+(1-delta)) + 1/c[0]=beta*1/c[1]*(R[0]/Pi[+1]) + R[0] * beta =(Pi[0]/Pibar)^phi_pi + # A[0]*k[-1]^alpha=c[0]+k[0]-(1-delta)*k[-1] + A[0]*k[-1]^alpha=c[0]+k[0]-(1-delta*z_delta[0])*k[-1] + z_delta[0] = 1 - rho_z_delta + rho_z_delta * z_delta[-1] + std_z_delta * delta_eps[x] + # z[0]=rhoz*z[-1]+std_eps*eps_z[x] + # A[0]=exp(z[0]) + A[0] = 1 - rhoz + rhoz * A[-1] + std_eps * eps_z[x] + # log(A[0]) = rhoz * log(A[-1]) + std_eps * eps_z[x] + end + + + @parameters RBC_CME verbose = true begin + alpha | k[ss] / (4 * y[ss]) = cap_share + cap_share = 1.66 + # alpha = .157 + + beta | R[ss] = R_ss + R_ss = 1.0035 + # beta = .999 + + delta | c[ss]/y[ss] = 1 - I_K_ratio + # delta | delta * k[ss] / y[ss] = I_K_ratio # this doesnt solve symbolically + I_K_ratio = .15 + # delta = .0226 + + Pibar | Pi[ss] = Pi_ss + Pi_ss = 1.0025 + # Pibar = 1.0008 + + phi_pi = 1.5 + rhoz = .9 + std_eps = .0068 + rho_z_delta = .9 + std_z_delta = .005 + + # cap_share > 0 + # R_ss > 0 + # Pi_ss > 0 + # I_K_ratio > 0 + + # 0 < alpha < 1 + # 0 < beta < 1 + # 0 < delta < 1 + # 0 < Pibar + # 0 <= rhoz < 1 + # phi_pi > 0 + + # 0 < A < 1 + # 0 < k < 50 + # 0 < y < 10 + # 0 < c < 10 + end + plot_irf(RBC_CME) + @test true + + RBC_CME = nothing end - plot_irf(RBC_CME) - @test true - - RBC_CME = nothing -end -GC.gc() - -if !test_higher_order # don't test estimation if you are testing higher order - include("test_estimation.jl") -end + GC.gc() +end \ No newline at end of file diff --git a/test/test_estimation.jl b/test/test_estimation.jl index 6c9679ef..eaade099 100644 --- a/test/test_estimation.jl +++ b/test/test_estimation.jl @@ -5,9 +5,7 @@ import Optim, LineSearches using Random, CSV, DataFrames, MCMCChains, AxisKeys import DynamicPPL: logjoint -include("models/FS2000.jl") - -FS2000 = m +include("../models/FS2000.jl") # load data dat = CSV.read("data/FS2000_data.csv", DataFrame) diff --git a/test/test_models.jl b/test/test_models.jl index caf8281c..a9bdce72 100644 --- a/test/test_models.jl +++ b/test/test_models.jl @@ -1,35 +1,122 @@ -include("models/Backus_Kehoe_Kydland_1992.jl") -SS = get_SS(Backus_Kehoe_Kydland_1992) +if !test_higher_order + include("models/Backus_Kehoe_Kydland_1992.jl") + SS = get_SS(Backus_Kehoe_Kydland_1992) -@test isapprox(SS(["A{F}","K{H}","L{F}","LGM"]),[0.606436, 11.0148, 0.696782, 0.278732],rtol = 1e-4) + @test isapprox(SS(["A{F}","K{H}","L{F}","LGM"]),[0.606436, 11.0148, 0.696782, 0.278732],rtol = 1e-4) -var_dec = get_var_decomp(Backus_Kehoe_Kydland_1992) + var_dec = get_var_decomp(Backus_Kehoe_Kydland_1992) -@test isapprox(var_dec(["K{F}","Y{H}","Z{F}"],"E{F}") * 100, [51.34, 42.44, 52.59],rtol = 1e-3) -@test isapprox(var_dec(["K{F}","Y{H}","Z{F}"],"E{H}") * 100, [48.66, 57.56, 47.41],rtol = 1e-3) + @test isapprox(var_dec(["K{F}","Y{H}","Z{F}"],"E{F}") * 100, [51.34, 42.44, 52.59],rtol = 1e-3) + @test isapprox(var_dec(["K{F}","Y{H}","Z{F}"],"E{H}") * 100, [48.66, 57.56, 47.41],rtol = 1e-3) -write_to_dynare_file(Backus_Kehoe_Kydland_1992) -Backus_Kehoe_Kydland_1992 = nothing + write_to_dynare_file(Backus_Kehoe_Kydland_1992) + Backus_Kehoe_Kydland_1992 = nothing + include("../models/NAWM_EAUS_2008.jl") + SS = get_SS(NAWM_EAUS_2008) + @test isapprox(SS([:EAUS_RER,:EA_Y,:EA_K,:EA_C,:US_Y,:US_K]),[0.937577, 3.62701, 33.4238, 2.18955, 3.92449, 33.6712],rtol = 1e-5) -include("models/NAWM_EAUS_2008.jl") -SS = get_SS(NAWM_EAUS_2008) + var_dec = get_var_decomp(NAWM_EAUS_2008) -@test isapprox(SS([:EAUS_RER,:EA_Y,:EA_K,:EA_C,:US_Y,:US_K]),[0.937577, 3.62701, 33.4238, 2.18955, 3.92449, 33.6712],rtol = 1e-5) + @test isapprox(var_dec(:EAUS_RER,[:EA_EPSR,:EA_EPSRP,:US_EPSTAUN]) * 100, [22.15, 54.99, 0.03],rtol = 1e-3) + @test isapprox(var_dec(:EA_Y,[:EA_EPSR,:EA_EPSZ,:US_EPSZ]) * 100, [50.02, 13.54, 4.35],rtol = 1e-3) + @test isapprox(var_dec(:US_K,[:EA_EPSRP,:US_EPSR,:US_EPSZ]) * 100, [17.48, 26.83, 27.76],rtol = 1e-3) -var_dec = get_var_decomp(NAWM_EAUS_2008) + write_to_dynare_file(NAWM_EAUS_2008) + NAWM_EAUS_2008 = nothing -@test isapprox(var_dec(:EAUS_RER,[:EA_EPSR,:EA_EPSRP,:US_EPSTAUN]) * 100, [22.15, 54.99, 0.03],rtol = 1e-3) -@test isapprox(var_dec(:EA_Y,[:EA_EPSR,:EA_EPSZ,:US_EPSZ]) * 100, [50.02, 13.54, 4.35],rtol = 1e-3) -@test isapprox(var_dec(:US_K,[:EA_EPSRP,:US_EPSR,:US_EPSZ]) * 100, [17.48, 26.83, 27.76],rtol = 1e-3) -write_to_dynare_file(NAWM_EAUS_2008) -NAWM_EAUS_2008 = nothing -include("models/SGU_2003_debt_premium.jl") + include("../models/Baxter_King_1993.jl") + moments = get_moments(Baxter_King_1993, derivatives = false) + + @test isapprox(moments[1][end-1:end],[0.334599,5.29504],rtol = 1e-3) + + corrr = get_correlation(Baxter_King_1993) + + @test isapprox(corrr(:k,:l),0.8553,rtol = 1e-3) + @test isapprox(corrr(:r,:w),-0.9898,rtol = 1e-3) + + write_to_dynare_file(Baxter_King_1993) + Baxter_King_1993 = nothing + + + include("../models/Ireland_2004.jl") + moments = get_moments(Ireland_2004, derivatives = false) + + @test isapprox(moments[2],[0.0709,0.0015,0.0077,0.0153,0.0075,0.0163,0.0062],atol = 1e-4) + + var_dec = get_variance_decomposition(Ireland_2004) + + @test isapprox(var_dec(:π̂,:) * 100, [4.51, 0.91, 87.44, 7.14],rtol = 1e-4) + + write_to_dynare_file(Ireland_2004) + Ireland_2004 = nothing + + + + + include("../models/QUEST3_2009.jl") + moments = get_moments(QUEST3_2009, derivatives = false) + + @test isapprox(moments[1]([:E_BGYN,:E_LUCYN,:E_LIGSN,:E_VL,:E_LCY],:),[2.4,4.99556,-3.68888,19.0693,-0.538115],rtol = 1e-5) + + var_dec = get_var_decomp(QUEST3_2009) + + @test isapprox(var_dec(:E_BGYN,:) * 100, [3.00, 0.23, 0.54, 0.01, 0.08, 0.38, 0.14, 0.10, 83.60, 3.28, 1.11, 3.36, 0.01, 1.56, 0.17, 0.17, 0.00, 2.24, 0.01], rtol = 1e-3) + + write_to_dynare_file(QUEST3_2009) + QUEST3_2009 = nothing + + + + + include("../models/GNSS_2010.jl") + moments = get_moments(GNSS_2010, derivatives = false) + + @test isapprox(moments[1]([:x,:C,:Y,:D,:BE,:BH,:B],:),exp.([0.182322,0.1305,0.273583,1.04257,0.674026,0.144027,1.13688]),rtol = 1e-5) + + var_dec = get_var_decomp(GNSS_2010) + + @test isapprox(var_dec(:B,:) * 100, [42.97, 19.31, 11.70, 0.36, 4.45, 1.41, 0.70, 0.00, 0.61, 12.54, 2.85, 2.72, 0.38],rtol = 1e-3) + + write_to_dynare_file(GNSS_2010) + GNSS_2010 = nothing + + + include("../models/Gali_Monacelli_2005_CITR.jl") + moments = get_moments(Gali_Monacelli_2005_CITR, derivatives = false) + + @test isapprox(moments[2]([:a,:r,:s,:pi],:),[2.2942, 0.4943, 2.7590, 0.3295],atol = 1e-4) + + var_dec = get_var_decomp(Gali_Monacelli_2005_CITR) + + @test isapprox(var_dec(:pih,:) * 100, [62.06, 37.94],rtol = 1e-3) + @test isapprox(var_dec(:x,:) * 100, [56.22, 43.78],rtol = 1e-3) + + write_to_dynare_file(Gali_Monacelli_2005_CITR) + Gali_Monacelli_2005_CITR = nothing + + + include("../models/Ascari_Sbordone_2014.jl") + moments = get_moments(Ascari_Sbordone_2014, derivatives = false) + + @test isapprox(log.(moments[1]([:i,:y,:psi,:phi],:)),[-4.59512, -1.09861, 1.25138, 1.35674],rtol = 1e-4) + + var_dec = get_var_decomp(Ascari_Sbordone_2014) + + @test isapprox(var_dec(:w,:) * 100, [2.02, 95.18, 2.80],rtol = 1e-3) + @test isapprox(var_dec(:y,:) * 100, [0.47, 99.41, 0.12],rtol = 1e-3) + + write_to_dynare_file(Ascari_Sbordone_2014) + Ascari_Sbordone_2014 = nothing + +end + +include("../models/SGU_2003_debt_premium.jl") moments = get_moments(SGU_2003_debt_premium, derivatives = false) @test isapprox(moments[1][4:8],[0.7442,exp(0.00739062),exp(-1.07949),exp(1.22309),exp(-3.21888)],rtol = 1e-5) @@ -51,23 +138,8 @@ write_to_dynare_file(SGU_2003_debt_premium) SGU_2003_debt_premium = nothing -include("models/Baxter_and_King_1993.jl") -moments = get_moments(Baxter_and_King_1993, derivatives = false) - -@test isapprox(moments[1][end-1:end],[0.334599,5.29504],rtol = 1e-3) - -corrr = get_correlation(Baxter_and_King_1993) - -@test isapprox(corrr(:k,:l),0.8553,rtol = 1e-3) -@test isapprox(corrr(:r,:w),-0.9898,rtol = 1e-3) - -write_to_dynare_file(Baxter_and_King_1993) -Baxter_and_King_1993 = nothing - - - -include("models/JQ_2012_RBC.jl") +include("../models/JQ_2012_RBC.jl") moments = get_moments(JQ_2012_RBC, derivatives = false) @test isapprox(moments[1][1:6],[1.01158,3.63583,0.811166,0.114801,0.251989,10.0795],rtol = 1e-5) @@ -91,38 +163,9 @@ JQ_2012_RBC = nothing -include("models/Ireland_2004.jl") -moments = get_moments(Ireland_2004, derivatives = false) - -@test isapprox(moments[2],[0.0709,0.0015,0.0077,0.0153,0.0075,0.0163,0.0062],atol = 1e-4) - -var_dec = get_variance_decomposition(Ireland_2004) - -@test isapprox(var_dec(:π̂,:) * 100, [4.51, 0.91, 87.44, 7.14],rtol = 1e-4) - -write_to_dynare_file(Ireland_2004) -Ireland_2004 = nothing - - - - -include("models/GNSS_2010.jl") -moments = get_moments(GNSS_2010, derivatives = false) - -@test isapprox(moments[1]([:x,:C,:Y,:D,:BE,:BH,:B],:),exp.([0.182322,0.1305,0.273583,1.04257,0.674026,0.144027,1.13688]),rtol = 1e-5) -var_dec = get_var_decomp(GNSS_2010) -@test isapprox(var_dec(:B,:) * 100, [42.97, 19.31, 11.70, 0.36, 4.45, 1.41, 0.70, 0.00, 0.61, 12.54, 2.85, 2.72, 0.38],rtol = 1e-3) - -write_to_dynare_file(GNSS_2010) -GNSS_2010 = nothing - - - - - -include("models/Ghironi_Melitz_2005.jl") +include("../models/Ghironi_Melitz_2005.jl") moments = get_moments(Ghironi_Melitz_2005, derivatives = false) @test isapprox(moments[1]([:Nd,:Nd̄,:Ne,:Nē,:Nx,:Nx̄],:),[7.50695, 7.50695,0.192486, 0.192486, 1.57988, 1.57988],rtol = 1e-5) @@ -147,24 +190,10 @@ Ghironi_Melitz_2005 = nothing -include("models/Gali_Monacelli_2005_CITR.jl") -moments = get_moments(Gali_Monacelli_2005_CITR, derivatives = false) - -@test isapprox(moments[2]([:a,:r,:s,:pi],:),[2.2942, 0.4943, 2.7590, 0.3295],atol = 1e-4) - -var_dec = get_var_decomp(Gali_Monacelli_2005_CITR) - -@test isapprox(var_dec(:pih,:) * 100, [62.06, 37.94],rtol = 1e-3) -@test isapprox(var_dec(:x,:) * 100, [56.22, 43.78],rtol = 1e-3) -write_to_dynare_file(Gali_Monacelli_2005_CITR) -Gali_Monacelli_2005_CITR = nothing - - - -include("models/Gali_2015_chapter_3_nonlinear.jl") +include("../models/Gali_2015_chapter_3_nonlinear.jl") moments = get_moments(Gali_2015_chapter_3_nonlinear, derivatives = false) @test isapprox(moments[1]([:C,:N,:M_real,:Y],:),[0.95058, 0.934655, 0.915236, 0.95058],rtol = 1e-5) @@ -187,7 +216,7 @@ Gali_2015_chapter_3_nonlinear = nothing -include("models/Caldara_et_al_2012.jl") +include("../models/Caldara_et_al_2012.jl") moments = get_moments(Caldara_et_al_2012, derivatives = false) @test isapprox(moments[1]([:Rᵏ,:V,:c,:i],:),[0.00908174, 0.687139, 0.724731, 0.18689],rtol = 1e-5) @@ -206,22 +235,8 @@ Caldara_et_al_2012 = nothing -include("models/Ascari_Sbordone_2014.jl") -moments = get_moments(Ascari_Sbordone_2014, derivatives = false) - -@test isapprox(log.(moments[1]([:i,:y,:psi,:phi],:)),[-4.59512, -1.09861, 1.25138, 1.35674],rtol = 1e-4) - -var_dec = get_var_decomp(Ascari_Sbordone_2014) - -@test isapprox(var_dec(:w,:) * 100, [2.02, 95.18, 2.80],rtol = 1e-3) -@test isapprox(var_dec(:y,:) * 100, [0.47, 99.41, 0.12],rtol = 1e-3) - -write_to_dynare_file(Ascari_Sbordone_2014) -Ascari_Sbordone_2014 = nothing - - -include("models/Aguiar_Gopinath_2007.jl") +include("../models/Aguiar_Gopinath_2007.jl") moments = get_moments(Aguiar_Gopinath_2007, derivatives = false) @test isapprox(moments[1]([:b,:c,:u,:ul],:),[0.0645177, 0.496156, -1.66644, -1.597],rtol = 1e-5) diff --git a/test/test_standalone_function.jl b/test/test_standalone_function.jl index c33401ea..53d85ff8 100644 --- a/test/test_standalone_function.jl +++ b/test/test_standalone_function.jl @@ -1,10 +1,10 @@ using SparseArrays using MacroModelling import MacroModelling: timings -using ForwardDiff, FiniteDifferences, Zygote -import Optim, LineSearches +using ForwardDiff import LinearAlgebra as ℒ - +using FiniteDifferences, Zygote +import Optim, LineSearches @testset verbose = true "Basic model solution and std" begin Random.seed!(3) @@ -57,7 +57,7 @@ import LinearAlgebra as ℒ end -SS_and_pars, _ = RBC_CME.SS_solve_func(RBC_CME.parameter_values, RBC_CME, true) +SS_and_pars, _ = RBC_CME.SS_solve_func(RBC_CME.parameter_values, RBC_CME, true, false, RBC_CME.solver_parameters) get_irf(RBC_CME, algorithm = :third_order) get_irf(RBC_CME, algorithm = :pruned_third_order) @@ -712,3 +712,13 @@ end end m = nothing 𝓂 = nothing + + + +@testset verbose = true "Occasionally binding constraints" begin + include("../models/Gali_2015_chapter_3_obc.jl") + + sims = simulate(Gali_2015_chapter_3_obc, variables = :R) + + @test isapprox(minimum(sims), 1, atol = eps(Float32)) +end \ No newline at end of file