Skip to content

Commit

Permalink
Merge pull request #48 from thorek1/higher_order__moments
Browse files Browse the repository at this point in the history
Higher order moments
  • Loading branch information
thorek1 authored Sep 24, 2023
2 parents 6ae5c7c + 0657dca commit fd38ae9
Show file tree
Hide file tree
Showing 23 changed files with 2,899 additions and 3,213 deletions.
31 changes: 7 additions & 24 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,19 @@ jobs:
fail-fast: false
matrix:
version:
# - '1.8'
- '1.9' #^1-0 and ^1.9-0 are not recognised
# - 'nightly' # fails for zygote
os:
- ubuntu-latest
- macOS-latest #slow
- windows-latest #slow
- macOS-latest
- windows-latest
arch:
- x64
# - aarch64 #not implemented in Github CI
include:
- os: ubuntu-latest
prefix: xvfb-run
- version: '1.8'
os: ubuntu-latest
arch: x64
#- version: '1.8'
# os: windows-latest
# arch: x64
- version: '^1.10.0-0'
os: ubuntu-latest
arch: x64
Expand All @@ -42,18 +36,8 @@ jobs:
arch: x64
allow_failure: true
steps:
- uses: actions/checkout@v3
#- uses: uraimo/[email protected]
# - name: Set up QEMU
# if: matrix.arch == 'aarch64'
# uses: docker/setup-qemu-action@v2
# - name: Set up Docker Buildx
# if: matrix.arch == 'aarch64'
# uses: docker/setup-buildx-action@v2
# - name: Build and push
# if: matrix.arch == 'aarch64'
# uses: docker/build-push-action@v3
- uses: julia-actions/setup-julia@latest
- uses: actions/checkout@v4
- uses: julia-actions/setup-julia@v1
with:
version: ${{ matrix.version }}
arch: ${{ matrix.arch }}
Expand All @@ -70,12 +54,11 @@ jobs:
${{ runner.os }}-test-${{ env.cache-name }}-
${{ runner.os }}-test-
${{ runner.os }}-
# - run: pip3 install sympy
- uses: julia-actions/julia-buildpkg@latest
- uses: julia-actions/julia-runtest@latest
- uses: julia-actions/julia-buildpkg@v1
- uses: julia-actions/julia-runtest@v1
with:
prefix: ${{ matrix.prefix }} # for `xvfb-run`
- uses: julia-actions/julia-processcoverage@latest
- uses: julia-actions/julia-processcoverage@v1
- uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
Expand Down
4 changes: 3 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "MacroModelling"
uuid = "687ffad2-3618-405e-ac50-e0f7b9c75e44"
authors = ["Thore Kockerols <[email protected]>"]
version = "0.1.28"
version = "0.1.29"

[deps]
AbstractDifferentiation = "c29ec348-61ec-40c8-8164-b8c60e9d9f3d"
Expand Down Expand Up @@ -31,6 +31,7 @@ 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"

[weakdeps]
StatsPlots = "f3b207a7-027a-5e70-b257-86293d7955fd"
Expand Down Expand Up @@ -61,6 +62,7 @@ SpeedMapping = "^0.3"
Subscripts = "^0.1"
SymPyPythonCall = "^0.1.1"
Symbolics = "^5"
ThreadedSparseArrays = "^0.2"
julia = "1.8"

[extras]
Expand Down
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@

**Author: Thore Kockerols (@thorek1)**

`MacroModelling.jl` is a package for developing and solving dynamic stochastic general equilibrium (DSGE) models. The package provides functions for creating, calibrating, simulating and estimating discrete-time DSGE models. These kind of models are typically used to describe the behaviour of a macroeconomy and are particularly suited for counterfactual analysis (economic policy evaluation) and exploring/quantifying specific mechanisms (academic research). These models are difficult to work with because they consist of a nonlinear system of equations describing a stochastic control problem.
`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 `MacroModelling.jl` is to reduce coding time and speed up model development.
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 facilitates fast prototyping of models. The target audience for the package includes central bankers, regulators, graduate students, and others working in academia with an interest in DSGE modelling.

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 perturbation solutions using (forward or reverse-mode) automatic differentiation (AD)
- calculate first, second, and third order (pruned) perturbation solutions using (forward or reverse-mode) automatic differentiation (AD)
- calculate (generalised) impulse response functions, simulate the model, or do conditional forecasts
- calibrate parameters using (non stochastic) steady state relationships
- match model moments
- match model moments (also for pruned higher order solutions)
- estimate the model on data (Kalman filter using first order perturbation)
- **differentiate** (forward AD) the model solution, Kalman filter loglikelihood (reverse-mode AD), model moments, steady state, **with respect to the parameters**

Expand Down Expand Up @@ -99,6 +99,7 @@ The package contains the following models in the `models` folder:
**Automatic declaration of variables and parameters**|yes|||||||||||||
**Derivatives (Automatic Differentiation) wrt parameters**|yes|||||||||yes - for all 1st, 2nd order perturbation solution related output *if user supplied steady state equations*|||
**Perturbation solution order**|1, 2, 3|k|1 to 5|1|1|1|1|1, 2, 3|1, 2, 3|1, 2|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||
**Global solution**||||||||yes|yes|||yes||
Expand All @@ -108,6 +109,7 @@ The package contains the following models in the `models` folder:
**Timing convention**|end-of-period|end-of-period|end-of-period|end-of-period|end-of-period||end-of-period|start-of-period|end-of-period|start-of-period|end-of-period|start-of-period|start-of-period|

## Bibliography

Andreasen, M. M., Fernández-Villaverde, J., and Rubio-Ramírez, J. F. (2018), "The pruned state-space system for non-linear DSGE models: Theory and empirical applications.", The Review of Economic Studies, 85.1, p. 1-49.

Durbin, J, and Koopman, S. J. (2012), "Time Series Analysis by State Space Methods, 2nd edn", Oxford University Press.
Expand Down
4 changes: 2 additions & 2 deletions benchmark/SW07_estimation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ function calculate_kalman_filter_loglikelihoods(𝓂::ℳ, data::AbstractArray{F

data_in_deviations = collect(data(observables)) .- SS_and_pars[obs_indices]

∇₁ = calculate_jacobian(parameters, SS_and_pars, 𝓂)
∇₁ = calculate_jacobian(parameters, SS_and_pars, 𝓂) |> Matrix

sol = calculate_first_order_solution(∇₁; T = 𝓂.timings)

Expand Down Expand Up @@ -485,7 +485,7 @@ function calculate_kalman_filter_loglikelihoods(𝓂::ℳ, data::AbstractArray{F

data_in_deviations = collect(data(observables)) .- SS_and_pars[obs_indices]

∇₁ = calculate_jacobian(parameters, SS_and_pars, 𝓂)
∇₁ = calculate_jacobian(parameters, SS_and_pars, 𝓂) |> Matrix

sol = calculate_first_order_solution(∇₁; T = 𝓂.timings)

Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ makedocs(
"Installation" => "tutorials/install.md",
"Write your first simple model - RBC" => "tutorials/rbc.md",
"Work with a more complex model - Smets and Wouters (2003)" => "tutorials/sw03.md",
"Calibration / method of moments (for higher order perturbation solutions) - Gali (2015)" => "tutorials/calibration.md",
"Estimate a model using gradient based samplers - Schorfheide (2000)" => "tutorials/estimation.md",
],
"How-to guides" => [
Expand Down
8 changes: 5 additions & 3 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

**Author: Thore Kockerols (@thorek1)**

`MacroModelling.jl` is a package for developing and solving dynamic stochastic general equilibrium (DSGE) models. The package provides functions for creating, calibrating, simulating and estimating discrete-time DSGE models. These kind of models are typically used to describe the behaviour of a macroeconomy and are particularly suited for counterfactual analysis (economic policy evaluation) and exploring/quantifying specific mechanisms (academic research). These models are difficult to work with because they consist of a nonlinear system of equations describing a stochastic control problem.
`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 `MacroModelling.jl` is to reduce coding time and speed up model development.
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 facilitates fast prototyping of models. The target audience for the package includes central bankers, regulators, graduate students, and others working in academia with an interest in DSGE modelling.

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 perturbation solutions using (forward or reverse-mode) automatic differentiation (AD)
- calculate first, second, and third order (pruned) perturbation solutions using (forward or reverse-mode) automatic differentiation (AD)
- calculate (generalised) impulse response functions, simulate the model, or do conditional forecasts
- calibrate parameters using (non stochastic) steady state relationships
- match model moments
Expand Down Expand Up @@ -54,6 +54,7 @@ The package contains the following models in the `models` folder:
**Automatic declaration of variables and parameters**|yes|||||||||||||
**Derivatives (Automatic Differentiation) wrt parameters**|yes|||||||||yes - for all 1st, 2nd order perturbation solution related output *if user supplied steady state equations*|||
**Perturbation solution order**|1, 2, 3|k|1 to 5|1|1|1|1|1, 2, 3|1, 2, 3|1, 2|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||
**Global solution**||||||||yes|yes|||yes||
Expand All @@ -63,6 +64,7 @@ The package contains the following models in the `models` folder:
**Timing convention**|end-of-period|end-of-period|end-of-period|end-of-period|end-of-period||end-of-period|start-of-period|end-of-period|start-of-period|end-of-period|start-of-period|start-of-period|

## Bibliography

Andreasen, M. M., Fernández-Villaverde, J., and Rubio-Ramírez, J. F. (2018), "The pruned state-space system for non-linear DSGE models: Theory and empirical applications.", The Review of Economic Studies, 85.1, p. 1-49.

Durbin, J, and Koopman, S. J. (2012), "Time Series Analysis by State Space Methods, 2nd edn", Oxford University Press.
Expand Down
Loading

2 comments on commit fd38ae9

@thorek1
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/92130

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.1.29 -m "<description of version>" fd38ae9e0550faa639a90eb9be19c805f7f5a716
git push origin v0.1.29

Please sign in to comment.