First steps with Dynare and moment matching.

Business Cycles and Fluctuations - AE2E6

Using Dynare:

  • get familiar with the structure of a modfile
  • interpret results
    • compare moments with the data
  • edit a model
    • fix steady-state
    • extend a model (in particular recheck/rederive first order conditions)

Uncomment the following lines to install needed packages (if not already present).

# uncomment the next lines, the first time you run
# import Pkg; Pkg.add(["DBnomics", "Dynare", "DataFrames"])
# import Pkg; Pkg.add(url="https://github.com/sdBrinkmann/HPFilter.jl") # we install hpfilter from github

Using Dynare

Download the rbc modfile.

using Dynare

Open the RBC model and solve the model. Fix the mistakes in the modfile if any.

context = @dynare "rbc.mod";
# ; mutes the output
# graphs and other outputs are stored in subdirectory `rbc`
# the structure `context contains all the results.`
Dynare version: 0.9.10
2024-04-12T11:45:17.545: Starting @dynare rbc.mod
["rbc.mod", "language=julia", "json=compute"]
Dynare preprocessor version: 6.4.0+0
2024-04-12T11:45:17.550: End of preprocessing
2024-04-12T11:45:17.553: Start parse_statements!
2024-04-12T11:45:17.558: End parse_statements!
2024-04-12T11:45:17.558: End parser
Starting preprocessing of the model file ...
Found 8 equation(s).
Evaluating expressions...
Computing static model derivatives (order 1).
Normalizing the static model...
Finding the optimal block decomposition of the static model...
2 block(s) found:
  1 recursive block(s) and 1 simultaneous block(s).
  the largest simultaneous block has 7 equation(s)
                                 and 5 feedback variable(s).
Computing dynamic model derivatives (order 2).
Normalizing the dynamic model...
Finding the optimal block decomposition of the dynamic model...
2 block(s) found:
  1 recursive block(s) and 1 simultaneous block(s).
  the largest simultaneous block has 7 equation(s)
                                 and 5 feedback variable(s).
JSON written after Computing step.
Preprocessing completed.

longname: c
texname: c
symboltype: Endogenous
orderintype: 6
longname: r
texname: r
symboltype: Endogenous
orderintype: 7
longname: khi
texname: khi
symboltype: Parameter
orderintype: 5
longname: a
texname: a
symboltype: Endogenous
orderintype: 4
longname: delta
texname: delta
symboltype: Parameter
orderintype: 2
longname: nss
texname: nss
symboltype: Parameter
orderintype: 4
longname: y
texname: y
symboltype: Endogenous
orderintype: 3
longname: i
texname: i
symboltype: Endogenous
orderintype: 2
longname: w
texname: w
symboltype: Endogenous
orderintype: 8
longname: k
texname: k
symboltype: Endogenous
orderintype: 1
endogenous_nbr: 8
exogenous_nbr: 1
lagged_exogenous_nbr: 0
exogenous_deterministic_nbr: 0
parameter_nbr: 7
original_endogenous_nbr: 8
lead_lag_incidence: [1 0 0 2 0 0 0 0; 3 4 5 6 7 8 9 10; 0 0 0 0 0 11 12 0]
n_static: 4
n_fwrd: 2
n_bkwrd: 2
n_both: 0
n_states: 2
DErows1: [1, 2, 3, 4]
DErows2: Int64[]
n_dyn: 4
i_static: [2, 3, 5, 8]
i_dyn: [1, 4, 6, 7]
i_bkwrd: [1, 4]
i_bkwrd_b: [1, 4]
i_bkwrd_ns: [1, 2]
i_fwrd: [6, 7]
i_fwrd_b: [6, 7]
i_fwrd_ns: [3, 4]
i_both: Int64[]
i_non_states: [2, 3, 5, 6, 7, 8]
p_static: [4, 5, 7, 10]
p_bkwrd: [1, 2]
p_bkwrd_b: [1, 2]
p_fwrd: [11, 12]
p_fwrd_b: [11, 12]
p_both_b: Int64[]
p_both_f: Int64[]
i_current: [1, 2, 3, 4, 5, 6, 7, 8]
p_current: [3, 4, 5, 6, 7, 8, 9, 10]
n_current: 8
i_current_ns: [1, 2, 3, 4]
p_current_ns: [3, 6, 8, 9]
n_current_ns: 4
icolsD: [1, 2, 3, 4]
jcolsD: [3, 6, 11, 12]
icolsE: [1, 2, 3, 4]
jcolsE: [1, 2, 8, 9]
colsUD: Int64[]
colsUE: Int64[]
i_cur_fwrd: [1, 2]
n_cur_fwrd: 2
p_cur_fwrd: [8, 9]
i_cur_bkwrd: [1, 2]
n_cur_bkwrd: 2
p_cur_bkwrd: [3, 6]
i_cur_both: Int64[]
n_cur_both: 0
p_cur_both: Int64[]
gx_rows: [3, 4]
hx_rows: [1, 2]
i_current_exogenous: [13]
i_lagged_exogenous: Int64[]
serially_correlated_exogenous: Int64[]
Sigma_e: [8.099999999999999e-5;;]
maximum_endo_lag: 1
maximum_endo_lead: 1
maximum_exo_lag: 0
maximum_exo_lead: 0
maximum_exo_det_lag: 0
maximum_exo_det_lead: 0
maximum_lag: 1
maximum_lead: 1
orig_maximum_endo_lag: 1
orig_maximum_endo_lead: 1
orig_maximum_exo_lag: 0
orig_maximum_exo_lead: 0
orig_maximum_exo_det_lag: 0
orig_maximum_exo_det_lead: 0
orig_maximum_lag: 1
orig_maximum_lead: 1
dynamic_indices: [1, 4, 6, 7]
current_dynamic_indices: [1, 4, 6, 7]
forward_indices_d: [3, 4]
backward_indices_d: [1, 2]
current_dynamic_indices_d: [1, 2, 3, 4]
exogenous_indices: [13]
NNZDerivatives: [25, 23, -1]
auxiliary_variables: Dict{String, Any}[]
mcps: Tuple{Int64, Int64, String, String}[]
dynamic_g1_sparse_rowval: [3, 7, 5, 3, 4, 3, 8, 4, 6, 7, 8, 4, 5, 2, 4, 6, 1, 2, 8, 7, 2, 6, 1, 1, 5]
dynamic_g1_sparse_colptr: [1, 3, 3, 3, 4, 4, 4, 4, 4, 6, 8, 12, 14, 17, 20, 21, 23, 23, 23, 23, 23, 23, 24, 25, 25, 26]
dynamic_g2_sparse_indices: [[1, 14, 14], [1, 22, 22], [1, 22, 23], [2, 13, 13], [2, 13, 14], [4, 9, 9], [4, 9, 12], [4, 9, 13], [4, 12, 13], [4, 13, 13], [5, 4, 4], [5, 12, 12], [6, 11, 13], [6, 13, 13], [7, 1, 1], [7, 1, 11]]
static_g1_sparse_rowval: [3, 4, 7, 3, 8, 4, 6, 7, 8, 4, 5, 2, 4, 6, 1, 2, 8, 1, 7, 2, 6]
static_g1_sparse_colptr: [1, 4, 6, 10, 12, 15, 18, 20, 22]
dynamic_tmp_nbr: [3, 4, 0, 0]
static_tmp_nbr: [3, 0, 0, 0]
ids: LinearRationalExpectations.Indices([1, 2, 3, 4, 5, 6, 7, 8], [6, 7], [6, 7], [1, 4], Int64[], [2, 3, 5, 6, 7, 8], [2, 3, 5, 8], [1, 4, 6, 7], [1, 4, 6, 7], [1, 2, 3, 4], [3, 4], [1, 2], [3, 6, 8, 9], [4, 5, 7, 10], [13], 8, (D = [1, 2, 3, 4], jacobian = [3, 6, 11, 12]), (E = [1, 2, 3, 4], jacobian = [1, 2, 8, 9]), Int64[], Int64[])
endval_is_reset: false
has_auxiliary_variables: false
has_calib_smoother: false
has_check: false
has_deterministic_trend: false
has_dynamic_file: true
has_endval: false
has_histval: false
has_histval_file: false
has_initval: false
has_initval_file: false
has_planner_objective: false
has_perfect_foresight_setup: false
has_perfect_foresight_solver: false
has_ramsey_model: false
has_shocks: true
has_static_file: true
has_steadystate_file: true
has_stoch_simul: false
has_trends: false
initval_is_reset: false
modfilepath: rbc
irfs: Dict{Symbol, AxisArrayTables.AxisArrayTable}()
endogenous_steady_state: Float64[]
endogenous_terminal_steady_state: Float64[]
endogenous_linear_trend: Float64[]
endogenous_quadratic_trend: Float64[]
exogenous_steady_state: [0.0]
exogenous_terminal_steady_state: Float64[]
exogenous_linear_trend: Float64[]
exogenous_quadratic_trend: Float64[]
exogenous_det_steady_state: Float64[]
exogenous_det_terminal_steady_state: Float64[]
exogenous_det_linear_trend: Float64[]
exogenous_det_quadratic_trend: Float64[]
trends: 
stationary_variables: Bool[0, 0, 0, 0, 0, 0, 0, 0]
estimation: Dynare.EstimationResults(Any[], Any[], Any[], Any[], Matrix{Any}(undef, 0, 0), Matrix{Any}(undef, 0, 0), 0)
filter: 
forecast: AxisArrayTables.AxisArrayTable[]
initial_smoother: 
linearrationalexpectations: LinearRationalExpectations.LinearRationalExpectationsResults(ComplexF64[], [0.0 0.0 0.0 0.0; 0.0 0.0 0.0 0.0; 0.0 0.0 0.0 0.0; 0.0 0.0 0.0 0.0; 0.0 0.0 0.0 0.0; 0.0 0.0 0.0 0.0; 0.0 0.0 0.0 0.0; 0.0 0.0 0.0 0.0], [0.0 0.0; 0.0 0.0], [0.0; 0.0;;], [0.0 0.0; 0.0 0.0; 0.0 0.0; 0.0 0.0; 0.0 0.0; 0.0 0.0], [0.0; 0.0; 0.0; 0.0; 0.0; 0.0;;], [0.0 0.0; 0.0 0.0; 0.0 0.0; 0.0 0.0; 0.0 0.0; 0.0 0.0; 0.0 0.0; 0.0 0.0], [0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0;;], [0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0; 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0; 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0; 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0; 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0; 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0; 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0; 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0], Bool[0, 0, 0, 0, 0, 0, 0, 0])
simulations: Simulation[]
smoother: 
solution_derivatives: Matrix{Float64}[]
analytical_steadystate_variables: [1, 2, 3, 4, 5, 6, 7, 8]
data: 
datafile: 
params: [0.985, 0.025, 0.33, 0.33, 1.7112427501331826, 1.0, 0.95]
residuals: [6.1794719649538e-310, 0.0, 6.1794718562609e-310, 0.0, 6.17954108527044e-310, 0.0, 6.17962015701543e-310, 5.0e-324]
dynamic_variables: [6.17961328859545e-310, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 6.17961324669474e-310, 6.17946974505755e-310, 7.1e-322, 2.76236e-318, 7.1e-322]
exogenous_variables: [1.0e-323, 6.1796167183312e-310, 6.17962441485657e-310]
observed_variables: String[]
Sigma_m: Matrix{Float64}(undef, 0, 0)
jacobian: Matrix{Float64}(undef, 0, 0)
qr_jacobian: Matrix{Float64}(undef, 0, 0)
model_has_trend: Bool[0]
histval: Matrix{Union{Missing, Float64}}(undef, 0, 0)
homotopy_setup: @NamedTuple{name::Symbol, type::SymbolType, index::Int64, endvalue::Float64, startvalue::Union{Missing, Float64}}[]
initval_endogenous: Matrix{Union{Missing, Float64}}(undef, 0, 0)
initval_exogenous: Matrix{Union{Missing, Float64}}(undef, 0, 0)
initval_exogenous_deterministic: Matrix{Union{Missing, Float64}}(undef, 0, 0)
endval_endogenous: Matrix{Union{Missing, Float64}}(undef, 0, 0)
endval_exogenous: Matrix{Union{Missing, Float64}}(undef, 0, 0)
endval_exogenous_deterministic: Matrix{Union{Missing, Float64}}(undef, 0, 0)
scenario: Dict{Union{Int64, Dates.UTInstant}, Dict{Union{Int64, Dates.UTInstant}, Dict{Symbol, Pair{Float64, Symbol}}}}()
shocks: Float64[]
perfect_foresight_setup: Dict{String, Any}("periods" => 0, "datafile" => "")
estimated_parameters: Dynare.EstimatedParameters(Union{Int64, Pair{Int64, Int64}}[], Union{Missing, Float64}[], Float64[], Union{Pair{String, String}, String}[], Dynare.EstimatedParameterType[], Float64[], Float64[], Float64[], Float64[], Float64[], Float64[], Distributions.Distribution[])
Context(Dict{String, DynareSymbol}("c" => , "r" => , "khi" => , "a" => , "delta" => , "nss" => , "y" => , "i" => , "w" => , "k" => …), Model[], , Results(ModelResults[]), , Dict{Any, Any}())

(if needed, download the correct model here )

Inspect the various elements of the solution (decision rule, unconditional moments, simulations).

Interpret the effect of a productivity shock. How does it depend on the productivity?

Bonus: open the same model with Dyno (see link on the course webpage). Compare the results.

Computing moments in the data

Download US time series from the world bank for: real gdp, investment, consumption, hours worked.

using Plots
using DBnomics
using DataFrames
using HPFilter: HP
using Statistics: cor, std
WARNING: Method definition HP(Array{T, 1} where T, Int64) in module HPFilter at /home/pablo/.julia/packages/HPFilter/981TT/src/HPFilterFunc.jl:8 overwritten at /home/pablo/.julia/packages/HPFilter/981TT/src/HPFilterFunc.jl:26.
ERROR: Method overwriting is not permitted during Module precompilation. Use `__precompile__(false)` to opt-out of precompilation.
# google OECD
df_ = rdb(ids = [
    "OECD/QNA/USA.P5.LNBQRSA.Q", # investment
    "OECD/QNA/USA.B1_GS1.LNBQRSA.Q", # GDP
    "OECD/QNA/USA.P3.LNBQRSA.Q"

]);
# keep only the relevant data, in long format
df_long = df_[!,["Subject","period","value"]]
740×3 DataFrame
715 rows omitted
Row Subject period value
String Date Float64
1 Gross capital formation 1970-01-01 2.15688e5
2 Gross capital formation 1970-04-01 2.14743e5
3 Gross capital formation 1970-07-01 217739.0
4 Gross capital formation 1970-10-01 2.08844e5
5 Gross capital formation 1971-01-01 2.23069e5
6 Gross capital formation 1971-04-01 2.27366e5
7 Gross capital formation 1971-07-01 2.29696e5
8 Gross capital formation 1971-10-01 2.23591e5
9 Gross capital formation 1972-01-01 2.34297e5
10 Gross capital formation 1972-04-01 2.45149e5
11 Gross capital formation 1972-07-01 2.4584e5
12 Gross capital formation 1972-10-01 249080.0
13 Gross capital formation 1973-01-01 2.62822e5
729 Final consumption expenditure 2021-01-01 4.31553e6
730 Final consumption expenditure 2021-04-01 4.42287e6
731 Final consumption expenditure 2021-07-01 4.44763e6
732 Final consumption expenditure 2021-10-01 4.48373e6
733 Final consumption expenditure 2022-01-01 4.47788e6
734 Final consumption expenditure 2022-04-01 4.49347e6
735 Final consumption expenditure 2022-07-01 4.51199e6
736 Final consumption expenditure 2022-10-01 4.52916e6
737 Final consumption expenditure 2023-01-01 4.5728e6
738 Final consumption expenditure 2023-04-01 4.5821e6
739 Final consumption expenditure 2023-07-01 4.61965e6
740 Final consumption expenditure 2023-10-01 4.65017e6
df = unstack(df_long,:period, :Subject,:value);
df = dropmissing(sort(df))
216×4 DataFrame
191 rows omitted
Row period Gross capital formation Gross domestic product Final consumption expenditure
Date Float64 Float64 Float64
1 1970-01-01 2.15688e5 1.32516e6 1.13697e6
2 1970-04-01 2.14743e5 1.32704e6 1.13882e6
3 1970-07-01 217739.0 1.33927e6 1.14738e6
4 1970-10-01 2.08844e5 1.32492e6 1.14562e6
5 1971-01-01 2.23069e5 1.3609e6 1.1627e6
6 1971-04-01 2.27366e5 1.36826e6 1.17093e6
7 1971-07-01 2.29696e5 1.37952e6 1.17765e6
8 1971-10-01 2.23591e5 1.38276e6 1.19219e6
9 1972-01-01 2.34297e5 1.40816e6 1.2072e6
10 1972-04-01 2.45149e5 1.44012e6 1.22563e6
11 1972-07-01 2.4584e5 1.45371e6 1.2364e6
12 1972-10-01 249080.0 1.47806e6 1.25882e6
13 1973-01-01 2.62822e5 1.51464e6 1.2765e6
205 2021-01-01 1.14623e6 5.24764e6 4.31553e6
206 2021-04-01 1.12988e6 5.32739e6 4.42287e6
207 2021-07-01 1.16292e6 5.37077e6 4.44763e6
208 2021-10-01 1.22444e6 5.4619e6 4.48373e6
209 2022-01-01 1.239e6 5.43472e6 4.47788e6
210 2022-04-01 1.20802e6 5.42704e6 4.49347e6
211 2022-07-01 1.1905e6 5.46278e6 4.51199e6
212 2022-10-01 1.20503e6 5.4975e6 4.52916e6
213 2023-01-01 1.18421e6 5.52808e6 4.5728e6
214 2023-04-01 1.20309e6 5.55634e6 4.5821e6
215 2023-07-01 1.23273e6 5.62267e6 4.61965e6
216 2023-10-01 1.2424e6 5.66821e6 4.65017e6
rename!(df,[:period, :investment, :gdp, :consumption])
216×4 DataFrame
191 rows omitted
Row period investment gdp consumption
Date Float64 Float64 Float64
1 1970-01-01 2.15688e5 1.32516e6 1.13697e6
2 1970-04-01 2.14743e5 1.32704e6 1.13882e6
3 1970-07-01 217739.0 1.33927e6 1.14738e6
4 1970-10-01 2.08844e5 1.32492e6 1.14562e6
5 1971-01-01 2.23069e5 1.3609e6 1.1627e6
6 1971-04-01 2.27366e5 1.36826e6 1.17093e6
7 1971-07-01 2.29696e5 1.37952e6 1.17765e6
8 1971-10-01 2.23591e5 1.38276e6 1.19219e6
9 1972-01-01 2.34297e5 1.40816e6 1.2072e6
10 1972-04-01 2.45149e5 1.44012e6 1.22563e6
11 1972-07-01 2.4584e5 1.45371e6 1.2364e6
12 1972-10-01 249080.0 1.47806e6 1.25882e6
13 1973-01-01 2.62822e5 1.51464e6 1.2765e6
205 2021-01-01 1.14623e6 5.24764e6 4.31553e6
206 2021-04-01 1.12988e6 5.32739e6 4.42287e6
207 2021-07-01 1.16292e6 5.37077e6 4.44763e6
208 2021-10-01 1.22444e6 5.4619e6 4.48373e6
209 2022-01-01 1.239e6 5.43472e6 4.47788e6
210 2022-04-01 1.20802e6 5.42704e6 4.49347e6
211 2022-07-01 1.1905e6 5.46278e6 4.51199e6
212 2022-10-01 1.20503e6 5.4975e6 4.52916e6
213 2023-01-01 1.18421e6 5.52808e6 4.5728e6
214 2023-04-01 1.20309e6 5.55634e6 4.5821e6
215 2023-07-01 1.23273e6 5.62267e6 4.61965e6
216 2023-10-01 1.2424e6 5.66821e6 4.65017e6
pl1 = plot(df[!,:period], df[!,:investment],label="investment")
pl2 = plot(df[!,:period], df[!,:gdp],label="gdp")
pl3 = plot(df[!,:period], df[!,:consumption],label="consumption")

plot(pl1,pl2,pl3;size=(800,800))

Detrend all series.

# detrend the consumption series 
series = df[!,:consumption]
trend = HP(series, 1600)
cycle = (series - trend)./trend
df[!,:consumption_trend] = trend
df[!,:consumption_cycle] = cycle;
pl1 = plot(series, title="consumption")
plot!(pl1, trend, label="consumption")
pl2 = plot(cycle, title="consumption (cycle)")
plot(pl1, pl2)
# detrend gdp

series = df[!,:gdp]
trend = HP(series, 1600)
cycle = (series - trend)./trend
df[!,:gdp_trend] = trend
df[!,:gdp_cycle] = cycle;
# detrend the investment series 

series = df[!,:investment]
trend = HP(series, 1600)
cycle = (series - trend)./trend
df[!,:investment_trend] = trend
df[!,:investment_cycle] = cycle;

Compute the correlations between the detrended series. Compute the ratios \(\frac{\sigma(investment)}{\sigma(gdp)}\) and \(\frac{\sigma (consumption)}{\sigma (gdp)}\). Compare with the RBC model and comment.

# keep only the relevant part of the dataframe
relevant_df = df[:,[:gdp_cycle,:investment_cycle,:consumption_cycle]]
216×3 DataFrame
191 rows omitted
Row gdp_cycle investment_cycle consumption_cycle
Float64 Float64 Float64
1 0.00632641 -0.00186061 0.00492124
2 -0.00165798 -0.0167415 -0.00174059
3 -0.00178395 -0.0134543 -0.00245991
4 -0.0215434 -0.063543 -0.0120762
5 -0.00411494 -0.00995981 -0.0054254
6 -0.00775725 -0.000994378 -0.00638908
7 -0.00851934 -0.00060419 -0.00859888
8 -0.0149411 -0.0363655 -0.00421424
9 -0.00554043 0.000597618 0.00053205
10 0.00837714 0.0378835 0.0080933
11 0.00944052 0.0323318 0.00937495
12 0.0180447 0.0380089 0.0201799
13 0.0350582 0.0876178 0.0271306
205 -0.00632488 -0.00651634 -0.00326442
206 0.00311629 -0.0269902 0.0149844
207 0.00553876 -0.00498233 0.0140822
208 0.0167419 0.0409745 0.0157087
209 0.00586001 0.0467197 0.00783958
210 -0.00135632 0.0142257 0.00484739
211 -0.0005876 -0.00659147 0.00253307
212 -5.02405e-5 -0.000550477 -5.67176e-5
213 -0.000292467 -0.0237068 0.00318781
214 -0.000971265 -0.0140678 -0.00109743
215 0.00515261 0.00421442 0.000788311
216 0.00750582 0.00610296 0.00113667
# to compute statistics, we need to convert the dataframe into a matrix
mat = Matrix(relevant_df)
using Statistics: std, cov, cor
cor(mat)
3×3 Matrix{Float64}:
 1.0       0.909062  0.850059
 0.909062  1.0       0.650094
 0.850059  0.650094  1.0

std_y = std(relevant_df[:,:gdp_cycle])
std_i = std(relevant_df[:,:investment_cycle])
std_c = std(relevant_df[:,:consumption_cycle])
0.010668175144878967
println("σ(i)/σ(y): $(std_i/std_y)")
println("σ(c)/σ(y): $(std_c/std_y)")
σ(i)/σ(y): 3.3208282679766574
σ(c)/σ(y): 0.6950802322318318

Small Open Economy

Start from the same rbc model. Assume the representative agent can save \(b^{\star}_t\) as foreign assets, remunerated at a constant interest rate \(r^{\star}-1\).

Write the new budget constraint for the representative household.

À une date donnée t, le ménage épargne \(b^{\star}_t\) sous forme de titres étrangers et reçoit le remboursement de son épargne de la période précédente \(b^{\star}_{t-1}\) plus les intérêts afférents \((r^{\star} − 1)b^{\star}_{t-1}\) . Par rapport au modèle de base, la contrainte budgétaire en t devient donc :

\[c_t + i_t + b^ {\star}_t \leq w_t n_t + r_t k_{t-1} + r^ {\star} b^{\star}_{t-1}\]

and the lagrangian is:

\[\mathcal{L} = E_t \sum_{j=0}^\infty \beta^j\left[\log c_{t+j} + \chi \dfrac{(1-n_{t+j})^{1-\eta}}{1-\eta} \right.\]

\[+\lambda_{t+j} (w_{t+j}n_{t+j} + r_{t+j}k_{t+j-1} - c_{t+j}-k_{t+j} + (1-\delta)k_{t+j-1} + r^* b^*_{t+j-1} - b^*_{t+j} )\Bigg]\]

Write the new optimality condition.

Il faut ajouter au modèle la condition d’optimalité par rapport à \(b^{\star}_t\) : le ménage représentatif choisit le niveau d’épargne en titres étrangers qui maximise son utilité intertemporelle sous contrainte. On trouve :

\[ -\lambda_t + \beta E_t[\lambda_{t+1}r^*]=0\] soit : \[ \frac{1}{c_t}=\beta r^* E_t\left[\frac{1}{c_{t+1}} \right]\]

What is the long run constraint on interest rate \(r^{\star}\)?

À l’état stationnaire, cette équation implique \(r^{\star}= \frac{1}{\beta}\) . Bien que \(r^{\star}\) représente un taux d’intérêt décidé à l’étranger, \(\frac{1}{\beta}\) est sa seule valeur compatible avec l’existence d’un équilibre de long terme dans le modèle. En effet, il ne peut pas y avoir d’opportunité d’arbitrage à l’équilibre : tous les placements ont la même rentabilité.

Update the modfile (set \(\overline{b^{\star}}=0\))

Pour mettre à jour le fichier .mod, il faut déclarer la nouvelle variable \(b^{\star}\) et le nouveau paramètre \(r^\star\)? en lui donnant la valeur \(\frac{1}{\beta}\) . Il faut ajouter au modèle la condition d’optimalité ci-dessus et mettre à jour l’équation donnant l’équilibre sur le marché des biens. En effet, cette équation est obtenue en équilibre général à partir de la contrainte budgétaire du ménage. En petite économie ouverte, on a :

\[c_t + i_t + b^{\star}_t = w_t n_t + r_t k_{t-1} + r^{\star} b^{\star}_{t-1}\]

Or l’entreprise, supposée en concurrence parfaite, ne fait pas de profit. Donc \(y_t = w_t n_t + r_t k_{t−1}\) et :

\[c_t + i_t + b^{\star}_t - r^{\star} b^{\star}_{t-1} = y_t\]

Ensuite, on remarque que le modèle statique ne détermine pas le niveau de \(b^{\star}\) à l’état stationnaire ; on choisit de le fixer à 0 de sorte que l’état stationnaire des autres variables du modèle ne soit pas affecté. On ajoute donc \(b^{\star}=0\) dans le bloc steady_state_model;.

Print theoretical moments. Comment.

On voit que Dynare ne parvient pas à calculer les moments (moyennes et variances) de certaines variables. De plus, les irfs ne reviennent pas tous à 0.

Simulate the model over 100 periods. Comment.

Avec la commande check;, on voit que le modèle a une valeur propre de module égal à 1 [PAS DANS Dynare Julia]. Dans Dynare, ceci ne provoque pas d’erreur par rapport aux conditions de Blanchard et Kahn mais est problématique : le modèle a une racine unitaire et n’est donc pas stationnaire. En effet, il manque au modèle une force de rappel : si les ménages sont transitoirement incités épargner plus sous forme de titres étrangers, rien ne les incite ensuite de façon endogène à baisser cette épargne vers son niveau initial – la rémunération de cette épargne étant toujours la même.

Assume the foreign interest rate depends on the amount of foreign assets

\[r^{\star}=\frac{1}{\beta} + exp(-\kappa b^{\star}_t) - 1\]

with \(\kappa=0.01\). How do you interpret the equation for \(r^{\star}_t\). How should you modify the model equations?

Plus le ménage détient de titres étrangers, moins ceux-ci sont rémunérateurs. Inversement, plus le ménage est endetté vis-à-vis de l’étranger \((b^{\star} < 0)\), plus les prêteurs étrangers vont exiger un taux d’ intérêt élevé. On peut donc interpréter le terme \(exp(−\kappa b^{\star}_t ) − 1\) comme une prime de risque sur le taux d’intérêt étranger. Pour mettre à jour le fichier .mod, il faut déclarer à présent \(r^{\star}\) comme une variable et non un paramètre, déclarer sa valeur à l’état stationnaire \(r^{\star} = \frac{1}{β}\) dans le bloc steady_state_model; et enfin ajouter l’équation ci-dessus dans le bloc model;.

Si on ne change pas les conditions d’ Euler, cela revient à supposer que les consommateurs/le gouvernment n’internalisent pas l’ effet de leur emprunt sur le taux d’ intérêt.

Update the modfile and comment on the generated moments. Do they depend on the choice of \(\kappa\)?