MacroModelling.BetaMethod
Beta(μ, σ, lower_bound, upper_bound; μσ)

Convenience wrapper for the truncated Beta distribution.

If μσ = true then μ and σ are translated to the parameters of the distribution. Otherwise μ and σ represent the parameters of the distribution.

Arguments

  • μ [Type: Real]: mean or first parameter of the distribution,
  • σ [Type: Real]: standard deviation or first parameter of the distribution
  • lower_bound [Type: Real]: truncation lower bound of the distribution
  • upper_bound [Type: Real]: truncation upper bound of the distribution

Keyword Arguments

  • μσ [Type: Bool]: switch whether μ and σ represent the moments of the distribution or their parameters
source
MacroModelling.BetaMethod
Beta(μ, σ; μσ)

Convenience wrapper for the Beta distribution.

If μσ = true then μ and σ are translated to the parameters of the distribution. Otherwise μ and σ represent the parameters of the distribution.

Arguments

  • μ [Type: Real]: mean or first parameter of the distribution,
  • σ [Type: Real]: standard deviation or first parameter of the distribution

Keyword Arguments

  • μσ [Type: Bool]: switch whether μ and σ represent the moments of the distribution or their parameters
source
MacroModelling.GammaMethod
Gamma(μ, σ, lower_bound, upper_bound; μσ)

Convenience wrapper for the truncated Inverse Gamma distribution.

If μσ = true then μ and σ are translated to the parameters of the distribution. Otherwise μ and σ represent the parameters of the distribution.

Arguments

  • μ [Type: Real]: mean or first parameter of the distribution,
  • σ [Type: Real]: standard deviation or first parameter of the distribution
  • lower_bound [Type: Real]: truncation lower bound of the distribution
  • upper_bound [Type: Real]: truncation upper bound of the distribution

Keyword Arguments

  • μσ [Type: Bool]: switch whether μ and σ represent the moments of the distribution or their parameters
source
MacroModelling.GammaMethod
Gamma(μ, σ; μσ)

Convenience wrapper for the Gamma distribution.

If μσ = true then μ and σ are translated to the parameters of the distribution. Otherwise μ and σ represent the parameters of the distribution.

Arguments

  • μ [Type: Real]: mean or first parameter of the distribution,
  • σ [Type: Real]: standard deviation or first parameter of the distribution

Keyword Arguments

  • μσ [Type: Bool]: switch whether μ and σ represent the moments of the distribution or their parameters
source
MacroModelling.InverseGammaMethod
InverseGamma(μ, σ, lower_bound, upper_bound; μσ)

Convenience wrapper for the truncated Inverse Gamma distribution.

If μσ = true then μ and σ are translated to the parameters of the distribution. Otherwise μ and σ represent the parameters of the distribution.

Arguments

  • μ [Type: Real]: mean or first parameter of the distribution,
  • σ [Type: Real]: standard deviation or first parameter of the distribution
  • lower_bound [Type: Real]: truncation lower bound of the distribution
  • upper_bound [Type: Real]: truncation upper bound of the distribution

Keyword Arguments

  • μσ [Type: Bool]: switch whether μ and σ represent the moments of the distribution or their parameters
source
MacroModelling.InverseGammaMethod
InverseGamma(μ, σ; μσ)

Convenience wrapper for the Inverse Gamma distribution.

If μσ = true then μ and σ are translated to the parameters of the distribution. Otherwise μ and σ represent the parameters of the distribution.

Arguments

  • μ [Type: Real]: mean or first parameter of the distribution,
  • σ [Type: Real]: standard deviation or first parameter of the distribution

Keyword Arguments

  • μσ [Type: Bool]: switch whether μ and σ represent the moments of the distribution or their parameters
source
MacroModelling.NormalMethod
Normal(μ, σ, lower_bound, upper_bound)

Convenience wrapper for the truncated Normal distribution.

Arguments

  • μ [Type: Real]: mean of the distribution,
  • σ [Type: Real]: standard deviation of the distribution
  • lower_bound [Type: Real]: truncation lower bound of the distribution
  • upper_bound [Type: Real]: truncation upper bound of the distribution
source
MacroModelling.get_autocorrelationMethod
get_autocorrelation(
    𝓂;
    autocorrelation_periods,
    parameters,
    algorithm,
    verbose
)

Return the autocorrelations of endogenous variables using the first, pruned second, or pruned third order perturbation solution.

Arguments

Keyword Arguments

  • autocorrelation_periods [Default: 1:5]: periods for which to return the autocorrelation
  • 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.
  • algorithm [Default: :first_order, Type: Symbol]: algorithm to solve for the dynamics of the model.
  • verbose [Default: false, Type: Bool]: print information about how the NSSS is solved (symbolic or numeric), which solver is used (Levenberg-Marquardt...), and the maximum absolute error.

Examples

using MacroModelling

@model RBC begin
    1  /  c[0] = (β  /  c[1]) * (α * exp(z[1]) * k[0]^(α - 1) + (1 - δ))
    c[0] + k[0] = (1 - δ) * k[-1] + q[0]
    q[0] = exp(z[0]) * k[-1]^α
    z[0] = ρ * z[-1] + std_z * eps_z[x]
end

@parameters RBC begin
    std_z = 0.01
    ρ = 0.2
    δ = 0.02
    α = 0.5
    β = 0.95
end

get_autocorrelation(RBC)
# output
2-dimensional KeyedArray(NamedDimsArray(...)) with keys:
↓   Variables ∈ 4-element Vector{Symbol}
→   Autocorrelation_orders ∈ 5-element UnitRange{Int64}
And data, 4×5 Matrix{Float64}:
        (1)         (2)         (3)         (4)         (5)
  (:c)    0.966974    0.927263    0.887643    0.849409    0.812761
  (:k)    0.971015    0.931937    0.892277    0.853876    0.817041
  (:q)    0.32237     0.181562    0.148347    0.136867    0.129944
  (:z)    0.2         0.04        0.008       0.0016      0.00032
source
MacroModelling.get_calibrated_parametersMethod
get_calibrated_parameters(𝓂; values)

Returns the parameters (and optionally the values) which are determined by a calibration equation.

Arguments

Keyword Arguments

  • values [Default: false, Type: Bool]: return the values together with the parameter names

Examples

using MacroModelling

@model RBC begin
    1  /  c[0] = (β  /  c[1]) * (α * exp(z{TFP}[1]) * k[0]^(α - 1) + (1 - exp(z{δ}[1]) * δ))
    c[0] + k[0] = (1 - exp(z{δ}[0])δ) * k[-1] + q[0]
    q[0] = exp(z{TFP}[0]) * k[-1]^α
    for shock in [TFP, δ]
        z{shock}[0] = ρ{shock} * z{shock}[-1] + σ{shock} * (eps{shock}[x] + eps_news{shock}[x-1])
    end
    Δc_share[0] = log(c[0]/q[0]) - log(c[-1]/q[-1])
    Δk_4q[0] = log(k[0]) - log(k[-4])
end

@parameters RBC begin
    σ = 0.01
    ρ = 0.2
    capital_to_output = 1.5
    k[ss] / (4 * q[ss]) = capital_to_output | δ
    alpha = .5
    α = alpha
    β = 0.95
end

get_calibrated_parameters(RBC)
# output
1-element Vector{String}:
 "δ"
source
MacroModelling.get_calibration_equation_parametersMethod
get_calibration_equation_parameters(𝓂)

Returns the parameters used in calibration equations which are not used in the equations of the model (see capital_to_output in example).

Arguments

Examples

using MacroModelling

@model RBC begin
    1  /  c[0] = (β  /  c[1]) * (α * exp(z{TFP}[1]) * k[0]^(α - 1) + (1 - exp(z{δ}[1]) * δ))
    c[0] + k[0] = (1 - exp(z{δ}[0])δ) * k[-1] + q[0]
    q[0] = exp(z{TFP}[0]) * k[-1]^α
    for shock in [TFP, δ]
        z{shock}[0] = ρ{shock} * z{shock}[-1] + σ{shock} * (eps{shock}[x] + eps_news{shock}[x-1])
    end
    Δc_share[0] = log(c[0]/q[0]) - log(c[-1]/q[-1])
    Δk_4q[0] = log(k[0]) - log(k[-4])
end

@parameters RBC begin
    σ = 0.01
    ρ = 0.2
    capital_to_output = 1.5
    k[ss] / (4 * q[ss]) = capital_to_output | δ
    alpha = .5
    α = alpha
    β = 0.95
end

get_calibration_equation_parameters(RBC)
# output
1-element Vector{String}:
 "capital_to_output"
source
MacroModelling.get_calibration_equationsMethod
get_calibration_equations(𝓂)

Return the calibration equations declared in the @parameters block. Calibration equations are additional equations which are part of the non-stochastic steady state problem. The additional equation is matched with a calibated parameter which is part of the equations declared in the @model block and can be retrieved with: get_calibrated_parameters

In case programmatic model writing was used this function returns the parsed equations (see loop over shocks in example).

Note that the ouput assumes the equations are equal to 0. As in, k / (q * 4) - capital_to_output implies k / (q * 4) - capital_to_output = 0 and therefore: k / (q * 4) = capital_to_output.

Arguments

Examples

using MacroModelling

@model RBC begin
    1  /  c[0] = (β  /  c[1]) * (α * exp(z{TFP}[1]) * k[0]^(α - 1) + (1 - exp(z{δ}[1]) * δ))
    c[0] + k[0] = (1 - exp(z{δ}[0])δ) * k[-1] + q[0]
    q[0] = exp(z{TFP}[0]) * k[-1]^α
    for shock in [TFP, δ]
        z{shock}[0] = ρ{shock} * z{shock}[-1] + σ{shock} * (eps{shock}[x] + eps_news{shock}[x-1])
    end
    Δc_share[0] = log(c[0]/q[0]) - log(c[-1]/q[-1])
    Δk_4q[0] = log(k[0]) - log(k[-4])
end

@parameters RBC begin
    σ = 0.01
    ρ = 0.2
    capital_to_output = 1.5
    k[ss] / (4 * q[ss]) = capital_to_output | δ
    alpha = .5
    α = alpha
    β = 0.95
end

get_calibration_equations(RBC)
# output
1-element Vector{String}:
 "k / (q * 4) - capital_to_output"
source
MacroModelling.get_conditional_forecastMethod
get_conditional_forecast(
    𝓂,
    conditions;
    shocks,
    initial_state,
    periods,
    parameters,
    variables,
    conditions_in_levels,
    algorithm,
    levels,
    verbose
)

Return the conditional forecast given restrictions on endogenous variables and shocks (optional) in a 2-dimensional array. By default (see levels), the values represent absolute deviations from the relevant steady state (e.g. higher order perturbation algorithms are relative to the stochastic steady state). A constrained minimisation problem is solved to find the combinations of shocks with the smallest magnitude to match the conditions.

Arguments

  • 𝓂: the object created by @model and @parameters for which to get the solution.
  • conditions [Type: Union{Matrix{Union{Nothing,Float64}}, SparseMatrixCSC{Float64}, KeyedArray{Union{Nothing,Float64}}, KeyedArray{Float64}}]: conditions for which to find the corresponding shocks. The input can have multiple formats, but for all types of entries the first dimension corresponds to the number of variables and the second dimension to the number of periods. The conditions can be specified using a matrix of type Matrix{Union{Nothing,Float64}}. In this case the conditions are matrix elements of type Float64 and all remaining (free) entries are nothing. You can also use a SparseMatrixCSC{Float64} as input. In this case only non-zero elements are taken as conditions. Note that you cannot condition variables to be zero using a SparseMatrixCSC{Float64} as input (use other input formats to do so). Another possibility to input conditions is by using a KeyedArray. You can use a KeyedArray{Union{Nothing,Float64}} where, similar to Matrix{Union{Nothing,Float64}}, all entries of type Float64 are recognised as conditions and all other entries have to be nothing. Furthermore, you can specify in the primary axis a subset of variables (of type Symbol or String) for which you specify conditions and all other variables are considered free. The same goes for the case when you use KeyedArray{Float64}} as input, whereas in this case the conditions for the specified variables bind for all periods specified in the KeyedArray, because there are no nothing entries permitted with this type.

Keyword Arguments

  • shocks [Default: nothing, Type: Union{Matrix{Union{Nothing,Float64}}, SparseMatrixCSC{Float64}, KeyedArray{Union{Nothing,Float64}}, KeyedArray{Float64}, Nothing} = nothing]: known values of shocks. This entry allows the user to include certain shock values. By entering restrictions on the shock sin this way the problem to match the conditions on endogenous variables is restricted to the remaining free shocks in the repective period. The input can have multiple formats, but for all types of entries the first dimension corresponds to the number of shocks and the second dimension to the number of periods. The shocks can be specified using a matrix of type Matrix{Union{Nothing,Float64}}. In this case the shocks are matrix elements of type Float64 and all remaining (free) entries are nothing. You can also use a SparseMatrixCSC{Float64} as input. In this case only non-zero elements are taken as certain shock values. Note that you cannot condition shocks to be zero using a SparseMatrixCSC{Float64} as input (use other input formats to do so). Another possibility to input known shocks is by using a KeyedArray. You can use a KeyedArray{Union{Nothing,Float64}} where, similar to Matrix{Union{Nothing,Float64}}, all entries of type Float64 are recognised as known shocks and all other entries have to be nothing. Furthermore, you can specify in the primary axis a subset of shocks (of type Symbol or String) for which you specify values and all other shocks are considered free. The same goes for the case when you use KeyedArray{Float64}} as input, whereas in this case the values for the specified shocks bind for all periods specified in the KeyedArray, because there are no nothing entries permitted with this type.
  • initial_state [Default: [0.0], Type: Union{Vector{Vector{Float64}},Vector{Float64}}]: The initial state defines the starting point for the model and is relevant for normal IRFs. In the case of pruned solution algorithms the initial state can be given as multiple state vectors (Vector{Vector{Float64}}). In this case the initial state must be given in devations from the non-stochastic steady state. In all other cases the initial state must be given in levels. If a pruned solution algorithm is selected and initial state is a Vector{Float64} then it impacts the first order initial state vector only. The state includes all variables as well as exogenous variables in leads or lags if present.
  • periods [Default: 40, Type: Int]: the total number of periods is the sum of the argument provided here and the maximum of periods of the shocks or conditions argument.
  • 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.
  • 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.
  • conditions_in_levels [Default: true, Type: Bool]: indicator whether the conditions are provided in levels. If true the input to the conditions argument will have the non stochastic steady state substracted.
  • algorithm [Default: :first_order, Type: Symbol]: algorithm to solve for the dynamics of the model.
  • levels [Default: false, Type: Bool]: return levels or absolute deviations from steady state corresponding to the solution algorithm (e.g. stochastic steady state for higher order solution algorithms).
  • verbose [Default: false, Type: Bool]: print information about how the NSSS is solved (symbolic or numeric), which solver is used (Levenberg-Marquardt...), and the maximum absolute error.

Examples

using MacroModelling
using SparseArrays, AxisKeys

@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 begin
    alpha = .157
    beta = .999
    delta = .0226
    Pibar = 1.0008
    phi_pi = 1.5
    rhoz = .9
    std_eps = .0068
    rho_z_delta = .9
    std_z_delta = .005
end

# c is conditioned to deviate by 0.01 in period 1 and y is conditioned to deviate by 0.02 in period 3
conditions = KeyedArray(Matrix{Union{Nothing,Float64}}(undef,2,2),Variables = [:c,:y], Periods = 1:2)
conditions[1,1] = .01
conditions[2,2] = .02

# in period 2 second shock (eps_z) is conditioned to take a value of 0.05
shocks = Matrix{Union{Nothing,Float64}}(undef,2,1)
shocks[1,1] = .05

get_conditional_forecast(RBC_CME, conditions, shocks = shocks, conditions_in_levels = false)
# output
2-dimensional KeyedArray(NamedDimsArray(...)) with keys:
↓   Variables_and_shocks ∈ 9-element Vector{Symbol}
→   Periods ∈ 42-element UnitRange{Int64}
And data, 9×42 Matrix{Float64}:
                (1)            (2)           …  (41)            (42)
  (:A)            0.0313639      0.0134792         0.000221372     0.000199235
  (:Pi)           0.000780257    0.00020929       -0.000146071    -0.000140137
  (:R)            0.00117156     0.00031425       -0.000219325    -0.000210417
  (:c)            0.01           0.00600605        0.00213278      0.00203751
  (:k)            0.034584       0.0477482   …     0.0397631       0.0380482
  (:y)            0.0446375      0.02              0.00129544      0.001222
  (:z_delta)      0.00025        0.000225          3.69522e-6      3.3257e-6
  (:delta_eps)    0.05           0.0               0.0             0.0
  (:eps_z)        4.61234       -2.16887           0.0             0.0

# The same can be achieved with the other input formats:
# conditions = Matrix{Union{Nothing,Float64}}(undef,7,2)
# conditions[4,1] = .01
# conditions[6,2] = .02

# using SparseArrays
# conditions = spzeros(7,2)
# conditions[4,1] = .01
# conditions[6,2] = .02

# shocks = KeyedArray(Matrix{Union{Nothing,Float64}}(undef,1,1),Variables = [:delta_eps], Periods = [1])
# shocks[1,1] = .05

# using SparseArrays
# shocks = spzeros(2,1)
# shocks[1,1] = .05
source
MacroModelling.get_conditional_variance_decompositionMethod
get_conditional_variance_decomposition(
    𝓂;
    periods,
    parameters,
    verbose
)

Return the conditional variance decomposition of endogenous variables with regards to the shocks using the linearised solution.

Arguments

Keyword Arguments

  • periods [Default: [1:20...,Inf], Type: Union{Vector{Int},Vector{Float64},UnitRange{Int64}}]: vector of periods for which to calculate the conditional variance decomposition. If the vector conatins Inf, also the unconditional variance decomposition is calculated (same output as get_variance_decomposition).
  • 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.
  • verbose [Default: false, Type: Bool]: print information about how the NSSS is solved (symbolic or numeric), which solver is used (Levenberg-Marquardt...), and the maximum absolute error.

Examples

using MacroModelling

@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 begin
    alpha = .157
    beta = .999
    delta = .0226
    Pibar = 1.0008
    phi_pi = 1.5
    rhoz = .9
    std_eps = .0068
    rho_z_delta = .9
    std_z_delta = .005
end

get_conditional_variance_decomposition(RBC_CME)
# output
3-dimensional KeyedArray(NamedDimsArray(...)) with keys:
↓   Variables ∈ 7-element Vector{Symbol}
→   Shocks ∈ 2-element Vector{Symbol}
◪   Periods ∈ 21-element Vector{Float64}
And data, 7×2×21 Array{Float64, 3}:
[showing 3 of 21 slices]
[:, :, 1] ~ (:, :, 1.0):
              (:delta_eps)  (:eps_z)
  (:A)         0.0           1.0
  (:Pi)        0.00158668    0.998413
  (:R)         0.00158668    0.998413
  (:c)         0.0277348     0.972265
  (:k)         0.00869568    0.991304
  (:y)         0.0           1.0
  (:z_delta)   1.0           0.0

[:, :, 11] ~ (:, :, 11.0):
              (:delta_eps)  (:eps_z)
  (:A)         5.88653e-32   1.0
  (:Pi)        0.0245641     0.975436
  (:R)         0.0245641     0.975436
  (:c)         0.0175249     0.982475
  (:k)         0.00869568    0.991304
  (:y)         7.63511e-5    0.999924
  (:z_delta)   1.0           0.0

[:, :, 21] ~ (:, :, Inf):
              (:delta_eps)  (:eps_z)
  (:A)         9.6461e-31    1.0
  (:Pi)        0.0156771     0.984323
  (:R)         0.0156771     0.984323
  (:c)         0.0134672     0.986533
  (:k)         0.00869568    0.991304
  (:y)         0.000313462   0.999687
  (:z_delta)   1.0           0.0
source
MacroModelling.get_correlationMethod
get_correlation(𝓂; parameters, algorithm, verbose)

Return the correlations of endogenous variables using the first, pruned second, or pruned third order perturbation solution.

Arguments

Keyword Arguments

  • 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.
  • algorithm [Default: :first_order, Type: Symbol]: algorithm to solve for the dynamics of the model.
  • verbose [Default: false, Type: Bool]: print information about how the NSSS is solved (symbolic or numeric), which solver is used (Levenberg-Marquardt...), and the maximum absolute error.

Examples

using MacroModelling

@model RBC begin
    1  /  c[0] = (β  /  c[1]) * (α * exp(z[1]) * k[0]^(α - 1) + (1 - δ))
    c[0] + k[0] = (1 - δ) * k[-1] + q[0]
    q[0] = exp(z[0]) * k[-1]^α
    z[0] = ρ * z[-1] + std_z * eps_z[x]
end

@parameters RBC begin
    std_z = 0.01
    ρ = 0.2
    δ = 0.02
    α = 0.5
    β = 0.95
end

get_correlation(RBC)
# output
2-dimensional KeyedArray(NamedDimsArray(...)) with keys:
↓   Variables ∈ 4-element Vector{Symbol}
→   𝑉𝑎𝑟𝑖𝑎𝑏𝑙𝑒𝑠 ∈ 4-element Vector{Symbol}
And data, 4×4 Matrix{Float64}:
        (:c)       (:k)       (:q)       (:z)
  (:c)   1.0        0.999812   0.550168   0.314562
  (:k)   0.999812   1.0        0.533879   0.296104
  (:q)   0.550168   0.533879   1.0        0.965726
  (:z)   0.314562   0.296104   0.965726   1.0
source
MacroModelling.get_dynamic_auxilliary_variablesMethod
get_dynamic_auxilliary_variables(𝓂)

Returns the auxilliary variables, without timing subscripts, part of the augmented system of equations describing the model dynamics. Augmented means that, in case of variables with leads or lags larger than 1, or exogenous shocks with leads or lags, the system is augemented by auxilliary variables containing variables or shocks in lead or lag. because the original equations included variables with leads or lags certain expression cannot be negative (e.g. given log(c/q) an auxilliary variable is created for c/q).

See get_dynamic_equations for more details on the auxilliary variables and equations.

Arguments

Examples

using MacroModelling

@model RBC begin
    1  /  c[0] = (β  /  c[1]) * (α * exp(z{TFP}[1]) * k[0]^(α - 1) + (1 - exp(z{δ}[1]) * δ))
    c[0] + k[0] = (1 - exp(z{δ}[0])δ) * k[-1] + q[0]
    q[0] = exp(z{TFP}[0]) * k[-1]^α
    for shock in [TFP, δ]
        z{shock}[0] = ρ{shock} * z{shock}[-1] + σ{shock} * (eps{shock}[x] + eps_news{shock}[x-1])
    end
    Δc_share[0] = log(c[0]/q[0]) - log(c[-1]/q[-1])
    Δk_4q[0] = log(k[0]) - log(k[-4])
end

@parameters RBC begin
    σ = 0.01
    ρ = 0.2
    capital_to_output = 1.5
    k[ss] / (4 * q[ss]) = capital_to_output | δ
    alpha = .5
    α = alpha
    β = 0.95
end

get_dynamic_auxilliary_variables(RBC)
# output
3-element Vector{String}:
 "kᴸ⁽⁻²⁾"
 "kᴸ⁽⁻³⁾"
 "kᴸ⁽⁻¹⁾"
source
MacroModelling.get_dynamic_equationsMethod
get_dynamic_equations(𝓂)

Return the augmented system of equations describing the model dynamics. Augmented means that, in case of variables with leads or lags larger than 1, or exogenous shocks with leads or lags, the system is augemented by auxilliary equations containing variables in lead or lag. The augmented system features only variables which are in the present [0], future [1], or past [-1]. For example, Δk_4q[0] = log(k[0]) - log(k[-3]) contains k[-3]. By introducing 2 auxilliary variables (kᴸ⁽⁻¹⁾ and kᴸ⁽⁻²⁾ with being the lead/lag operator) and augmenting the system (kᴸ⁽⁻²⁾[0] = kᴸ⁽⁻¹⁾[-1] and kᴸ⁽⁻¹⁾[0] = k[-1]) we can ensure that the timing is smaller than 1 in absolute terms: Δk_4q[0] - (log(k[0]) - log(kᴸ⁽⁻²⁾[-1])).

In case programmatic model writing was used this function returns the parsed equations (see loop over shocks in example).

Note that the ouput assumes the equations are equal to 0. As in, kᴸ⁽⁻¹⁾[0] - k[-1] implies kᴸ⁽⁻¹⁾[0] - k[-1] = 0 and therefore: kᴸ⁽⁻¹⁾[0] = k[-1].

Arguments

Examples

using MacroModelling

@model RBC begin
    1  /  c[0] = (β  /  c[1]) * (α * exp(z{TFP}[1]) * k[0]^(α - 1) + (1 - exp(z{δ}[1]) * δ))
    c[0] + k[0] = (1 - exp(z{δ}[0])δ) * k[-1] + q[0]
    q[0] = exp(z{TFP}[0]) * k[-1]^α
    for shock in [TFP, δ]
        z{shock}[0] = ρ{shock} * z{shock}[-1] + σ{shock} * (eps{shock}[x] + eps_news{shock}[x-1])
    end
    Δc_share[0] = log(c[0]/q[0]) - log(c[-1]/q[-1])
    Δk_4q[0] = log(k[0]) - log(k[-4])
end

@parameters RBC begin
    σ = 0.01
    ρ = 0.2
    capital_to_output = 1.5
    k[ss] / (4 * q[ss]) = capital_to_output | δ
    alpha = .5
    α = alpha
    β = 0.95
end

get_dynamic_equations(RBC)
# output
12-element Vector{String}:
 "1 / c[0] - (β / c[1]) * (α * ex" ⋯ 25 bytes ⋯ " - 1) + (1 - exp(z{δ}[1]) * δ))"
 "(c[0] + k[0]) - ((1 - exp(z{δ}[0]) * δ) * k[-1] + q[0])"
 "q[0] - exp(z{TFP}[0]) * k[-1] ^ α"
 "eps_news{TFP}[0] - eps_news{TFP}[x]"
 "z{TFP}[0] - (ρ{TFP} * z{TFP}[-1] + σ{TFP} * (eps{TFP}[x] + eps_news{TFP}[-1]))"
 "eps_news{δ}[0] - eps_news{δ}[x]"
 "z{δ}[0] - (ρ{δ} * z{δ}[-1] + σ{δ} * (eps{δ}[x] + eps_news{δ}[-1]))"
 "Δc_share[0] - (log(c[0] / q[0]) - log(c[-1] / q[-1]))"
 "kᴸ⁽⁻³⁾[0] - kᴸ⁽⁻²⁾[-1]"
 "kᴸ⁽⁻²⁾[0] - kᴸ⁽⁻¹⁾[-1]"
 "kᴸ⁽⁻¹⁾[0] - k[-1]"
 "Δk_4q[0] - (log(k[0]) - log(kᴸ⁽⁻³⁾[-1]))"
source
MacroModelling.get_equationsMethod
get_equations(𝓂)

Return the equations of the model. In case programmatic model writing was used this function returns the parsed equations (see loop over shocks in example).

Arguments

Examples

using MacroModelling

@model RBC begin
    1  /  c[0] = (β  /  c[1]) * (α * exp(z{TFP}[1]) * k[0]^(α - 1) + (1 - exp(z{δ}[1]) * δ))
    c[0] + k[0] = (1 - exp(z{δ}[0])δ) * k[-1] + q[0]
    q[0] = exp(z{TFP}[0]) * k[-1]^α
    for shock in [TFP, δ]
        z{shock}[0] = ρ{shock} * z{shock}[-1] + σ{shock} * (eps{shock}[x] + eps_news{shock}[x-1])
    end
    Δc_share[0] = log(c[0]/q[0]) - log(c[-1]/q[-1])
    Δk_4q[0] = log(k[0]) - log(k[-4])
end

@parameters RBC begin
    σ = 0.01
    ρ = 0.2
    capital_to_output = 1.5
    k[ss] / (4 * q[ss]) = capital_to_output | δ
    alpha = .5
    α = alpha
    β = 0.95
end

get_equations(RBC)
# output
7-element Vector{String}:
 "1 / c[0] = (β / c[1]) * (α * ex" ⋯ 25 bytes ⋯ " - 1) + (1 - exp(z{δ}[1]) * δ))"
 "c[0] + k[0] = (1 - exp(z{δ}[0]) * δ) * k[-1] + q[0]"
 "q[0] = exp(z{TFP}[0]) * k[-1] ^ α"
 "z{TFP}[0] = ρ{TFP} * z{TFP}[-1]" ⋯ 18 bytes ⋯ "TFP}[x] + eps_news{TFP}[x - 1])"
 "z{δ}[0] = ρ{δ} * z{δ}[-1] + σ{δ} * (eps{δ}[x] + eps_news{δ}[x - 1])"
 "Δc_share[0] = log(c[0] / q[0]) - log(c[-1] / q[-1])"
 "Δk_4q[0] = log(k[0]) - log(k[-4])"
source
MacroModelling.get_estimated_shocksMethod
get_estimated_shocks(
    𝓂,
    data;
    parameters,
    algorithm,
    filter,
    warmup_iterations,
    data_in_levels,
    smooth,
    verbose
)

Return the estimated shocks based on the inversion filter (depending on the filter keyword argument), or Kalman filter or smoother (depending on the smooth keyword argument) using the provided data and (non-)linear solution of the model. Data is by default assumed to be in levels unless data_in_levels is set to false.

Arguments

  • 𝓂: the object created by @model and @parameters for which to get the solution.
  • data [Type: KeyedArray]: data matrix with variables (String or Symbol) in rows and time in columns

Keyword Arguments

  • 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.
  • algorithm [Default: :first_order, Type: Symbol]: algorithm to solve for the dynamics of the model.
  • filter [Default: :kalman, Type: Symbol]: filter used to compute the shocks given the data, model, and parameters. The Kalman filter only works for linear problems, whereas the inversion filter (:inversion) works for linear and nonlinear models. If a nonlinear solution algorithm is selected, the inversion filter is used.
  • warmup_iterations [Default: 0, Type: Int]: periods added before the first observation for which shocks are computed such that the first observation is matched. A larger value alleviates the problem that the initial value is the relevant steady state.
  • data_in_levels [Default: true, Type: Bool]: indicator whether the data is provided in levels. If true the input to the data argument will have the non stochastic steady state substracted.
  • smooth [Default: true, Type: Bool]: whether to return smoothed (true) or filtered (false) shocks/variables. Only works for the Kalman filter. The inversion filter only returns filtered shocks/variables.
  • verbose [Default: false, Type: Bool]: print information about how the NSSS is solved (symbolic or numeric), which solver is used (Levenberg-Marquardt...), and the maximum absolute error.

Examples

using MacroModelling

@model RBC begin
    1  /  c[0] = (β  /  c[1]) * (α * exp(z[1]) * k[0]^(α - 1) + (1 - δ))
    c[0] + k[0] = (1 - δ) * k[-1] + q[0]
    q[0] = exp(z[0]) * k[-1]^α
    z[0] = ρ * z[-1] + std_z * eps_z[x]
end

@parameters RBC begin
    std_z = 0.01
    ρ = 0.2
    δ = 0.02
    α = 0.5
    β = 0.95
end

simulation = simulate(RBC)

get_estimated_shocks(RBC,simulation([:c],:,:simulate))
# output
2-dimensional KeyedArray(NamedDimsArray(...)) with keys:
↓   Shocks ∈ 1-element Vector{Symbol}
→   Periods ∈ 40-element UnitRange{Int64}
And data, 1×40 Matrix{Float64}:
               (1)          (2)         (3)         (4)         …  (37)         (38)        (39)         (40)
  (:eps_z₍ₓ₎)    0.0603617    0.614652   -0.519048    0.711454       -0.873774     1.27918    -0.929701    -0.2255
source
MacroModelling.get_estimated_variable_standard_deviationsMethod
get_estimated_variable_standard_deviations(
    𝓂,
    data;
    parameters,
    data_in_levels,
    smooth,
    verbose
)

Return the standard deviations of the Kalman smoother or filter (depending on the smooth keyword argument) estimates of the model variables based on the provided data and first order solution of the model. Data is by default assumed to be in levels unless data_in_levels is set to false.

Arguments

  • 𝓂: the object created by @model and @parameters for which to get the solution.
  • data [Type: KeyedArray]: data matrix with variables (String or Symbol) in rows and time in columns

Keyword Arguments

  • 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.
  • data_in_levels [Default: true, Type: Bool]: indicator whether the data is provided in levels. If true the input to the data argument will have the non stochastic steady state substracted.
  • smooth [Default: true, Type: Bool]: whether to return smoothed (true) or filtered (false) shocks/variables. Only works for the Kalman filter. The inversion filter only returns filtered shocks/variables.
  • verbose [Default: false, Type: Bool]: print information about how the NSSS is solved (symbolic or numeric), which solver is used (Levenberg-Marquardt...), and the maximum absolute error.

Examples

using MacroModelling

@model RBC begin
    1  /  c[0] = (β  /  c[1]) * (α * exp(z[1]) * k[0]^(α - 1) + (1 - δ))
    c[0] + k[0] = (1 - δ) * k[-1] + q[0]
    q[0] = exp(z[0]) * k[-1]^α
    z[0] = ρ * z[-1] + std_z * eps_z[x]
end

@parameters RBC begin
    std_z = 0.01
    ρ = 0.2
    δ = 0.02
    α = 0.5
    β = 0.95
end

simulation = simulate(RBC)

get_estimated_variable_standard_deviations(RBC,simulation([:c],:,:simulate))
# output
2-dimensional KeyedArray(NamedDimsArray(...)) with keys:
↓   Standard_deviations ∈ 4-element Vector{Symbol}
→   Periods ∈ 40-element UnitRange{Int64}
And data, 4×40 Matrix{Float64}:
        (1)           (2)            (3)            (4)            …  (38)            (39)            (40)
  (:c)    1.23202e-9    1.84069e-10    8.23181e-11    8.23181e-11        8.23181e-11     8.23181e-11     0.0
  (:k)    0.00509299    0.000382934    2.87922e-5     2.16484e-6         1.6131e-9       9.31323e-10     1.47255e-9
  (:q)    0.0612887     0.0046082      0.000346483    2.60515e-5         1.31709e-9      1.31709e-9      9.31323e-10
  (:z)    0.00961766    0.000723136    5.43714e-5     4.0881e-6          3.08006e-10     3.29272e-10     2.32831e-10
source
MacroModelling.get_estimated_variablesMethod
get_estimated_variables(
    𝓂,
    data;
    parameters,
    algorithm,
    filter,
    warmup_iterations,
    data_in_levels,
    levels,
    smooth,
    verbose
)

Return the estimated variables (in levels by default, see levels keyword argument) based on the inversion filter (depending on the filter keyword argument), or Kalman filter or smoother (depending on the smooth keyword argument) using the provided data and (non-)linear solution of the model. Data is by default assumed to be in levels unless data_in_levels is set to false.

Arguments

  • 𝓂: the object created by @model and @parameters for which to get the solution.
  • data [Type: KeyedArray]: data matrix with variables (String or Symbol) in rows and time in columns

Keyword Arguments

  • 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.
  • algorithm [Default: :first_order, Type: Symbol]: algorithm to solve for the dynamics of the model.
  • filter [Default: :kalman, Type: Symbol]: filter used to compute the shocks given the data, model, and parameters. The Kalman filter only works for linear problems, whereas the inversion filter (:inversion) works for linear and nonlinear models. If a nonlinear solution algorithm is selected, the inversion filter is used.
  • warmup_iterations [Default: 0, Type: Int]: periods added before the first observation for which shocks are computed such that the first observation is matched. A larger value alleviates the problem that the initial value is the relevant steady state.
  • data_in_levels [Default: true, Type: Bool]: indicator whether the data is provided in levels. If true the input to the data argument will have the non stochastic steady state substracted.
  • levels [Default: false, Type: Bool]: return levels or absolute deviations from steady state corresponding to the solution algorithm (e.g. stochastic steady state for higher order solution algorithms).
  • smooth [Default: true, Type: Bool]: whether to return smoothed (true) or filtered (false) shocks/variables. Only works for the Kalman filter. The inversion filter only returns filtered shocks/variables.
  • verbose [Default: false, Type: Bool]: print information about how the NSSS is solved (symbolic or numeric), which solver is used (Levenberg-Marquardt...), and the maximum absolute error.

Examples

using MacroModelling

@model RBC begin
    1  /  c[0] = (β  /  c[1]) * (α * exp(z[1]) * k[0]^(α - 1) + (1 - δ))
    c[0] + k[0] = (1 - δ) * k[-1] + q[0]
    q[0] = exp(z[0]) * k[-1]^α
    z[0] = ρ * z[-1] + std_z * eps_z[x]
end

@parameters RBC begin
    std_z = 0.01
    ρ = 0.2
    δ = 0.02
    α = 0.5
    β = 0.95
end

simulation = simulate(RBC)

get_estimated_variables(RBC,simulation([:c],:,:simulate))
# output
2-dimensional KeyedArray(NamedDimsArray(...)) with keys:
↓   Variables ∈ 4-element Vector{Symbol}
→   Periods ∈ 40-element UnitRange{Int64}
And data, 4×40 Matrix{Float64}:
        (1)           (2)           (3)           (4)          …  (37)          (38)            (39)           (40)
  (:c)    5.92901       5.92797       5.92847       5.92048          5.95845       5.95697         5.95686        5.96173
  (:k)   47.3185       47.3087       47.3125       47.2392          47.6034       47.5969         47.5954        47.6402
  (:q)    6.87159       6.86452       6.87844       6.79352          7.00476       6.9026          6.90727        6.95841
  (:z)   -0.00109471   -0.00208056    4.43613e-5   -0.0123318        0.0162992     0.000445065     0.00119089     0.00863586
source
MacroModelling.get_irfMethod
get_irf(
    𝓂,
    parameters;
    periods,
    variables,
    shocks,
    negative_shock,
    initial_state,
    levels,
    verbose
)

Return impulse response functions (IRFs) of the model in a 3-dimensional array. Function to use when differentiating IRFs with repect to parameters.

Arguments

  • 𝓂: the object created by @model and @parameters for which to get the solution.
  • parameters [Type: Vector]: Parameter values in alphabetical order (sorted by parameter name).

Keyword Arguments

  • 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.
  • 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.
  • 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.
  • negative_shock [Default: false, Type: Bool]: calculate a negative shock. Relevant for generalised IRFs.
  • initial_state [Default: [0.0], Type: Vector{Float64}]: provide state (in levels, not deviations) from which to start IRFs. Relevant for normal IRFs. The state includes all variables as well as exogenous variables in leads or lags if present.
  • levels [Default: false, Type: Bool]: return levels or absolute deviations from steady state corresponding to the solution algorithm (e.g. stochastic steady state for higher order solution algorithms).
  • verbose [Default: false, Type: Bool]: print information about how the NSSS is solved (symbolic or numeric), which solver is used (Levenberg-Marquardt...), and the maximum absolute error.

Examples

using MacroModelling

@model RBC begin
    1  /  c[0] = (β  /  c[1]) * (α * exp(z[1]) * k[0]^(α - 1) + (1 - δ))
    c[0] + k[0] = (1 - δ) * k[-1] + q[0]
    q[0] = exp(z[0]) * k[-1]^α
    z[0] = ρ * z[-1] + std_z * eps_z[x]
end

@parameters RBC begin
    std_z = 0.01
    ρ = 0.2
    δ = 0.02
    α = 0.5
    β = 0.95
end

get_irf(RBC, RBC.parameter_values)
# output
4×40×1 Array{Float64, 3}:
[:, :, 1] =
 0.00674687  0.00729773  0.00715114  0.00687615  …  0.00146962   0.00140619
 0.0620937   0.0718322   0.0712153   0.0686381      0.0146789    0.0140453
 0.0688406   0.0182781   0.00797091  0.0057232      0.00111425   0.00106615
 0.01        0.002       0.0004      8.0e-5         2.74878e-29  5.49756e-30
source
MacroModelling.get_irfMethod
get_irf(
    𝓂;
    periods,
    algorithm,
    parameters,
    variables,
    shocks,
    negative_shock,
    generalised_irf,
    initial_state,
    levels,
    ignore_obc,
    verbose
)

Return impulse response functions (IRFs) of the model in a 3-dimensional KeyedArray. By default (see levels), the values represent absolute deviations from the relevant steady state (e.g. higher order perturbation algorithms are relative to the stochastic steady state).

Arguments

Keyword Arguments

  • 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.
  • algorithm [Default: :first_order, Type: Symbol]: algorithm to solve for the dynamics of the model.
  • 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.
  • 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.
  • 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.
  • negative_shock [Default: false, Type: Bool]: calculate a negative shock. Relevant for generalised IRFs.
  • generalised_irf [Default: false, Type: Bool]: calculate generalised IRFs. Relevant for nonlinear solutions. Reference steady state for deviations is the stochastic steady state.
  • initial_state [Default: [0.0], Type: Union{Vector{Vector{Float64}},Vector{Float64}}]: The initial state defines the starting point for the model and is relevant for normal IRFs. In the case of pruned solution algorithms the initial state can be given as multiple state vectors (Vector{Vector{Float64}}). In this case the initial state must be given in devations from the non-stochastic steady state. In all other cases the initial state must be given in levels. If a pruned solution algorithm is selected and initial state is a Vector{Float64} then it impacts the first order initial state vector only. The state includes all variables as well as exogenous variables in leads or lags if present.
  • levels [Default: false, Type: Bool]: return levels or absolute deviations from steady state corresponding to the solution algorithm (e.g. stochastic steady state for higher order solution algorithms).
  • ignore_obc [Default: false, Type: Bool]: solve the model ignoring the occasionally binding constraints.
  • verbose [Default: false, Type: Bool]: print information about how the NSSS is solved (symbolic or numeric), which solver is used (Levenberg-Marquardt...), and the maximum absolute error.

Examples

using MacroModelling

@model RBC begin
    1  /  c[0] = (β  /  c[1]) * (α * exp(z[1]) * k[0]^(α - 1) + (1 - δ))
    c[0] + k[0] = (1 - δ) * k[-1] + q[0]
    q[0] = exp(z[0]) * k[-1]^α
    z[0] = ρ * z[-1] + std_z * eps_z[x]
end

@parameters RBC begin
    std_z = 0.01
    ρ = 0.2
    δ = 0.02
    α = 0.5
    β = 0.95
end

get_irf(RBC)
# output
3-dimensional KeyedArray(NamedDimsArray(...)) with keys:
↓   Variables ∈ 4-element Vector{Symbol}
→   Periods ∈ 40-element UnitRange{Int64}
◪   Shocks ∈ 1-element Vector{Symbol}
And data, 4×40×1 Array{Float64, 3}:
[:, :, 1] ~ (:, :, :eps_z):
        (1)           (2)           …  (39)            (40)
  (:c)    0.00674687    0.00729773        0.00146962      0.00140619
  (:k)    0.0620937     0.0718322         0.0146789       0.0140453
  (:q)    0.0688406     0.0182781         0.00111425      0.00106615
  (:z)    0.01          0.002             2.74878e-29     5.49756e-30
source
MacroModelling.get_jump_variablesMethod
get_jump_variables(𝓂)

Returns the jump variables of the model. Jumper variables occur in the future and not in the past or occur in all three: past, present, and future.

In case programmatic model writing was used this function returns the parsed variables (see z in example).

Arguments

Examples

using MacroModelling

@model RBC begin
    1  /  c[0] = (β  /  c[1]) * (α * exp(z{TFP}[1]) * k[0]^(α - 1) + (1 - exp(z{δ}[1]) * δ))
    c[0] + k[0] = (1 - exp(z{δ}[0])δ) * k[-1] + q[0]
    q[0] = exp(z{TFP}[0]) * k[-1]^α
    for shock in [TFP, δ]
        z{shock}[0] = ρ{shock} * z{shock}[-1] + σ{shock} * (eps{shock}[x] + eps_news{shock}[x-1])
    end
    Δc_share[0] = log(c[0]/q[0]) - log(c[-1]/q[-1])
    Δk_4q[0] = log(k[0]) - log(k[-4])
end

@parameters RBC begin
    σ = 0.01
    ρ = 0.2
    capital_to_output = 1.5
    k[ss] / (4 * q[ss]) = capital_to_output | δ
    alpha = .5
    α = alpha
    β = 0.95
end

get_jump_variables(RBC)
# output
3-element Vector{String}:
 "c"
 "z{TFP}"
 "z{δ}"
source
MacroModelling.get_loglikelihoodMethod
get_loglikelihood(
    𝓂,
    data,
    parameter_values;
    algorithm,
    filter,
    warmup_iterations,
    presample_periods,
    initial_covariance,
    tol,
    verbose
)

Return the loglikelihood of the model given the data and parameters provided. The loglikelihood is either calculated based on the inversion or the Kalman filter (depending on the filter keyword argument). In case of a nonlinear solution algorithm the inversion filter will be used. The data must be provided as a KeyedArray{Float64} with the names of the variables to be matched in rows and the periods in columns.

This function is differentiable (so far for the Kalman filter only) and can be used in gradient based sampling or optimisation.

Arguments

  • 𝓂: the object created by @model and @parameters for which to get the solution.
  • data [Type: KeyedArray]: data matrix with variables (String or Symbol) in rows and time in columns
  • parameter_values [Type: Vector]: Parameter values.

Keyword Arguments

  • algorithm [Default: :first_order, Type: Symbol]: algorithm to solve for the dynamics of the model.
  • filter [Default: :kalman, Type: Symbol]: filter used to compute the shocks given the data, model, and parameters. The Kalman filter only works for linear problems, whereas the inversion filter (:inversion) works for linear and nonlinear models. If a nonlinear solution algorithm is selected, the inversion filter is used.
  • warmup_iterations [Default: 0, Type: Int]: periods added before the first observation for which shocks are computed such that the first observation is matched. A larger value alleviates the problem that the initial value is the relevant steady state.
  • presample_periods [Default: 0, Type: Int]: periods at the beginning of the data for which the loglikelihood is discarded.
  • initial_covariance [Default: :theoretical, Type: Symbol]: defines the method to initialise the Kalman filters covariance matrix. It can be initialised with the theoretical long run values (option :theoretical) or large values (10.0) along the diagonal (option :diagonal).
  • verbose [Default: false, Type: Bool]: print information about how the NSSS is solved (symbolic or numeric), which solver is used (Levenberg-Marquardt...), and the maximum absolute error.

Examples

using MacroModelling

@model RBC begin
    1  /  c[0] = (β  /  c[1]) * (α * exp(z[1]) * k[0]^(α - 1) + (1 - δ))
    c[0] + k[0] = (1 - δ) * k[-1] + q[0]
    q[0] = exp(z[0]) * k[-1]^α
    z[0] = ρ * z[-1] + std_z * eps_z[x]
end

@parameters RBC begin
    std_z = 0.01
    ρ = 0.2
    δ = 0.02
    α = 0.5
    β = 0.95
end

simulated_data = simulate(RBC)

get_loglikelihood(RBC, simulated_data([:k], :, :simulate), RBC.parameter_values)
# output
58.24780188977981
source
MacroModelling.get_momentsMethod
get_moments(
    𝓂;
    parameters,
    non_stochastic_steady_state,
    mean,
    standard_deviation,
    variance,
    covariance,
    variables,
    derivatives,
    parameter_derivatives,
    algorithm,
    dependencies_tol,
    verbose,
    silent
)

Return the first and second moments of endogenous variables using the first, pruned second, or pruned third order perturbation solution. By default returns: non stochastic steady state (SS), and standard deviations, but can optionally return variances, and covariance matrix.

Arguments

Keyword Arguments

  • 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.
  • non_stochastic_steady_state [Default: true, Type: Bool]: switch to return SS of endogenous variables
  • mean [Default: false, Type: Bool]: switch to return mean of endogenous variables (the mean for the linearised solutoin is the NSSS)
  • standard_deviation [Default: true, Type: Bool]: switch to return standard deviation of endogenous variables
  • variance [Default: false, Type: Bool]: switch to return variance of endogenous variables
  • covariance [Default: false, Type: Bool]: switch to return covariance matrix of endogenous 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.
  • derivatives [Default: true, Type: Bool]: calculate derivatives with respect to the parameters.
  • parameter_derivatives [Default: :all]: parameters for which to calculate partial derivatives. Inputs can be a parameter name passed on as either a Symbol or String (e.g. :alpha, or "alpha"), or Tuple, Matrix or Vector of String or Symbol. :all will include all parameters.
  • algorithm [Default: :first_order, Type: Symbol]: algorithm to solve for the dynamics of the model.
  • dependencies_tol [Default: 1e-12, Type: AbstractFloat]: tolerance for the effect of a variable on the variable of interest when isolating part of the system for calculating covariance related statistics
  • verbose [Default: false, Type: Bool]: print information about how the NSSS is solved (symbolic or numeric), which solver is used (Levenberg-Marquardt...), and the maximum absolute error.

Examples

using MacroModelling

@model RBC begin
    1  /  c[0] = (β  /  c[1]) * (α * exp(z[1]) * k[0]^(α - 1) + (1 - δ))
    c[0] + k[0] = (1 - δ) * k[-1] + q[0]
    q[0] = exp(z[0]) * k[-1]^α
    z[0] = ρ * z[-1] + std_z * eps_z[x]
end

@parameters RBC begin
    std_z = 0.01
    ρ = 0.2
    δ = 0.02
    α = 0.5
    β = 0.95
end

moments = get_moments(RBC);

moments[1]
# output
2-dimensional KeyedArray(NamedDimsArray(...)) with keys:
↓   Variables ∈ 4-element Vector{Symbol}
→   Steady_state_and_∂steady_state∂parameter ∈ 6-element Vector{Symbol}
And data, 4×6 Matrix{Float64}:
        (:Steady_state)  (:std_z)  (:ρ)     (:δ)      (:α)       (:β)
  (:c)   5.93625          0.0       0.0   -116.072    55.786     76.1014
  (:k)  47.3903           0.0       0.0  -1304.95    555.264   1445.93
  (:q)   6.88406          0.0       0.0    -94.7805   66.8912   105.02
  (:z)   0.0              0.0       0.0      0.0       0.0        0.0
moments[2]
# output
2-dimensional KeyedArray(NamedDimsArray(...)) with keys:
↓   Variables ∈ 4-element Vector{Symbol}
→   Standard_deviation_and_∂standard_deviation∂parameter ∈ 6-element Vector{Symbol}
And data, 4×6 Matrix{Float64}:
        (:Standard_deviation)  (:std_z)  …  (:δ)       (:α)       (:β)
  (:c)   0.0266642              2.66642     -0.384359   0.2626     0.144789
  (:k)   0.264677              26.4677      -5.74194    2.99332    6.30323
  (:q)   0.0739325              7.39325     -0.974722   0.726551   1.08
  (:z)   0.0102062              1.02062      0.0        0.0        0.0
source
MacroModelling.get_non_stochastic_steady_state_residualsMethod
get_non_stochastic_steady_state_residuals(
    𝓂,
    values;
    parameters
)

Calculate the residuals of the non-stochastic steady state equations of the model for a given set of values. Values not provided, will be filled with the non-stochastic steady state values corresponding to the current parameters.

Arguments

  • 𝓂: the object created by @model and @parameters for which to get the solution.
  • values [Type: Union{Vector{Float64}, Dict{Symbol, Float64}, Dict{String, Float64}, KeyedArray{Float64, 1}}]: A Vector, Dict, or KeyedArray containing the values of the variables and calibrated parameters in the non-stochastic steady state equations (including calibration equations).

Keyword Arguments

  • 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.

Returns

  • A KeyedArray containing the absolute values of the residuals of the non-stochastic steady state equations.

Examples

using MacroModelling

@model RBC begin
    1  /  c[0] = (β  /  c[1]) * (α * exp(z[1]) * k[0]^(α - 1) + (1 - δ))
    c[0] + k[0] = (1 - δ) * k[-1] + q[0]
    q[0] = exp(z[0]) * k[-1]^α
    z[0] = ρ * z[-1] + std_z * eps_z[x]
end

@parameters RBC begin
    std_z = 0.01
    ρ = 0.2
    δ = 0.02
    k[ss] / q[ss] = 2.5 | α
    β = 0.95
end

steady_state = SS(RBC, derivatives = false)

get_non_stochastic_steady_state_residuals(RBC, steady_state)
# output
1-dimensional KeyedArray(NamedDimsArray(...)) with keys:
↓   Equation ∈ 5-element Vector{Symbol}
And data, 5-element Vector{Float64}:
 (:Equation₁)             0.0
 (:Equation₂)             0.0
 (:Equation₃)             0.0
 (:Equation₄)             0.0
 (:CalibrationEquation₁)  0.0

get_non_stochastic_steady_state_residuals(RBC, [1.1641597, 3.0635781, 1.2254312, 0.0, 0.18157895])
# output
1-dimensional KeyedArray(NamedDimsArray(...)) with keys:
↓   Equation ∈ 5-element Vector{Symbol}
And data, 5-element Vector{Float64}:
 (:Equation₁)             2.7360991250446887e-10
 (:Equation₂)             6.199999980083248e-8
 (:Equation₃)             2.7897102183871425e-8
 (:Equation₄)             0.0
 (:CalibrationEquation₁)  8.160392850342646e-8
source
MacroModelling.get_nonnegativity_auxilliary_variablesMethod
get_nonnegativity_auxilliary_variables(𝓂)

Returns the auxilliary variables, without timing subscripts, added to the non-stochastic steady state problem because certain expression cannot be negative (e.g. given log(c/q) an auxilliary variable is created for c/q).

See get_steady_state_equations for more details on the auxilliary variables and equations.

Arguments

Examples

using MacroModelling

@model RBC begin
    1  /  c[0] = (β  /  c[1]) * (α * exp(z{TFP}[1]) * k[0]^(α - 1) + (1 - exp(z{δ}[1]) * δ))
    c[0] + k[0] = (1 - exp(z{δ}[0])δ) * k[-1] + q[0]
    q[0] = exp(z{TFP}[0]) * k[-1]^α
    for shock in [TFP, δ]
        z{shock}[0] = ρ{shock} * z{shock}[-1] + σ{shock} * (eps{shock}[x] + eps_news{shock}[x-1])
    end
    Δc_share[0] = log(c[0]/q[0]) - log(c[-1]/q[-1])
    Δk_4q[0] = log(k[0]) - log(k[-4])
end

@parameters RBC begin
    σ = 0.01
    ρ = 0.2
    capital_to_output = 1.5
    k[ss] / (4 * q[ss]) = capital_to_output | δ
    alpha = .5
    α = alpha
    β = 0.95
end

get_nonnegativity_auxilliary_variables(RBC)
# output
2-element Vector{String}:
 "➕₁"
 "➕₂"
source
MacroModelling.get_parametersMethod
get_parameters(𝓂; values)

Returns the parameters (and optionally the values) which have an impact on the model dynamics but do not depend on other parameters and are not determined by calibration equations.

In case programmatic model writing was used this function returns the parsed parameters (see σ in example).

Arguments

Keyword Arguments

  • values [Default: false, Type: Bool]: return the values together with the parameter names

Examples

using MacroModelling

@model RBC begin
    1  /  c[0] = (β  /  c[1]) * (α * exp(z{TFP}[1]) * k[0]^(α - 1) + (1 - exp(z{δ}[1]) * δ))
    c[0] + k[0] = (1 - exp(z{δ}[0])δ) * k[-1] + q[0]
    q[0] = exp(z{TFP}[0]) * k[-1]^α
    for shock in [TFP, δ]
        z{shock}[0] = ρ{shock} * z{shock}[-1] + σ{shock} * (eps{shock}[x] + eps_news{shock}[x-1])
    end
    Δc_share[0] = log(c[0]/q[0]) - log(c[-1]/q[-1])
    Δk_4q[0] = log(k[0]) - log(k[-4])
end

@parameters RBC begin
    σ = 0.01
    ρ = 0.2
    capital_to_output = 1.5
    k[ss] / (4 * q[ss]) = capital_to_output | δ
    alpha = .5
    α = alpha
    β = 0.95
end

get_parameters(RBC)
# output
7-element Vector{String}:
 "σ{TFP}"
 "σ{δ}"
 "ρ{TFP}"
 "ρ{δ}"
 "capital_to_output"
 "alpha"
 "β"
source
MacroModelling.get_parameters_defined_by_parametersMethod
get_parameters_defined_by_parameters(𝓂)

Returns the parameters which are defined by other parameters which are not necessarily used in the equations of the model (see α in example).

Arguments

Examples

using MacroModelling

@model RBC begin
    1  /  c[0] = (β  /  c[1]) * (α * exp(z{TFP}[1]) * k[0]^(α - 1) + (1 - exp(z{δ}[1]) * δ))
    c[0] + k[0] = (1 - exp(z{δ}[0])δ) * k[-1] + q[0]
    q[0] = exp(z{TFP}[0]) * k[-1]^α
    for shock in [TFP, δ]
        z{shock}[0] = ρ{shock} * z{shock}[-1] + σ{shock} * (eps{shock}[x] + eps_news{shock}[x-1])
    end
    Δc_share[0] = log(c[0]/q[0]) - log(c[-1]/q[-1])
    Δk_4q[0] = log(k[0]) - log(k[-4])
end

@parameters RBC begin
    σ = 0.01
    ρ = 0.2
    capital_to_output = 1.5
    k[ss] / (4 * q[ss]) = capital_to_output | δ
    alpha = .5
    α = alpha
    β = 0.95
end

get_parameters_defined_by_parameters(RBC)
# output
1-element Vector{String}:
 "α"
source
MacroModelling.get_parameters_defining_parametersMethod
get_parameters_defining_parameters(𝓂)

Returns the parameters which define other parameters in the @parameters block which are not necessarily used in the equations of the model (see alpha in example).

Arguments

Examples

using MacroModelling

@model RBC begin
    1  /  c[0] = (β  /  c[1]) * (α * exp(z{TFP}[1]) * k[0]^(α - 1) + (1 - exp(z{δ}[1]) * δ))
    c[0] + k[0] = (1 - exp(z{δ}[0])δ) * k[-1] + q[0]
    q[0] = exp(z{TFP}[0]) * k[-1]^α
    for shock in [TFP, δ]
        z{shock}[0] = ρ{shock} * z{shock}[-1] + σ{shock} * (eps{shock}[x] + eps_news{shock}[x-1])
    end
    Δc_share[0] = log(c[0]/q[0]) - log(c[-1]/q[-1])
    Δk_4q[0] = log(k[0]) - log(k[-4])
end

@parameters RBC begin
    σ = 0.01
    ρ = 0.2
    capital_to_output = 1.5
    k[ss] / (4 * q[ss]) = capital_to_output | δ
    alpha = .5
    α = alpha
    β = 0.95
end

get_parameters_defining_parameters(RBC)
# output
1-element Vector{String}:
 "alpha"
source
MacroModelling.get_parameters_in_equationsMethod
get_parameters_in_equations(𝓂)

Returns the parameters contained in the model equations. Note that these parameters might be determined by other parameters or calibration equations defined in the @parameters block.

In case programmatic model writing was used this function returns the parsed parameters (see σ in example).

Arguments

Examples

using MacroModelling

@model RBC begin
    1  /  c[0] = (β  /  c[1]) * (α * exp(z{TFP}[1]) * k[0]^(α - 1) + (1 - exp(z{δ}[1]) * δ))
    c[0] + k[0] = (1 - exp(z{δ}[0])δ) * k[-1] + q[0]
    q[0] = exp(z{TFP}[0]) * k[-1]^α
    for shock in [TFP, δ]
        z{shock}[0] = ρ{shock} * z{shock}[-1] + σ{shock} * (eps{shock}[x] + eps_news{shock}[x-1])
    end
    Δc_share[0] = log(c[0]/q[0]) - log(c[-1]/q[-1])
    Δk_4q[0] = log(k[0]) - log(k[-4])
end

@parameters RBC begin
    σ = 0.01
    ρ = 0.2
    capital_to_output = 1.5
    k[ss] / (4 * q[ss]) = capital_to_output | δ
    alpha = .5
    α = alpha
    β = 0.95
end

get_parameters_in_equations(RBC)
# output
7-element Vector{String}:
 "α"
 "β"
 "δ"
 "ρ{TFP}"
 "ρ{δ}"
 "σ{TFP}"
 "σ{δ}"
source
MacroModelling.get_shock_decompositionMethod
get_shock_decomposition(
    𝓂,
    data;
    parameters,
    filter,
    algorithm,
    data_in_levels,
    warmup_iterations,
    smooth,
    verbose
)

Return the shock decomposition in absolute deviations from the relevant steady state (e.g. higher order perturbation algorithms are relative to the stochastic steady state) based on the Kalman smoother or filter (depending on the smooth keyword argument) or inversion filter using the provided data and solution of the model. Data is by default assumed to be in levels unless data_in_levels is set to false.

Arguments

  • 𝓂: the object created by @model and @parameters for which to get the solution.
  • data [Type: KeyedArray]: data matrix with variables (String or Symbol) in rows and time in columns

Keyword Arguments

  • 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.
  • data_in_levels [Default: true, Type: Bool]: indicator whether the data is provided in levels. If true the input to the data argument will have the non stochastic steady state substracted.
  • smooth [Default: true, Type: Bool]: whether to return smoothed (true) or filtered (false) shocks/variables. Only works for the Kalman filter. The inversion filter only returns filtered shocks/variables.
  • verbose [Default: false, Type: Bool]: print information about how the NSSS is solved (symbolic or numeric), which solver is used (Levenberg-Marquardt...), and the maximum absolute error.

Examples

using MacroModelling

@model RBC begin
    1  /  c[0] = (β  /  c[1]) * (α * exp(z[1]) * k[0]^(α - 1) + (1 - δ))
    c[0] + k[0] = (1 - δ) * k[-1] + q[0]
    q[0] = exp(z[0]) * k[-1]^α
    z[0] = ρ * z[-1] + std_z * eps_z[x]
end

@parameters RBC begin
    std_z = 0.01
    ρ = 0.2
    δ = 0.02
    α = 0.5
    β = 0.95
end

simulation = simulate(RBC)

get_shock_decomposition(RBC,simulation([:c],:,:simulate))
# output
3-dimensional KeyedArray(NamedDimsArray(...)) with keys:
↓   Variables ∈ 4-element Vector{Symbol}
→   Shocks ∈ 2-element Vector{Symbol}
◪   Periods ∈ 40-element UnitRange{Int64}
And data, 4×2×40 Array{Float64, 3}:
[showing 3 of 40 slices]
[:, :, 1] ~ (:, :, 1):
        (:eps_z₍ₓ₎)   (:Initial_values)
  (:c)   0.000407252  -0.00104779
  (:k)   0.00374808   -0.0104645
  (:q)   0.00415533   -0.000807161
  (:z)   0.000603617  -1.99957e-6

[:, :, 21] ~ (:, :, 21):
        (:eps_z₍ₓ₎)  (:Initial_values)
  (:c)   0.026511    -0.000433619
  (:k)   0.25684     -0.00433108
  (:q)   0.115858    -0.000328764
  (:z)   0.0150266    0.0

[:, :, 40] ~ (:, :, 40):
        (:eps_z₍ₓ₎)  (:Initial_values)
  (:c)   0.0437976   -0.000187505
  (:k)   0.4394      -0.00187284
  (:q)   0.00985518  -0.000142164
  (:z)  -0.00366442   8.67362e-19
source
MacroModelling.get_shocksMethod
get_shocks(𝓂)

Returns the exogenous shocks.

In case programmatic model writing was used this function returns the parsed variables (see eps in example).

Arguments

Examples

using MacroModelling

@model RBC begin
    1  /  c[0] = (β  /  c[1]) * (α * exp(z{TFP}[1]) * k[0]^(α - 1) + (1 - exp(z{δ}[1]) * δ))
    c[0] + k[0] = (1 - exp(z{δ}[0])δ) * k[-1] + q[0]
    q[0] = exp(z{TFP}[0]) * k[-1]^α
    for shock in [TFP, δ]
        z{shock}[0] = ρ{shock} * z{shock}[-1] + σ{shock} * (eps{shock}[x] + eps_news{shock}[x-1])
    end
    Δc_share[0] = log(c[0]/q[0]) - log(c[-1]/q[-1])
    Δk_4q[0] = log(k[0]) - log(k[-4])
end

@parameters RBC begin
    σ = 0.01
    ρ = 0.2
    capital_to_output = 1.5
    k[ss] / (4 * q[ss]) = capital_to_output | δ
    alpha = .5
    α = alpha
    β = 0.95
end

get_shocks(RBC)
# output
4-element Vector{String}:
 "eps_news{TFP}"
 "eps_news{δ}"
 "eps{TFP}"
 "eps{δ}"
source
MacroModelling.get_solutionMethod
get_solution(𝓂; parameters, algorithm, silent, verbose)

Return the solution of the model. In the linear case it returns the linearised solution and the non stochastic steady state (NSSS) of the model. In the nonlinear case (higher order perturbation) the function returns a multidimensional array with the endogenous variables as the second dimension and the state variables, shocks, and perturbation parameter (:Volatility) in the case of higher order solutions as the other dimensions.

The values of the output represent the NSSS in the case of a linear solution and below it the effect that deviations from the NSSS of the respective past states, shocks, and perturbation parameter have (perturbation parameter = 1) on the present value (NSSS deviation) of the model variables.

Arguments

Keyword Arguments

  • 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.
  • algorithm [Default: :first_order, Type: Symbol]: algorithm to solve for the dynamics of the model.
  • verbose [Default: false, Type: Bool]: print information about how the NSSS is solved (symbolic or numeric), which solver is used (Levenberg-Marquardt...), and the maximum absolute error.

The returned KeyedArray shows as columns the endogenous variables inlcuding the auxilliary endogenous and exogenous variables (due to leads and lags > 1). The rows and other dimensions (depending on the chosen perturbation order) include the NSSS for the linear case only, followed by the states, and exogenous shocks. Subscripts following variable names indicate the timing (e.g. variable₍₋₁₎ indicates the variable being in the past). Superscripts indicate leads or lags (e.g. variableᴸ⁽²⁾ indicates the variable being in lead by two periods). If no super- or subscripts follow the variable name, the variable is in the present.

Examples

using MacroModelling

@model RBC begin
    1  /  c[0] = (β  /  c[1]) * (α * exp(z[1]) * k[0]^(α - 1) + (1 - δ))
    c[0] + k[0] = (1 - δ) * k[-1] + q[0]
    q[0] = exp(z[0]) * k[-1]^α
    z[0] = ρ * z[-1] + std_z * eps_z[x]
end

@parameters RBC begin
    std_z = 0.01
    ρ = 0.2
    δ = 0.02
    α = 0.5
    β = 0.95
end

get_solution(RBC)
# output
2-dimensional KeyedArray(NamedDimsArray(...)) with keys:
↓   Steady_state__States__Shocks ∈ 4-element Vector{Symbol}
→   Variables ∈ 4-element Vector{Symbol}
And data, 4×4 adjoint(::Matrix{Float64}) with eltype Float64:
                   (:c)         (:k)        (:q)        (:z)
  (:Steady_state)   5.93625     47.3903      6.88406     0.0
  (:k₍₋₁₎)          0.0957964    0.956835    0.0726316  -0.0
  (:z₍₋₁₎)          0.134937     1.24187     1.37681     0.2
  (:eps_z₍ₓ₎)       0.00674687   0.0620937   0.0688406   0.01
source
MacroModelling.get_state_variablesMethod
get_state_variables(𝓂)

Returns the state variables of the model. State variables occur in the past and not in the future or occur in all three: past, present, and future.

In case programmatic model writing was used this function returns the parsed variables (see z in example).

Arguments

Examples

using MacroModelling

@model RBC begin
    1  /  c[0] = (β  /  c[1]) * (α * exp(z{TFP}[1]) * k[0]^(α - 1) + (1 - exp(z{δ}[1]) * δ))
    c[0] + k[0] = (1 - exp(z{δ}[0])δ) * k[-1] + q[0]
    q[0] = exp(z{TFP}[0]) * k[-1]^α
    for shock in [TFP, δ]
        z{shock}[0] = ρ{shock} * z{shock}[-1] + σ{shock} * (eps{shock}[x] + eps_news{shock}[x-1])
    end
    Δc_share[0] = log(c[0]/q[0]) - log(c[-1]/q[-1])
    Δk_4q[0] = log(k[0]) - log(k[-4])
end

@parameters RBC begin
    σ = 0.01
    ρ = 0.2
    capital_to_output = 1.5
    k[ss] / (4 * q[ss]) = capital_to_output | δ
    alpha = .5
    α = alpha
    β = 0.95
end

get_state_variables(RBC)
# output
10-element Vector{String}:
 "c"
 "eps_news{TFP}"
 "eps_news{δ}"
 "k"
 "kᴸ⁽⁻²⁾"
 "kᴸ⁽⁻³⁾"
 "kᴸ⁽⁻¹⁾"
 "q"
 "z{TFP}"
 "z{δ}"
source
MacroModelling.get_statisticsMethod
get_statistics(
    𝓂,
    parameter_values;
    parameters,
    non_stochastic_steady_state,
    mean,
    standard_deviation,
    variance,
    covariance,
    autocorrelation,
    autocorrelation_periods,
    algorithm,
    verbose
)

Return the first and second moments of endogenous variables using either the linearised solution or the pruned second or third order perturbation solution. By default returns: non stochastic steady state (SS), and standard deviations, but can also return variances, and covariance matrix. Function to use when differentiating model moments with repect to parameters.

Arguments

  • 𝓂: the object created by @model and @parameters for which to get the solution.
  • parameter_values [Type: Vector]: Parameter values.

Keyword Arguments

  • parameters [Type: Vector{Symbol}]: Corresponding names of parameters values.
  • non_stochastic_steady_state [Default: Symbol[], Type: Vector{Symbol}]: if values are provided the function returns the SS of endogenous variables
  • mean [Default: Symbol[], Type: Vector{Symbol}]: if values are provided the function returns the mean of endogenous variables (the mean for the linearised solutoin is the NSSS)
  • standard_deviation [Default: Symbol[], Type: Vector{Symbol}]: if values are provided the function returns the standard deviation of the mentioned variables
  • variance [Default: Symbol[], Type: Vector{Symbol}]: if values are provided the function returns the variance of the mentioned variables
  • covariance [Default: Symbol[], Type: Vector{Symbol}]: if values are provided the function returns the covariance of the mentioned variables
  • autocorrelation [Default: Symbol[], Type: Vector{Symbol}]: if values are provided the function returns the autocorrelation of the mentioned variables
  • autocorrelation_periods [Default: 1:5]: periods for which to return the autocorrelation of the mentioned variables
  • algorithm [Default: :first_order, Type: Symbol]: algorithm to solve for the dynamics of the model.
  • verbose [Default: false, Type: Bool]: print information about how the NSSS is solved (symbolic or numeric), which solver is used (Levenberg-Marquardt...), and the maximum absolute error.

Examples

using MacroModelling

@model RBC begin
    1  /  c[0] = (β  /  c[1]) * (α * exp(z[1]) * k[0]^(α - 1) + (1 - δ))
    c[0] + k[0] = (1 - δ) * k[-1] + q[0]
    q[0] = exp(z[0]) * k[-1]^α
    z[0] = ρ * z[-1] + std_z * eps_z[x]
end

@parameters RBC begin
    std_z = 0.01
    ρ = 0.2
    δ = 0.02
    α = 0.5
    β = 0.95
end

get_statistics(RBC, RBC.parameter_values, parameters = RBC.parameters, standard_deviation = RBC.var)
# output
1-element Vector{Any}:
 [0.02666420378525503, 0.26467737291221793, 0.07393254045396483, 0.010206207261596574]
source
MacroModelling.get_steady_stateMethod
get_steady_state(
    𝓂;
    parameters,
    derivatives,
    stochastic,
    algorithm,
    parameter_derivatives,
    return_variables_only,
    verbose,
    silent,
    tol
)

Return the (non stochastic) steady state, calibrated parameters, and derivatives with respect to model parameters.

Arguments

Keyword Arguments

  • 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.
  • derivatives [Default: true, Type: Bool]: calculate derivatives with respect to the parameters.
  • stochastic [Default: false, Type: Bool]: return stochastic steady state using second order perturbation
  • algorithm [Default: :first_order, Type: Symbol]: algorithm to solve for the dynamics of the model.
  • parameter_derivatives [Default: :all]: parameters for which to calculate partial derivatives. Inputs can be a parameter name passed on as either a Symbol or String (e.g. :alpha, or "alpha"), or Tuple, Matrix or Vector of String or Symbol. :all will include all parameters.
  • return_variables_only [Defaut: false, Type: Bool]: return only variables and not calibrated parameters
  • verbose [Default: false, Type: Bool]: print information about how the NSSS is solved (symbolic or numeric), which solver is used (Levenberg-Marquardt...), and the maximum absolute error.

The columns show the (non stochastic) steady state and parameters for which derivatives are taken. The rows show the variables and calibrated parameters.

Examples

using MacroModelling

@model RBC begin
    1  /  c[0] = (β  /  c[1]) * (α * exp(z[1]) * k[0]^(α - 1) + (1 - δ))
    c[0] + k[0] = (1 - δ) * k[-1] + q[0]
    q[0] = exp(z[0]) * k[-1]^α
    z[0] = ρ * z[-1] + std_z * eps_z[x]
end

@parameters RBC begin
    std_z = 0.01
    ρ = 0.2
    δ = 0.02
    α = 0.5
    β = 0.95
end

get_steady_state(RBC)
# output
2-dimensional KeyedArray(NamedDimsArray(...)) with keys:
↓   Variables_and_calibrated_parameters ∈ 4-element Vector{Symbol}
→   Steady_state_and_∂steady_state∂parameter ∈ 6-element Vector{Symbol}
And data, 4×6 Matrix{Float64}:
        (:Steady_state)  (:std_z)  (:ρ)     (:δ)      (:α)       (:β)
  (:c)   5.93625          0.0       0.0   -116.072    55.786     76.1014
  (:k)  47.3903           0.0       0.0  -1304.95    555.264   1445.93
  (:q)   6.88406          0.0       0.0    -94.7805   66.8912   105.02
  (:z)   0.0              0.0       0.0      0.0       0.0        0.0
source
MacroModelling.get_steady_state_equationsMethod
get_steady_state_equations(𝓂)

Return the non-stochastic steady state (NSSS) equations of the model. The difference to the equations as they were written in the @model block is that exogenous shocks are set to 0, time subscripts are eliminated (e.g. c[-1] becomes c), trivial simplifications are carried out (e.g. log(k) - log(k) = 0), and auxilliary variables are added for expressions that cannot become negative.

Auxilliary variables facilitate the solution of the NSSS problem. The package substitutes expressions which cannot become negative with auxilliary variables and adds another equation to the system of equations determining the NSSS. For example, log(c/q) cannot be negative and c/q is substituted by an auxilliary varaible ➕₁ and an additional equation is added: ➕₁ = c / q.

Note that the ouput assumes the equations are equal to 0. As in, -z{δ} * ρ{δ} + z{δ} implies -z{δ} * ρ{δ} + z{δ} = 0 and therefore: z{δ} * ρ{δ} = z{δ}.

Arguments

Examples

using MacroModelling

@model RBC begin
    1  /  c[0] = (β  /  c[1]) * (α * exp(z{TFP}[1]) * k[0]^(α - 1) + (1 - exp(z{δ}[1]) * δ))
    c[0] + k[0] = (1 - exp(z{δ}[0])δ) * k[-1] + q[0]
    q[0] = exp(z{TFP}[0]) * k[-1]^α
    for shock in [TFP, δ]
        z{shock}[0] = ρ{shock} * z{shock}[-1] + σ{shock} * (eps{shock}[x] + eps_news{shock}[x-1])
    end
    Δc_share[0] = log(c[0]/q[0]) - log(c[-1]/q[-1])
    Δk_4q[0] = log(k[0]) - log(k[-4])
end

@parameters RBC begin
    σ = 0.01
    ρ = 0.2
    capital_to_output = 1.5
    k[ss] / (4 * q[ss]) = capital_to_output | δ
    alpha = .5
    α = alpha
    β = 0.95
end

get_steady_state_equations(RBC)
# output
9-element Vector{String}:
 "(-β * ((k ^ (α - 1) * α * exp(z{TFP}) - δ * exp(z{δ})) + 1)) / c + 1 / c"
 "((c - k * (-δ * exp(z{δ}) + 1)) + k) - q"
 "-(k ^ α) * exp(z{TFP}) + q"
 "-z{TFP} * ρ{TFP} + z{TFP}"
 "-z{δ} * ρ{δ} + z{δ}"
 "➕₁ - c / q"
 "➕₂ - c / q"
 "(Δc_share - log(➕₁)) + log(➕₂)"
 "Δk_4q - 0"
source
MacroModelling.get_variablesMethod
get_variables(𝓂)

Returns the variables of the model without timing subscripts and not including auxilliary variables.

In case programmatic model writing was used this function returns the parsed variables (see z in example).

Arguments

Examples

using MacroModelling

@model RBC begin
    1  /  c[0] = (β  /  c[1]) * (α * exp(z{TFP}[1]) * k[0]^(α - 1) + (1 - exp(z{δ}[1]) * δ))
    c[0] + k[0] = (1 - exp(z{δ}[0])δ) * k[-1] + q[0]
    q[0] = exp(z{TFP}[0]) * k[-1]^α
    for shock in [TFP, δ]
        z{shock}[0] = ρ{shock} * z{shock}[-1] + σ{shock} * (eps{shock}[x] + eps_news{shock}[x-1])
    end
    Δc_share[0] = log(c[0]/q[0]) - log(c[-1]/q[-1])
    Δk_4q[0] = log(k[0]) - log(k[-4])
end

@parameters RBC begin
    σ = 0.01
    ρ = 0.2
    capital_to_output = 1.5
    k[ss] / (4 * q[ss]) = capital_to_output | δ
    alpha = .5
    α = alpha
    β = 0.95
end

get_variables(RBC)
# output
7-element Vector{String}:
 "c"
 "k"
 "q"
 "z{TFP}"
 "z{δ}"
 "Δc_share"
 "Δk_4q"
source
MacroModelling.get_variance_decompositionMethod
get_variance_decomposition(𝓂; parameters, verbose)

Return the variance decomposition of endogenous variables with regards to the shocks using the linearised solution.

Arguments

Keyword Arguments

  • 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.
  • verbose [Default: false, Type: Bool]: print information about how the NSSS is solved (symbolic or numeric), which solver is used (Levenberg-Marquardt...), and the maximum absolute error.

Examples

using MacroModelling

@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 begin
    alpha = .157
    beta = .999
    delta = .0226
    Pibar = 1.0008
    phi_pi = 1.5
    rhoz = .9
    std_eps = .0068
    rho_z_delta = .9
    std_z_delta = .005
end

get_variance_decomposition(RBC_CME)
# output
2-dimensional KeyedArray(NamedDimsArray(...)) with keys:
↓   Variables ∈ 7-element Vector{Symbol}
→   Shocks ∈ 2-element Vector{Symbol}
And data, 7×2 Matrix{Float64}:
              (:delta_eps)  (:eps_z)
  (:A)         9.78485e-31   1.0
  (:Pi)        0.0156771     0.984323
  (:R)         0.0156771     0.984323
  (:c)         0.0134672     0.986533
  (:k)         0.00869568    0.991304
  (:y)         0.000313462   0.999687
  (:z_delta)   1.0           0.0
source
MacroModelling.plot_conditional_forecastMethod
plot_conditional_forecast(
    𝓂,
    conditions;
    shocks,
    initial_state,
    periods,
    parameters,
    variables,
    conditions_in_levels,
    algorithm,
    levels,
    show_plots,
    save_plots,
    save_plots_format,
    save_plots_path,
    plots_per_page,
    plot_attributes,
    verbose
)

Plot conditional forecast given restrictions on endogenous variables and shocks (optional) of the model. The algorithm finds the combinations of shocks with the smallest magnitude to match the conditions and plots both the endogenous variables and shocks.

The left axis shows the level, and the right axis the deviation from the (non) stochastic steady state, depending on the solution algorithm (e.g. higher order perturbation algorithms will show the stochastic steady state). Variable names are above the subplots, conditioned values are marked, and the title provides information about the model, and number of pages.

Arguments

  • 𝓂: the object created by @model and @parameters for which to get the solution.
  • conditions [Type: Union{Matrix{Union{Nothing,Float64}}, SparseMatrixCSC{Float64}, KeyedArray{Union{Nothing,Float64}}, KeyedArray{Float64}}]: conditions for which to find the corresponding shocks. The input can have multiple formats, but for all types of entries the first dimension corresponds to the number of variables and the second dimension to the number of periods. The conditions can be specified using a matrix of type Matrix{Union{Nothing,Float64}}. In this case the conditions are matrix elements of type Float64 and all remaining (free) entries are nothing. You can also use a SparseMatrixCSC{Float64} as input. In this case only non-zero elements are taken as conditions. Note that you cannot condition variables to be zero using a SparseMatrixCSC{Float64} as input (use other input formats to do so). Another possibility to input conditions is by using a KeyedArray. You can use a KeyedArray{Union{Nothing,Float64}} where, similar to Matrix{Union{Nothing,Float64}}, all entries of type Float64 are recognised as conditions and all other entries have to be nothing. Furthermore, you can specify in the primary axis a subset of variables (of type Symbol or String) for which you specify conditions and all other variables are considered free. The same goes for the case when you use KeyedArray{Float64}} as input, whereas in this case the conditions for the specified variables bind for all periods specified in the KeyedArray, because there are no nothing entries permitted with this type.

Keyword Arguments

  • shocks [Default: nothing, Type: Union{Matrix{Union{Nothing,Float64}}, SparseMatrixCSC{Float64}, KeyedArray{Union{Nothing,Float64}}, KeyedArray{Float64}, Nothing} = nothing]: known values of shocks. This entry allows the user to include certain shock values. By entering restrictions on the shock sin this way the problem to match the conditions on endogenous variables is restricted to the remaining free shocks in the repective period. The input can have multiple formats, but for all types of entries the first dimension corresponds to the number of shocks and the second dimension to the number of periods. The shocks can be specified using a matrix of type Matrix{Union{Nothing,Float64}}. In this case the shocks are matrix elements of type Float64 and all remaining (free) entries are nothing. You can also use a SparseMatrixCSC{Float64} as input. In this case only non-zero elements are taken as certain shock values. Note that you cannot condition shocks to be zero using a SparseMatrixCSC{Float64} as input (use other input formats to do so). Another possibility to input known shocks is by using a KeyedArray. You can use a KeyedArray{Union{Nothing,Float64}} where, similar to Matrix{Union{Nothing,Float64}}, all entries of type Float64 are recognised as known shocks and all other entries have to be nothing. Furthermore, you can specify in the primary axis a subset of shocks (of type Symbol or String) for which you specify values and all other shocks are considered free. The same goes for the case when you use KeyedArray{Float64}} as input, whereas in this case the values for the specified shocks bind for all periods specified in the KeyedArray, because there are no nothing entries permitted with this type.
  • initial_state [Default: [0.0], Type: Union{Vector{Vector{Float64}},Vector{Float64}}]: The initial state defines the starting point for the model and is relevant for normal IRFs. In the case of pruned solution algorithms the initial state can be given as multiple state vectors (Vector{Vector{Float64}}). In this case the initial state must be given in devations from the non-stochastic steady state. In all other cases the initial state must be given in levels. If a pruned solution algorithm is selected and initial state is a Vector{Float64} then it impacts the first order initial state vector only. The state includes all variables as well as exogenous variables in leads or lags if present.
  • periods [Default: 40, Type: Int]: the total number of periods is the sum of the argument provided here and the maximum of periods of the shocks or conditions argument.
  • 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.
  • 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.

conditions_in_levels [Default: true, Type: Bool]: indicator whether the conditions are provided in levels. If true the input to the conditions argument will have the non stochastic steady state substracted.

  • levels [Default: false, Type: Bool]: return levels or absolute deviations from steady state corresponding to the solution algorithm (e.g. stochastic steady state for higher order solution algorithms).
  • algorithm [Default: :first_order, Type: Symbol]: algorithm to solve for the dynamics of the model.
  • show_plots [Default: true, Type: Bool]: show plots. Separate plots per shocks and varibles depending on number of variables and plots_per_page.
  • save_plots [Default: false, Type: Bool]: switch to save plots using path and extension from save_plots_path and save_plots_format. Separate files per shocks and variables depending on number of variables and plots_per_page
  • save_plots_format [Default: :pdf, Type: Symbol]: output format of saved plots. See input formats compatible with GR for valid formats.
  • save_plots_path [Default: pwd(), Type: String]: path where to save plots
  • plots_per_page [Default: 9, Type: Int]: how many plots to show per page
  • verbose [Default: false, Type: Bool]: print information about how the NSSS is solved (symbolic or numeric), which solver is used (Levenberg-Marquardt...), and the maximum absolute error.

Examples

using MacroModelling, StatsPlots

@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 begin
    alpha = .157
    beta = .999
    delta = .0226
    Pibar = 1.0008
    phi_pi = 1.5
    rhoz = .9
    std_eps = .0068
    rho_z_delta = .9
    std_z_delta = .005
end

# c is conditioned to deviate by 0.01 in period 1 and y is conditioned to deviate by 0.02 in period 3
conditions = KeyedArray(Matrix{Union{Nothing,Float64}}(undef,2,2),Variables = [:c,:y], Periods = 1:2)
conditions[1,1] = .01
conditions[2,2] = .02

# in period 2 second shock (eps_z) is conditioned to take a value of 0.05
shocks = Matrix{Union{Nothing,Float64}}(undef,2,1)
shocks[1,1] = .05

plot_conditional_forecast(RBC_CME, conditions, shocks = shocks, conditions_in_levels = false)

# The same can be achieved with the other input formats:
# conditions = Matrix{Union{Nothing,Float64}}(undef,7,2)
# conditions[4,1] = .01
# conditions[6,2] = .02

# using SparseArrays
# conditions = spzeros(7,2)
# conditions[4,1] = .01
# conditions[6,2] = .02

# shocks = KeyedArray(Matrix{Union{Nothing,Float64}}(undef,1,1),Variables = [:delta_eps], Periods = [1])
# shocks[1,1] = .05

# using SparseArrays
# shocks = spzeros(2,1)
# shocks[1,1] = .05
source
MacroModelling.plot_conditional_variance_decompositionMethod
plot_conditional_variance_decomposition(
    𝓂;
    periods,
    variables,
    parameters,
    show_plots,
    save_plots,
    save_plots_format,
    save_plots_path,
    plots_per_page,
    plot_attributes,
    max_elements_per_legend_row,
    extra_legend_space,
    verbose
)

Plot conditional variance decomposition of the model.

The vertical axis shows the share of the shocks variance contribution, and horizontal axis the period of the variance decomposition. The stacked bars represent each shocks variance contribution at a specific time horizon.

Arguments

Keyword Arguments

  • 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.
  • 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.
  • 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.
  • show_plots [Default: true, Type: Bool]: show plots. Separate plots per shocks and varibles depending on number of variables and plots_per_page.
  • save_plots [Default: false, Type: Bool]: switch to save plots using path and extension from save_plots_path and save_plots_format. Separate files per shocks and variables depending on number of variables and plots_per_page
  • save_plots_format [Default: :pdf, Type: Symbol]: output format of saved plots. See input formats compatible with GR for valid formats.
  • save_plots_path [Default: pwd(), Type: String]: path where to save plots
  • plots_per_page [Default: 9, Type: Int]: how many plots to show per page
  • verbose [Default: false, Type: Bool]: print information about how the NSSS is solved (symbolic or numeric), which solver is used (Levenberg-Marquardt...), and the maximum absolute error.

Examples

using MacroModelling, StatsPlots

@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 begin
    alpha = .157
    beta = .999
    delta = .0226
    Pibar = 1.0008
    phi_pi = 1.5
    rhoz = .9
    std_eps = .0068
    rho_z_delta = .9
    std_z_delta = .005
end

plot_conditional_variance_decomposition(RBC_CME)
source
MacroModelling.plot_irfMethod
plot_irf(
    𝓂;
    periods,
    shocks,
    variables,
    parameters,
    show_plots,
    save_plots,
    save_plots_format,
    save_plots_path,
    plots_per_page,
    algorithm,
    negative_shock,
    generalised_irf,
    initial_state,
    ignore_obc,
    plot_attributes,
    verbose
)

Plot impulse response functions (IRFs) of the model.

The left axis shows the level, and the right the deviation from the reference steady state. Linear solutions have the non stochastic steady state as reference other solution the stochastic steady state. The horizontal black line indicates the reference steady state. Variable names are above the subplots and the title provides information about the model, shocks and number of pages per shock.

Arguments

Keyword Arguments

  • 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.
  • 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.
  • 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.
  • 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.
  • show_plots [Default: true, Type: Bool]: show plots. Separate plots per shocks and varibles depending on number of variables and plots_per_page.
  • save_plots [Default: false, Type: Bool]: switch to save plots using path and extension from save_plots_path and save_plots_format. Separate files per shocks and variables depending on number of variables and plots_per_page
  • save_plots_format [Default: :pdf, Type: Symbol]: output format of saved plots. See input formats compatible with GR for valid formats.
  • save_plots_path [Default: pwd(), Type: String]: path where to save plots
  • plots_per_page [Default: 9, Type: Int]: how many plots to show per page
  • algorithm [Default: :first_order, Type: Symbol]: algorithm to solve for the dynamics of the model.
  • negative_shock [Default: false, Type: Bool]: calculate a negative shock. Relevant for generalised IRFs.
  • generalised_irf [Default: false, Type: Bool]: calculate generalised IRFs. Relevant for nonlinear solutions. Reference steady state for deviations is the stochastic steady state.
  • initial_state [Default: [0.0], Type: Union{Vector{Vector{Float64}},Vector{Float64}}]: The initial state defines the starting point for the model and is relevant for normal IRFs. In the case of pruned solution algorithms the initial state can be given as multiple state vectors (Vector{Vector{Float64}}). In this case the initial state must be given in devations from the non-stochastic steady state. In all other cases the initial state must be given in levels. If a pruned solution algorithm is selected and initial state is a Vector{Float64} then it impacts the first order initial state vector only. The state includes all variables as well as exogenous variables in leads or lags if present.
  • ignore_obc [Default: false, Type: Bool]: solve the model ignoring the occasionally binding constraints.
  • verbose [Default: false, Type: Bool]: print information about how the NSSS is solved (symbolic or numeric), which solver is used (Levenberg-Marquardt...), and the maximum absolute error.

Examples

using MacroModelling, StatsPlots

@model RBC begin
    1  /  c[0] = (β  /  c[1]) * (α * exp(z[1]) * k[0]^(α - 1) + (1 - δ))
    c[0] + k[0] = (1 - δ) * k[-1] + q[0]
    q[0] = exp(z[0]) * k[-1]^α
    z[0] = ρ * z[-1] + std_z * eps_z[x]
end;

@parameters RBC begin
    std_z = 0.01
    ρ = 0.2
    δ = 0.02
    α = 0.5
    β = 0.95
end;

plot_irf(RBC)
source
MacroModelling.plot_model_estimatesMethod
plot_model_estimates(
    𝓂,
    data;
    parameters,
    algorithm,
    filter,
    warmup_iterations,
    variables,
    shocks,
    presample_periods,
    data_in_levels,
    shock_decomposition,
    smooth,
    show_plots,
    save_plots,
    save_plots_format,
    save_plots_path,
    plots_per_page,
    transparency,
    max_elements_per_legend_row,
    extra_legend_space,
    plot_attributes,
    verbose
)

Plot model estimates of the variables given the data. The default plot shows the estimated variables, shocks, and the data to estimate the former. The left axis shows the level, and the right the deviation from the reference steady state. The horizontal black line indicates the non stochastic steady state. Variable names are above the subplots and the title provides information about the model, shocks and number of pages per shock.

In case shock_decomposition = true, then the plot shows the variables, shocks, and data in absolute deviations from the non stochastic steady state plus the contribution of the shocks as a stacked bar chart per period.

Arguments

  • 𝓂: the object created by @model and @parameters for which to get the solution.
  • data [Type: KeyedArray]: data matrix with variables (String or Symbol) in rows and time in columns

Keyword Arguments

  • 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.
  • 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.
  • shocks [Default: :all]: shocks for which to plot the estimates. Inputs can be either a Symbol (e.g. :y, or :all), Tuple{Symbol, Vararg{Symbol}}, Matrix{Symbol}, or Vector{Symbol}.
  • data_in_levels [Default: true, Type: Bool]: indicator whether the data is provided in levels. If true the input to the data argument will have the non stochastic steady state substracted.
  • shock_decomposition [Default: false, Type: Bool]: whether to show the contribution of the shocks to the deviations from NSSS for each variable. If false, the plot shows the values of the selected variables, data, and shocks
  • smooth [Default: true, Type: Bool]: whether to return smoothed (true) or filtered (false) shocks/variables. Only works for the Kalman filter. The inversion filter only returns filtered shocks/variables.
  • show_plots [Default: true, Type: Bool]: show plots. Separate plots per shocks and varibles depending on number of variables and plots_per_page.
  • save_plots [Default: false, Type: Bool]: switch to save plots using path and extension from save_plots_path and save_plots_format. Separate files per shocks and variables depending on number of variables and plots_per_page
  • save_plots_format [Default: :pdf, Type: Symbol]: output format of saved plots. See input formats compatible with GR for valid formats.
  • save_plots_path [Default: pwd(), Type: String]: path where to save plots
  • plots_per_page [Default: 9, Type: Int]: how many plots to show per page
  • transparency [Default: 0.6, Type: Float64]: transparency of bars
  • verbose [Default: false, Type: Bool]: print information about how the NSSS is solved (symbolic or numeric), which solver is used (Levenberg-Marquardt...), and the maximum absolute error.

Examples

using MacroModelling, StatsPlots


@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 begin
    alpha = .157
    beta = .999
    delta = .0226
    Pibar = 1.0008
    phi_pi = 1.5
    rhoz = .9
    std_eps = .0068
    rho_z_delta = .9
    std_z_delta = .005
end

simulation = simulate(RBC_CME)

plot_model_estimates(RBC_CME, simulation([:k],:,:simulate))
source
MacroModelling.plot_solutionMethod
plot_solution(
    𝓂,
    state;
    variables,
    algorithm,
    σ,
    parameters,
    ignore_obc,
    show_plots,
    save_plots,
    save_plots_format,
    save_plots_path,
    plots_per_page,
    plot_attributes,
    verbose
)

Plot the solution of the model (mapping of past states to present variables) around the (non) stochastic steady state (depending on chosen solution algorithm). Each plot shows the relationship between the chosen state (defined in state) and one of the chosen variables (defined in variables).

The (non) stochastic steady state is plotted along with the mapping from the chosen past state to one present variable per plot. All other (non-chosen) states remain in the (non) stochastic steady state.

In the case of pruned solutions there as many (latent) state vectors as the perturbation order. The first and third order baseline state vectors are the non stochastic steady state and the second order baseline state vector is the stochastic steady state. Deviations for the chosen state are only added to the first order baseline state. The plot shows the mapping from σ standard deviations (first order) added to the first order non stochastic steady state and the present variables. Note that there is no unique mapping from the "pruned" states and the "actual" reported state. Hence, the plots shown are just one realisation of inifite possible mappings.

Arguments

  • 𝓂: the object created by @model and @parameters for which to get the solution.
  • state [Type: Union{Symbol,String}]: state variable to be shown on x-axis.

Keyword Arguments

  • 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.
  • algorithm [Default: :first_order, Type: Union{Symbol,Vector{Symbol}}]: solution algorithm for which to show the IRFs. Can be more than one, e.g.: [:second_order,:pruned_third_order]"
  • σ [Default: 2, Type: Union{Int64,Float64}]: defines the range of the state variable around the (non) stochastic steady state in standard deviations. E.g. a value of 2 means that the state variable is plotted for values of the (non) stochastic steady state in standard deviations +/- 2 standard deviations.
  • 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.
  • ignore_obc [Default: false, Type: Bool]: solve the model ignoring the occasionally binding constraints.
  • show_plots [Default: true, Type: Bool]: show plots. Separate plots per shocks and varibles depending on number of variables and plots_per_page.
  • save_plots [Default: false, Type: Bool]: switch to save plots using path and extension from save_plots_path and save_plots_format. Separate files per shocks and variables depending on number of variables and plots_per_page
  • save_plots_format [Default: :pdf, Type: Symbol]: output format of saved plots. See input formats compatible with GR for valid formats.
  • save_plots_path [Default: pwd(), Type: String]: path where to save plots
  • plots_per_page [Default: 6, Type: Int]: how many plots to show per page
  • verbose [Default: false, Type: Bool]: print information about how the NSSS is solved (symbolic or numeric), which solver is used (Levenberg-Marquardt...), and the maximum absolute error.

Examples

using MacroModelling, StatsPlots

@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 begin
    alpha = .157
    beta = .999
    delta = .0226
    Pibar = 1.0008
    phi_pi = 1.5
    rhoz = .9
    std_eps = .0068
    rho_z_delta = .9
    std_z_delta = .005
end

plot_solution(RBC_CME, :k)
source
MacroModelling.translate_mod_fileMethod
translate_mod_file(path_to_mod_file)

Reads in a dynare .mod-file, adapts the syntax, tries to capture parameter definitions, and writes a julia file in the same folder containing the model equations and parameters in MacroModelling.jl syntax. This function is not guaranteed to produce working code. It's purpose is to make it easier to port a model from dynare to MacroModelling.jl.

The recommended workflow is to use this function to translate a .mod-file, and then adapt the output so that it runs and corresponds to the input.

Note that this function copies the .mod-file to a temporary folder and executes it there. All references within that .mod-file are therefore not valid (because those filesare not copied) and must be made copied into the .mod-file.

Arguments

  • path_to_mod_file [Type: AbstractString]: path including filename of the .mod-file to be translated
source
MacroModelling.write_mod_fileMethod
write_mod_file(m)

Writes a dynare .mod-file in the current working directory. This function is not guaranteed to produce working code. It's purpose is to make it easier to port a model from MacroModelling.jl to dynare.

The recommended workflow is to use this function to write a .mod-file, and then adapt the output so that it runs and corresponds to the input.

Arguments

source
MacroModelling.@modelMacro

Parses the model equations and assigns them to an object.

Arguments

  • 𝓂: 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 square brackets. Endogenous variables can have the following:

  • present: c[0]
  • non-stcohastic steady state: c[ss] instead of ss any of the following is also a valid flag for the non-stochastic steady state: ss, stst, steady, steadystate, steady_state, and the parser is case-insensitive (SS or sTst will work as well).
  • past: c[-1] or any negative Integer: e.g. c[-12]
  • future: c[1] or any positive Integer: e.g. c[16] or c[+16]

Signed integers are recognised and parsed as such.

Exogenous variables (shocks) can have the following:

  • present: eps_z[x] instead of x any of the following is also a valid flag for exogenous variables: ex, exo, exogenous, and the parser is case-insensitive (Ex or exoGenous will work as well).
  • past: eps_z[x-1]
  • future: eps_z[x+1]

Parameters enter the equations without square 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

using MacroModelling

@model RBC begin
    1  /  c[0] = (β  /  c[1]) * (α * exp(z[1]) * k[0]^(α - 1) + (1 - δ))
    c[0] + k[0] = (1 - δ) * k[-1] + q[0]
    q[0] = exp(z[0]) * k[-1]^α
    z[0] = ρ * z[-1] + std_z * eps_z[x]
end

Programmatic model writing

Parameters and variables can be indexed using curly braces: e.g. c{H}[0], eps_z{F}[x], or α{H}.

for loops can be used to write models programmatically. They can either be used to generate expressions where you iterate over the time index or the index in curly braces:

  • generate equation with different indices in curly braces: for co in [H,F] C{co}[0] + X{co}[0] + Z{co}[0] - Z{co}[-1] end = for co in [H,F] Y{co}[0] end
  • generate multiple equations with different indices in curly braces: for co in [H, F] K{co}[0] = (1-delta{co}) * K{co}[-1] + S{co}[0] end
  • generate equation with different time indices: Y_annual[0] = for lag in -3:0 Y[lag] end or R_annual[0] = for operator = :*, lag in -3:0 R[lag] end
source
MacroModelling.@parametersMacro

Adds parameter values and calibration equations to the previously defined model. Allows to provide an initial guess for the non-stochastic steady state (NSSS).

Arguments

  • 𝓂: name of the object previously created containing the model information.
  • ex: parameter, parameters values, and calibration equations

Parameters can be defined in either of the following ways:

  • plain number: δ = 0.02
  • expression containing numbers: δ = 1/50
  • expression containing other parameters: δ = 2 * std_z in this case it is irrelevant if std_z is defined before or after. The definitons including other parameters are treated as a system of equaitons and solved accordingly.
  • expressions containing a target parameter and an equations with endogenous variables in the non-stochastic steady state, and other parameters, or numbers: k[ss] / (4 * q[ss]) = 1.5 | δ or α | 4 * q[ss] = δ * k[ss] in this case the target parameter will be solved simultaneaously with the non-stochastic steady state using the equation defined with it.

Optional arguments to be placed between 𝓂 and ex

  • guess [Type: Dict{Symbol, <:Real}, Dict{String, <:Real}}]: Guess for the non-stochastic steady state. The keys must be the variable (and calibrated parameters) names and the values the guesses. Missing values are filled with standard starting values.
  • verbose [Default: false, Type: Bool]: print more information about how the non stochastic steady state is solved
  • silent [Default: false, Type: Bool]: do not print any information
  • symbolic [Default: false, Type: Bool]: try to solve the non stochastic steady state symbolically and fall back to a numerical solution if not possible
  • perturbation_order [Default: 1, Type: Int]: take derivatives only up to the specified order at this stage. In case you want to work with higher order perturbation later on, respective derivatives will be taken at that stage.
  • simplify [Default: true, Type: Bool]: whether to elminiate redundant variables and simplify the non stochastic steady state (NSSS) problem. Setting this to false can speed up the process, but might make it harder to find the NSSS. If the model does not parse at all (at step 1 or 2), setting this option to false might solve it.

Examples

using MacroModelling

@model RBC begin
    1  /  c[0] = (β  /  c[1]) * (α * exp(z[1]) * k[0]^(α - 1) + (1 - δ))
    c[0] + k[0] = (1 - δ) * k[-1] + q[0]
    q[0] = exp(z[0]) * k[-1]^α
    z[0] = ρ * z[-1] + std_z * eps_z[x]
end

@parameters RBC verbose = true begin
    std_z = 0.01
    ρ = 0.2
    δ = 0.02
    α = 0.5
    β = 0.95
end

@model RBC_calibrated begin
    1  /  c[0] = (β  /  c[1]) * (α * exp(z[1]) * k[0]^(α - 1) + (1 - δ))
    c[0] + k[0] = (1 - δ) * k[-1] + q[0]
    q[0] = exp(z[0]) * k[-1]^α
    z[0] = ρ * z[-1] + std_z * eps_z[x]
end

@parameters RBC_calibrated verbose = true guess = Dict(:k => 3) begin
    std_z = 0.01
    ρ = 0.2
    δ = 0.02
    k[ss] / q[ss] = 2.5 | α
    β = 0.95
end

Programmatic model writing

Variables and parameters indexed with curly braces can be either referenced specifically (e.g. c{H}[ss]) or generally (e.g. alpha). If they are referenced generaly the parse assumes all instances (indices) are meant. For example, in a model where alpha has two indices H and F, the expression alpha = 0.3 is interpreted as two expressions: alpha{H} = 0.3 and alpha{F} = 0.3. The same goes for calibration equations.

source