Eisenberg-Noe clearing of interbank payments
The clearing of interbank payments of Eisenberg and Noe.
- Class:
EisenbergNoeClearingSystem - Import:
from skcomplex.systems.economics.finance import EisenbergNoeClearingSystem - Field:
economics/finance - Topics:
systemic risk,network,clearing,payments,fixed point,agents - References:
- Bardoscia et al. 2021
- Eisenberg and Noe 2001
Use this system
The block imports the class and simulates the system with its default parameters and its tuned run settings.
from skcomplex.systems.economics.finance import EisenbergNoeClearingSystem
trajectory = EisenbergNoeClearingSystem().prepare().simulate()
Parameters
The model parameters take these defaults, and set_params changes them.
| Parameter | Default |
|---|---|
liabilities |
None |
external |
None |
n_banks |
50 |
density |
0.1 |
random_state |
0 |
solver |
'auto' |
backend |
'auto' |
Tags
The system with its default parameters has these capability tags, which solvers and analyses check.
| Tag | Values |
|---|---|
| Time | discrete |
| Space | none |
| Laws | update |
| Randomness | deterministic |
| Domains | integer, real |
| Structure | variable membership |
Class
The source of the class shows how it builds its components from its model parameters.
class EisenbergNoeClearingSystem(BaseSystem):
"""The clearing of interbank payments of Eisenberg and Noe.
It is a fixed point of proportional payments. Bank `i` owes `L_ij` to bank `j`, `p_bar_i` in all, and holds external
assets `e_i`. A clearing vector pays `p_i = min(p_bar_i, e_i + sum_j Pi_ji p_j)`, every bank paying in full or all
it has, its debtors paying in proportion `Pi_ij = L_ij / p_bar_i`, the liquidity contagion of Bardoscia et al.
(2021, Section 3.1). Every step is one round of the iteration from full payments, which falls monotonically to the
greatest clearing vector, the solution of the linear programme `max sum_i p_i` with `p <= p_bar` and
`p <= e + Pi^T p`. Without a given network the liabilities are random and the external assets are small for a few
banks.
The system has the group `banks` of the payments `banks.payment`, and the clearing `clearing`, whose reporters are
the total unpaid liabilities `clearing.shortfall` and the number of defaulting banks `clearing.defaults`.
Args:
liabilities:
The interbank liabilities, or `None` for a random network.
external:
The external assets of every bank, or `None` for random ones.
n_banks:
The number of banks of a random network.
density:
The probability of a liability between two banks of a random network.
random_state:
The seed or generator of a random network.
label:
The label of the system, which names it when it is nested in another one.
solver:
The solver of the problem, or `'auto'` for the one the system chooses.
backend:
The backend that evaluates the compiled functions, or `'auto'` for the one the system chooses.
Examples:
>>> from skcomplex.systems.economics.finance import EisenbergNoeClearingSystem
>>> system = EisenbergNoeClearingSystem([[0.0, 2.0], [1.0, 0.0]], [0.5, 1.0]).prepare().system_
>>> system.elements[0].size
2
"""
field = 'economics/finance'
topics = ('systemic risk', 'network', 'clearing', 'payments', 'fixed point', 'agents')
references = ('Bardoscia et al. 2021', 'Eisenberg and Noe 2001')
until = 30
def __init__(
self,
liabilities: Sequence[Sequence[float]] | None = None,
external: Sequence[float] | None = None,
*,
n_banks: int = 50,
density: float = 0.1,
random_state: int | np.random.Generator | None = 0,
label: str = 'system',
solver: BaseSolver | str = 'auto',
backend: BaseBackend | str = 'auto',
) -> None:
super().__init__(label, solver=solver, backend=backend)
self.liabilities = liabilities
self.external = external
self.n_banks = n_banks
self.density = density
self.random_state = random_state
def _prepare(self, context: Sequence[Observable] | None = None) -> None:
"""Set the system of the components built from the model parameters."""
super()._prepare(context)
if self.liabilities is None or self.external is None:
rng = np.random.default_rng(self.random_state)
links = rng.random((self.n_banks, self.n_banks)) < self.density
np.fill_diagonal(links, val=False)
matrix = links * rng.uniform(1.0, 10.0, (self.n_banks, self.n_banks))
assets = rng.exponential(5.0, self.n_banks)
else:
matrix, assets = np.asarray(self.liabilities, dtype=float), np.asarray(self.external, dtype=float)
banks = BalanceSheetElement('banks', external=assets, payment=matrix.sum(axis=1), size=len(matrix))
clearing = PaymentClearingInteraction('clearing', banks='banks', liabilities=matrix.tolist())
self.system_ = System(self.label, elements=[banks], interactions=[clearing])
Components
The system uses these element and interaction classes, each with its nearest class of the core.
Elements:
BalanceSheetElement, fromElement
Interactions:
PaymentClearingInteraction, fromInteraction
class BalanceSheetElement(Element):
"""Bank of an interbank network.
It holds its external assets, its equity, its payments, and its state of default. The bank is a passive agent that
the contagion of the system updates, a solvency cascade through its equity or a clearing of payments through its
payment.
Args:
label:
The label of the agent or group.
external:
The external assets.
equity:
The equity, the assets minus the liabilities.
payment:
The payment the bank makes on its interbank liabilities.
status:
0 for solvent, 1 for defaulting in this step, and 2 for defaulted.
size:
The number of members, or `None` for one.
Examples:
>>> from skcomplex.systems.economics.finance import BalanceSheetElement
>>> BalanceSheetElement('banks', equity=4.0, size=3).size
3
"""
visual = VisualSpec('agents', {'color_by': 'status'})
def __init__(
self,
label: str,
*,
external: Annotated[object, RealSet.closed_open(0, oo)] = 0.0,
equity: object = 0.0,
payment: Annotated[object, RealSet.closed_open(0, oo)] = 0.0,
status: Annotated[object, NN] = SOLVENT,
size: int | None = None,
) -> None:
super().__init__(label, size=size)
self.external = external
self.equity = equity
self.payment = payment
self.status = status
class PaymentClearingInteraction(PolicyRuleInteraction[SystemView]):
"""Clearing of interbank payments of Eisenberg and Noe.
It iterates `p <- min(p_bar, e + Pi^T p)`. Every step every bank pays the smaller of what it owes,
`p_bar_i = sum_j L_ij`, and what it has, its external assets plus the payments it receives, which its debtors make
in proportion to their liabilities, `Pi_ij = L_ij / p_bar_i`. From full payments the iteration falls to the greatest
clearing vector, and a bank that pays less than it owes defaults.
Args:
label:
The label of the clearing.
rule:
Unused, since the clearing overrides `act`.
phase:
The phase the clearing acts in, or `None` for the default phase.
banks:
The path of the group of banks.
liabilities:
The interbank liabilities, `liabilities[i][j]` owed by bank `i` to bank `j`.
Examples:
>>> from skcomplex.systems.economics.finance import PaymentClearingInteraction
>>> PaymentClearingInteraction('clearing', banks='banks').reports
('shortfall', 'defaults')
"""
reports: ClassVar[tuple[str, ...]] = ('shortfall', 'defaults')
def __init__(
self,
label: str,
*,
rule: None = None,
phase: str | None = None,
banks: Role,
liabilities: Sequence[Sequence[float]] = (),
) -> None:
super().__init__(label, rule=rule, phase=phase)
self.banks = banks
self.liabilities = liabilities
def act(self, system: SystemView) -> None:
"""Make one round of payments and record the shortfall and the defaults.
Args:
system:
The system view of the clearing.
"""
banks = sorted(cast(list[BalanceSheetView], system.get_agents('banks')), key=lambda bank: bank.id)
matrix = np.asarray(self.liabilities, dtype=float)
owed = matrix.sum(axis=1)
shares = np.divide(matrix, owed[:, None], out=np.zeros_like(matrix), where=owed[:, None] > 0)
payments = np.array([bank.payment for bank in banks])
external = np.array([bank.external for bank in banks])
payments = np.minimum(owed, external + shares.T @ payments)
equity = external + shares.T @ payments - payments
defaulted = payments < owed * (1 - 1e-12)
for bank, paid, value, flag in zip(banks, payments, equity, defaulted, strict=True):
bank.payment, bank.equity, bank.status = float(paid), float(value), float(DEFAULTED * flag)
system.report('shortfall', float(np.sum(owed - payments)))
system.report('defaults', float(defaulted.sum()))
Equations
The equations are those that symbolic returns for the system with its default parameters.