Code reference
In this page we document the functions which constitute the bulk of BeforeIT.jl functionality.
Agent types
BeforeIT.@object — Macro
Bit.@object struct YourObjectType{X}(ObjectTypeToInherit) [<: OptionalSupertype]
extra_property::X
other_extra_property_with_default::Bool = true
const other_extra_const_property::Int
# etc...
endDefine an object struct which includes all fields that YourObjectType has, as well as any additional ones the user may provide. The macro supports all syntaxes that the standard Julia struct command allows for, such as const field declaration or default values for some fields. Additionally, the resulting type will always have a keyword constructor defined for it (using @kwdef).
Using Bit.@object is the recommended way to create types for BeforeIT.jl.
Structs created with Bit.@object by default subtype Bit.AbstractObject. If you want YourObjectType to subtype something other than Bit.AbstractObject, use the optional argument OptionalSupertype.
Usage
The macro Bit.@object has two primary uses:
- To include the mandatory fields for a particular object in your object struct. In this case you would use one of the minimal object types.
- A convenient way to include fields from another, already existing struct, thereby establishing a toolkit for "type inheritance" in Julia.
The existing minimal object types are:
Bit.WorkersBit.FirmsBit.BankBit.CentralBankBit.GovernmentBit.RestOfTheWorldBit.AggregatesBit.Data
which describe which fields they will contribute to the new type.
Example
# you can either constrain the type (to Float64 in this case) at definition time
Bit.@object mutable struct CentralBankNew(CentralBank) <: Bit.AbstractCentralBank
new_field::Float64
end
# or keep it generic so that you can change it at construction time
Bit.@object mutable struct CentralBankNew2{T}(CentralBank) <: Bit.AbstractCentralBank
new_field::T
endConsult the CANVAS Extension page in the documentation for a more advanced example on how to use the macro.
BeforeIT.Aggregates — Type
This is a Aggregates type. It is used to store the aggregate variables of the economy. Note that t is an integer, while the rest are floats or vectors of floats.
Fields
Y [vector]: GDP data + predictionspi_ [vector]: inflation data + predictionsP_bar: Global price indexP_bar_g [vector]: Producer price index for principal good gP_bar_HH: Consumer price indexP_bar_CF: Capital price indexP_bar_h: CPI_hP_bar_CF_h: Capital price index _hY_e: Expected GDPgamma_e: Expected growthpi_e: Expected inflationt: Time index
BeforeIT.Bank — Type
This is a Bank type. It represents the bank of the model.
Fields
E_k: equity capital (common equity) of the bankPi_k: Profits of the bankPi_e_k: Expected profits of the bankD_k: Residual and balancing item on the bank’s balance sheetr: Rate for loans and morgages
Household fields (bank' owner)
Y_h: Net disposable income of bank owner (investor)C_d_h: Consumption budgetI_d_h: Investment budgetC_h: Realised consumptionI_h: Realised investmentK_h: Capital stockD_h: Deposits
BeforeIT.CentralBank — Type
This is a CentralBank type. It represents the central bank of the model.
Fields
r_bar: Nominal interest rater_G: Interest rate on government bondsrho: Parameter for gradual adjustment of the policy rater_star: Real equilibrium interest ratepi_star: Inflation target by CBxi_pi: Weight the CB puts on inflation targetingxi_gamma: Weight placed on economicE_CB: Central bank equity
BeforeIT.Firms — Type
This is a Firms type. Each field is an array which stores the values for all the firms in the economy. Note that the G_i, N_i and V_i fields are integers, while the rest are floats.
For all fields the entry at index i corresponds to the ith firm.
Fields
G_i: Principal productalpha_bar_i: Average productivity of laborbeta_i: Productivity of intermediate consumptionkappa_i: Productivity of capitalw_i: Wagesw_bar_i: Average wage ratedelta_i: Depreciation rate for capitaltau_Y_i: Net tax rate on productstau_K_i: Net tax rate on productionN_i: Number of persons employedY_i: Production of goodsQ_i: Sales of goodsQ_d_i: Demand for goodsP_i: PriceS_i: InventoriesK_i: Capital, in real termsM_i: Intermediate goods/services and raw materials, in real termsL_i: Outstanding loanspi_bar_i: Operating marginD_i: Deposits of the firmPi_i: ProfitsV_i: VacanciesI_i: InvestmentsE_i: EquityP_bar_i: Price indexP_CF_i: Price indexDS_i: Differnece in stock of final goodsDM_i: Difference in stock of intermediate goodsDL_i: Obtained loansDL_d_i: Target loansK_e_i: Expected capitalL_e_i: Expected loansQ_s_i: Expected salesI_d_i: Desired investmentsDM_d_i: Desired materialsN_d_i: Desired employmentPi_e_i: Expected profits
Household fields (firms' owners)
Y_h: Net disposable income of firm owner (investor)C_d_h: Consumption budgetI_d_h: Investment budgetC_h: Realised consumptionI_h: Realised investmentK_h: Capital stockD_h: Deposits of the owner of the firms
BeforeIT.Government — Type
This is a Government type. It represents the government of the model.
Fields
alpha_G: Autoregressive coefficient for government consumptionbeta_G: Scalar constant for government consumptionsigma_G: Variance coefficient for government consumptionY_G: Government revenuesC_G: Consumption demand of the general governmentL_G: Loans taken out by the governmentsb_inact: Social benefits for inactive personssb_other: Social benefits for allC_d_j [vector]: Local governments consumption demandC_j: Realised government consumptionP_j: Price inflation of government goods <- ??
BeforeIT.Model — Type
This is a Model type. It is used to store all the agents of the economy.
Fields
w_act: Workers that are activew_inact: Workers that are inactivefirms: Firmsbank: Bankcb: CentralBankgov: Governmentrotw: RestOfTheWorldagg: Aggregates
BeforeIT.RestOfTheWorld — Type
This is a RestOfTheWorld type. It represents the rest of the world of the model.
Fields
alpha_E: Autoregressive coefficient for exportsbeta_E: Scalar constant for exportssigma_E: Variance coefficient for exportsalpha_I: Autoregressive coefficient for importsbeta_I: Scalar constant for importssigma_I: Variance coefficient for importsY_EA: GDP euro areagamma_EA: Growth euro areapi_EA: Inflation euro areaalpha_pi_EA: Autoregressive coefficient for euro area inflationbeta_pi_EA: Autoregressive coefficient for euro area inflation Scalar constant for euro area inflationsigma_pi_EA: Variance coefficient for euro area inflationalpha_Y_EA: Autoregressive coefficient for euro area GDPbeta_Y_EA: Autoregressive coefficient for euro area GDP Scalar constant for euro area GDPsigma_Y_EA: Variance coefficient for euro area GDPD_RoW: Net creditor/debtor position of the national economy to the rest of the worldY_I: Supply of imports (in real terms)C_E: Total demand for exportsC_d_l [vector]: Demand for exports of specific productC_l: Realised consumption by foreign consumersY_m [vector]: Supply of imports per sectorQ_m [vector]: Sales for imports per sectorQ_d_m [vector]: Demand for goodsP_m [vector]: Price of imports per sectorP_l: Price inflation of exports <- ??
BeforeIT.Workers — Type
This is a Workers. Each field is an array which stores the values for all the workers in the economy. Note that the O_h field is an integer, while the rest are floats.
For all fields the entry at index i corresponds to the ith worker.
Fields
Y_h: Net disposable income of worker owner (investor)D_h: DepositsK_h: Capital stockw_h: Wages (0 if inactive or unemployed)O_h: Occupation (0 if unemployed, -1 if inactive)C_d_h: Consumption budgetI_d_h: Investment budgetC_h: Realised consumptionI_h: Realised investment
Initialisation function
BeforeIT.Model — Method
Model(parameters, initial_conditions)Initializes the model with given parameters and initial conditions.
Parameters:
parameters: A dictionary containing the model parameters.- initial_conditions: A dictionary containing the initial conditions.
Returns:
- model::AbstractModel: The initialized model.
BeforeIT.update_variables_with_totals! — Method
update_variables_with_totals!(model::AbstractModel)Update the variables in the given model with some global quantities obtained from all agents. This is the last step in the initialization process and it must be performed after all agents have been initialized.
Arguments
model::AbstractModel: The model object to update.
Returns
- Nothing
Functions to run an entire simulation
BeforeIT.ensemblerun! — Function
ensemblerun!(models, T=1; shock! = NoShock(), parallel = true)A function that runs the models simulations for T steps on each of them.
Arguments
models: The models to simulate. The models can either be in aVectororGenerator.T: the number of steps to perform.
Returns
models: The updated models.
Example
parameters = Bit.AUSTRIA2010Q1.parameters
initial_conditions = Bit.AUSTRIA2010Q1.initial_conditions
models = (Bit.Model(parameters, initial_conditions) for _ in 1:10)
Bit.ensemblerun!(models, 2)BeforeIT.ensemblerun — Method
ensemblerun(model, T, n_sims; shock! = NoShock(), parallel = true)A function that creates n_sims copies of a model and runs simulations for T steps on each of them.
Arguments
model::AbstractModel: The base model to be copied.T: The number of steps to perform on each model.n_sims: The number of model copies to create and simulate.
Keyword Arguments
shock: The shock to apply during simulation (default:NoShock()).parallel: Whether to run simulations in parallel (default:true).
Returns
models: A vector containing then_simsupdated models after simulation.
Example
parameters = Bit.AUSTRIA2010Q1.parameters
initial_conditions = Bit.AUSTRIA2010Q1.initial_conditions
model = Bit.Model(parameters, initial_conditions)
models = Bit.ensemblerun(model, 2, 10) # Create 10 copies and run for 2 stepsBeforeIT.run! — Function
run!(model, T; shock! = NoShock(), parallel = false)Run a single simulation based on the provided model. The simulation runs for a number of steps T.
Arguments
model::AbstractModel: The model configuration used for the simulation.T: the number of steps to perform.
Returns
model::AbstractModel: The model updated during the simulation.
Details
The function iteratively updates the model and data for each step using Bit.step!(model).
Example
parameters = Bit.AUSTRIA2010Q1.parameters
initial_conditions = Bit.AUSTRIA2010Q1.initial_conditions
model = Bit.Model(parameters, initial_conditions)
Bit.run!(model, 2)Firms actions
BeforeIT.Firms — Method
Firms(parameters, initial_conditions)Initialize firms with given parameters and initial conditions.
Arguments
parameters: The parameters for initializing the firms.initial_conditions: The initial conditions for the firms.
Returns
- firms::Firms: The initialized firms.
BeforeIT.firms_deposits — Method
firms_deposits(model)Calculate the new deposits of firms.
Returns
DD_i: Vector of new deposits
The new deposits DD_i are calculated as follows:
DD_i = sales + labour_cost + material_cost + taxes_products + taxes_production + corporate_tax + dividend_payments + interest_payments + interest_received + investment_cost + new_credit + debt_installmentwhere:
sales = P_i * Q_ilabour_cost = (1 + tau_SIF) * w_i * N_i * P_bar_HHmaterial_cost = -DM_i * P_bar_itaxes_products = -tau_Y_i * P_i * Y_itaxes_production = -tau_K_i * P_i * Y_icorporate_tax = -tau_FIRM * pos(Pi_i)dividend_payments = -theta_DIV * (1 - tau_FIRM) * pos(Pi_i)interest_payments = -r * (L_i + pos(-D_i))interest_received = r_bar * pos(D_i)investment_cost = -P_CF_i * I_inew_credit = DL_idebt_installment = -theta * L_i
BeforeIT.firms_equity — Method
firms_equity(model)Calculate the equity of firms.
Returns
E_i: Vector of equity
The equity E_i is calculated as follows:
\[E_i = D_i + M_i * \sum(a_{sg}[:, G_i] * \bar{P}_g) + P_i * S_i + \bar{P}_{CF} * K_i - L_i\]
where:
D_i: DepositsM_i: Intermediate goodsa_sg: Technology coefficient of the gth product in the sth industryG_i: Vector of goodsP_bar_g: Producer price index for principal good gP_i: PriceS_i: StockP_bar_CF: Capital price indexK_i: Capital stockL_i: Loans
BeforeIT.firms_expectations_and_decisions — Method
firms_expectations_and_decisions(model)Calculate the expectations and decisions of firms. That is: compute firm quantity, price, investment and intermediate-goods, employment decisions, expected profits, and desired/expected loans and capital.
Returns
Q_s_i: Vector of desired quantitiesI_d_i: Vector of desired investmentsDM_d_i: Vector of desired intermediate goodsN_d_i: Vector of desired employmentPi_e_i: Vector of expected profitsDL_d_i: Vector of desired new loansK_e_i: Vector of expected capitalL_e_i: Vector of expected loansP_i: Vector of prices
BeforeIT.firms_loans — Method
firms_loans(model)Calculate the new loans of firms.
Returns
L_i: Vector of new loans
The new loans L_i are calculated as follows:
\[L_i = (1 - theta) * L_i + DL_i\]
where:
theta: Rate of repaymentL_i: LoansDL_i: Acquired new loans
BeforeIT.firms_production — Method
firms_production(model)Calculate the production of firms.
Returns
Y_i: Vector of production
The production Y_i is computed using a Leontief technology.
BeforeIT.firms_profits — Method
firms_profits(model)Calculate the profits of firms.
Returns
Pi_i: Vector of profits
The profits Pi_i are calculated as follows:
Pi_i = in_sales + in_deposits - out_wages - out_expenses - out_depreciation - out_taxes_prods - out_taxes_capital - out_loanswhere:
in_sales = P_i * Q_i + P_i * DS_iin_deposits = r_bar * pos(D_i)out_wages = (1 + tau_SIF) * w_i * N_i * P_bar_HHout_expenses = 1 / beta_i * P_bar_i * Y_iout_depreciation = delta_i / kappa_i * P_CF_i * Y_iout_taxes_prods = tau_Y_i * P_i * Y_iout_taxes_capital = tau_K_i * P_i * Y_iout_loans = r * (L_i + pos(-D_i))
BeforeIT.firms_stocks — Method
firms_stocks(model)Calculate the stocks of firms.
Returns
K_i: Vector of capital stockM_i: Vector of intermediate goodsDS_i: Vector of differneces in stock of final goodsS_i: Vector of stock of final goods
The stocks are calculated as follows:
K_i = K_i - delta_i / kappa_i * Y_i + I_i
M_i = M_i - Y_i / beta_i + DM_i
DS_i = Y_i - Q_i
S_i = S_i + DS_iBeforeIT.firms_wages — Method
firms_wages(model)Calculate the wages set by firms.
Returns
w_i: Vector of wages
BeforeIT.leontief_production — Method
leontief_production(Q_s_i, N_i, alpha_i, K_i, kappa_i, M_i, beta_i)Calculate the production function of firms.
Arguments
Q_s_i: Vector of desired quantitiesN_i: Vector of employmentalpha_i: Vector of labour productivityK_i: Vector of capital stockkappa_i: Vector of capital productivityM_i: Vector of intermediate goodsbeta_i: Vector of intermediate goods productivity
Returns
Y_i: Vector of production
The Leontief production function Y_i is calculated as follows:
\[Y_i = \min(Q_s_i, \min(N_i \cdot \alpha_i, \min(K_i \cdot \kappa_i, M_i \cdot \beta_i)))\]
Households actions
Government actions
BeforeIT.Government — Method
Government(parameters, initial_conditions)Initialize the government agent.
Arguments
parameters: The parameters.initial_conditions: The initial conditions.
Returns
- The initialized government model.
BeforeIT.gov_expenditure — Method
gov_expenditure(model)Computes government expenditure on consumption and transfers to households.
Returns
C_G: government consumptionC_d_j: local government consumptions
BeforeIT.gov_loans — Method
gov_loans(model)Computes government new government debt.
Returns
L_G: new government debt
BeforeIT.gov_revenues — Method
gov_revenues(model)Computes government revenues from taxes and social security contributions. The government collects taxes on labour income, capital income, value added, and corporate income. It also collects social security contributions from workers and firms. The government also collects taxes on consumption and capital formation. Finally, the government collects taxes on exports and imports.
Returns
Y_G: government revenues
BeforeIT.gov_social_benefits — Method
gov_social_benefits(model)Computes social benefits paid by the government households.
Returns
sb_other: social benefits for other householdssb_inact: social benefits for inactive households
Bank and Central Bank actions
BeforeIT.bank_deposits — Method
bank_deposits(model)Calculate the new deposits of a bank.
Returns
D_k: New deposits of the bank
The new deposits D_k are calculated as the sum of the deposits of the active workers, the inactive workers, the firms, and the bank owner itself, plus the bank's equity, minus the loans of the firms.
BeforeIT.bank_equity — Method
bank_equity(model)Calculate the net profits of the bank.
Returns
E_k: The updated equity of the bank.
The net profits DE_k are calculated as:
\[DE_k = \Pi_k - \theta_{DIV} \cdot (1 - \tau_{FIRM}) \cdot \max(0, \Pi_k) - \tau_{FIRM} \cdot \max(0, \Pi_k)\]
and the equity E_k is updated as:
\[E_k = E_k + DE_k\]
BeforeIT.bank_expected_profits — Method
bank_expected_profits(model)Calculate the expected profits of a bank.
Returns
E_Pi_k: Expected profits of the bank
The expected profits E_Pi_k are calculated as follows:
\[E_{\Pi_k} = \Pi_k \cdot (1 + \pi_e) \cdot (1 + \gamma_e)\]
where
Pi_k: Past profits of the bankpi_e: Expected inflation rategamma_e: Expected growth rate
BeforeIT.bank_profits — Method
bank_profits(model)Calculate the total profits of the bank.
Returns
Pi_k: The total profits of the bank.
The total profits Pi_k are calculated as:
\[\Pi_k = r \cdot \sum_i(L_i + \max(0, -D_i)) + r \cdot \sum_h(\max(0, -D_h)) + r_{bar} \cdot \max(0, D_k) - r_{bar} \cdot \sum_i(\max(0, D_i)) - r_{bar} \cdot \sum_h(\max(0, D_h)) - r_{bar} \cdot \max(0, -D_k)\]
where
L_i: Array of loans provided by the bankD_i: Array of deposits from firmsD_h: Array of deposits from householdsD_k: Residual and balancing item on the bank’s balance sheetr_bar: Base interest rater: Interest rate set by the bank
BeforeIT.bank_rate — Method
bank_rate(model)Update the interest rate set by the bank.
Returns
r: The updated interest rate
\[r = \bar{r} + \mu\]
BeforeIT.central_bank_equity — Method
central_bank_equity(model)Calculate the equity of the central bank.
Returns
E_CB: The equity of the central bank
The equity E_CB is calculated as follows:
\[E_{CB} = E_{CB} + \Pi_{CB}\]
where \Pi_{CB} are the profits of the central bank.
BeforeIT.central_bank_profits — Method
central_bank_profits(cb, model)Function to calculate the profits of a central bank.
Returns
Pi_CB: Profits of the central bank
The profits Pi_CB are calculated as follows:
\[\{Pi}_{CB} = r_{G} \cdot L_{G} - r_{bar} \cdot D_{k}\]
where
r_bar: The base interest rateD_k: Deposits from commercial banksL_G: Loans provided to the governmentr_G: Interest rate on government loans
BeforeIT.central_bank_rate — Method
central_bank_rate(cb, model)Update the base interest rate set by the central bank according to the Taylor rule.
Arguments
cb: The central bank whose base interest rate is to be updatedmodel: The model object
Returns
r_bar: The updated base interest rate
BeforeIT.finance_insolvent_firms! — Method
finance_insolvent_firms!(model)Re-finance insolvent firms using bank equity.
BeforeIT.taylor_rule — Method
taylor_rule(rho, r_bar, r_star, pi_star, xi_pi, xi_gamma, gamma_EA, pi_EA)Calculate the interest rate according to the Taylor rule.
Arguments
rho: Parameter for gradual adjustment of the policy rate.r_bar: Nominal interest rate.r_star: Real equilibrium interest rate.pi_star: The target inflation rate.xi_pi: Weight the CB puts on inflation targeting.xi_gamma: Weight placed on economic growth.gamma_EA: The output growth rate.pi_EA: The inflation rate.
Returns
rate: The calculated interest rate.
The Taylor rule is given by the following equation:
\[r_t = ρ * r_{t-1} + (1 - ρ) * (r^* + π^* + ξ_π * (π_t - π^*) + ξ_γ * γ_t)```\]
Rest Of The World actions
BeforeIT.rotw_deposits — Method
rotw_deposits(model)Calculate the deposits of the rest of the world.
Returns
D_RoW: The deposits of the rest of the world.
The deposits D_RoW are calculated as follows:
\[D_{RoW} = D_{RoW} + \left( \sum_{m} P_m \cdot Q_m \right) - (1 + \tau_{EXPORT}) \cdot C_l\]
BeforeIT.rotw_import_export — Method
rotw_import_export(model)Calculate the demand for exports and supply of imports of the rest of the world.
Returns
C_E: Total demand for exports.Y_I: Supply of imports (in real terms).C_d_l: TDemand for exports of specific product.Y_m: Supply of imports per sector.P_m: Price of imports per sector.
Markets
BeforeIT.search_and_matching_credit! — Method
search_and_matching_credit!(firms::Firms, model)This function calculates the credit allocation for each firm in the given firms object.
Parameters:
- firms::Firms: The firms object.
- model: The model object.
Returns:
- DL_i: An array of credit allocations for each firm.
BeforeIT.search_and_matching_labour! — Method
search_and_matching_labour!(firms::Firms, model)This function implements a labor search and matching algorithm. It takes in a Firms object and a Model object as input. The Firms object contains information about the number of desired employees (N_d_i) and the current number of employees (N_i) for each firm. The model object contains information about the current employment status (O_h) of each worker.
The function performs the following steps:
- Calculates the vacancies (
V_i) for each firm as the difference between desired and current employees. - Identifies employed workers and shuffles them randomly.
- Fires workers from firms with negative vacancies to adjust the workforce.
- Identifies unemployed workers and firms with positive vacancies.
- Randomly matches unemployed workers to firms with vacancies until all vacancies are filled or there are no more unemployed workers.
The function returns:
N_i: An updated array of the number of employed workers for each firm.O_h: An updated array where each element represents the firm a worker is employed with (0 if unemployed).
BeforeIT.perform_firms_market! — Method
Perform the firms market exchange process
BeforeIT.perform_retail_market! — Method
Perform the retail market exchange process
BeforeIT.search_and_matching! — Method
search_and_matching!(model; parallel::Bool = false)This function performs a search and matching algorithm for firms and for retail markets. It takes in a model object and an optional boolean argument for multi-threading. The function loops over all goods and performs the firms market and retail market operations for each good. Finally, it updates the aggregate variables based on the results of markets.
This function updates the model in-place and does not return any value.