thorek1 / macromodelling.jl Goto Github PK
View Code? Open in Web Editor NEWMacros and functions to work with DSGE models.
Home Page: https://thorek1.github.io/MacroModelling.jl/stable
License: MIT License
Macros and functions to work with DSGE models.
Home Page: https://thorek1.github.io/MacroModelling.jl/stable
License: MIT License
Hello Thore, Can you suggest how I handle this inequality, it's part of my equilibrium conditions; w[0] * N[0] ≤ ξ * q[0] * K[0]
this is how i handled it, but didn't work;
@model G begin
1 / c[0] = λ[0]
θ*N[0]^χ = λ[0] * w[0]
λ[0] = β *(λ[1] * (1 + r[0]))
w[0] * (1 + μ[0]) = (1 - α) * A[0] * K[0]^α * N[0]^(1 - α)
1 = q[0] * (1 - Φ* (I[0]/K[0] - δ))
q[0] = (β * (λ[1] / λ[0])) * (α * A[1] * K[1]^(α - 1) * N[1]^(1 - α) + q[1] + Φ* (I[1]/K[1] + δ - 1)^2 / 2 - Φ* (I[1]/K[1] - δ) * (I[1]/K[1] + δ - 1) / 2)
Y[0] = A[0] * (K[0]^α )* (N[0]^(1 - α))
Y[0] = c[0] + I[0]
K[1] = I[0] - Φ/2 * (I[0]/K[0] - δ)^2 + (1 - δ) * K[0]
w[0]=max(w[0],ξ[0]*(q[0] * K[0])/ (N[0]))
log(A[0]) = ρ * log(A[-1]) + σᵃ*A[x]
log(ξ[0]) = (1 - ρᵋ) * log(ξ[ss]) + ρᵋ* log(ξ[-1]) + σᵋ*E[x]
end
@parameters G begin
σᵃ= 0.01
σᵋ= 0.01
ρ= 0.98
ρᵋ= 0.90
δ = 0.02
α = 0.33
β = 0.99
θ=7.71
Φ=4.0
χ=1.0
end
I am able to get first order solution but unable to get non-linear solution
@model FP begin
1 / c[0] = β * 1 / c[1] * ((1-tₖ[1])*R[1] + 1 - δ)
θ*n[0]^χ=(1/c[0])*(1-tₙ[0])*w[0]
Y[0]= c[0] + I[0] + G[0]
Y[0]=A[0]*k[0]^α*n[0]^(1-α)
k[0]= I[0]+(1-δ)* k[-1]
R[0]=α*A[0]*k[-1]^(α-1)*n[0]^(1-α)
w[0]=(1-α)*A[0]*k[-1]^α*n[0]^(-α)
log(A[0])=(1-ρ) *log(Ā)+ ρ *log(A[-1]) + σ*a[x]
log(G[0])= (1-η )*log(ω*Y[ss]) + η*log(G[-1]) + ϵ*g[x]
1 / c[0] = β * 1 / c[1] *(1 + r[0])
R[0]= α*A[0]*k[-1]^(α-1)*n[0]^(1-α)
tₖ[0]=(1-ϕ)*(tᵏ)+ ϕ*tₖ[-1] + (1-ϕ)*γₖ*((D[0]/Y[0])-Dᵧ) + κ*Kᵏ[x]
tₙ[0]=(1-μ)*(tⁿ)+ μ*tₙ[-1] + (1-μ)*γₙ*((D[0]/Y[0])-Dᵧ) + ζ*Nⁿ[x]
G[0]+(1-r[-1])*D[0] = R[0]*k[0]*tₖ[0] + w[0]*n[0]*tₙ[0] + D[0]-D[1]
end
I get this result:
"name": "DimensionMismatch",
"message": "DimensionMismatch: matrix is not square: dimensions are (14, 13)",
"stack": "DimensionMismatch: matrix is not square: dimensions are (14, 13)
I think it would be nice (although not essential) to add comments to the RBC code example, saying what the variables and parameters stand for.
A few typos in this section:
σ_z
The paper claims that the software
stands out for its ability to calculate sensitivities of model moments, its automatic variable declaration, and effective steady state solver.
However, a detailed comparison with related packages is only provided in the README. I think this comparison also belongs in the docs, and a synthetic version in the main paper.
When I'm lazy, I often copy README.md
into docs/src/index.md
so that I don't have to write the same content twice. The only thing that gets lost in the way are the edit links, but that can be fixed.
Apparently it's because of a lack of memory
openjournals/joss-reviews#5598 (comment)
I think #34 is a sign that there are unwanted memory leaks. Curious about the answer there.
Hello,
First off -- this package is incredible! I've been spreading the word. Thank you for the great work!
I'm dealing with a bizarre issue: I recently added and have been using MacroModeling.jl in a project. Since then, I've tried adding the package to other projects, and it's just not happening -- (1) The precompilation progress bar never completes; (2) As the package precompiles, it creates a .CondaPkg directory populated with about 200MBs worth of files (python dependencies?). Neither of these things happened in my first project. I have no clue what's going wrong.
I'm working on some time-sensitive stuff, so any help with this would be much appreciated.
Hi there, congrats on the package!
I'm reviewing your JOSS submission, so expect more issues from me as I make my way through the checklist :)
openjournals/joss-reviews#5598
When I try to install MacroModelling.jl, some Python compatibility issues pop up.
I strongly suggest you use PythonCall.jl + CondaPkg.jl to manage your Python dependencies.
As the following bug suggests, PyCall is less reliable and reproducible.
(@v1.9) pkg> activate --temp
Activating new project at `/tmp/jl_ZNvdrc`
(jl_ZNvdrc) pkg> add MacroModelling
...
Precompiling project...
✗ MacroModelling
0 dependencies successfully precompiled in 2 seconds. 196 already precompiled.
1 dependency errored. To see a full report either run `import Pkg; Pkg.precompile()` or load the package
julia> using MacroModelling
[ Info: Precompiling MacroModelling [687ffad2-3618-405e-ac50-e0f7b9c75e44]
ERROR: LoadError: InitError: Failed to import required Python module sympy.
For automated sympy installation, try configuring PyCall to use the Conda.jl package's Python "Miniconda" distribution within Julia. Relaunch Julia and run:
ENV["PYTHON"]=""
Pkg.build("PyCall")
before trying again.
Note that Conda.jl can use custom conda environment. Read more about `CONDA_JL_HOME` configuration in Conda.jl documentation:
https://github.com/JuliaPy/Conda.jl
To install sympy using /home/guillaume/mambaforge/bin/conda, you can run the following command from your system shell:
/home/guillaume/mambaforge/bin/conda install sympy
The pyimport exception was: PyError (PyImport_ImportModule
The Python package sympy could not be imported by pyimport. Usually this means
that you did not install sympy in the Python version being used by PyCall.
PyCall is currently configured to use the Python version at:
/home/guillaume/mambaforge/bin/python3
and you should use whatever mechanism you usually use (apt-get, pip, conda,
etcetera) to install the Python package containing the sympy module.
One alternative is to re-configure PyCall to use a different Python
version on your system: set ENV["PYTHON"] to the path/name of the python
executable you want to use, run Pkg.build("PyCall"), and re-launch Julia.
Another alternative is to configure PyCall to use a Julia-specific Python
distribution via the Conda.jl package (which installs a private Anaconda
Python distribution), which has the advantage that packages can be installed
and kept up-to-date via Julia. As explained in the PyCall documentation,
set ENV["PYTHON"]="", run Pkg.build("PyCall"), and re-launch Julia. Then,
To install the sympy module, you can use `pyimport_conda("sympy", PKG)`,
where PKG is the Anaconda package that contains the module sympy,
or alternatively you can use the Conda package directly (via
`using Conda` followed by `Conda.add` etcetera).
) <class 'ModuleNotFoundError'>
ModuleNotFoundError("No module named 'sympy'")
Hello, this is my constraint and slackness condition, how do I write in macro modeling to capture it?
constraint : Lₑ[0] = min(Lₑ[0], mₕ*(q[1]*Hₑ[0])/(Rₑ[0]) - mₙ*(wₕ[0]*nₕ[0]))
slackness : (mₕ*(q[1]*Hₑ[0])/(Rₑ[0]) - mₙ*(wₕ[0]*nₕ[0]) - Lₑ[0]) * λₑ[0]=0
constraint : d[0] = min(d[0], γ * (Lₑ[0]- ξₕ[1]))
slackness : (γ * (Lₑ[0]- ξₕ[1])- d[0]) * λᵦ[0]=0
I'm not an economist, so I have no clue what a DSGE model is. Adding one or two sentences to the paper explaining what they to and outlining their relevance in your field would go a long way
I'm not sure if
The package stands out for its [...] effective steady state solver.
is a performance claim, but if it is, it needs to be backed up with benchmarks against competing packages.
If you're looking for inspiration, I recently did cross-language benchmarks (Julia/Python) for HiddenMarkovModels.jl.
They are compatible with PkgBenchmark.jl and are also automatically added to the docs for each new release I tag.
This issue is used to trigger TagBot; feel free to unsubscribe.
If you haven't already, you should update your TagBot.yml
to include issue comment triggers.
Please see this post on Discourse for instructions and more details.
If you'd like for me to do this for you, comment TagBot fix
on this issue.
I'll open a PR within a few hours, please be patient!
Hi Thore, thanks for this package!
I came across a weird breakdown when I formatted the parameters differently under a same model. I am on an Archlinux and using Julia 1.9.0 and the newset MacroModelling release.
@model BK1993_fig3 begin
uc[0] = c[0]^-1
ul[0] = θ_l * l[0]^-1
y[0] = A * k[-1]^θ_k * n[0]^θ_n
fk[0] = θ_k * A * k[-1]^(θ_k - 1) * n[0]^θ_n
fn[0] = θ_n * A * k[-1]^θ_k * n[0]^(θ_n - 1)
γ_x * k[0] = (1- δ_k) * k[-1] + iv[0]
l[0] + n[0] = 1
c[0] + iv[0] = (1 - τ) * y[0] + tr[0] + check_walras[0]
c[0] + iv[0] + gb[0] = y[0]
τ * y[0] = gb[0] + tr[0]
uc[0] = λ[0]
ul[0] = λ[0] * (1 - τ) * fn[0]
β * λ[1] * (q[1] + 1 - δ_k) = γ_x * λ[0]
q[0] = (1 - τ) * fk[0]
gb[0] = GB_BAR + e_gb[x]
1 + r[0] = γ_x * λ[0] / (λ[1] * β)
w[0] = fn[0]
end
When I use the following simple parameter block, it works perfectly:
@parameters BK1993_fig3 begin
A = 1.0
γ_x = 1.016
θ_k = 0.42
θ_n = 1 - θ_k
δ_k = 0.1
β = 0.954
τ = 0.2
GB_BAR = 0.0667
θ_l = 3.29
end
But when using a more detailed one, the julia session broke:
@parameters BK1993_fig3 begin
A = 1.0
γ_x = 1.016
θ_k = 0.42
θ_n = 1 - θ_k
δ_k = 0.1
N = 0.2
L = 1 - N
R = 0.065
# β = 0.954
β = γ_x / (1 + R)
sG = 0.2
τBAR = 0.2
τ = 0.2
Q = γ_x / β -1 + δ_k
FK = Q/(1 - τBAR)
K = (FK / ((θ_k * A * N^θ_n)))^(1 / (θ_k - 1))
FN = θ_n * A * K^θ_k * N^(θ_n - 1)
# W = FN
IV = (γ_x - 1 + δ_k) * K
Y = A * N^(1- θ_k) * K^θ_k
GB_BAR = sG * Y
# GB_BAR = 0.0667
C = Y - IV - GB_BAR
UC = C^(-1)
UL = UC * (1 - τBAR) * FN
θ_l = UL * L
# θ_l = 3.29
end
The erros message:
`[4449] signal (11.1): Segmentation fault
in expression starting at none:1
unknown function (ip: 0x7f2edc436396)
unknown function (ip: 0x7f2edc4360fd)
macro expansion at /home/zach/.julia/packages/PyCall/twYvK/src/exception.jl:108 [inlined]
#107 at /home/zach/.julia/packages/PyCall/twYvK/src/pyfncall.jl:43 [inlined]
disable_sigint at ./c.jl:473 [inlined]
__pycall! at /home/zach/.julia/packages/PyCall/twYvK/src/pyfncall.jl:42 [inlined]
_pycall! at /home/zach/.julia/packages/PyCall/twYvK/src/pyfncall.jl:29
pycall! at /home/zach/.julia/packages/PyCall/twYvK/src/pyfncall.jl:11 [inlined]
##114 at /home/zach/.julia/packages/PyCall/twYvK/src/pyfncall.jl:86 [inlined]
PyObject at /home/zach/.julia/packages/PyCall/twYvK/src/pyfncall.jl:86
unknown function (ip: 0x7f2f541b28e2)
_jl_invoke at /cache/build/default-amdci4-0/julialang/julia-release-1-dot-9/src/gf.c:2758 [inlined]
ijl_apply_generic at /cache/build/default-amdci4-0/julialang/julia-release-1-dot-9/src/gf.c:2940
Hi Thore,
As mentioned in the title, having trouble getting the package 0.1.32 installed in julia 1.10 on Archlinux.
Error during loading of extension NLoptMathOptInterfaceExt of NLopt.
InitError: Creating a new global in closed moduleNLopt
(Optimizer
) breaks incremental compilation because the side effects will not be permanent
I am trying to understand how to simulate an AR1 process.
I was having some issues with negative values even after taking exponentials.
I will try to reproduce this in a simple example below.
@model AR1 begin
exp_z[0] = exp(z[0])
z[0] = rho * z[-1] + std_z * eps_z[x]
end;
@parameters AR1 begin
std_z = 0.01
rho = 0.2
end;
simulation = simulate(AR1, periods=1000, algorithm=:third_order);
df_res = unstack(simulation |> DataFrame, :Periods, :Variables, :value)
@combine(df_res, :exp_z=mean(:exp_z), :z=mean(:z))
Both of the variables are set at zero (when we would expect exp_z to be at 1).
The counterpart in dynare would look like
var
z exp_z junk;
varexo
eps_z ;
parameters
rho std_z ;
std_z = 0.01;
rho = 0.2;
model;
z(0) = rho * z(-1) + std_z * eps_z;
exp_z(0) = exp(z(0));
junk=0.9*junk(+1);
end;
shocks;
var eps_z = 1;
end;
initval;
z = 0.0;
exp_z = 1.0;
junk = 0.0;
end;
stoch_simul(
irf_shocks = (
eps_z
),
order = 3,
irf = 0,
noprint,
periods = 1000,
replic = 1
)
z exp_z;
and in matlab, looking at the simulation results gives:
mean(oo_.endo_simul,2)
ans =
0.0001
1.0001
0
I am wondering if I am missing something about the log-linearization of the variables here?
@model BM begin
c[0]^(-1) = α*β * c[1]^-1 * a[1] * k[0]^(α - 1.0)
k[0] = a[0] * k[-1]^α - c[0]
log(a[0]) = ρ * log(a[-1]) + σ_a * eps_a[x]
end
@parameters BM begin
α = 0.3
β = 0.96
ρ = 0.5
σ_a = 0.2
end
plot_irf(BM, periods=30)
get_irf(BM, periods=30)
I tested the above simple RBC model with the latest release on Julia 1.10 archlinux.
get_irf
gives following expected results:
[:, :, 1] ~ (:, :, :eps_a):
(1) (2) … (30)
(:a) 0.2 0.1 3.72529e-10
(:c) 0.0835259 0.0668207 3.88948e-10
(:k) 0.0337857 0.0270286 1.57327e-10
However, the plot command shows different percent deviations.
irf__BM__eps_a__1.pdf
MacroModelling.jl/test/runtests.jl
Line 31 in f4e752e
Why is this needed after every test set?
Hi and thanks for this package!
I'd like to use your package to solve a simple problem.
First the deterministic version:
using MacroModelling;
@model m begin
I[0] = ((ρ + δ - Z)/(1 - δ)) - ((1 + ρ)/(1 - δ)) * I[-1]
end
@parameters m begin
ρ = 0.05
δ = 0.10
Z = .17
end
m_ss = get_steady_state(m)
# note the ss can be solved in closed form
#I_SS = (Z-ρ-δ)/(ρ+δ); #(.17-0.05-0.10)/(0.05 + 0.10) # 0.13333333333333333
m_sol = get_solution(m)
ERROR: TypeError: in Type, in parameter, expected Type, got a value of type Vector{Any}
Not sure what to do about this error.
This time it seems to be because of our crappy ImplicitDifferentiation interface
I'm working on it today, hopefully @mohamed82008 and I can issue a new release this weekend with a simpler API
I am wondering how to use the macro to scale models up programmatically.
What I have in mind is a model with multiple regions where most of the equations are the same for each region and could be recycled.
In dynare this can be done with the dynare macro which allows for loops in building a mod file.
I am sure it is possible to modify the expression in between @model
and also @parameters
but I tried using basic Meta.parse and could not get it to work.
Any pointer would be appreciated.
Thank you.
Hi,
I noticed a frustrating fact that this excellent toolkit is not found on the first page when googling "dynare Julia". Wondering if you consider adding a "dynare" tag to those on the repo front page, or some more dynare related descriptions?
Happy new year btw!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.