Perturbation of Neoclassical Model

Author

Pablo Winant

Our goal here is to compute a linear approximation of solution to the neoclassical model, c# execute: # freeze: true
# execute: # enabled: falselose ot the steady-state.

  1. Warm-up: install the ForwardDiff library. Use it to differentiate the function below. Check the jacobian function.

Note: the signature of function f needs to be fixed first to allow for dual numbers as arguments.

# function f(x::Vector{T}) where T <: Number
function f(x)
    a = x[1]
    b = x[2]
    x1 = a+b
    x2 = a*exp(b)
    return [x1,x2]
end
# your code here
  1. Create a NamedTuple to hold the model parameters.
# your code here
  1. Define two functions:
  1. Using multiple dispatch, define two variants of the same functions, that take vectors as input and output arguments:
# your code here
# your code here
# your code here
  1. Write a function steady_state(p)::Tuple{Vector,Vector} which computes the steady-state of the model computed by hand. It returns two vectors, one for the states, one for the controls. Check that the steady-state satisfies the model equations.
# your code here
# your code here

The first order system satisfies: \[\begin{align}A s_t + B x_t + C s_{t+1} + D x_{t+1} & = & 0 \\\\ s_{t+1} & = & E s_t + F x_t \end{align}\]

  1. Define a structure PerturbedModel to hold matrices A,B,C,D,E,F.
# your code here
  1. Write a function first_order_model(s::Vector, x::Vector, p)::PerturbedModel, which returns the first order model, given the steady-state and the calibration. Suggestion: use ForwardDiff.jl library.
# your code here
  1. We look for a linear solution \(x_t = X s_t\) . Write the matrix equation which X must satisfy. Write a function residual(X::Array, M::PerturbedModel) which computes the residual of this equation for a given X.
# your code here
  1. Write a function T(X, M::PerturbedModel) which implements the time iteration step.
# your code here
  1. Write function linear_time_iteration(X_0::Matrix, m::PerturbedModel)::Matrix which implements the time iteration algorithm. Apply it to X0 = rand(1,2) and check that the result satisfies the first order model.
# your code here
  1. Check blanchard Kahn Conditions
# your code here
  1. Write a function simulate(s0::Vector, X::Matrix, p, T::Int64)::Tuple{Matrix, Matrix} to simulate the model over \(T\) periods (by using the formula \(\Delta s_t = (E + F X) \Delta s_{t-1})\). Return a matrix for the states (one line per date) and another matrix for the controls. Bonus: add a keyword option to compute variables levels or log-deviations. If possible, return a DataFrame object.
# your code here
  1. Make some nice plots.