Skip to content

Commit

Permalink
Merge pull request #58 from thorek1/obc
Browse files Browse the repository at this point in the history
obc
  • Loading branch information
thorek1 authored Nov 19, 2023
2 parents 3bd0791 + cf9a1ae commit 93bc6e7
Show file tree
Hide file tree
Showing 55 changed files with 5,427 additions and 4,482 deletions.
35 changes: 34 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 26 additions & 3 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -33,40 +36,60 @@ 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]
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]
Expand Down
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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)
Expand Down Expand Up @@ -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`
Expand All @@ -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`
Expand All @@ -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|||||
Expand Down
4 changes: 2 additions & 2 deletions benchmark/SW07_estimation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Loading

0 comments on commit 93bc6e7

Please sign in to comment.