-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from JohannesNaegele/new-structure
New structure
- Loading branch information
Showing
20 changed files
with
642 additions
and
285 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,31 @@ | ||
using Consistent | ||
|
||
PC_gdp = @model begin | ||
@endogenous Y YD T V C | ||
@exogenous r G B_h | ||
@parameters α_1 α_2 θ | ||
@equations begin | ||
PC_gdp = model( | ||
endos = @variables(Y, YD, T, V, C), | ||
exos = @variables(r, G, B_h), | ||
params = @variables(α_1, α_2, θ), | ||
eqs = @equations begin | ||
Y = C + G | ||
YD = Y - T + r[-1] * B_h[-1] | ||
T = θ * (Y + r[-1] * B_h[-1]) | ||
V = V[-1] + (YD - C) | ||
C = α_1 * YD + α_2 * V[-1] | ||
end | ||
end | ||
) | ||
|
||
PC_hh = @model begin | ||
@endogenous H_h B_h B_s H_s B_cb r | ||
@exogenous r_exo G V YD T | ||
@parameters λ_0 λ_1 λ_2 | ||
@equations begin | ||
PC_hh = model( | ||
endos = @variables(H_h, B_h, B_s, H_s, B_cb, r), | ||
exos = @variables(r_exo, G, V, YD, T), | ||
params = @variables(λ_0, λ_1, λ_2), | ||
eqs = @equations begin | ||
H_h = V - B_h | ||
B_h = (λ_0 + λ_1 * r - λ_2 * (YD / V)) * V | ||
B_s = (G + r[-1] * B_s[-1]) - (T + r[-1] * B_cb[-1]) + B_s[-1] | ||
H_s = B_cb - B_cb[-1] + H_s[-1] | ||
B_cb = B_s - B_h | ||
r = r_exo | ||
end | ||
end | ||
) | ||
|
||
# Note: Since the variables and equations are ordered this operation is not commutative! | ||
PC_complete = PC_gdp + PC_hh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
using Consistent | ||
using NLsolve | ||
using Distributions | ||
using Plots | ||
using StatsPlots | ||
|
||
# SIM_stoch | ||
model = SIMStoch() | ||
g_0 = 20.0 | ||
u_G = rand(Normal(0, 1), 1000 * 100) | ||
u_T = rand(Normal(0, 0.25), 1000 * 100) | ||
u_C = rand(Normal(0, 0.5), 1000 * 100) | ||
exos = zeros(4, 1) | ||
exos[1] = g_0 | ||
initial_guess = fill(1.0, length(model.endogenous_variables)) | ||
lags = fill(0.0, length(model.endogenous_variables)) | ||
lags = lags[:, :] | ||
param_values = map(x -> params[x], model.parameters) | ||
a_0 = solve(model, lags, exos, param_values) | ||
simulation = zeros(101, 1000) | ||
simulation[1, :] .= a_0[2] | ||
|
||
for i in 1:1000 | ||
a = a_0 | ||
for j = 1:100 | ||
exos[2] = u_G[j+(i-1)*100] | ||
exos[3] = u_T[j+(i-1)*100] | ||
exos[4] = u_C[j+(i-1)*100] | ||
a = solve(model, a[:, :], exos, param_values) | ||
simulation[j+1, i] = a[2] | ||
end | ||
end | ||
|
||
plot(simulation[:, 1]) | ||
violin(transpose(simulation[1:50, :]), linewidth = 0, legend = false) | ||
# plot(simulation[1:30,1:1000], legend = false, seriestype = :scatter) | ||
|
||
# DIS steady state | ||
initial_guess = fill(1.0, length(sfc_model.endogenous_variables)) | ||
lags = fill(0.1, (length(sfc_model.endogenous_variables), 1)) # quite arbitrary | ||
param_values = map(x -> get(values, x, nothing), sfc_model.parameters) | ||
a = solve(initial_guess, lags, Matrix[], param_values) | ||
for i in 1:1000 | ||
a = solve(initial_guess, a[:,:], Matrix[], param_values) | ||
end | ||
a |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,24 @@ | ||
module Consistent | ||
|
||
export @model, @endogenous, @exogenous, @parameters, @equations | ||
export @parameters, @equations, @variables | ||
export model, solve | ||
|
||
include("Helpers.jl") | ||
include("ModelComponents.jl") | ||
include("Model.jl") | ||
include("Variables.jl") | ||
include("ConstructResiduals.jl") | ||
include("Macros.jl") | ||
include("CombineModels.jl") | ||
include("Solve.jl") | ||
|
||
# Godley/Lavoie | ||
include("models/SIM.jl") | ||
include("models/SIM_stoch.jl") | ||
include("models/LP.jl") | ||
include("models/DIS.jl") | ||
include("models/PC.jl") | ||
|
||
include("models/BMW.jl") | ||
|
||
end # module Consistent |
Oops, something went wrong.