Coder Social home page Coder Social logo

dsgesolves.jl's Introduction

DsgeSolves.jl

Solution methods for simple DSGE models in Julia

Installation

Pkg.clone("https://github.com/lucabrugnolini/DsgeSolves.jl")

Introduction

This package is a work for solving locally and globally simple DSGE models

Status

  • Linear DSGE
    • Blanchard Kahn (1980)
      • Impulse response functions (IRFs)
      • Simulating data from the model
      • Forecast error variance decomposition (FEVD)
  • Non-linear DSGE
    • Projection methods ---> NOT GENERAL YET
      • Neural network
        • Impulse response functions (IRFs)
        • Simulating data from the model

Example

## Model
## Two equations NK model on the form (1)-(2):  
# (1) A*Y(+1) = B*Y + C*X
# (2) X(+1) = D*X + E*ϵ, ϵ ~ N(0,Σ) 
# Solution has the form of (3):
# (3) Y(+1) = inv(A)*B*Y + inv(A)*C*X
# provided A full rank and eigenvalues in inv(A)*B respecting Blanchard and Kahn (1980) conditions

## Example
# NKIS: x(t+1) + σ^(-1)π(t+1) = x(t) + σ^(-1)δπ(t) + σ^(-1)v(t)
# NKPC: βπ(t+1) = -kx(t) +π(t)
using DsgeSolves, Plots
plotly()

# Declare number of variables
nb = 2 # #backwardlooking variables
nf = 2 # #forward looking variables
ns = 2 # #forcing variables
m = DSGE(nb,nf,ns)

# Preallocations and hyperparameters
rep = 1000
burn_in = 100

## Indexing variables for filling A
iv = 1
iu = 2
ix = 3= 4

# Indexing shock
iϵ_v = 1
iϵ_u = 2

## Calibration
# Structural parameters
β = 0.99
σ = 1
χ = 1.55
η = 0
θ = 2.064
ω = 0.5
α = 3
δ = 1.5
κ = (1-ω)*(1-β*ω)/*ω)

# Non-structural parameters
ρ_u = 0.5
ρ_v = 0.8
σ_v = 1
σ_u = 0.5
Σ = diagm([σ_v, σ_u])

## Filling matrices A, B, C
# four variables:
#                  2 forward-looking -- output gap and inflation
#                  2 predetermined -- interest rate shock

# Equation #1 monetary policy shock
# v(t+1) = ρ_vv(t) + ϵ_v(t+1)
nequ = 1
m.A[nequ, iv] = 1
m.B[nequ, iv] = ρ_v
m.C[nequ, iϵ_v] = 1

# Equation #2 cost-push shock
# u(t+1) = ρ_uu(t) + ϵ_u(t+1)
nequ = 2
m.A[nequ, iu] = 1
m.B[nequ, iu] = ρ_u
m.C[nequ, iϵ_u] = 1

# Equation #3 IS curve
# x(t+1) + σ^(-1)π(t+1) = x(t) + σ^(-1)δπ(t) + σ^(-1)v(t)
nequ = 3
m.A[nequ, ix] = 1
m.A[nequ, iπ] = 1/σ
m.B[nequ, iv] = 1/σ
m.B[nequ, ix] = 1
m.B[nequ, iπ] = δ/σ

# Equation #4 NKPC
# βπ(t+1) = -kx(t) +π(t)
nequ = 4
m.A[nequ, iπ] = β
m.B[nequ, iu] = -1
m.B[nequ, ix] = -κ
m.B[nequ, iπ] = 1

## Solve and simulate the model
(A, B, Λ, P, pstar, R) = create_matrices(m)
(w, y) = simulating_dsge(m,pstar,Λ,R,Σ,rep)
# Plot model simulation
pSimulation = plot(layout = grid(2,2));
plot!(pSimulation, w[1,burn_in+1:end], subplot = 1, color = "blue", title = ":ϵ_u");
plot!(pSimulation, w[2,burn_in+1:end], subplot = 2, color = "blue", title = ":ϵ_v");
plot!(pSimulation, y[1,burn_in+1:end], subplot = 3, color = "blue", title = ":x");
plot!(pSimulation, y[2,burn_in+1:end], subplot = 4, color = "blue", title = "");
gui(pSimulation)

# Impulse response functions
shk = 1 # choose the shock number
h = 20
(irf_w,irf_y) = irf_dsge(m,pstar,Λ,R,shk,h)
# Plot model IRFs
pIRF = plot(layout = grid(1,2));
plot!(pIRF, irf_y[1,:], subplot = 1, color = "blue", title = ":x");
plot!(pIRF, irf_y[2,:], subplot = 2, color = "blue", title = "");
gui(pIRF)

# Computing stylized facts as standard deviation and correlation of series
mean(w,2), mean(y,2)
std(w,2), std(y,2)

dsgesolves.jl's People

Contributors

lucabrugnolini avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

jngod2011

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.