From f948654ee4763e11e05060fd2e22eda4874c500d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20N=C3=A4gele?= Date: Mon, 9 Oct 2023 14:13:01 +0200 Subject: [PATCH] Create Model struct --- src/Model.jl | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/Model.jl diff --git a/src/Model.jl b/src/Model.jl new file mode 100644 index 0000000..1cfa631 --- /dev/null +++ b/src/Model.jl @@ -0,0 +1,33 @@ +using Crayons + +""" +Type for a stock-flow consistent model. +""" +mutable struct Model + endogenous_variables::Vector{Symbol} + exogenous_variables::Vector{Symbol} + parameters::Vector{Symbol} + math_operators::Set{Symbol} + equations::Vector{Expr} + f!::Function +end + +Model() = Model(Symbol[], Symbol[], Symbol[], math_operators, Expr[], x -> nothing) + +const math_operators = Set([:+, :-, :*, :/, :รท, :\, :^, :%]) +const name = [:diff, :endos, :lags, :exos, :params] + +function Base.show(io::IO, m::Model) + descriptors = ["Endogenous Variables: ", "Exogenous Variables: ", "Parameters: ", "Equations: "] + max_width = maximum(length.(descriptors)) + for i in eachindex(descriptors) + descriptors[i] = descriptors[i] * ' '^(max_width - length(descriptors[i])) + end + print(io, Crayon(foreground = :green), descriptors[1]); println(io, Crayon(reset=true), m.endogenous_variables) + print(io, Crayon(foreground = :yellow), descriptors[2]); println(io, Crayon(reset=true), m.exogenous_variables) + print(io, Crayon(foreground = :blue), descriptors[3]); println(io, Crayon(reset=true), m.parameters) + print(io, Crayon(foreground = :red), descriptors[4]); print(io, Crayon(reset=true)) + for i in 1:length(m.equations) + print(io, "\n", ' '^max_width, "($i) ", m.equations[i]) + end +end \ No newline at end of file