-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
292 additions
and
551 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,43 @@ | ||
using BeforeIT, MAT, FileIO, Random | ||
using Test | ||
|
||
dir = @__DIR__ | ||
|
||
parameters = BeforeIT.AUSTRIA2010Q1.parameters | ||
initial_conditions = BeforeIT.AUSTRIA2010Q1.initial_conditions | ||
|
||
T = 1 | ||
model = BeforeIT.initialise_model(parameters, initial_conditions, T) | ||
data = BeforeIT.initialise_data(model) | ||
|
||
println(BeforeIT.get_accounting_identities(data)) | ||
println(BeforeIT.get_accounting_identity_banks(model)) | ||
|
||
for t in 1:T | ||
println(t) | ||
BeforeIT.one_epoch!(model; multi_threading = false) | ||
BeforeIT.update_data!(data, model) | ||
end | ||
|
||
# println(BeforeIT.get_accounting_identities(data)) | ||
# println(BeforeIT.get_accounting_identity_banks(model)) | ||
|
||
# income accounting and production accounting should be equal | ||
zero = sum(data.nominal_gva - data.compensation_employees - data.operating_surplus - data.taxes_production) | ||
# println(zero) | ||
@test isapprox(zero, 0.0, atol = 1e-9) | ||
|
||
# compare nominal_gdp to total expenditure | ||
zero = sum( | ||
data.nominal_gdp - data.nominal_household_consumption - data.nominal_government_consumption - | ||
data.nominal_capitalformation - data.nominal_exports + data.nominal_imports, | ||
) | ||
# println(zero) | ||
@test isapprox(zero, 0.0, atol = 1e-9) | ||
|
||
zero = sum( | ||
data.real_gdp - data.real_household_consumption - data.real_government_consumption - data.real_capitalformation - data.real_exports + data.real_imports, | ||
) | ||
# println(zero) | ||
@test isapprox(zero, 0.0, atol = 1e-8) | ||
|
||
# accounting identity of balance sheet of central bank | ||
zero = model.cb.E_CB + model.rotw.D_RoW - model.gov.L_G + model.bank.D_k | ||
# println(zero) | ||
@test isapprox(zero, 0.0, atol = 1e-9) | ||
|
||
# accounting identity of balance sheet of commercial bank | ||
tot_D_h = sum(model.w_act.D_h) + sum(model.w_inact.D_h) + sum(model.firms.D_h) + model.bank.D_h | ||
zero = sum(model.firms.D_i) + tot_D_h + sum(model.bank.E_k) - sum(model.firms.L_i) - model.bank.D_k | ||
# println(zero) | ||
@test isapprox(zero, 0.0, atol = 1e-9) | ||
@testset "accounting identities" begin | ||
dir = @__DIR__ | ||
|
||
parameters = BeforeIT.AUSTRIA2010Q1.parameters | ||
initial_conditions = BeforeIT.AUSTRIA2010Q1.initial_conditions | ||
|
||
T = 1 | ||
model = BeforeIT.initialise_model(parameters, initial_conditions, T) | ||
data = BeforeIT.initialise_data(model) | ||
|
||
for t in 1:T | ||
BeforeIT.one_epoch!(model; multi_threading = false) | ||
BeforeIT.update_data!(data, model) | ||
end | ||
|
||
# income accounting and production accounting should be equal | ||
zero = sum(data.nominal_gva - data.compensation_employees - data.operating_surplus - data.taxes_production) | ||
@test isapprox(zero, 0.0, atol = 1e-9) | ||
|
||
# compare nominal_gdp to total expenditure | ||
zero = sum( | ||
data.nominal_gdp - data.nominal_household_consumption - data.nominal_government_consumption - | ||
data.nominal_capitalformation - data.nominal_exports + data.nominal_imports, | ||
) | ||
@test isapprox(zero, 0.0, atol = 1e-9) | ||
|
||
zero = sum( | ||
data.real_gdp - data.real_household_consumption - data.real_government_consumption - data.real_capitalformation - data.real_exports + data.real_imports, | ||
) | ||
@test isapprox(zero, 0.0, atol = 1e-8) | ||
|
||
# accounting identity of balance sheet of central bank | ||
zero = model.cb.E_CB + model.rotw.D_RoW - model.gov.L_G + model.bank.D_k | ||
@test isapprox(zero, 0.0, atol = 1e-9) | ||
|
||
# accounting identity of balance sheet of commercial bank | ||
tot_D_h = sum(model.w_act.D_h) + sum(model.w_inact.D_h) + sum(model.firms.D_h) + model.bank.D_h | ||
zero = sum(model.firms.D_i) + tot_D_h + sum(model.bank.E_k) - sum(model.firms.L_i) - model.bank.D_k | ||
@test isapprox(zero, 0.0, atol = 1e-9) | ||
end |
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,102 +1,104 @@ | ||
using BeforeIT, Test, MAT, StatsBase | ||
using Random | ||
|
||
Random.seed!(1) | ||
|
||
dir = @__DIR__ | ||
|
||
parameters = BeforeIT.AUSTRIA2010Q1.parameters | ||
initial_conditions = BeforeIT.AUSTRIA2010Q1.initial_conditions | ||
|
||
T = 1 | ||
model = BeforeIT.initialise_model(parameters, initial_conditions, T;) | ||
|
||
|
||
gov = model.gov # government | ||
cb = model.cb # central bank | ||
rotw = model.rotw # rest of the world | ||
firms = model.firms # firms | ||
bank = model.bank # bank | ||
w_act = model.w_act # active workers | ||
w_inact = model.w_inact # inactive workers | ||
agg = model.agg # aggregate variables | ||
|
||
prop = model.prop # model properties | ||
|
||
|
||
gamma_e = 0.01 # set expected growth in euro area | ||
pi_e = 0.001 # set expected inflation in euro area | ||
|
||
agg.gamma_e = gamma_e | ||
agg.pi_e = pi_e | ||
|
||
Q_s_i, I_d_i, DM_d_i, N_d_i, Pi_e_i, DL_d_i, K_e_i, L_e_i, P_i = | ||
BeforeIT.firms_expectations_and_decisions(model.firms, model) | ||
|
||
firms.Q_s_i .= Q_s_i | ||
firms.I_d_i .= I_d_i | ||
firms.DM_d_i .= DM_d_i | ||
firms.N_d_i .= N_d_i | ||
firms.Pi_e_i .= Pi_e_i | ||
firms.P_i .= P_i | ||
firms.DL_d_i .= DL_d_i | ||
firms.K_e_i .= K_e_i | ||
firms.L_e_i .= L_e_i | ||
|
||
Pi_e_k = BeforeIT.bank_expected_profits(bank, model) | ||
bank.Pi_e_k = Pi_e_k | ||
|
||
C_d_h, I_d_h = BeforeIT.households_budget_act(w_act, model) | ||
w_act.C_d_h .= C_d_h | ||
w_act.I_d_h .= I_d_h | ||
C_d_h, I_d_h = BeforeIT.households_budget_inact(w_inact, model) | ||
w_inact.C_d_h .= C_d_h | ||
w_inact.I_d_h .= I_d_h | ||
C_d_h, I_d_h = BeforeIT.households_budget(firms, model) | ||
firms.C_d_h .= C_d_h | ||
firms.I_d_h .= I_d_h | ||
bank.C_d_h, bank.I_d_h = BeforeIT.households_budget(bank, model) | ||
|
||
C_G, C_d_j = BeforeIT.gov_expenditure(gov, model) | ||
gov.C_G = C_G | ||
gov.C_d_j .= C_d_j | ||
|
||
|
||
epsilon_E = 0.28 | ||
epsilon_I = 0.36 | ||
|
||
agg.epsilon_E = epsilon_E | ||
agg.epsilon_I = epsilon_I | ||
|
||
C_E, Y_I, C_d_l, Y_m, P_m = BeforeIT.rotw_import_export(rotw, model) | ||
rotw.C_E = C_E | ||
rotw.Y_I = Y_I | ||
rotw.C_d_l .= C_d_l | ||
rotw.Y_m .= Y_m | ||
rotw.P_m .= P_m | ||
|
||
BeforeIT.search_and_matching!(model, false) | ||
|
||
rtol = 0.0001 | ||
|
||
# NOTE: the expected numbers come out of the original implementation, | ||
# and only hold for the serial code (without multithreading) | ||
@test isapprox(mean(w_act.C_h), 4.148850396106796, rtol = rtol) | ||
@test isapprox(mean(w_inact.C_h), 2.205381003981018, rtol = rtol) | ||
@test isapprox(mean(firms.C_h), 9.060799641122962, rtol = rtol) | ||
@test isapprox(bank.C_h, 2931.5395701704915, rtol = rtol) | ||
|
||
@test isapprox(mean(w_act.I_h), 0.34186063655926524, rtol = rtol) | ||
@test isapprox(mean(w_inact.I_h), 0.18217582636296747, rtol = rtol) | ||
@test isapprox(mean(firms.I_h), 0.7442975169996757, rtol = rtol) | ||
@test isapprox(bank.I_h, 233.5381841004737, rtol = rtol) | ||
|
||
@test isapprox(gov.C_j, 14686.094833493271, rtol = rtol) | ||
@test isapprox(rotw.C_l, 44241.742486622454, rtol = rtol) | ||
|
||
@test isapprox(mean(firms.I_i), 20.671016463479898, rtol = rtol) | ||
@test isapprox(mean(firms.DM_i), 110.18635469222951, rtol = rtol) | ||
@test isapprox(mean(firms.P_bar_i), 1.0010000000000023, rtol = rtol) | ||
@test isapprox(mean(firms.P_CF_i), 1.0010000000000023, rtol = rtol) | ||
@test isapprox(mean(firms.Q_d_i), 216.70740037345882, rtol = rtol) | ||
@test isapprox(mean(rotw.Q_d_m), 719.2385742449192, rtol = rtol) | ||
@testset "search and matching" begin | ||
Random.seed!(1) | ||
|
||
dir = @__DIR__ | ||
|
||
parameters = BeforeIT.AUSTRIA2010Q1.parameters | ||
initial_conditions = BeforeIT.AUSTRIA2010Q1.initial_conditions | ||
|
||
T = 1 | ||
model = BeforeIT.initialise_model(parameters, initial_conditions, T;) | ||
|
||
|
||
gov = model.gov # government | ||
cb = model.cb # central bank | ||
rotw = model.rotw # rest of the world | ||
firms = model.firms # firms | ||
bank = model.bank # bank | ||
w_act = model.w_act # active workers | ||
w_inact = model.w_inact # inactive workers | ||
agg = model.agg # aggregate variables | ||
|
||
prop = model.prop # model properties | ||
|
||
|
||
gamma_e = 0.01 # set expected growth in euro area | ||
pi_e = 0.001 # set expected inflation in euro area | ||
|
||
agg.gamma_e = gamma_e | ||
agg.pi_e = pi_e | ||
|
||
Q_s_i, I_d_i, DM_d_i, N_d_i, Pi_e_i, DL_d_i, K_e_i, L_e_i, P_i = | ||
BeforeIT.firms_expectations_and_decisions(model.firms, model) | ||
|
||
firms.Q_s_i .= Q_s_i | ||
firms.I_d_i .= I_d_i | ||
firms.DM_d_i .= DM_d_i | ||
firms.N_d_i .= N_d_i | ||
firms.Pi_e_i .= Pi_e_i | ||
firms.P_i .= P_i | ||
firms.DL_d_i .= DL_d_i | ||
firms.K_e_i .= K_e_i | ||
firms.L_e_i .= L_e_i | ||
|
||
Pi_e_k = BeforeIT.bank_expected_profits(bank, model) | ||
bank.Pi_e_k = Pi_e_k | ||
|
||
C_d_h, I_d_h = BeforeIT.households_budget_act(w_act, model) | ||
w_act.C_d_h .= C_d_h | ||
w_act.I_d_h .= I_d_h | ||
C_d_h, I_d_h = BeforeIT.households_budget_inact(w_inact, model) | ||
w_inact.C_d_h .= C_d_h | ||
w_inact.I_d_h .= I_d_h | ||
C_d_h, I_d_h = BeforeIT.households_budget(firms, model) | ||
firms.C_d_h .= C_d_h | ||
firms.I_d_h .= I_d_h | ||
bank.C_d_h, bank.I_d_h = BeforeIT.households_budget(bank, model) | ||
|
||
C_G, C_d_j = BeforeIT.gov_expenditure(gov, model) | ||
gov.C_G = C_G | ||
gov.C_d_j .= C_d_j | ||
|
||
|
||
epsilon_E = 0.28 | ||
epsilon_I = 0.36 | ||
|
||
agg.epsilon_E = epsilon_E | ||
agg.epsilon_I = epsilon_I | ||
|
||
C_E, Y_I, C_d_l, Y_m, P_m = BeforeIT.rotw_import_export(rotw, model) | ||
rotw.C_E = C_E | ||
rotw.Y_I = Y_I | ||
rotw.C_d_l .= C_d_l | ||
rotw.Y_m .= Y_m | ||
rotw.P_m .= P_m | ||
|
||
BeforeIT.search_and_matching!(model, false) | ||
|
||
rtol = 0.0001 | ||
|
||
# NOTE: the expected numbers come out of the original implementation, | ||
# and only hold for the serial code (without multithreading) | ||
@test isapprox(mean(w_act.C_h), 4.148850396106796, rtol = rtol) | ||
@test isapprox(mean(w_inact.C_h), 2.205381003981018, rtol = rtol) | ||
@test isapprox(mean(firms.C_h), 9.060799641122962, rtol = rtol) | ||
@test isapprox(bank.C_h, 2931.5395701704915, rtol = rtol) | ||
|
||
@test isapprox(mean(w_act.I_h), 0.34186063655926524, rtol = rtol) | ||
@test isapprox(mean(w_inact.I_h), 0.18217582636296747, rtol = rtol) | ||
@test isapprox(mean(firms.I_h), 0.7442975169996757, rtol = rtol) | ||
@test isapprox(bank.I_h, 233.5381841004737, rtol = rtol) | ||
|
||
@test isapprox(gov.C_j, 14686.094833493271, rtol = rtol) | ||
@test isapprox(rotw.C_l, 44241.742486622454, rtol = rtol) | ||
|
||
@test isapprox(mean(firms.I_i), 20.671016463479898, rtol = rtol) | ||
@test isapprox(mean(firms.DM_i), 110.18635469222951, rtol = rtol) | ||
@test isapprox(mean(firms.P_bar_i), 1.0010000000000023, rtol = rtol) | ||
@test isapprox(mean(firms.P_CF_i), 1.0010000000000023, rtol = rtol) | ||
@test isapprox(mean(firms.Q_d_i), 216.70740037345882, rtol = rtol) | ||
@test isapprox(mean(rotw.Q_d_m), 719.2385742449192, rtol = rtol) | ||
end |
Oops, something went wrong.