Commit e8c681af authored by MichelJuillard's avatar MichelJuillard
Browse files

adding simulation

parent 6ec00b15
......@@ -4,9 +4,9 @@
uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
[[Crayons]]
git-tree-sha1 = "cb7a62895da739fe5bb43f1a26d4292baf4b3dc0"
git-tree-sha1 = "9f3adcb26c79d6270eb678f3c61bf44cc6b7077e"
uuid = "a8cc5b0e-0ffa-5ad4-8c14-923d3ee1735f"
version = "4.0.1"
version = "4.0.2"
[[DataAPI]]
git-tree-sha1 = "176e23402d80e7743fc26c19c681bfb11246af32"
......@@ -28,7 +28,7 @@ uuid = "8ba89e20-285c-5b6f-9357-94700520ee1b"
[[FastLapackInterface]]
deps = ["LinearAlgebra"]
git-tree-sha1 = "924b02d08308717e0a71be06f23441fa2375ebf2"
git-tree-sha1 = "7e5ea6ccb6382088c4dfda745af75b3bc01a4bee"
repo-rev = "master"
repo-url = "https://git.dynare.org/julia-packages/fastlapackinterface.jl.git"
uuid = "29a986be-02c6-4525-aec4-84b980013641"
......@@ -68,7 +68,7 @@ uuid = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
[[LinearRationalExpectations]]
deps = ["FastLapackInterface", "LinearAlgebra", "PolynomialMatrixEquations"]
git-tree-sha1 = "f73d8b3d56f5fe4d213d30c381781a4cefb48775"
git-tree-sha1 = "c172ef0003ac5c0a357b45cc7061a948b6bf23f8"
repo-rev = "master"
repo-url = "https://git.dynare.org/julia-packages/linearrationalexpectations.jl.git"
uuid = "45f42fbc-210c-4ecc-9452-59ec793b9bfd"
......@@ -85,22 +85,21 @@ uuid = "d6f4376e-aef5-505a-96c1-9c027394607a"
uuid = "a63ad114-7e13-5084-954f-fe012c677804"
[[OrderedCollections]]
deps = ["Random", "Serialization", "Test"]
git-tree-sha1 = "c4c13474d23c60d20a67b217f1d7f22a40edf8f1"
git-tree-sha1 = "12ce190210d278e12644bcadf5b21cbdcf225cd3"
uuid = "bac558e1-5e72-5ebc-8fee-abe8a469f55d"
version = "1.1.0"
version = "1.2.0"
[[Parameters]]
deps = ["OrderedCollections"]
git-tree-sha1 = "b62b2558efb1eef1fa44e4be5ff58a515c287e38"
deps = ["OrderedCollections", "UnPack"]
git-tree-sha1 = "38b2e970043613c187bd56a995fe2e551821eb4a"
uuid = "d96e819e-fc66-5662-9728-84c9c7592b0a"
version = "0.12.0"
version = "0.12.1"
[[Parsers]]
deps = ["Dates", "Test"]
git-tree-sha1 = "75d07cb840c300084634b4991761886d0d762724"
git-tree-sha1 = "f0abb338b4d00306500056a3fd44c221b8473ef2"
uuid = "69de0a69-1ddd-5017-9359-2bf0b02dc9f0"
version = "1.0.1"
version = "1.0.4"
[[Pkg]]
deps = ["Dates", "LibGit2", "Libdl", "Logging", "Markdown", "Printf", "REPL", "Random", "SHA", "UUIDs"]
......@@ -108,7 +107,7 @@ uuid = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
[[PolynomialMatrixEquations]]
deps = ["FastLapackInterface", "LinearAlgebra"]
git-tree-sha1 = "2dff425d84418003dee3d5fa5286b5cd965fa98e"
git-tree-sha1 = "c402e009baf88774f76d770a2640ee67959d3a4b"
repo-rev = "master"
repo-url = "https://git.dynare.org/julia-packages/polynomialmatrixequations.jl.git"
uuid = "4f9d485d-518f-41ed-81c8-372cd804c93b"
......@@ -167,5 +166,10 @@ uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
deps = ["Random", "SHA"]
uuid = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"
[[UnPack]]
git-tree-sha1 = "d4bfa022cd30df012700cf380af2141961bb3bfb"
uuid = "3a884ed6-31ef-47d7-9d2a-63182c4928ed"
version = "1.0.1"
[[Unicode]]
uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5"
......@@ -3,6 +3,7 @@ module Dynare
include("model.jl")
export get_abc, get_de
include("symboltable.jl")
include("first_order/simul_first_order.jl")
include("parser/DynareParser.jl")
export parser, get_jacobian_at_steadystate!
include("parser/DynarePreprocessor.jl")
......
function make_state_space!(A, B, Σy, g1_1, g1_2, context, ws)
vA = view(A, :, context.models[1].i_bckwrd_b]
vA .= g1_1
B = g1_2
extended_lyapd!(Σy, A, B, ws.lyapd_ws)
end
using LinearAlgebra
function simul_first_order!(results, initial_values, x, c, A, B, periods)
y_1 = initial_values
for t = 1:periods
r = view(results, t, :)
e = view(x, t, :)
mul!(r, B, e)
mul!(r, A, y_1, 1.0, 1.0)
r .= c
end
end
......@@ -58,6 +58,7 @@ struct Model
i_current_exogenous
i_lagged_exogenous
serially_correlated_exogenous
Sigma_e
dynamic!
static!
steady_state!
......@@ -115,6 +116,7 @@ function Model(modfilename, endo_nbr, lead_lag_incidence, exogenous_nbr, lagged_
hx_rows = 1:(n_bkwrd + n_both)
i_current_exogenous = maximum(lead_lag_incidence) .+ (1:exogenous_nbr)
i_lagged_exogenous = 0:-1
Sigma_e = zeros(exogenous_nbr, exogenous_nbr)
serially_correlated_exogenous = false
dynamic! = load_dynare_function(modfilename*"Dynamic.jl")
static! = load_dynare_function(modfilename*"Static.jl")
......@@ -134,7 +136,7 @@ function Model(modfilename, endo_nbr, lead_lag_incidence, exogenous_nbr, lagged_
i_cur_bkwrd, n_cur_bkwrd, p_cur_bkwrd, i_cur_both,
n_cur_both, p_cur_both, gx_rows, hx_rows,
i_current_exogenous, i_lagged_exogenous,
serially_correlated_exogenous, dynamic!, static!,
serially_correlated_exogenous, Sigma_e, dynamic!, static!,
steady_state!)
end
......
......@@ -51,7 +51,6 @@ function parser(modfilename)
modeljson["exogenous_deterministic"],
ExogenousDeterministic)
param_nbr = set_symbol_table!(symboltable, modeljson["parameters"], Parameter)
Sigma_e = zeros(exo_nbr, exo_nbr)
model_info = get_model_info(modeljson["model_info"])
model = Model(modfilename,
endo_nbr,
......@@ -86,7 +85,7 @@ function parser(modfilename)
elseif field["statementName"] == "initval"
initval(field)
elseif field["statementName"] == "shocks"
shocks!(Sigma_e, field, symboltable)
shocks!(model.Sigma_e, field, symboltable)
elseif field["statementName"] == "verbatim"
verbatim(field)
elseif field["statementName"] == "check"
......@@ -198,13 +197,34 @@ function display_stoch_simul(x, title, context)
dynare_table(data, title, column_header, row_header, note)
end
function make_A_B!(A, B, model, results)
vA = view(A, :, model.i_bkwrd_b)
vA .= results.linearrationalexpectations.g1_1
B = results.linearrationalexpectations.g1_2
end
function stoch_simul!(context, field)
context.options["stoch_simul"] = Dict()
copy!(context.options["stoch_simul"], field["options"])
compute_stoch_simul(context)
x = context.results.model_results[1].linearrationalexpectations.g1
model = context.models[1]
options = context.options
results = context.results.model_results[1]
options["stoch_simul"] = Dict()
copy!(options["stoch_simul"], field["options"])
compute_stoch_simul!(context)
x = results.linearrationalexpectations.g1
vx = view(x, :, 1:size(x, 2) - 1)
display_stoch_simul(vx', "Coefficients of approximate solution function", context)
if (periods = get(options["stoch_simul"], "periods", 0)) > 0
simulresults = Matrix{Float64}(undef, periods + 1, model.endogenous_nbr)
y0 = results.endogenous_steady_state
C = cholesky(model.Sigma_e)
x = randn(periods, model.exogenous_nbr)*C.U
c = results.endogenous_steady_state
A = zeros(model.endogenous_nbr, model.endogenous_nbr)
B = zeros(model.endogenous_nbr, model.exogenous_nbr)
make_A_B!(A, B, model, results)
simul_first_order!(simulresults, y0, x, c, A, B, periods)
@show simulresults
end
end
function perfect_foresight_setup(context, field)
......@@ -227,7 +247,7 @@ end
function check(field)
end
function compute_stoch_simul(context)
function compute_stoch_simul!(context)
m = context.models[1]
results = context.results.model_results[1]
options = context.options["stoch_simul"]
......
......@@ -3,6 +3,10 @@
[[Base64]]
uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
[[Dates]]
deps = ["Printf"]
uuid = "ade2ca70-3891-5945-98fb-dc099432e06a"
[[Distributed]]
deps = ["Random", "Serialization", "Sockets"]
uuid = "8ba89e20-285c-5b6f-9357-94700520ee1b"
......@@ -11,6 +15,12 @@ uuid = "8ba89e20-285c-5b6f-9357-94700520ee1b"
deps = ["Markdown"]
uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
[[JSON]]
deps = ["Dates", "Mmap", "Parsers", "Unicode"]
git-tree-sha1 = "b34d7cef7b337321e97d22242c3c2b91f476748e"
uuid = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
version = "0.21.0"
[[Logging]]
uuid = "56ddb016-857b-54e1-b83d-db4d58db5568"
......@@ -18,6 +28,19 @@ uuid = "56ddb016-857b-54e1-b83d-db4d58db5568"
deps = ["Base64"]
uuid = "d6f4376e-aef5-505a-96c1-9c027394607a"
[[Mmap]]
uuid = "a63ad114-7e13-5084-954f-fe012c677804"
[[Parsers]]
deps = ["Dates", "Test"]
git-tree-sha1 = "f0abb338b4d00306500056a3fd44c221b8473ef2"
uuid = "69de0a69-1ddd-5017-9359-2bf0b02dc9f0"
version = "1.0.4"
[[Printf]]
deps = ["Unicode"]
uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7"
[[Random]]
deps = ["Serialization"]
uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
......@@ -31,3 +54,6 @@ uuid = "6462fe0b-24de-5631-8697-dd941f90decc"
[[Test]]
deps = ["Distributed", "InteractiveUtils", "Logging", "Random"]
uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
[[Unicode]]
uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5"
[deps]
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
// one auxiliary variable
// Generalized Schur algorithm
var y, c, k, a, h, b;
varexo e, u;
verbatim;
% I want these comments included in
% example1.m 1999q1 1999y
%
var = 1;
end;
parameters beta, rho, alpha, delta, theta, psi, tau;
alpha = 0.36;
rho = 0.95;
tau = 0.025;
beta = 0.99;
delta = 0.025;
psi = 0;
theta = 2.95;
phi = 0.1;
model;
c*theta*h^(1+psi)=(1-alpha)*y;
k = beta*(((exp(b)*c)/(exp(b(+1))*0.5*(c(+1)+c(+2))))
*(exp(b(+1))*alpha*y(+1)+(1-delta)*k));
y = exp(a)*(k(-1)^alpha)*(h^(1-alpha));
k = exp(b)*(y-c)+(1-delta)*k(-1);
a = rho*a(-1)+tau*b(-1) + e;
b = tau*a(-1)+rho*b(-1) + u;
end;
steady_state_model;
K_Y = beta*alpha /(1 - beta*(1 - delta));
H_Y = K_Y^(-alpha/(1 - alpha));
C_Y = 1 - delta*K_Y;
y = (theta*C_Y*H_Y^(1 + psi)/(1 - alpha))^(-1/(1 + psi));
c = C_Y*y;
k = K_Y*y;
h = H_Y*y;
a = 0;
b = 0;
end;
shocks;
var e; stderr 0.009;
var u; stderr 0.009;
//var e, u = phi*0.009*0.009;
var e, u = 0.009*0.009;
end;
check;
stoch_simul(order=1, periods=100);
//calib_smoother(datafile=data, diffuse_filter, filtered_vars);
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment