Skip to content

Default cascades with thresholds and recovery

A cascade of defaults through interbank exposures.

  • Class: DefaultCascadeSystem
  • Import: from skcomplex.systems.economics.finance import DefaultCascadeSystem
  • Field: economics/finance
  • Topics: systemic risk, network, contagion, default cascade, agents
  • References:
    • Thurner et al. 2018
    • Bardoscia et al. 2021
    • Gai and Kapadia 2010

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 DefaultCascadeSystem

trajectory = DefaultCascadeSystem().prepare().simulate()

Parameters

The model parameters take these defaults, and set_params changes them.

Parameter Default
liabilities None
equity None
shocked (0,)
shock 1.0
threshold 0.0
recovery 0.0
n_banks 250
degree 4.0
interbank_share 0.2
capital_ratio 0.04
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 DefaultCascadeSystem(BaseSystem):
    """A cascade of defaults through interbank exposures.

    It starts from a shock to the external assets of some banks. Banks are linked by contracts, `liabilities[i][j]` the
    amount bank `i` owes bank `j`. A bank whose equity falls below the threshold `h` defaults, and its creditors write
    off their claims on it, losing `(1 - R) L_ij` of their equity at the next step, which may default them in turn. This
    is the cascade of Thurner et al. (2018, Section 5.5.3.2), and with `h = 0` and the recovery rate `R = 0` it is the
    contagion on default of Gai and Kapadia (2010) as Bardoscia et al. (2021, Section 3.1) review it. The shocked banks
    lose the share `shock` of their external assets at the start. Without a given network, every bank has assets of 100,
    a fifth of them interbank claims split evenly over a random number of debtors of mean `degree`, and capital of 4
    percent, the network of Gai and Kapadia, whose cascades are large in a window of intermediate degrees and rare for
    sparse or dense networks.

    The system has the group `banks` and the cascade `cascade`, whose reporters are the number of defaulted banks
    `cascade.defaults` and the losses written off in the step `cascade.losses`.

    Args:
        liabilities:
            The interbank liabilities, or `None` for the random network of Gai and Kapadia.

        equity:
            The equity of every bank before the shock, or `None` for the capital of the random network.

        shocked:
            The indices of the banks whose external assets the shock hits.

        shock:
            The share of their external assets the shocked banks lose.

        threshold:
            The equity below which a bank defaults.

        recovery:
            The share of a claim on a defaulted bank that its creditor recovers.

        n_banks:
            The number of banks of the random network.

        degree:
            The mean number of debtors of a bank of the random network.

        interbank_share:
            The share of the assets of a bank of the random network that are interbank claims.

        capital_ratio:
            The capital of a bank of the random network as a share of its assets.

        random_state:
            The seed or generator of the 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 DefaultCascadeSystem
        >>> DefaultCascadeSystem([[0.0, 5.0], [0.0, 0.0]], [1.0, 2.0]).prepare().system_.elements[0].size
        2
    """

    field = 'economics/finance'
    topics = ('systemic risk', 'network', 'contagion', 'default cascade', 'agents')
    references = ('Thurner et al. 2018', 'Bardoscia et al. 2021', 'Gai and Kapadia 2010')
    until = 30

    def __init__(
        self,
        liabilities: Sequence[Sequence[float]] | None = None,
        equity: Sequence[float] | None = None,
        *,
        shocked: Sequence[int] = (0,),
        shock: float = 1.0,
        threshold: float = 0.0,
        recovery: float = 0.0,
        n_banks: int = 250,
        degree: float = 4.0,
        interbank_share: float = 0.2,
        capital_ratio: float = 0.04,
        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.equity = equity
        self.shocked = shocked
        self.shock = shock
        self.threshold = threshold
        self.recovery = recovery
        self.n_banks = n_banks
        self.degree = degree
        self.interbank_share = interbank_share
        self.capital_ratio = capital_ratio
        self.random_state = random_state

    @staticmethod
    def _get_gai_kapadia_network(
        n_banks: int,
        degree: float,
        interbank_share: float,
        capital_ratio: float,
        rng: np.random.Generator,
    ) -> tuple[Array, Array, Array]:
        """Return the liabilities, external assets, and capitals of a random network.

        The network is that of Gai and Kapadia. Every bank has assets of 100, of which the share `interbank_share` are
        claims split evenly over its debtors, links drawn with probability `degree / (n - 1)`, and capital of
        `capital_ratio` of its assets.
        """
        links = rng.random((n_banks, n_banks)) < degree / (n_banks - 1)
        np.fill_diagonal(links, val=False)
        debtors = links.sum(axis=0)
        claims = np.divide(100.0 * interbank_share, debtors, out=np.zeros(n_banks), where=debtors > 0)
        liabilities = np.asarray(links * claims[None, :], dtype=float)
        external = 100.0 - liabilities.sum(axis=0)
        capital = np.full(n_banks, 100.0 * capital_ratio)
        return liabilities, external, capital

    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.equity is None:
            rng = np.random.default_rng(self.random_state)
            matrix, external, capital = self._get_gai_kapadia_network(
                self.n_banks,
                self.degree,
                self.interbank_share,
                self.capital_ratio,
                rng,
            )
        else:
            matrix, capital = np.asarray(self.liabilities, dtype=float), np.asarray(self.equity, dtype=float)
            external = np.maximum(capital, 0.0)
        size = len(matrix)
        hit = np.zeros(size, dtype=bool)
        hit[list(self.shocked)] = True
        losses = np.where(hit, self.shock * external, 0.0)
        after = capital - losses
        status = np.where(after < self.threshold, DEFAULTING, SOLVENT).astype(float)
        banks = BalanceSheetElement('banks', external=external - losses, equity=after, status=status, size=size)
        cascade = DefaultCascadeInteraction(
            'cascade',
            banks='banks',
            liabilities=matrix.tolist(),
            threshold=self.threshold,
            recovery=self.recovery,
        )
        self.system_ = System(self.label, elements=[banks], interactions=[cascade])

Components

The system uses these element and interaction classes, each with its nearest class of the core.

Elements:

  • BalanceSheetElement, from Element

Interactions:

  • DefaultCascadeInteraction, from Interaction
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 DefaultCascadeInteraction(PolicyRuleInteraction[SystemView]):
    """Synchronous cascade of defaults.

    The creditors of a defaulting bank write off their claims on it. Every step the banks that defaulted in the last
    step pass their losses on: every creditor `j` of a defaulting bank `i` loses `(1 - recovery) L_ij` of its equity,
    and a solvent bank whose equity falls below the threshold defaults.

    Args:
        label:
            The label of the cascade.

        rule:
            Unused, since the cascade overrides `act`.

        phase:
            The phase the cascade 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`.

        threshold:
            The equity below which a bank defaults.

        recovery:
            The share of a claim on a defaulted bank that its creditor recovers.

    Examples:
        >>> from skcomplex.systems.economics.finance import DefaultCascadeInteraction
        >>> DefaultCascadeInteraction('cascade', banks='banks').reports
        ('defaults', 'losses')
    """

    reports: ClassVar[tuple[str, ...]] = ('defaults', 'losses')

    def __init__(
        self,
        label: str,
        *,
        rule: None = None,
        phase: str | None = None,
        banks: Role,
        liabilities: Sequence[Sequence[float]] = (),
        threshold: float = 0.0,
        recovery: Annotated[float, RealSet.closed(0, 1)] = 0.0,
    ) -> None:
        super().__init__(label, rule=rule, phase=phase)
        self.banks = banks
        self.liabilities = liabilities
        self.threshold = threshold
        self.recovery = recovery

    def act(self, system: SystemView) -> None:
        """Pass on the losses of the defaulting banks.

        Then default the banks below the threshold.

        Args:
            system:
                The system view of the cascade.
        """
        banks = sorted(cast(list[BalanceSheetView], system.get_agents('banks')), key=lambda bank: bank.id)
        status = np.array([bank.status for bank in banks])
        equity = np.array([bank.equity for bank in banks])
        defaulting = status == DEFAULTING
        losses = (1 - system.get_parameter('recovery')) * np.asarray(self.liabilities, dtype=float).T @ defaulting
        equity = equity - losses
        hit = (status == SOLVENT) & (equity < system.get_parameter('threshold'))
        status = np.where(defaulting, DEFAULTED, np.where(hit, DEFAULTING, status))
        for bank, value, code in zip(banks, equity, status, strict=True):
            bank.equity, bank.status = float(value), float(code)
        system.report('defaults', float(np.sum(status != SOLVENT)))
        system.report('losses', float(losses.sum()))

Equations

The equations are those that symbolic returns for the system with its default parameters.