Skip to content

Commit ddc3854

Browse files
authored
Use import BeforeIT as Bit everywhere (#43)
1 parent 0bdf7bd commit ddc3854

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+486
-440
lines changed

README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,14 @@ Pkg.instantiate()
6262
Now you should be able to run the the following code
6363

6464
```julia
65-
using BeforeIT
65+
import BeforeIT as Bit
6666

67-
parameters = BeforeIT.AUSTRIA2010Q1.parameters
68-
initial_conditions = BeforeIT.AUSTRIA2010Q1.initial_conditions
67+
parameters = Bit.AUSTRIA2010Q1.parameters
68+
initial_conditions = Bit.AUSTRIA2010Q1.initial_conditions
6969

7070
T = 20
71-
model = BeforeIT.init_model(parameters, initial_conditions, T)
72-
data = BeforeIT.run!(model)
71+
model = Bit.init_model(parameters, initial_conditions, T)
72+
data = Bit.run!(model)
7373
```
7474

7575
This will simulate the model with the original Austrian parametrisation for 20 quarters and save the results in the `data` object.

docs/src/index.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ Pkg.add("BeforeIT")
2929
To check that the installation worked, try running the model in your terminal with
3030

3131
```julia
32-
using BeforeIT
32+
import BeforeIT as Bit
3333

34-
parameters = BeforeIT.AUSTRIA2010Q1.parameters
35-
initial_conditions = BeforeIT.AUSTRIA2010Q1.initial_conditions
34+
parameters = Bit.AUSTRIA2010Q1.parameters
35+
initial_conditions = Bit.AUSTRIA2010Q1.initial_conditions
3636

3737
T = 20
38-
model = BeforeIT.initialise_model(parameters, initial_conditions, T)
39-
data = BeforeIT.run!(model)
38+
model = Bit.initialise_model(parameters, initial_conditions, T)
39+
data = Bit.run!(model)
4040
```
4141

4242
To plot the results of the simulation, you can use the `Plots` package

examples/basic_example.jl

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# We start by importing the BeforeIT library and other useful libraries.
44

55
import BeforeIT as Bit
6+
67
using FileIO, Plots
78

89
# We then initialise the model loading some precomputed set of parameters and by specifying a number of epochs.
@@ -36,7 +37,7 @@ for t in 1:T
3637
end
3738

3839
# Note that we can equivalently run the model for a number of epochs in the single command
39-
# `data = BeforeIT.run!(model)`, but writing the loop explicitely is more instructive.
40+
# `data = Bit.run!(model)`, but writing the loop explicitely is more instructive.
4041

4142
# We can then plot any time series stored in the data tracker, for example
4243

examples/benchmark_w_matlab.jl

+9-7
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,25 @@
44
# by running the same model for the same number of epochs and measuring
55
# the time taken.
66

7-
using BeforeIT, CairoMakie, Statistics, ThreadPinning
7+
import BeforeIT as Bit
8+
9+
using CairoMakie, Statistics, ThreadPinning
810

911
pinthreads(:cores)
1012

1113
function run(parameters, initial_conditions, T; multi_threading = false)
12-
model = BeforeIT.init_model(parameters, initial_conditions, T)
13-
data = BeforeIT.init_data(model);
14+
model = Bit.init_model(parameters, initial_conditions, T)
15+
data = Bit.init_data(model);
1416

1517
for _ in 1:T
16-
BeforeIT.step!(model; multi_threading = multi_threading)
17-
BeforeIT.update_data!(data, model)
18+
Bit.step!(model; multi_threading = multi_threading)
19+
Bit.update_data!(data, model)
1820
end
1921
return model, data
2022
end
2123

22-
parameters = BeforeIT.AUSTRIA2010Q1.parameters
23-
initial_conditions = BeforeIT.AUSTRIA2010Q1.initial_conditions
24+
parameters = Bit.AUSTRIA2010Q1.parameters
25+
initial_conditions = Bit.AUSTRIA2010Q1.initial_conditions
2426
T = 12
2527

2628
# We run the code to compile it first

examples/change_expectations.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# different expectations of the agents in the model.
55

66
import BeforeIT as Bit
7+
78
using Random, Plots
89

910
# Import standard parameters and initial conditions
@@ -22,8 +23,7 @@ data = Bit.run!(model)
2223
# We will change the function `estimate_next_value` to make the agents expect
2324
# the last value of the time series (so to represent backward looking expectations)
2425

25-
import BeforeIT: estimate_next_value
26-
function estimate_next_value(data)
26+
function Bit.estimate_next_value(data)
2727
return data[end]
2828
end
2929

examples/compare_model_vs_real.jl

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
using BeforeIT
2-
using MAT, FileIO, Plots, StatsPlots
3-
using Dates
1+
import BeforeIT as Bit
2+
3+
using MAT, FileIO, Plots, StatsPlots, Dates
44

55
# load data from 1996
66

7-
real_data = BeforeIT.ITALY_CALIBRATION.data
7+
real_data = Bit.ITALY_CALIBRATION.data
88

99
# load predictions from 2010Q1
1010

@@ -48,7 +48,7 @@ function plot_model_vs_real(model, real, varname; crop = true)
4848
year_ticks = []
4949
for r in all_tick_numbers
5050
# get year of r
51-
y = year(BeforeIT.num2date(r))
51+
y = year(Bit.num2date(r))
5252
# save year only if it's new
5353
if !(y in year_ticks)
5454
push!(num_ticks, r)
@@ -76,7 +76,7 @@ num_ticks = []
7676
year_ticks = []
7777
for r in real_data["years_num"]
7878
# get year of r
79-
y = year(BeforeIT.num2date(r))
79+
y = year(Bit.num2date(r))
8080
# save year only if it's new
8181
if !(y in year_ticks)
8282
push!(num_ticks, r)

examples/get_parameters_and_initial_conditions.jl

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# In this tutorial we illustrate how to calibrate the model to the Italian data for a specific quarter
22

33
import BeforeIT as Bit
4+
45
using Dates, FileIO
56

67
# We start from loading the calibration object for italy, which contains

examples/get_predictions.jl

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
# In this tutorial we illustrate how to get predictions from the model for
22
# a number of quarters starting from previous simulations.
33

4-
using BeforeIT, FileIO
5-
using Dates
4+
import BeforeIT as Bit
5+
6+
using FileIO, Dates
67

78
year_ = 2010
89
number_years = 9
@@ -12,18 +13,18 @@ number_seeds = 4
1213
number_sectors = 62
1314

1415
# Load the real time series
15-
data = BeforeIT.ITALY_CALIBRATION.data
16+
data = Bit.ITALY_CALIBRATION.data
1617

1718
quarters_num = []
1819
year_m = year_
1920
for month in 4:3:((number_years + 1) * 12 + 1)
2021
year_m = year_ + (month ÷ 12)
2122
mont_m = month % 12
2223
date = DateTime(year_m, mont_m, 1) - Day(1)
23-
push!(quarters_num, BeforeIT.date2num(date))
24+
push!(quarters_num, Bit.date2num(date))
2425
end
2526

2627
for i in 1:number_quarters
2728
quarter_num = quarters_num[i]
28-
BeforeIT.get_predictions_from_sims(data, quarter_num, horizon, number_seeds)
29+
Bit.get_predictions_from_sims(data, quarter_num, horizon, number_seeds)
2930
end

examples/get_simulations.jl

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
# Here we show how to get simulations for all quarters
22
# from `2010Q1` to `2019Q4`, and for all years from 2010 to 2019.
33

4-
using BeforeIT, MAT, FileIO
4+
import BeforeIT as Bit
5+
6+
using MAT, FileIO
57

68
# The following code loads the parameters and initial conditions,
79
# it initialises the model, runs the model `n_sims` times, and finally
@@ -15,9 +17,9 @@ for year in 2010:2019
1517
parameters = load("data/italy/parameters/" * string(year) * "Q" * string(quarter) * ".jld2")
1618
initial_conditions = load("data/italy/initial_conditions/" * string(year) * "Q" * string(quarter) * ".jld2")
1719
T = 12
18-
model = BeforeIT.init_model(parameters, initial_conditions, T)
20+
model = Bit.init_model(parameters, initial_conditions, T)
1921
n_sims = 4
20-
data_vector = BeforeIT.ensemblerun(model, n_sims)
22+
data_vector = Bit.ensemblerun(model, n_sims)
2123
save("data/italy/simulations/" * string(year) * "Q" * string(quarter) * ".jld2", "data_vector", data_vector)
2224
end
2325
end

examples/multithreading_speedup.jl

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# to allow for faster executions of single simulation runs.
55

66
import BeforeIT as Bit
7+
78
using FileIO, Plots, StatsPlots
89

910
# First, we initialise the model, this time we use the Italy 2010Q1 scenario,

examples/scenario_analysis_via_overload.jl

+2-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
# unshocked model.
66

77
import BeforeIT as Bit
8+
89
using Plots, StatsPlots
910

1011
parameters = Bit.AUSTRIA2010Q1.parameters
@@ -23,9 +24,7 @@ data_vec_baseline = Bit.ensemblerun(model, 4)
2324
# Now, apply a shock to the model and simulate it again
2425
# Here, we do this by overloading the central_bank_rate function with the wanted behaviour
2526

26-
import BeforeIT: central_bank_rate
27-
28-
function central_bank_rate(cb::Bit.CentralBank, model::Bit.Model)
27+
function Bit.central_bank_rate(cb::Bit.CentralBank, model::Bit.Model)
2928
gamma_EA = model.rotw.gamma_EA
3029
pi_EA = model.rotw.pi_EA
3130
taylor_rate = Bit.taylor_rule(cb.rho, cb.r_bar, cb.r_star, cb.pi_star, cb.xi_pi, cb.xi_gamma, gamma_EA, pi_EA)

examples/scenario_analysis_via_shock.jl

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
# results with the unshocked model.
66

77
import BeforeIT as Bit
8+
89
using Plots, StatsPlots
910

1011
parameters = Bit.AUSTRIA2010Q1.parameters

main.jl

+9-8
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
1-
using BeforeIT, Random
2-
using Plots
1+
import BeforeIT as Bit
32

4-
parameters = BeforeIT.AUSTRIA2010Q1.parameters
5-
initial_conditions = BeforeIT.AUSTRIA2010Q1.initial_conditions
3+
using Random, Plots
4+
5+
parameters = Bit.AUSTRIA2010Q1.parameters
6+
initial_conditions = Bit.AUSTRIA2010Q1.initial_conditions
67

78
T = 20
8-
model = BeforeIT.init_model(parameters, initial_conditions, T)
9-
data = BeforeIT.init_data(model)
9+
model = Bit.init_model(parameters, initial_conditions, T)
10+
data = Bit.init_data(model)
1011

1112
for t in 1:T
1213
println("Epoch: ", t)
13-
BeforeIT.step!(model; multi_threading = true)
14-
BeforeIT.update_data!(data, model)
14+
Bit.step!(model; multi_threading = true)
15+
Bit.update_data!(data, model)
1516
end
1617

1718
p1 = plot(data.real_gdp, title = "gdp", titlefont = 10)

src/BeforeIT.jl

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ using LinearAlgebra
99
using Random
1010
using StatsBase
1111

12+
const Bit = BeforeIT
13+
1214
# definition of agents
1315
include("model_init/agents.jl")
1416

src/model_init/init.jl

+8-8
Original file line numberDiff line numberDiff line change
@@ -21,29 +21,29 @@ Returns:
2121
function init_model(parameters::Dict{String, Any}, initial_conditions::Dict{String, Any}, T, typeInt::DataType = Int64, typeFloat::DataType = Float64)
2222

2323
# properties
24-
properties = BeforeIT.init_properties(parameters, T; typeInt = typeInt, typeFloat = typeFloat)
24+
properties = Bit.init_properties(parameters, T; typeInt = typeInt, typeFloat = typeFloat)
2525

2626
# firms
27-
firms, _ = BeforeIT.init_firms(parameters, initial_conditions; typeInt = typeInt, typeFloat = typeFloat)
27+
firms, _ = Bit.init_firms(parameters, initial_conditions; typeInt = typeInt, typeFloat = typeFloat)
2828

2929
# workers, and update firms vacancies
30-
workers_act, workers_inact, V_i_new, _, _ = BeforeIT.init_workers(parameters, initial_conditions, firms; typeInt = typeInt, typeFloat = typeFloat)
30+
workers_act, workers_inact, V_i_new, _, _ = Bit.init_workers(parameters, initial_conditions, firms; typeInt = typeInt, typeFloat = typeFloat)
3131
firms.V_i = V_i_new
3232

3333
# bank
34-
bank, _ = BeforeIT.init_bank(parameters, initial_conditions, firms; typeInt = typeInt, typeFloat = typeFloat)
34+
bank, _ = Bit.init_bank(parameters, initial_conditions, firms; typeInt = typeInt, typeFloat = typeFloat)
3535

3636
# central bank
37-
central_bank, _ = BeforeIT.init_central_bank(parameters, initial_conditions; typeInt = typeInt, typeFloat = typeFloat)
37+
central_bank, _ = Bit.init_central_bank(parameters, initial_conditions; typeInt = typeInt, typeFloat = typeFloat)
3838

3939
# government
40-
government, _ = BeforeIT.init_government(parameters, initial_conditions; typeInt = typeInt, typeFloat = typeFloat)
40+
government, _ = Bit.init_government(parameters, initial_conditions; typeInt = typeInt, typeFloat = typeFloat)
4141

4242
# rest of the world
43-
rotw, _ = BeforeIT.init_rotw(parameters, initial_conditions; typeInt = typeInt, typeFloat = typeFloat)
43+
rotw, _ = Bit.init_rotw(parameters, initial_conditions; typeInt = typeInt, typeFloat = typeFloat)
4444

4545
# aggregates
46-
agg, _ = BeforeIT.init_aggregates(parameters, initial_conditions, T; typeInt = typeInt, typeFloat = typeFloat)
46+
agg, _ = Bit.init_aggregates(parameters, initial_conditions, T; typeInt = typeInt, typeFloat = typeFloat)
4747

4848
# model
4949
model = Model(workers_act, workers_inact, firms, bank, central_bank, government, rotw, agg, properties)

0 commit comments

Comments
 (0)