Macroeconomics
Macroeconomics: growth, business cycles, investment, and trade.
It also holds international trade and mortal monetary economies.
BalanceSheetsInteraction(label, *, firms, banks)
Bases: Interaction
Plan and settlement of the balance sheets of the firms and the banks of the credit network.
In the plan of a step every firm requests a loan of leverage times its net worth, and every bank asks the rate
alpha * equity ** -alpha of Delli Gatti et al. (2010), so better capitalised banks lend cheaper, and offers
loans up to equity / capital_ratio. In the settlement every firm earns a normal rate of return, at least -1, on
its net worth and its loan, every bank earns the interest of its borrowers less what the defaulting ones cannot
repay, and a firm whose net worth after interest turns negative defaults and takes the net worth of an entrant.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
The label of the interaction. |
required |
firms
|
Role
|
The path of the group of firms. |
required |
banks
|
Role
|
The path of the group of banks. |
required |
Examples:
>>> from skcomplex.systems.economics.macroeconomics import BalanceSheetsInteraction
>>> BalanceSheetsInteraction('sheets', firms='firms', banks='banks').banks
'banks'
Source code in src/skcomplex/systems/economics/macroeconomics/_credit.py
257 258 259 260 | |
plan(system)
Set the loan request of every firm, and then the rate and the lending capacity of every bank.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
system
|
SystemView
|
The system view of the plan. |
required |
Source code in src/skcomplex/systems/economics/macroeconomics/_credit.py
280 281 282 283 284 285 286 287 288 289 290 291 292 293 | |
settle(system)
Draw the return of every firm, settle the banks, and replace every defaulting firm by an entrant.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
system
|
SystemView
|
The system view of the settlement. |
required |
Source code in src/skcomplex/systems/economics/macroeconomics/_credit.py
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 | |
BrockMirmanGrowthSystem(K=0.2, *, alpha=1 / 3, beta=0.95, z_low=0.9, z_high=1.1, persistence=0.9, regime=0, label='system', solver='auto', backend='auto')
Bases: BaseSystem
The Brock-Mirman economy.
It is the optimal growth of a representative agent whose productivity is Markov. A representative consumer maximises
E_0 sum_t beta^t ln C_t subject to K_{t+1} = Y_t - C_t, with full depreciation and the output
Y_t = z_t K_t^alpha of a representative firm, whose productivity z_t follows a Markov chain. The solution is the
linear consumption rule C_t = (1 - alpha beta) Y_t, C = 0.68 Y for alpha = 1/3 and beta = 0.95, so the
capital follows K_{t+1} = alpha beta z_t K_t^alpha and ln K is a stationary autoregression around
(ln(alpha beta) + E ln z) / (1 - alpha). This is the standard model that Caiani et al. (2016, Section 1.1.4, Eqs.
1.3 to 1.9) compare with an agent-based economy. The source leaves the chain open, so the productivity takes two
levels that stay with the probability persistence.
The system has the capital economy.K and the regime economy.regime. The observables of the system are
economy.productivity, economy.output, and economy.consumption.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
K
|
float
|
The initial capital. |
0.2
|
alpha
|
float
|
The capital share of the technology. |
1 / 3
|
beta
|
float
|
The discount factor of the household. |
0.95
|
z_low
|
float
|
The low productivity. |
0.9
|
z_high
|
float
|
The high productivity. |
1.1
|
persistence
|
float
|
The probability that the productivity keeps its level from one period to the next. |
0.9
|
regime
|
int
|
The initial regime, 0 for the low and 1 for the high productivity. |
0
|
label
|
str
|
The label of the system, which names it when it is nested in another one. |
'system'
|
solver
|
BaseSolver | str
|
The solver of the problem, or |
'auto'
|
backend
|
BaseBackend | str
|
The backend that evaluates the compiled functions, or |
'auto'
|
Examples:
>>> from skcomplex.systems.economics.macroeconomics import BrockMirmanGrowthSystem
>>> BrockMirmanGrowthSystem(beta=0.9).prepare().system_.elements[0].beta
0.9
Source code in src/skcomplex/systems/economics/macroeconomics/_stochastic_growth.py
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 | |
BusinessElement(label, *, money=0.0, loans=0.0, stock=0.0, wage=4.0, price=1.0, owner=-1.0, workers=1.0, vacancies=1.0, revenue=0.0, interest=0.003, repayment=0.004, adjustment=0.05, stock_limit=30.0, values=None, size=None, space=None)
Bases: Element
Firm on a patch that harvests with its workers and sells food in its shop.
It pays wages with money it borrows. Every step the workers pool their labour on the firm's patch, the firm pays
each the wage, borrowing what it lacks from the bank, and pays the interest and a share of the principal of its
loans. A firm that sold out raises its price, and one with a stock above stock_limit lowers it and lays a worker
off. Otherwise a firm posts vacancies up to the workforce that harvests the whole capacity of its patch, raises the
wage while a vacancy went unfilled, and lowers it while its sales fall short of its wage bill. Profits above twice
the wage bill go to the owner, and a firm without a living owner passes to one of its workers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
The label of the firm or the group. |
required |
money
|
Annotated[object, Quantity(money)]
|
The money the firm holds. |
0.0
|
loans
|
Annotated[object, Quantity(credit)]
|
The loans of the firm, negative for its debt. |
0.0
|
stock
|
Annotated[object, closed_open(0, oo)]
|
The food in the shop. |
0.0
|
wage
|
Annotated[object, closed_open(0, oo)]
|
The wage of a worker. |
4.0
|
price
|
Annotated[object, open(0, oo)]
|
The price of a unit of food. |
1.0
|
owner
|
Annotated[object, Member(people)]
|
The owner among the people, or -1. |
-1.0
|
workers
|
Annotated[object, NN]
|
The number of workers in the step. |
1.0
|
vacancies
|
Annotated[object, NN]
|
The open vacancies. |
1.0
|
revenue
|
Annotated[object, closed_open(0, oo)]
|
The sales of the step. |
0.0
|
interest
|
Annotated[object, closed_open(0, oo)]
|
The interest rate of loans per step. |
0.003
|
repayment
|
Annotated[object, closed_open(0, oo)]
|
The share of the principal repaid per step. |
0.004
|
adjustment
|
Annotated[object, closed_open(0, oo)]
|
The relative step of a change of price or wage. |
0.05
|
stock_limit
|
Annotated[object, closed_open(0, oo)]
|
The stock above which the firm lowers its price and lays off. |
30.0
|
values
|
Mapping[str, object] | None
|
Further values by name, such as the cells |
None
|
size
|
int | None
|
The number of firms, or |
None
|
space
|
BaseSpace | None
|
The land the firms live on, whose axes |
None
|
Examples:
>>> from skcomplex.systems.economics.macroeconomics import BusinessElement
>>> BusinessElement('businesses', size=2).size
2
Source code in src/skcomplex/systems/economics/macroeconomics/_metaphoria.py
605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 | |
CapitalStockSystem(capital=100.0, *, investment_fraction=0.2, output_per_capital=1 / 3, lifetime=15.0, label='system', solver='auto', backend='auto')
Bases: DynamicalSystem
Meadows' capital stock, grown by reinvested output and drained by depreciation.
The stock follows dK/dt = investment_fraction * output_per_capital * K - K / lifetime. It grows exponentially when
the capital lives longer than 1 / (investment_fraction * output_per_capital), declines when it lives shorter, and
stays in dynamic equilibrium otherwise. The system has the capital stock economy.K.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
capital
|
float
|
The initial capital stock. |
100.0
|
investment_fraction
|
float
|
The fraction of the output that is reinvested. |
0.2
|
output_per_capital
|
float
|
The annual output per unit of capital. |
1 / 3
|
lifetime
|
float
|
The average lifetime of the capital. |
15.0
|
label
|
str
|
The label of the system, which names it when it is nested in another one. |
'system'
|
solver
|
BaseSolver | str
|
The solver of the problem, or |
'auto'
|
backend
|
BaseBackend | str
|
The backend that evaluates the compiled functions, or |
'auto'
|
Examples:
>>> from skcomplex.systems.economics.macroeconomics import CapitalStockSystem
>>> CapitalStockSystem(lifetime=20.0).prepare().system_.elements[0].values['lifetime']
20.0
Source code in src/skcomplex/systems/economics/macroeconomics/_capital.py
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | |
CategorizedPurchasingPowerSystem(policy=(0.0, 0.0, 1.0), policy_time=(1.0, 1.0, 1.0), *, feedback=True, A=A_MATRIX, B=B_MATRIX, C=C_MATRIX, D=D_MATRIX, label='system', solver='auto', backend='auto')
Bases: BaseSystem
Forrest's categorized purchasing power of money.
Its three sectors can be steered one by one by feedback. The economy is split into the sectors of the basic, the
desired, and the luxurious living conditions, with the gaps z_i = D_i - S_i between the demand and the supply of
money of each, which the categorized monetary and fiscal policies x_i move through z' = A z + B x, and the
indices of the sectors y = C z + D x, from the zero state (Forrest 2018, Eqs. 22.6 and 22.7). The policies of one
sector act on all of them. By Theorem 11.3 and Example 11.2 the system can be decoupled by feedback into the systems
w' = A w + B_i x_i and y_i = C_i w + D_i x_i of the sectors (Eqs. 22.9 to 22.12), whose market reactions keep
each index on its own policy, so money poured into the luxury sector leaves the basic sector alone. The source gives
no numbers, so the matrices are illustrative, with a stable A and a stable A - B D^-1 C, and the policies are
steps.
The system has the gaps economy.z1 to economy.z3 and, with feedback, the decoupled states economy.w11 to
economy.w33. The observables of the system are the indices economy.y1 to economy.y3 and the inputs of the
economy economy.u1 to economy.u3.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
policy
|
Sequence[float]
|
The size of the step policy of every sector. |
(0.0, 0.0, 1.0)
|
policy_time
|
Sequence[float]
|
The time of the step policy of every sector. |
(1.0, 1.0, 1.0)
|
feedback
|
bool
|
Whether the feedback component decouples the sectors. |
True
|
A
|
Sequence[Sequence[float]]
|
The matrix of the state. |
A_MATRIX
|
B
|
Sequence[Sequence[float]]
|
The matrix of the policies in the state. |
B_MATRIX
|
C
|
Sequence[Sequence[float]]
|
The matrix of the state in the indices. |
C_MATRIX
|
D
|
Sequence[Sequence[float]]
|
The nonsingular matrix of the policies in the indices. |
D_MATRIX
|
label
|
str
|
The label of the system, which names it when it is nested in another one. |
'system'
|
solver
|
BaseSolver | str
|
The solver of the problem, or |
'auto'
|
backend
|
BaseBackend | str
|
The backend that evaluates the compiled functions, or |
'auto'
|
Examples:
>>> from skcomplex.systems.economics.macroeconomics import CategorizedPurchasingPowerSystem
>>> CategorizedPurchasingPowerSystem(feedback=False).prepare().system_.interactions[0].feedback
False
Source code in src/skcomplex/systems/economics/macroeconomics/_purchasing_power.py
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 | |
CentralBankElement(label, *, money=0.0, loans=0.0, values=None, size=None, space=None)
Bases: Element
Bank that creates money as loans.
The transfer dividends of the system pays the income to a random person, or to a random firm when nobody lives.
The money it issued, a negative holding, and the loans it holds sum to zero after every step, so every unit of money in the economy is matched by a loan.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
The label of the bank or the group. |
required |
money
|
Annotated[object, Quantity(money)]
|
The money of the bank, the negative of the money it issued plus its income of the step. |
0.0
|
loans
|
Annotated[object, Quantity(credit)]
|
The loans the bank holds. |
0.0
|
values
|
Mapping[str, object] | None
|
Further values by name, such as the cells |
None
|
size
|
int | None
|
The number of banks, or |
None
|
space
|
BaseSpace | None
|
The land the banks live on, whose axes |
None
|
Examples:
>>> from skcomplex.systems.economics.macroeconomics import CentralBankElement
>>> CentralBankElement('bank', size=1).size
1
Source code in src/skcomplex/systems/economics/macroeconomics/_metaphoria.py
106 107 108 109 110 111 112 113 114 115 116 117 118 | |
CircuitInteraction(label, *, households, firms, bank)
Bases: Interaction
Circuit of money between households, firms, and a bank, one period per step.
The flows of a period between the deposits of the sectors are consumption, wages, interest, dividends, and profits, lending from the environment, and repayments to it, each reading the parameters of the sectors. Every flow is labelled, so the trajectory records it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
The label of the circuit. |
required |
households
|
Role
|
The path of the households. |
required |
firms
|
Role
|
The path of the firms. |
required |
bank
|
Role
|
The path of the bank. |
required |
Examples:
>>> from skcomplex.systems.economics.macroeconomics import CircuitInteraction
>>> CircuitInteraction('circuit', households='households', firms='firms', bank='bank').bank
'bank'
Source code in src/skcomplex/systems/economics/macroeconomics/_monetary.py
185 186 187 188 189 | |
CommonsInteraction(label, *, people)
Bases: Interaction
Harvest of the hunter-gatherers.
The adults of a patch harvest min(food, labour - resistance), and everyone on the patch, child or adult, gets an
equal share.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
The label of the interaction. |
required |
people
|
Role
|
The path of the group of people. |
required |
Examples:
>>> from skcomplex.systems.economics.macroeconomics import CommonsInteraction
>>> CommonsInteraction('commons', people='people').people
'people'
Source code in src/skcomplex/systems/economics/macroeconomics/_metaphoria.py
793 794 795 796 797 798 799 800 | |
harvest(system)
Harvest every occupied patch and share the food among the people on it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
system
|
SystemView
|
The system view of the interaction. |
required |
Source code in src/skcomplex/systems/economics/macroeconomics/_metaphoria.py
812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 | |
CreditMarketInteraction(label, *, requesters, providers, rule=RandomSearchSpec(), reserve='reserve', quantity='quantity', cap='cap', transfers=(), phase=None, on_match=None)
Bases: MatchingInteraction[SystemView]
Credit market that also reports the spread of the rates firms pay.
The spread is over the cheapest bank's rate. The firms request loans and the banks provide them. The spread is the
mean of r_i / r_min - 1 over the borrowing firms, the dispersion of rates that a market with costly search leaves
and that switching to cheaper lenders erodes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
The label of the market. |
required |
requesters
|
Role
|
The path of the group of firms. |
required |
providers
|
Role
|
The path of the group of banks. |
required |
rule
|
MatchingRule | Pairing
|
The spec of the algorithm that matches firms with banks, such as |
RandomSearchSpec()
|
reserve
|
str | tuple[str, str]
|
The state with the rate of both sides, or a pair of the firms' and the banks' states. |
'reserve'
|
quantity
|
str | tuple[str, str]
|
The state with the loan of both sides, or a pair of the firms' and the banks' states. |
'quantity'
|
cap
|
str
|
The state of a firm with what it can spend. |
'cap'
|
transfers
|
Sequence[tuple[str, int]]
|
The states every loan moves, each with the sign |
()
|
phase
|
str | None
|
The phase the market clears in, or |
None
|
on_match
|
Callable[[MatchSpec, SystemT], None] | None
|
A function of every loan and the system view, run after the transfers, or |
None
|
Examples:
>>> from skcomplex.systems.economics.macroeconomics import CreditMarketInteraction
>>> CreditMarketInteraction('credit', requesters='firms', providers='banks').reports[-1]
'spread'
Source code in src/skcomplex/systems/general/matching/_matching.py
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 | |
CreditNetworksSystem(firms=100, banks=10, *, sample=3, intensity=4.0, leverage=1.0, mean_return=0.03, volatility=0.3, net_worth=10.0, equity=100.0, alpha=0.1, capital_ratio=0.1, random_state=0, label='system', solver='auto', backend='auto')
Bases: BaseSystem
A credit market where firms sample banks and switch to cheaper lenders.
Defaults hit the lenders. Every step the banks quote rates that fall with their equity, every firm samples sample
banks and switches from its lender to the cheapest of them with probability
1 - exp(intensity * (r_new - r_old) / r_new), borrows, and invests at a random return. Interest and write-offs of
defaulted firms move net worth between firms and banks, so the total net worth changes only by the firms' returns
and the entrants' net worth. A higher intensity of switching concentrates the loans in the cheapest banks and
narrows the spread of the rates that firms pay.
The system has the groups firms and banks, the market credit with its reporter credit.spread, and the
observables herfindahl, largest_share, bank_equity, firm_worth, returns, injected, defaults, and
bad_debt.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
firms
|
int
|
The number of firms. |
100
|
banks
|
int
|
The number of banks. |
10
|
sample
|
int
|
The number of banks every firm samples. |
3
|
intensity
|
float
|
The intensity of switching to a cheaper bank. |
4.0
|
leverage
|
float
|
The ratio of the loan a firm wants to its net worth. |
1.0
|
mean_return
|
float
|
The mean return on capital. |
0.03
|
volatility
|
float
|
The standard deviation of the return on capital. |
0.3
|
net_worth
|
float
|
The initial net worth of every firm and of every entrant. |
10.0
|
equity
|
float
|
The mean initial equity of the banks, drawn uniformly within 50% of it. |
100.0
|
alpha
|
float
|
The elasticity of the interest rate to the equity. |
0.1
|
capital_ratio
|
float
|
The smallest ratio of a bank's equity to its loans. |
0.1
|
random_state
|
int | Generator | None
|
The seed or generator of the initial equities. |
0
|
label
|
str
|
The label of the system, which names it when it is nested in another one. |
'system'
|
solver
|
BaseSolver | str
|
The solver of the problem, or |
'auto'
|
backend
|
BaseBackend | str
|
The backend that evaluates the compiled functions, or |
'auto'
|
Examples:
>>> from skcomplex.systems.economics.macroeconomics import CreditNetworksSystem
>>> [element.label for element in CreditNetworksSystem().prepare().system_.elements]
['firms', 'banks']
Source code in src/skcomplex/systems/economics/macroeconomics/_credit.py
492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 | |
DepositorElement(label, *, bank=-1, deposit=10.0, loan=0.0, spending=0.1, repayment=0.05, size=None)
Bases: Element
Customer of a bank, with a deposit at the bank and a loan from it.
Its value bank names the bank among the banks. The system pays a share of the deposit to a random customer, which
moves deposits and as many reserves from the payer's bank to the payee's bank, and repays a share of the loan from
the deposit, which cancels as much deposit and loan at the customer's bank and destroys broad money.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
The label of the agent or group. |
required |
bank
|
Annotated[object, Member(banks)]
|
The index of the customer's bank among the banks, or -1 for none. |
-1
|
deposit
|
Annotated[object, closed_open(0, oo)]
|
The deposit at the bank. |
10.0
|
loan
|
Annotated[object, closed_open(0, oo)]
|
The loan owed to the bank. |
0.0
|
spending
|
Annotated[object, closed_open(0, oo)]
|
The share of the deposit paid to a random customer every step. |
0.1
|
repayment
|
Annotated[object, closed_open(0, oo)]
|
The share of the loan repaid every step. |
0.05
|
size
|
int | None
|
The number of customers, or |
None
|
Examples:
>>> from skcomplex.systems.economics.macroeconomics import DepositorElement
>>> DepositorElement('customers', deposit=5.0, size=10).size
10
Source code in src/skcomplex/systems/economics/macroeconomics/_banking.py
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 | |
EconomyElement(label, *, k=1.0)
Bases: Element
Economy described by its capital per worker.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
The label of the economy. |
required |
k
|
Annotated[float, closed_open(0, oo)]
|
The initial capital per worker. |
1.0
|
Examples:
>>> from skcomplex.systems.economics.macroeconomics import EconomyElement
>>> EconomyElement('country', k=1.0).k
1.0
Source code in src/skcomplex/systems/economics/macroeconomics/_growth.py
41 42 43 44 45 46 47 48 | |
EstateInteraction(label, *, people)
Bases: Interaction
Settlement of the estates of the dead, with a census of the step.
The dead leave their money and loans to an heir. The money and the loans of a dead person go to a random living
person of its patch, or of anywhere. When nobody lives to inherit them, the dead person stays as an estate that
holds them. The reporters births, starvations, and old_age count the events of a step.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
The label of the interaction. |
required |
people
|
Role
|
The path of the group of people. |
required |
Examples:
>>> from skcomplex.systems.economics.macroeconomics import EstateInteraction
>>> EstateInteraction('census', people='people').reports
('births', 'starvations', 'old_age')
Source code in src/skcomplex/systems/economics/macroeconomics/_metaphoria.py
858 859 860 861 862 863 864 865 | |
count(system)
Count the births and deaths of the step and remove the dead.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
system
|
SystemView
|
The system view of the interaction. |
required |
Source code in src/skcomplex/systems/economics/macroeconomics/_metaphoria.py
880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 | |
ExchangeRatesSystem(exports=32.0, imports=34.0, *, home_price=1.2, inflation=0.1, export_elasticity=-1.0, import_elasticity=-1.0, floating=True, demand=52.0, government=50.0, world_price=1.0, label='system', solver='auto', backend='auto')
Bases: BaseSystem
Hamill and Gilbert's staged adjustment of trade and the exchange rate.
The adjustment follows a rise in home prices. The economy starts in balance at the exchange rate
E = M * PW / (X * PH), in units of World currency per unit of Home currency, with the export and import volumes
and prices of the United Kingdom in 1999 by default. Home prices rise by inflation at the first stage. At every
stage a floating rate takes the value that balances the currency market at the current volumes, a fixed rate stays,
and the volumes respond to the prices of the stage before with constant price elasticities. The book follows two
stages, the default.
The system has the economy home, the balance of trade at home prices balance, the real exchange rate
real_rate, and the output output.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
exports
|
float
|
The initial export volume. |
32.0
|
imports
|
float
|
The initial import volume. |
34.0
|
home_price
|
float
|
The home price of home-produced goods before the rise. |
1.2
|
inflation
|
float
|
The relative rise of the home prices. |
0.1
|
export_elasticity
|
float
|
The price elasticity of the exports. |
-1.0
|
import_elasticity
|
float
|
The price elasticity of the imports. |
-1.0
|
floating
|
bool
|
Whether the exchange rate floats, or is fixed as in the Eurozone. |
True
|
demand
|
float
|
The private domestic demand, consumption and investment. |
52.0
|
government
|
float
|
The government spending. |
50.0
|
world_price
|
float
|
The world price level. |
1.0
|
label
|
str
|
The label of the system, which names it when it is nested in another one. |
'system'
|
solver
|
BaseSolver | str
|
The solver of the problem, or |
'auto'
|
backend
|
BaseBackend | str
|
The backend that evaluates the compiled functions, or |
'auto'
|
Examples:
>>> from skcomplex.systems.economics.macroeconomics import ExchangeRatesSystem
>>> round(ExchangeRatesSystem().prepare().system_.elements[0].E, 3)
0.885
Source code in src/skcomplex/systems/economics/macroeconomics/_trade.py
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 | |
FirmElement(label, *, net_worth=10.0, demand=0.0, bid=1.0, loan=0.0, rate=0.0, partner=-1, gross_return=0.0, injected=0.0, defaulted=0, leverage=1.0, mean_return=0.03, volatility=0.3, entry=10.0, size=None)
Bases: Element
Firm that borrows in proportion to its net worth and invests.
It invests at a random return, and defaults on negative worth. Every step the firm asks for leverage times its net
worth from its bank, invests its net worth and the loan at the return mean_return + volatility * z, and pays the
interest. When its net worth becomes negative it repays what it can, the bank writes off the rest, and a new firm
with the net worth entry replaces it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
The label of the agent or group. |
required |
net_worth
|
Annotated[object, closed_open(0, oo)]
|
The initial net worth. |
10.0
|
demand
|
Annotated[object, closed_open(0, oo)]
|
The loan still wanted in the current step. |
0.0
|
bid
|
Annotated[object, closed_open(0, oo)]
|
The highest interest rate the firm pays. |
1.0
|
loan
|
Annotated[object, closed_open(0, oo)]
|
The loan of the current step. |
0.0
|
rate
|
Annotated[object, closed_open(0, oo)]
|
The interest rate of the loan, zero without a loan. |
0.0
|
partner
|
Annotated[object, Member(banks)]
|
The bank of the firm among the banks, |
-1
|
gross_return
|
object
|
The return on the capital of the last step. |
0.0
|
injected
|
Annotated[object, closed_open(0, oo)]
|
The net worth of an entrant that replaced the firm in the last step, zero otherwise. |
0.0
|
defaulted
|
Annotated[object, FiniteEnumeratedSet([0, 1])]
|
Whether the firm defaulted in the last step. |
0
|
leverage
|
Annotated[object, closed_open(0, oo)]
|
The ratio of the loan wanted to the net worth. |
1.0
|
mean_return
|
object
|
The mean return on capital. |
0.03
|
volatility
|
Annotated[object, closed_open(0, oo)]
|
The standard deviation of the return on capital. |
0.3
|
entry
|
Annotated[object, open(0, oo)]
|
The net worth of an entrant. |
10.0
|
size
|
int | None
|
The number of firms, or |
None
|
Examples:
>>> from skcomplex.systems.economics.macroeconomics import FirmElement
>>> FirmElement('firms', net_worth=5.0, size=10).size
10
Source code in src/skcomplex/systems/economics/macroeconomics/_credit.py
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 | |
FirmsElement(label, *, deposits=20.0, loans=50.0, sales=40.0, wage_share=0.7, distribution=0.3, repayment=0.08)
Bases: Element
Firms sector, with its deposits, its loans, and the sales of the last period.
It pays wages and profits.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
The label of the sector. |
required |
deposits
|
Annotated[object, closed_open(0, oo), Quantity(money)]
|
The deposits of the firms, which are money. |
20.0
|
loans
|
Annotated[object, closed_open(0, oo)]
|
The loans of the firms. |
50.0
|
sales
|
Annotated[object, closed_open(0, oo)]
|
The sales of the last period. |
40.0
|
wage_share
|
Annotated[float, closed_open(0, oo)]
|
The share of sales paid as wages. |
0.7
|
distribution
|
Annotated[float, closed_open(0, oo)]
|
The share of the firms' deposits distributed as profits per period. |
0.3
|
repayment
|
Annotated[float, closed_open(0, oo)]
|
The share of loans repaid per period. |
0.08
|
Examples:
>>> from skcomplex.systems.economics.macroeconomics import FirmsElement
>>> FirmsElement('firms').loans
50.0
Source code in src/skcomplex/systems/economics/macroeconomics/_monetary.py
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | |
FoodMarketInteraction(label, *, requesters, providers, rule=RandomSearchSpec(), reserve='reserve', quantity='quantity', cap='cap', transfers=(), phase=None, on_match=None)
Bases: MatchingInteraction[SystemView]
Food market in which people short of food buy from the cheapest shop in sight.
They buy in random order, from stocked shops. A matching of the people, who request their shortfall of food for
reserve steps within the budget of their money, with the firms, which provide their stock at their price. The
market reads the shortfall of a person as reserve * need - food, and a purchase lowers it by raising the food.
Every purchase moves the money to the firm, which books it as revenue, and the food to the buyer. Build it with
PartnerMatchingSpec(sight, 'score', score=FoodMarketInteraction.score, value='provider'), whose score prefers the
lowest price. Besides the reporters of a matching, the reporter gdp sums the value of the sales of a step.
Examples:
>>> from skcomplex.core.components.laws import PartnerSpec
>>> from skcomplex.systems.economics.macroeconomics import FoodMarketInteraction
>>> rule = PartnerMatchingSpec(5.0, 'score', score=FoodMarketInteraction.score, value='provider')
>>> FoodMarketInteraction('shops', requesters='people', providers='businesses', rule=rule).reports[-1]
'gdp'
Source code in src/skcomplex/systems/general/matching/_matching.py
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 | |
score(person, firm)
staticmethod
Return the score of a firm for a person, higher for a lower price.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
person
|
object
|
The person that buys. |
required |
firm
|
object
|
The firm that sells. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
score |
float
|
Minus the price of the firm. |
Source code in src/skcomplex/systems/economics/macroeconomics/_metaphoria.py
927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 | |
sell(match, system)
staticmethod
Book the value of a sale as revenue of the firm.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
match
|
MatchSpec
|
The match of a buyer with a firm. |
required |
system
|
SystemView
|
The system view of the market. |
required |
Source code in src/skcomplex/systems/economics/macroeconomics/_metaphoria.py
945 946 947 948 949 950 951 952 953 954 955 956 957 958 | |
FractionalReserveBankingSystem(customers=100, banks=5, *, base_money=1000.0, ratio=0.1, new_ratio=None, change_at=150.0, spending=0.1, repayment=0.05, random_state=0, label='system', solver='auto', backend='auto')
Bases: BaseSystem
Customers and banks whose lending of excess reserves multiplies the base money.
The multiplier is 1 / ratio. The base money starts as equal deposits of the customers, held as reserves by their
banks, picked at random. Every step the customers pay a share of their deposits to random customers and repay a
share of their loans from their deposits, and every bank lends its reserves above the required share of its
deposits. The loans are spent and redeposited at random banks. The reserves stay equal to the base money, so the
broad money, the sum of deposits, settles near base_money / ratio. A regulator changes the reserve ratio to
new_ratio at change_at, and the broad money moves to the new multiplier.
The system has the groups customers and banks, the institution regulator, and the observables broad_money,
reserves, loans, and reserve_ratio.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
customers
|
int
|
The number of customers. |
100
|
banks
|
int
|
The number of banks. |
5
|
base_money
|
float
|
The base money, deposited by the customers in equal shares. |
1000.0
|
ratio
|
float
|
The reserve ratio. |
0.1
|
new_ratio
|
float | None
|
The reserve ratio from |
None
|
change_at
|
float
|
The time the reserve ratio changes. |
150.0
|
spending
|
float
|
The share of its deposit a customer pays to a random customer every step. |
0.1
|
repayment
|
float
|
The share of its loan a customer repays every step. |
0.05
|
random_state
|
int | Generator | None
|
The seed or generator of the customers' banks. |
0
|
label
|
str
|
The label of the system, which names it when it is nested in another one. |
'system'
|
solver
|
BaseSolver | str
|
The solver of the problem, or |
'auto'
|
backend
|
BaseBackend | str
|
The backend that evaluates the compiled functions, or |
'auto'
|
Examples:
>>> from skcomplex.systems.economics.macroeconomics import FractionalReserveBankingSystem
>>> FractionalReserveBankingSystem(new_ratio=0.2).prepare().system_.interactions[0].new_ratio
0.2
Source code in src/skcomplex/systems/economics/macroeconomics/_banking.py
470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 | |
HerdingAgentElement(label, *, c=0.0, x=1.0, gamma=1.0, sigma=0.0, size=None)
Bases: Element
Agent whose choice c is a weighted sum of the past choices of others.
It adds its individual characteristic.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
The label of the agent or group. |
required |
c
|
object
|
The choice of the agent, such as its consumption. |
0.0
|
x
|
object
|
The mean of the individual characteristic of the agent. |
1.0
|
gamma
|
object
|
The weight |
1.0
|
sigma
|
object
|
The standard deviation of the shocks of the individual characteristic. |
0.0
|
size
|
int | None
|
The number of members, or |
None
|
Examples:
>>> from skcomplex.systems.economics.macroeconomics import HerdingAgentElement
>>> HerdingAgentElement('agents', x=[1.0, 2.0, 3.0], size=3).size
3
Source code in src/skcomplex/systems/economics/macroeconomics/_herding.py
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | |
HerdingInteraction(label, *, target, weights=())
Bases: Interaction
Herding of agents on the past choices of the agents they are linked to.
The next choice of agent i is c_i = sum_j theta_ij c_j + gamma (x_i + sigma eps_i), the past choices of the
others weighted by the links theta, plus gamma times its individual characteristic shocked by a standard normal
eps_i.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
The label of the interaction. |
required |
target
|
Role
|
The path of the group of agents. |
required |
weights
|
tuple[tuple[float, ...], ...]
|
The weight |
()
|
Examples:
>>> from skcomplex.systems.economics.macroeconomics import HerdingInteraction
>>> HerdingInteraction('herding', target='agents', weights=((0.0, 0.5), (0.5, 0.0))).weights
((0.0, 0.5), (0.5, 0.0))
Source code in src/skcomplex/systems/economics/macroeconomics/_herding.py
97 98 99 100 | |
HouseholdsElement(label, *, deposits=60.0, alpha_income=0.6, alpha_wealth=0.4)
Bases: Element
Households sector, whose deposits are money.
It consumes out of its wages and its deposits.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
The label of the sector. |
required |
deposits
|
Annotated[object, closed_open(0, oo), Quantity(money)]
|
The deposits of the households. |
60.0
|
alpha_income
|
Annotated[float, closed_open(0, oo)]
|
The propensity to consume out of wages. |
0.6
|
alpha_wealth
|
Annotated[float, closed_open(0, oo)]
|
The propensity to consume out of deposits. |
0.4
|
Examples:
>>> from skcomplex.systems.economics.macroeconomics import HouseholdsElement
>>> HouseholdsElement('households').deposits
60.0
Source code in src/skcomplex/systems/economics/macroeconomics/_monetary.py
100 101 102 103 104 105 106 107 108 109 110 111 | |
InvestingFirmElement(label, *, A=1.0, K=1.0, Z=0.0, B=0.0, Y=0.0, P=0.0, gamma=1.1, phi=0.1, r=0.1, pbar=0.01, size=None)
Bases: Element
Firm of the toy business-cycle system.
It invests a share of its last profit and sells at a random price. Every period the firm invests I = gamma * Z,
accumulates capital K = K + I, produces Y = phi * K, borrows B = max(K - A, 0), sells at the price
P = pbar + 2 U(0, 1), earns Z = P * Y - r * K, and adds the profit to its net worth A. A firm whose net worth
turns negative is replaced by an entrant with A = K = 1 and Z = 0.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
The label of the agent or group. |
required |
A
|
object
|
The initial net worth. |
1.0
|
K
|
Annotated[object, closed_open(0, oo)]
|
The initial capital. |
1.0
|
Z
|
object
|
The initial profit. |
0.0
|
B
|
Annotated[object, closed_open(0, oo)]
|
The initial debt. |
0.0
|
Y
|
Annotated[object, closed_open(0, oo)]
|
The initial production. |
0.0
|
P
|
Annotated[object, closed_open(0, oo)]
|
The initial price. |
0.0
|
gamma
|
Annotated[object, open(0, oo)]
|
The investment accelerator. |
1.1
|
phi
|
Annotated[object, open(0, oo)]
|
The productivity of capital. |
0.1
|
r
|
Annotated[object, open(0, oo)]
|
The interest rate. |
0.1
|
pbar
|
Annotated[object, closed_open(0, oo)]
|
The constant part of the price. |
0.01
|
size
|
int | None
|
The number of members, or |
None
|
Examples:
>>> from skcomplex.systems.economics.macroeconomics import InvestingFirmElement
>>> InvestingFirmElement('firms', gamma=1.2, size=10).size
10
Source code in src/skcomplex/systems/economics/macroeconomics/_firms.py
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 | |
InvestmentInteraction(label, *, target)
Bases: Interaction
Investment rule of the firms of the toy business-cycle system.
Every period a firm invests I = gamma * Z, accumulates capital K = K + I, produces Y = phi * K, borrows
B = max(K - A, 0), sells at the random price P = pbar + 2 U(0, 1), earns Z = P * Y - r * K, and adds the
profit to its net worth A. A firm whose net worth turns negative is replaced by an entrant with A = K = 1 and
Z = 0.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
The label of the interaction. |
required |
target
|
Role
|
The path of the group of firms. |
required |
Examples:
>>> from skcomplex.systems.economics.macroeconomics import InvestmentInteraction
>>> InvestmentInteraction('investment', target='firms').target
'firms'
Source code in src/skcomplex/systems/economics/macroeconomics/_firms.py
147 148 149 | |
invest(agent, system)
Run one period of a firm, and replace it by an entrant when its net worth turns negative.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
agent
|
InvestingFirmView
|
The firm. |
required |
system
|
SystemView
|
The system view of the rule. |
required |
Source code in src/skcomplex/systems/economics/macroeconomics/_firms.py
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 | |
LabourMarketInteraction(label, *, requesters, providers, rule=RandomSearchSpec(), reserve='reserve', quantity='quantity', cap='cap', transfers=(), phase=None, on_match=None)
Bases: MatchingInteraction[SystemView]
Labour market in which unemployed adults take the best-paying vacancy in sight.
They take it in random order. A matching of the people, who request a job, with the firms, which provide their
vacancies: a person whose hireable limit admits a job takes the firm of the highest wage within its sight that
still has a vacancy, and moves to it. The market reads the hireable limit of a person as unlimited for an
unemployed adult and as none otherwise. Build it with
PartnerMatchingSpec(sight, 'score', score=LabourMarketInteraction.score, value='provider').
Examples:
>>> from skcomplex.core.components.laws import PartnerSpec
>>> from skcomplex.systems.economics.macroeconomics import LabourMarketInteraction
>>> LabourMarketInteraction(
... 'jobs',
... requesters='people',
... providers='businesses',
... rule=PartnerMatchingSpec(5.0, 'score', score=LabourMarketInteraction.score, value='provider'),
... reserve=('hireable', 'reserve'),
... quantity=('quantity', 'vacancies'),
... on_match=LabourMarketInteraction.hire,
... ).providers
'businesses'
Source code in src/skcomplex/systems/general/matching/_matching.py
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 | |
hire(match, system)
staticmethod
Employ a matched person at its firm and move it there.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
match
|
MatchSpec
|
The match of a person with a firm. |
required |
system
|
SystemView
|
The system view of the market. |
required |
Source code in src/skcomplex/systems/economics/macroeconomics/_metaphoria.py
1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 | |
score(person, firm)
staticmethod
Return the wage of a firm, the score by which a person prefers it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
person
|
object
|
The person who seeks a job. |
required |
firm
|
object
|
The firm with a vacancy. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
score |
float
|
The wage of the firm. |
Source code in src/skcomplex/systems/economics/macroeconomics/_metaphoria.py
1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 | |
LenderElement(label, *, equity=100.0, ask=0.0, supply=0.0, lent=0.0, losses=0.0, alpha=0.1, capital_ratio=0.1, size=None)
Bases: Element
Bank that lends up to a multiple of its equity.
Its rate falls with its equity. The bank asks the rate alpha * equity ** -alpha of Delli Gatti et al. (2010), so
better capitalised banks lend cheaper, and it offers loans up to equity / capital_ratio. The interest and
the defaults of the firms reach the bank they name in their value partner, by the rules of
BalanceSheetsInteraction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
The label of the agent or group. |
required |
equity
|
object
|
The initial equity. |
100.0
|
ask
|
Annotated[object, closed_open(0, oo)]
|
The interest rate the bank asks. |
0.0
|
supply
|
Annotated[object, closed_open(0, oo)]
|
The loans the bank can still grant in the current step. |
0.0
|
lent
|
Annotated[object, closed_open(0, oo)]
|
The loans granted in the current step. |
0.0
|
losses
|
Annotated[object, closed_open(0, oo)]
|
The loans written off in the current step. |
0.0
|
alpha
|
Annotated[object, open(0, oo)]
|
The elasticity of the interest rate to the equity. |
0.1
|
capital_ratio
|
Annotated[object, open(0, oo)]
|
The smallest ratio of equity to loans. |
0.1
|
size
|
int | None
|
The number of banks, or |
None
|
Examples:
>>> from skcomplex.systems.economics.macroeconomics import LenderElement
>>> LenderElement('banks', equity=100.0, size=5).size
5
Source code in src/skcomplex/systems/economics/macroeconomics/_credit.py
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 | |
LendingInteraction(label, *, target='banks', customers='customers', phase=None)
Bases: Interaction
Banks that lend their excess reserves to one of their customers.
The excess reserves are those beyond the required share of a bank's deposits. The borrower spends the loan at once,
and the payee, a random customer, deposits it at its own bank, whose reserves and deposits grow by the loan. The
customers of a bank are those whose value bank names it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
The label of the interaction. |
required |
target
|
Role
|
The banks that lend. |
'banks'
|
customers
|
Role
|
The customers who borrow and are paid. |
'customers'
|
phase
|
str | None
|
The phase the banks lend in, or |
None
|
Examples:
>>> from skcomplex.systems.economics.macroeconomics import LendingInteraction
>>> LendingInteraction('lending', phase='lend').phase
'lend'
Source code in src/skcomplex/systems/economics/macroeconomics/_banking.py
287 288 289 290 291 292 293 294 295 296 297 298 | |
lend(agent, system)
Lend the excess reserves to a random customer.
The payment is redeposited at a random customer's bank.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
agent
|
ReserveBankView
|
The bank. |
required |
system
|
SystemView
|
The system. |
required |
Source code in src/skcomplex/systems/economics/macroeconomics/_banking.py
310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 | |
LivingInteraction(label, *, target='people', phase=None)
Bases: Interaction
Life of every person: ageing, eating, dying, having children, and moving or working.
It is the rule of SettlerElement in the phase of living, run by each person in turn.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
The label of the interaction. |
required |
target
|
Role
|
The people who live. |
'people'
|
phase
|
str | None
|
The phase the people live in, or |
None
|
Examples:
>>> from skcomplex.systems.economics.macroeconomics import LivingInteraction
>>> LivingInteraction('living', phase='living').phase
'living'
Source code in src/skcomplex/systems/economics/macroeconomics/_metaphoria.py
451 452 453 454 | |
live(agent, system)
Age, eat, die, have children, and move or work.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
agent
|
SettlerView
|
The person. |
required |
system
|
SystemView
|
The system. |
required |
Source code in src/skcomplex/systems/economics/macroeconomics/_metaphoria.py
507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 | |
Mark0EconomyInteraction(label, *, rule=None, phase=None, firms, c0=0.5, beta=2.0, gamma=0.01, eta_minus=0.2, ratio=2.0, delta=0.02, theta=3.0, phi=0.1, zeta=1.0, omega=0.2, f=0.5, shock_time=100.0, shock_length=0.0, dc=0.0, dzeta=0.0, kappa=1.0, offset=1.25, credit='none')
Bases: PolicyRuleInteraction[SystemView]
Representative household and bank of the Mark-0 economy.
They run the firms through one month every step. Every step the firms adjust their workforce, prices, and wages by
the rules of thumb of Mark-0 (Eqs. 11 to 17 of Sharma et al. 2020) from the demand and the profit of the last month,
pay their wages, and sell to the household, whose consumption budget c (S + W + rho_d S) (Eq. 5) splits among the
firms by the logit demand of their prices relative to the mean price (Eq. 9). Firms pay interest and, when
profitable with positive cash, a share delta of their cash as dividends (Eqs. 18 and 19). A firm whose debt to
payroll Phi = -E / (W N) reaches the bankruptcy threshold Theta defaults, its debt falls on the bank, which
moves the loan and deposit rates (Eqs. 21 and 22), and a bankrupt firm is revived with probability phi per month
at the mean price and wage. Following the simplifications of the source, inflation expectations, the feedback of
inflation on consumption, the effect of fragility on hiring, and the central bank are switched off, so the base rate
is zero.
During the shock, from shock_time for shock_length months, the productivity falls by the share dzeta and the
consumption propensity by the share dc. The credit policy 'naive' lifts the threshold during the shock and
restores it at once after it, and 'adaptive' restores it to max(offset <Phi>, Theta) with the
production-weighted mean fragility <Phi> (Eq. 24). At the end of the shock the household's savings are multiplied
by kappa, the helicopter money.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
The label of the economy. |
required |
rule
|
None
|
Unused, since the economy overrides |
None
|
phase
|
str | None
|
The phase the economy acts in, or |
None
|
firms
|
Role
|
The path of the group of firms. |
required |
c0
|
Annotated[float, open(0, 1)]
|
The consumption propensity of the household. |
0.5
|
beta
|
Annotated[float, closed_open(0, oo)]
|
The intensity of choice of the demand and of the workers. |
2.0
|
gamma
|
Annotated[float, closed_open(0, 1)]
|
The relative size of the adjustments of prices and wages. |
0.01
|
eta_minus
|
Annotated[float, closed(0, 1)]
|
The firing propensity |
0.2
|
ratio
|
Annotated[float, closed_open(0, oo)]
|
The hiring to firing ratio |
2.0
|
delta
|
Annotated[float, closed(0, 1)]
|
The share of their cash that profitable firms pay as dividends. |
0.02
|
theta
|
Annotated[float, open(0, oo)]
|
The bankruptcy threshold of the debt to payroll ratio. |
3.0
|
phi
|
Annotated[float, closed(0, 1)]
|
The probability per month that a bankrupt firm is revived. |
0.1
|
zeta
|
Annotated[float, open(0, oo)]
|
The productivity of a worker. |
1.0
|
omega
|
Annotated[float, closed(0, 1)]
|
The weight of the last inflation in its moving average. |
0.2
|
f
|
Annotated[float, closed(0, 1)]
|
The share of the costs of defaults borne by the borrowers rather than the depositors. |
0.5
|
shock_time
|
Annotated[float, closed_open(0, oo)]
|
The month the shock starts. |
100.0
|
shock_length
|
Annotated[float, closed_open(0, oo)]
|
The months the shock lasts. |
0.0
|
dc
|
Annotated[float, closed_open(0, 1)]
|
The relative fall of the consumption propensity during the shock. |
0.0
|
dzeta
|
Annotated[float, closed_open(0, 1)]
|
The relative fall of the productivity during the shock. |
0.0
|
kappa
|
Annotated[float, closed_open(0, oo)]
|
The factor of the household's savings at the end of the shock, 1 for no helicopter money. |
1.0
|
offset
|
Annotated[float, open(0, oo)]
|
The factor of the mean fragility of the adaptive credit policy. |
1.25
|
credit
|
str
|
The credit policy, |
'none'
|
Raises:
| Type | Description |
|---|---|
ValidationError
|
The credit policy is unknown, raised by |
Examples:
>>> from skcomplex.systems.economics.macroeconomics import Mark0EconomyInteraction
>>> Mark0EconomyInteraction('economy', firms='firms').reports[:2]
('unemployment', 'inflation')
Source code in src/skcomplex/systems/economics/macroeconomics/_mark0.py
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 | |
act(system)
Run one month of the economy.
It adjusts, pays, sells, distributes, defaults, revives, and sets the rates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
system
|
SystemView
|
The system view of the economy. |
required |
Source code in src/skcomplex/systems/economics/macroeconomics/_mark0.py
344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 | |
Mark0FirmElement(label, *, workforce=0.5, demand=0.5, price=1.0, wage=1.0, cash=0.0, profit=0.0, active=1.0, size=None)
Bases: Element
Firm of the Mark-0 economy.
It holds its workforce, demand, price, wage, cash balance, and profit. The production is the productivity times the workforce, a negative cash balance is a debt, and the economy of the system updates every firm at once.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
The label of the agent or group. |
required |
workforce
|
Annotated[object, closed_open(0, oo)]
|
The workers of the firm, as a share of the households. |
0.5
|
demand
|
Annotated[object, closed_open(0, oo)]
|
The demand for the goods of the firm. |
0.5
|
price
|
Annotated[object, open(0, oo)]
|
The price of the goods of the firm. |
1.0
|
wage
|
Annotated[object, open(0, oo)]
|
The wage the firm pays. |
1.0
|
cash
|
object
|
The cash balance, negative for a debt. |
0.0
|
profit
|
object
|
The profit of the last step. |
0.0
|
active
|
Annotated[object, closed(0, 1)]
|
1 for a firm in business, 0 for a bankrupt firm waiting to be revived. |
1.0
|
size
|
int | None
|
The number of members, or |
None
|
Examples:
>>> from skcomplex.systems.economics.macroeconomics import Mark0FirmElement
>>> Mark0FirmElement('firms', size=3).size
3
Source code in src/skcomplex/systems/economics/macroeconomics/_mark0.py
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | |
Mark0System(n_firms=500, *, c0=0.5, beta=2.0, gamma=0.01, eta_minus=0.2, ratio=2.0, delta=0.02, theta=3.0, phi=0.1, shock_time=100.0, shock_length=0.0, dc=0.0, dzeta=0.0, kappa=1.0, credit='none', random_state=0, label='system', solver='auto', backend='auto')
Bases: BaseSystem
The Mark-0 economy of Sharma, Bouchaud, and co-authors.
It has a Covid shock to supply and demand. Firms produce perishable goods with a linear technology, sell them to a
representative household at prices they adjust by rules of thumb, hire and fire by the gap between production and
demand, and borrow from a representative bank, defaulting when their debt to payroll exceeds the threshold Theta
(Sharma et al. 2020, Section 2). A month is a step, the money starts at zero, and the economy is stock-flow
consistent apart from the written-off debts and the helicopter money. With the defaults of Table 1 the economy sits
in the full employment phase. A lockdown lowers the productivity and the consumption propensity for shock_length
months, after which a mild shock recovers in a V shape and a strong one tips the economy into an L-shaped recession
of high unemployment, which easy credit and helicopter money can prevent. The source summarizes the model of earlier
papers, so the initial firms (a workforce between 0.9 and 1, prices around 1, unit wages, no cash) and revived firms
(the mean price and wage and a random share of the unemployed) follow Gualdi et al. (2015), and the demand reads
prices relative to the mean price.
The system has the group firms and the economy economy, whose reporters are economy.unemployment,
economy.inflation, economy.output, economy.savings, economy.fragility, economy.bankruptcies,
economy.threshold, economy.price, and economy.wage.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_firms
|
int
|
The number of firms, equal to the number of households. |
500
|
c0
|
float
|
The consumption propensity of the household. |
0.5
|
beta
|
float
|
The intensity of choice of the demand and of the workers. |
2.0
|
gamma
|
float
|
The relative size of the adjustments of prices and wages. |
0.01
|
eta_minus
|
float
|
The firing propensity. |
0.2
|
ratio
|
float
|
The hiring to firing ratio. |
2.0
|
delta
|
float
|
The share of their cash that profitable firms pay as dividends. |
0.02
|
theta
|
float
|
The bankruptcy threshold of the debt to payroll ratio. |
3.0
|
phi
|
float
|
The probability per month that a bankrupt firm is revived. |
0.1
|
shock_time
|
float
|
The month the shock starts. |
100.0
|
shock_length
|
float
|
The months the shock lasts, 0 for no shock. |
0.0
|
dc
|
float
|
The relative fall of the consumption propensity during the shock. |
0.0
|
dzeta
|
float
|
The relative fall of the productivity during the shock. |
0.0
|
kappa
|
float
|
The factor of the household's savings at the end of the shock, 1 for no helicopter money. |
1.0
|
credit
|
str
|
The credit policy, |
'none'
|
random_state
|
int | Generator | None
|
The seed or generator of the initial firms. |
0
|
label
|
str
|
The label of the system, which names it when it is nested in another one. |
'system'
|
solver
|
BaseSolver | str
|
The solver of the problem, or |
'auto'
|
backend
|
BaseBackend | str
|
The backend that evaluates the compiled functions, or |
'auto'
|
Examples:
>>> from skcomplex.systems.economics.macroeconomics import Mark0System
>>> Mark0System(10).prepare().system_.elements[0].size
10
Source code in src/skcomplex/systems/economics/macroeconomics/_mark0.py
531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 | |
MetaphoriaSystem(n_people=100, *, mode='hunter_gatherer', shape=(20, 20), max_food=15.0, max_resistance=5.0, regrowth=1.0, need=2.0, labour=5.0, interest=0.003, repayment=0.004, n_firms=5, random_state=0, label='system', solver='auto', backend='auto')
Bases: BaseSystem
Gooding's Metaphoria.
It is a mortal population of hunter-gatherers or of a monetary economy. Patches of a periodic lattice hold food that grows back to a random capacity and resist harvesting with a random resistance. People need food every step, age, die of starvation or old age, and have children who inherit their propensities to breed, explore, found firms, and quit jobs, with mutations, so the propensities evolve under the test of survival. Hunter-gatherers pool the labour of the adults on a patch and share the harvest. In the monetary economy firms harvest with paid workers, sell the food in shops, and borrow the wages from a bank that creates money as loans, so the money of all holders sums to zero at every step. Gooding found the hunter-gatherers stable, and the monetary population smaller and less healthy, with money concentrating to a Gini coefficient near 0.5. On land where the hunter-gatherers thrive the monetary population dwindles towards extinction, and with abundant food it lives on with persistent starvation.
The system has the group patches, one per cell, the variable group people, the reporters census.births,
census.starvations, and census.old_age, and the observables population and money_gini. The monetary economy
adds the variable group businesses, the group bank, and the reporter shops.gdp.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_people
|
int
|
The initial number of adults. |
100
|
mode
|
str
|
|
'hunter_gatherer'
|
shape
|
Sequence[int]
|
The number of patches along each axis. |
(20, 20)
|
max_food
|
float
|
The largest capacity of a patch, drawn uniformly from 0. |
15.0
|
max_resistance
|
float
|
The largest resistance of a patch, drawn uniformly from 0. |
5.0
|
regrowth
|
float
|
The share of the capacity that grows back in a step. |
1.0
|
need
|
float
|
The food a person eats in a step. |
2.0
|
labour
|
float
|
The labour of an adult in a step. |
5.0
|
interest
|
float
|
The interest rate of loans per step. |
0.003
|
repayment
|
float
|
The share of the principal repaid per step. |
0.004
|
n_firms
|
int
|
The number of firms of the monetary economy at the start, each without an owner until it has a worker. |
5
|
random_state
|
int | Generator | None
|
The seed or generator of the patches, the places, ages, and propensities of the people. |
0
|
label
|
str
|
The label of the system, which names it when it is nested in another one. |
'system'
|
solver
|
BaseSolver | str
|
The solver of the problem, or |
'auto'
|
backend
|
BaseBackend | str
|
The backend that evaluates the compiled functions, or |
'auto'
|
Raises:
| Type | Description |
|---|---|
ValueError
|
The mode is unknown. |
Examples:
>>> from skcomplex.systems.economics.macroeconomics import MetaphoriaSystem
>>> [group.label for group in MetaphoriaSystem(10, mode='monetary', shape=(5, 5)).prepare().system_.elements]
['patches', 'people', 'businesses', 'bank']
Source code in src/skcomplex/systems/economics/macroeconomics/_metaphoria.py
1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 | |
MonetaryBankElement(label, *, deposits=10.0, interest=0.03, payout=0.5, credit=0.1)
Bases: Element
Bank of a stock-flow consistent economy, whose own funds are money.
It lends and charges interest.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
The label of the bank. |
required |
deposits
|
Annotated[object, closed_open(0, oo), Quantity(money)]
|
The own funds of the bank. |
10.0
|
interest
|
Annotated[float, closed_open(0, oo)]
|
The interest rate on loans per period. |
0.03
|
payout
|
Annotated[float, closed_open(0, oo)]
|
The share of the bank's funds paid out as dividends per period. |
0.5
|
credit
|
Annotated[float, closed_open(0, oo)]
|
The new loans per unit of sales. |
0.1
|
Examples:
>>> from skcomplex.systems.economics.macroeconomics import MonetaryBankElement
>>> MonetaryBankElement('bank').deposits
10.0
Source code in src/skcomplex/systems/economics/macroeconomics/_monetary.py
141 142 143 144 145 146 147 148 149 150 151 152 153 154 | |
MultiplierAcceleratorSystem(income=110.0, previous=100.0, *, c=0.8, v=1.5, G=20.0, label='system', solver='auto', backend='auto')
Bases: DynamicalSystem
Samuelson's multiplier-accelerator, Y_{t+1} = c (1 + v) Y_t - c v Y_{t-1} + G.
Income oscillates around G / (1 - c), with growing amplitude when c v > 1 and complex characteristic roots. The
system has the income economy.Y and its previous value economy.Y_lag1.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
income
|
float
|
The income of the current period. |
110.0
|
previous
|
float
|
The income of the previous period. |
100.0
|
c
|
float
|
The marginal propensity to consume. |
0.8
|
v
|
float
|
The accelerator, the investment response to the change in consumption. |
1.5
|
G
|
float
|
The government spending. |
20.0
|
label
|
str
|
The label of the system, which names it when it is nested in another one. |
'system'
|
solver
|
BaseSolver | str
|
The solver of the problem, or |
'auto'
|
backend
|
BaseBackend | str
|
The backend that evaluates the compiled functions, or |
'auto'
|
Examples:
>>> from skcomplex.systems.economics.macroeconomics import MultiplierAcceleratorSystem
>>> MultiplierAcceleratorSystem(v=0.5).prepare().system_.elements[0].values['v']
0.5
Source code in src/skcomplex/systems/economics/macroeconomics/_growth.py
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 | |
NetworkHerdingSystem(theta=None, x=None, *, gamma=1.0, sigma=0.1, n_agents=50, density=0.1, herding=0.5, random_state=0, label='system', solver='auto', backend='auto')
Bases: BaseSystem
Agents whose linear choices herd on the past choices of linked agents.
They herd on the agents they are linked to. The choice of agent i is c_it = sum_j theta_ij c_j,t-1 + gamma x_it,
so the choices follow c_t = Theta c_t-1 + gamma x_t on the weighted network Theta, without self-links, Eqs. 1.10
and 1.11 of Caiani et al. (2016, Section 1.1.6). The individual characteristic is x_it = x_i + sigma eps_it, with
a standard normal shock eps_it. The mean choice follows c_t = (1/N) sum_i d_i c_i,t-1 + gamma x_t (Eq. 1.12),
where the out-degree d_i of agent i, the sum of column i of Theta, measures how much its choice moves the
others, so the persistence of the aggregate depends on the out-degrees and on how they correlate with the choices.
Without shocks the choices settle at (I - Theta)^-1 gamma x when the spectral radius of Theta is below 1.
The system has the group agents of the choices agents.c and the herding herding. The observable of the system
is the mean choice mean_choice.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
theta
|
Sequence[Sequence[float]] | None
|
The weights, |
None
|
x
|
Sequence[float] | None
|
The means of the individual characteristics, or |
None
|
gamma
|
float
|
The weight of the individual characteristic. |
1.0
|
sigma
|
float
|
The standard deviation of the shocks of the individual characteristics. |
0.1
|
n_agents
|
int
|
The number of agents of a random network. |
50
|
density
|
float
|
The probability of a link from one agent to another in a random network. |
0.1
|
herding
|
float
|
The sum of the weights of every agent with links in a random network, below 1 for stable choices. |
0.5
|
random_state
|
int | Generator | None
|
The seed or generator of the random network and characteristics. |
0
|
label
|
str
|
The label of the system, which names it when it is nested in another one. |
'system'
|
solver
|
BaseSolver | str
|
The solver of the problem, or |
'auto'
|
backend
|
BaseBackend | str
|
The backend that evaluates the compiled functions, or |
'auto'
|
Examples:
>>> from skcomplex.systems.economics.macroeconomics import NetworkHerdingSystem
>>> NetworkHerdingSystem([[0.0, 0.5], [0.5, 0.0]], [1.0, 1.0]).prepare().system_.elements[0].size
2
Source code in src/skcomplex/systems/economics/macroeconomics/_herding.py
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 | |
OptimalConsumptionSystem(k=1.0, *, A=1.0, alpha=0.3, delta=0.05, rho=0.03, v=0.7, label='system', solver='auto', backend='auto')
Bases: DynamicalSystem
The Ramsey economy that chooses its consumption path.
The path maximises its discounted utility and the value of the capital left at the horizon, the objective law
ObjectiveLaw(-utility, controls=[s.target.c], terminal=-value). Run with an optimal control solver from little
capital, consumption rises with capital along the saddle path towards the modified golden rule, and the economy
saves a falling share of its output. The system has the capital economy.k, the consumption economy.c, and the
observable saving_rate.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
k
|
float
|
The initial capital per worker. |
1.0
|
A
|
float
|
The total factor productivity. |
1.0
|
alpha
|
float
|
The capital share of output. |
0.3
|
delta
|
float
|
The depreciation rate. |
0.05
|
rho
|
float
|
The discount rate. |
0.03
|
v
|
float
|
The value per unit of capital left at the horizon. |
0.7
|
label
|
str
|
The label of the system, which names it when it is nested in another one. |
'system'
|
solver
|
BaseSolver | str
|
The solver of the problem, or |
'auto'
|
backend
|
BaseBackend | str
|
The backend that evaluates the compiled functions, or |
'auto'
|
Examples:
>>> from skcomplex.systems.economics.macroeconomics import OptimalConsumptionSystem
>>> OptimalConsumptionSystem(rho=0.05).prepare().system_.elements[0].get_params()['rho']
0.05
Source code in src/skcomplex/systems/economics/macroeconomics/_optimal_growth.py
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 | |
PaymentsInteraction(label, *, customers, phase='pay')
Bases: Interaction
Payments and repayments of the customers of the banks.
Every customer pays a share spending of its deposit to a random customer, in random order, which moves the
deposit and as many deposits and reserves from the payer's bank to the payee's bank. Every customer then repays a
share repayment of its loan, at most its deposit, in random order, which cancels as much deposit and loan at the
customer's bank and destroys broad money.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
The label of the interaction. |
required |
customers
|
Role
|
The path of the group of customers. |
required |
phase
|
str | None
|
The phase the customers pay in. |
'pay'
|
Examples:
>>> from skcomplex.systems.economics.macroeconomics import PaymentsInteraction
>>> PaymentsInteraction('payments', customers='customers').phase
'pay'
Source code in src/skcomplex/systems/economics/macroeconomics/_banking.py
190 191 192 193 | |
pay(system)
Let every customer pay a share of its deposit to a random customer, in random order.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
system
|
SystemView
|
The system view of the payments. |
required |
Source code in src/skcomplex/systems/economics/macroeconomics/_banking.py
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 | |
repay(system)
Let every customer repay a share of its loan from its deposit, in random order.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
system
|
SystemView
|
The system view of the repayments. |
required |
Source code in src/skcomplex/systems/economics/macroeconomics/_banking.py
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 | |
PlotElement(label, *, food=0.0, capacity=10.0, resistance=0.0, regrowth=1.0, values=None, size=None, space=None)
Bases: Element
Patch of land whose food grows back by a share of its capacity every step.
It is harvested against a resistance. The regrowth is a RegrowthInteraction of the group of patches, relative to
the capacity.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
The label of the patch or the site group. |
required |
food
|
Annotated[object, closed_open(0, oo)]
|
The food on the patch. |
0.0
|
capacity
|
Annotated[object, closed_open(0, oo)]
|
The most food the patch holds. |
10.0
|
resistance
|
Annotated[object, closed_open(0, oo)]
|
The labour lost to the resistance of the patch before any food is harvested. |
0.0
|
regrowth
|
Annotated[object, closed_open(0, oo)]
|
The share of the capacity that grows back in a step. |
1.0
|
values
|
Mapping[str, object] | None
|
Further values by name, such as the cells |
None
|
size
|
int | None
|
The number of patches, or |
None
|
space
|
BaseSpace | None
|
The land the patches live on, whose axes |
None
|
Examples:
>>> from skcomplex.systems.economics.macroeconomics import PlotElement
>>> PlotElement('patch').regrowth
1.0
Source code in src/skcomplex/systems/economics/macroeconomics/_metaphoria.py
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 | |
PolicySwitchInteraction(label, *, rule=None, phase=None, ratio=0.1, new_ratio=0.1, change_at=0.0, banks='banks')
Bases: PolicyRuleInteraction[SystemView]
Policy switch of a central bank.
It moves the reserve ratio of the banks from ratio to new_ratio. The ratio switches at the time change_at.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
The label of the institution. |
required |
rule
|
Callable[[SystemView], None] | None
|
Unused, the regulator overrides |
None
|
phase
|
str | None
|
The phase the regulator acts in, or |
None
|
ratio
|
Annotated[float, open(0, oo)]
|
The reserve ratio before the change. |
0.1
|
new_ratio
|
Annotated[float, open(0, oo)]
|
The reserve ratio after the change. |
0.1
|
change_at
|
Annotated[float, closed_open(0, oo)]
|
The time of the change. |
0.0
|
banks
|
str
|
The path of the group of banks. |
'banks'
|
Examples:
>>> from skcomplex.systems.economics.macroeconomics import PolicySwitchInteraction
>>> PolicySwitchInteraction('regulator', ratio=0.1, new_ratio=0.2, change_at=100.0).new_ratio
0.2
Source code in src/skcomplex/systems/economics/macroeconomics/_banking.py
373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 | |
act(system)
Set the reserve ratio of the banks from the schedule.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
system
|
SystemView
|
The system view of the regulator. |
required |
Source code in src/skcomplex/systems/economics/macroeconomics/_banking.py
390 391 392 393 394 395 396 397 398 399 400 | |
ProductionInteraction(label, *, target='businesses', phase=None)
Bases: Interaction
Production of every firm: harvest with its workers, pay wages and the bank, and adjust.
It is the rule of BusinessElement in the phase of work, run by each firm in turn.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
The label of the interaction. |
required |
target
|
Role
|
The firms that produce. |
'businesses'
|
phase
|
str | None
|
The phase the firms produce in, or |
None
|
Examples:
>>> from skcomplex.systems.economics.macroeconomics import ProductionInteraction
>>> ProductionInteraction('production', phase='work').phase
'work'
Source code in src/skcomplex/systems/economics/macroeconomics/_metaphoria.py
680 681 682 683 | |
produce(agent, system)
Harvest with the workers, pay wages and the bank, and adjust.
It then pays a dividend to the owner.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
agent
|
BusinessView
|
The firm. |
required |
system
|
SystemView
|
The system. |
required |
Source code in src/skcomplex/systems/economics/macroeconomics/_metaphoria.py
733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 | |
PurchasingPowerInteraction(label, *, target, A=A_MATRIX, B=B_MATRIX, C=C_MATRIX, D=D_MATRIX, feedback=False)
Bases: Interaction
Dynamics of a national economy of three spending sectors, with sector policies.
It follows z' = A z + B u and y = C z + D u. The state z_i of the economy is the gap between the demand and
the supply of money of sector i, the basic, the desired, and the luxurious living conditions, the output y_i is
the index of the sector, and the policy x_i of a sector is a step of size policy_i at the time policy_time_i,
values of the economy. Without feedback the economy takes the policies as its inputs, u = x. With feedback, the
market reactions of Forrest's feedback component set u so that every sector responds to its own policy only, as
the decoupled systems w_i' = A w_i + B_i x_i and y_i = C_i w_i + D_i x_i, whose states w_ik the economy holds.
The feedback component holds a copy of z that equals z from the common zero start, so u = D^-1 (y - C z) with
the decoupled outputs y.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
The label of the interaction. |
required |
target
|
Role
|
The path of the economy. |
required |
A
|
Sequence[Sequence[float]]
|
The matrix of the state. |
A_MATRIX
|
B
|
Sequence[Sequence[float]]
|
The matrix of the inputs in the state. |
B_MATRIX
|
C
|
Sequence[Sequence[float]]
|
The matrix of the state in the outputs. |
C_MATRIX
|
D
|
Sequence[Sequence[float]]
|
The nonsingular matrix of the inputs in the outputs. |
D_MATRIX
|
feedback
|
bool
|
Whether the feedback component decouples the sectors. |
False
|
Examples:
>>> from skcomplex.systems.economics.macroeconomics import PurchasingPowerInteraction
>>> PurchasingPowerInteraction('dynamics', target='economy', feedback=True).feedback
True
Source code in src/skcomplex/systems/economics/macroeconomics/_purchasing_power.py
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | |
get_inputs(s)
Return the inputs u of the economy.
They are the policies, or D^-1 (y - C z) with feedback.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
s
|
SimpleNamespace
|
The namespace of the economy, with the time |
required |
Returns:
| Name | Type | Description |
|---|---|---|
inputs |
list[Expression]
|
One input per sector. |
Source code in src/skcomplex/systems/economics/macroeconomics/_purchasing_power.py
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 | |
get_outputs(s)
Return the indices y of the sectors.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
s
|
SimpleNamespace
|
The namespace of the economy, with the time |
required |
Returns:
| Name | Type | Description |
|---|---|---|
outputs |
list[Expression]
|
One index per sector. |
Source code in src/skcomplex/systems/economics/macroeconomics/_purchasing_power.py
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 | |
get_values(policy, policy_time)
Return the values of the economy: the states z_i, with feedback w_ik, at zero, then the policies.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
policy
|
Sequence[float]
|
The size of the step policy of every sector. |
required |
policy_time
|
Sequence[float]
|
The time of the step policy of every sector. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
values |
dict[str, float]
|
The value of every state and parameter of the economy by name. |
Source code in src/skcomplex/systems/economics/macroeconomics/_purchasing_power.py
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 | |
ReserveBankElement(label, *, reserves=0.0, deposits=0.0, loans=0.0, reserve_ratio=0.1, size=None)
Bases: Element
Bank with reserves, the deposits of its customers, and loans to them.
The excess reserves are those beyond the required share reserve_ratio of its deposits, which LendingInteraction
lends.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
The label of the agent or group. |
required |
reserves
|
object
|
The reserves of the bank. |
0.0
|
deposits
|
Annotated[object, closed_open(0, oo)]
|
The deposits of its customers. |
0.0
|
loans
|
Annotated[object, closed_open(0, oo)]
|
The loans to its customers. |
0.0
|
reserve_ratio
|
Annotated[object, open(0, oo)]
|
The required ratio of reserves to deposits. |
0.1
|
size
|
int | None
|
The number of banks, or |
None
|
Examples:
>>> from skcomplex.systems.economics.macroeconomics import ReserveBankElement
>>> ReserveBankElement('banks', reserves=10.0, size=3).size
3
Source code in src/skcomplex/systems/economics/macroeconomics/_banking.py
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 | |
SettlerElement(label, *, food=10.0, money=0.0, loans=0.0, age=20.0, parent=-1.0, employer=-1.0, harvested=0.0, born=-100.0, fate=ALIVE, fertility=0.5, exploration=0.5, enterprise=0.5, restlessness=0.1, labour=5.0, need=2.0, maturity=15.0, lifespan=85.0, spacing=2.0, endowment=5.0, mutation=0.05, sight=5.0, reserve=5.0, monetary=0.0, values=None, size=None, space=None)
Bases: Element
Mortal person who eats, ages, raises children, and moves.
In the monetary economy, the person also works and founds firms. Every step a person eats need food and starves
when its food runs out, and past lifespan it dies of old age with probability 1/7. A child takes need food from
its parent and follows it. A fed adult has a child with the probability fertility, at most once every spacing
steps, and gives it endowment food. The child inherits the four propensities, each moved by a normal mutation and
kept in [0, 1]. A person that harvested too little and holds less than reserve steps of food moves, far with the
probability exploration. In the monetary economy an unemployed adult on a patch with food but no firm founds one
with the probability enterprise, and a worker quits with the probability restlessness.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
The label of the person or the group. |
required |
food
|
object
|
The food the person holds. |
10.0
|
money
|
Annotated[object, Quantity(money)]
|
The money the person holds. |
0.0
|
loans
|
Annotated[object, Quantity(credit)]
|
The loans the person holds, negative for a debt taken over from a firm. |
0.0
|
age
|
Annotated[object, NN]
|
The age in steps. |
20.0
|
parent
|
Annotated[object, Member(people)]
|
The parent among the people, or -1. |
-1.0
|
employer
|
Annotated[object, Member(businesses)]
|
The firm that employs the person among the firms, or -1. |
-1.0
|
harvested
|
object
|
The food the person harvested or earned in the step. |
0.0
|
born
|
object
|
The step of the person's last child. |
-100.0
|
fate
|
object
|
0 while alive, 1 after starving, and 2 after dying of old age, until the census removes the person. |
ALIVE
|
fertility
|
Annotated[object, closed_open(0, oo)]
|
The probability of a child in a step. |
0.5
|
exploration
|
Annotated[object, closed_open(0, oo)]
|
The probability of moving far. |
0.5
|
enterprise
|
Annotated[object, closed_open(0, oo)]
|
The probability of founding a firm. |
0.5
|
restlessness
|
Annotated[object, closed_open(0, oo)]
|
The probability of quitting a job. |
0.1
|
labour
|
Annotated[object, closed_open(0, oo)]
|
The labour of an adult in a step. |
5.0
|
need
|
Annotated[object, closed_open(0, oo)]
|
The food a person eats in a step. |
2.0
|
maturity
|
Annotated[object, closed_open(0, oo)]
|
The age of adulthood. |
15.0
|
lifespan
|
Annotated[object, closed_open(0, oo)]
|
The age after which death by old age is possible. |
85.0
|
spacing
|
Annotated[object, closed_open(0, oo)]
|
The fewest steps between two children. |
2.0
|
endowment
|
Annotated[object, closed_open(0, oo)]
|
The food a parent gives a newborn child. |
5.0
|
mutation
|
Annotated[object, closed_open(0, oo)]
|
The standard deviation of the mutation of a propensity. |
0.05
|
sight
|
Annotated[object, closed_open(0, oo)]
|
The distance within which a person sees firms and explores. |
5.0
|
reserve
|
Annotated[object, closed_open(0, oo)]
|
The steps of food a person buys up to, and below which a person that harvests too little moves. |
5.0
|
monetary
|
Annotated[object, closed_open(0, oo)]
|
One in the monetary economy, zero among hunter-gatherers. |
0.0
|
values
|
Mapping[str, object] | None
|
Further values by name, such as the cells |
None
|
size
|
int | None
|
The number of people, or |
None
|
space
|
BaseSpace | None
|
The land the people live on, whose axes |
None
|
Examples:
>>> from skcomplex.systems.economics.macroeconomics import SettlerElement
>>> SettlerElement('people', size=3).size
3
Source code in src/skcomplex/systems/economics/macroeconomics/_metaphoria.py
339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 | |
SolowGrowthInteraction(label, *, target, s=0.2, alpha=0.3, delta=0.05)
Bases: Interaction
Solow growth of the capital per worker k of a target.
It follows dk/dt = s * k**alpha - delta * k, the saving of a Cobb-Douglas output minus depreciation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
The label of the interaction. |
required |
target
|
Role
|
The path of the economy. |
required |
s
|
Annotated[float, closed_open(0, oo)]
|
The saving rate. |
0.2
|
alpha
|
Annotated[float, open(0, oo)]
|
The output elasticity of capital. |
0.3
|
delta
|
Annotated[float, open(0, oo)]
|
The depreciation rate. |
0.05
|
Examples:
>>> from skcomplex.systems.economics.macroeconomics import SolowGrowthInteraction
>>> SolowGrowthInteraction('solow', target='country', s=0.3).s
0.3
Source code in src/skcomplex/systems/economics/macroeconomics/_growth.py
80 81 82 83 84 85 86 87 88 89 90 91 92 93 | |
SolowSystem(k=1.0, *, s=0.2, alpha=0.3, delta=0.05, label='system', solver='auto', backend='auto')
Bases: BaseSystem
An economy whose capital per worker approaches its steady state.
It approaches through saving and depreciation. The system has the economy economy.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
k
|
float
|
The initial capital per worker. |
1.0
|
s
|
float
|
The saving rate. |
0.2
|
alpha
|
float
|
The capital share of output. |
0.3
|
delta
|
float
|
The depreciation rate. |
0.05
|
label
|
str
|
The label of the system, which names it when it is nested in another one. |
'system'
|
solver
|
BaseSolver | str
|
The solver of the problem, or |
'auto'
|
backend
|
BaseBackend | str
|
The backend that evaluates the compiled functions, or |
'auto'
|
Examples:
>>> from skcomplex.systems.economics.macroeconomics import SolowSystem
>>> SolowSystem(s=0.3).prepare().system_.interactions[0].s
0.3
Source code in src/skcomplex/systems/economics/macroeconomics/_growth.py
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 | |
StochasticGrowthElement(label, *, K=0.2, regime=0.0, alpha=1.0 / 3, beta=0.95, z_low=0.9, z_high=1.1)
Bases: Element
Representative economy with capital and a productivity regime.
Its technology is the Cobb-Douglas Y = z K^alpha. The productivity z is z_low in regime 0 and z_high in
regime 1, and a Markov chain of the system moves the regime. With logarithmic utility and full depreciation, the
optimal consumption is C = (1 - alpha beta) Y and the capital of the next period is the output saved,
K' = alpha beta z K^alpha.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
The label of the economy. |
required |
K
|
Annotated[float, open(0, oo)]
|
The capital. |
0.2
|
regime
|
Annotated[float, NN]
|
The productivity regime, 0 for low and 1 for high. |
0.0
|
alpha
|
Annotated[float, open(0, 1)]
|
The capital share of the technology. |
1.0 / 3
|
beta
|
Annotated[float, open(0, 1)]
|
The discount factor of the household. |
0.95
|
z_low
|
Annotated[float, open(0, oo)]
|
The productivity of regime 0. |
0.9
|
z_high
|
Annotated[float, open(0, oo)]
|
The productivity of regime 1. |
1.1
|
Examples:
>>> from skcomplex.systems.economics.macroeconomics import StochasticGrowthElement
>>> StochasticGrowthElement('economy', beta=0.9).beta
0.9
Source code in src/skcomplex/systems/economics/macroeconomics/_stochastic_growth.py
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | |
get_consumption(s)
staticmethod
Return the optimal consumption (1 - alpha beta) Y.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
s
|
SimpleNamespace
|
The namespace of the economy. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
consumption |
Expression
|
The consumption. |
Source code in src/skcomplex/systems/economics/macroeconomics/_stochastic_growth.py
109 110 111 112 113 114 115 116 117 118 119 120 121 | |
get_output(s)
staticmethod
Return the output z K^alpha.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
s
|
SimpleNamespace
|
The namespace of the economy. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
output |
Expression
|
The output. |
Source code in src/skcomplex/systems/economics/macroeconomics/_stochastic_growth.py
95 96 97 98 99 100 101 102 103 104 105 106 107 | |
get_productivity(s)
staticmethod
Return the productivity of the current regime.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
s
|
SimpleNamespace
|
The namespace of the economy. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
z |
Expression
|
The productivity. |
Source code in src/skcomplex/systems/economics/macroeconomics/_stochastic_growth.py
81 82 83 84 85 86 87 88 89 90 91 92 93 | |
StockFlowConsistentEconomySystem(*, household_deposits=60.0, firm_deposits=20.0, bank_deposits=10.0, loans=50.0, sales=40.0, alpha_income=0.6, alpha_wealth=0.4, wage_share=0.7, interest=0.03, payout=0.5, distribution=0.3, credit=0.1, repayment=0.08, label='system', solver='auto', backend='auto')
Bases: BaseSystem
A stock-flow consistent economy.
It is a closed circuit of money between households, firms, and a bank. Money is the deposits of the three sectors,
tagged as the quantity money, and every transaction of a period is a flow, so each payment is one sector's outflow
and another's inflow. Households consume a share alpha_income of their wages and a share alpha_wealth of their
deposits, firms pay the wage share of last period's sales and the interest on their loans, and distribute a share of
their deposits as profits, and the bank pays out a share of its funds as dividends. Lending creates money and
repayment destroys it, the only flows with the environment, so the total money changes exactly by lending minus
repayment, in the spirit of the systems of Godley and Lavoie (2007) and the balance sheets of Caiani et al. (2016).
Loans approach credit * sales / repayment and sales settle where the stocks stop growing. The circuit moves the
money of a period, and the interactions loans and sales set the loans and the sales of the firms.
The system has the deposits households.deposits, firms.deposits, and bank.deposits, the loans firms.loans,
the sales firms.sales, the flows circuit.consumption, circuit.wages, circuit.interest, circuit.dividends,
and circuit.profits between the sectors, the flows firms.lending and firms.repayments with the environment,
and the net money created __boundary.money.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
household_deposits
|
float
|
The initial deposits of the households. |
60.0
|
firm_deposits
|
float
|
The initial deposits of the firms. |
20.0
|
bank_deposits
|
float
|
The initial own funds of the bank. |
10.0
|
loans
|
float
|
The initial loans of the firms. |
50.0
|
sales
|
float
|
The sales of the previous period. |
40.0
|
alpha_income
|
float
|
The propensity to consume out of wages. |
0.6
|
alpha_wealth
|
float
|
The propensity to consume out of deposits. |
0.4
|
wage_share
|
float
|
The share of sales paid as wages. |
0.7
|
interest
|
float
|
The interest rate on loans per period. |
0.03
|
payout
|
float
|
The share of the bank's funds paid out as dividends per period. |
0.5
|
distribution
|
float
|
The share of the firms' deposits distributed to households as profits per period. |
0.3
|
credit
|
float
|
The new loans per unit of sales. |
0.1
|
repayment
|
float
|
The share of loans repaid per period. |
0.08
|
label
|
str
|
The label of the system, which names it when it is nested in another one. |
'system'
|
solver
|
BaseSolver | str
|
The solver of the problem, or |
'auto'
|
backend
|
BaseBackend | str
|
The backend that evaluates the compiled functions, or |
'auto'
|
Examples:
>>> from skcomplex.systems.economics.macroeconomics import StockFlowConsistentEconomySystem
>>> [element.label for element in StockFlowConsistentEconomySystem().prepare().system_.elements]
['households', 'firms', 'bank']
Source code in src/skcomplex/systems/economics/macroeconomics/_monetary.py
309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 | |
ToyFirmInvestmentSystem(n_firms=100, *, gamma=1.1, phi=0.1, r=0.1, pbar=0.01, random_state=0, label='system', solver='auto', backend='auto')
Bases: BaseSystem
Heterogeneous firms that invest out of past profits and sell at random prices.
Firms enter and exit. The firms start with net worth and capital 1 and a profit drawn from pbar + 2 U(0, 1), as in
the toy system of Bargigli et al. in Caiani et al. (2016, sect. 2.1). Aggregate production fluctuates as bankrupt
firms are replaced. The system has the group firms and the aggregate production production.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_firms
|
int
|
The number of firms. |
100
|
gamma
|
float
|
The investment accelerator. |
1.1
|
phi
|
float
|
The productivity of capital. |
0.1
|
r
|
float
|
The interest rate. |
0.1
|
pbar
|
float
|
The constant part of the price. |
0.01
|
random_state
|
int | Generator | None
|
The seed or generator of the initial profits. |
0
|
label
|
str
|
The label of the system, which names it when it is nested in another one. |
'system'
|
solver
|
BaseSolver | str
|
The solver of the problem, or |
'auto'
|
backend
|
BaseBackend | str
|
The backend that evaluates the compiled functions, or |
'auto'
|
Examples:
>>> from skcomplex.systems.economics.macroeconomics import ToyFirmInvestmentSystem
>>> ToyFirmInvestmentSystem(20).prepare().system_.elements[0].size
20
Source code in src/skcomplex/systems/economics/macroeconomics/_firms.py
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 | |
TradingEconomyElement(label, *, E=0.885, X=32.0, M=34.0, PH=1.2, home_price=1.2, inflation=0.1, world_price=1.0, exports=32.0, imports=34.0, export_price=1.062, import_price=1.13, export_elasticity=-1.0, import_elasticity=-1.0, floating=1.0, import_share=0.34, demand=52.0, government=50.0)
Bases: Element
Open economy that trades with the World at an exchange rate, floating or fixed.
Its states are the exchange rate E in World currency per unit of home currency, the export and import volumes
X and M, and the home price PH. Its parameters are the prices, volumes, and elasticities of the balanced
start, the rise inflation of home prices, whether the rate floats, and the shares of the output.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
The label of the economy. |
required |
E
|
Annotated[object, open(0, oo)]
|
The exchange rate. |
0.885
|
X
|
Annotated[object, closed_open(0, oo)]
|
The export volume. |
32.0
|
M
|
Annotated[object, closed_open(0, oo)]
|
The import volume. |
34.0
|
PH
|
Annotated[object, open(0, oo)]
|
The home price of home-produced goods. |
1.2
|
home_price
|
Annotated[object, open(0, oo)]
|
The home price before the rise. |
1.2
|
inflation
|
object
|
The relative rise of the home prices. |
0.1
|
world_price
|
Annotated[object, open(0, oo)]
|
The world price level. |
1.0
|
exports
|
Annotated[object, closed_open(0, oo)]
|
The export volume of the balanced start. |
32.0
|
imports
|
Annotated[object, closed_open(0, oo)]
|
The import volume of the balanced start. |
34.0
|
export_price
|
Annotated[object, open(0, oo)]
|
The World price of the exports at the start. |
1.062
|
import_price
|
Annotated[object, open(0, oo)]
|
The home price of the imports at the start. |
1.13
|
export_elasticity
|
object
|
The price elasticity of the exports. |
-1.0
|
import_elasticity
|
object
|
The price elasticity of the imports. |
-1.0
|
floating
|
Annotated[object, closed_open(0, oo)]
|
1 when the exchange rate floats, 0 when it is fixed. |
1.0
|
import_share
|
Annotated[object, closed_open(0, oo)]
|
The share of the imports in the output. |
0.34
|
demand
|
Annotated[object, closed_open(0, oo)]
|
The private domestic demand. |
52.0
|
government
|
Annotated[object, closed_open(0, oo)]
|
The government spending. |
50.0
|
Examples:
>>> from skcomplex.systems.economics.macroeconomics import TradingEconomyElement
>>> TradingEconomyElement('home').floating
1.0
Source code in src/skcomplex/systems/economics/macroeconomics/_trade.py
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 | |