Skip to content

Kesten processes

Firms whose sizes follow Kesten's process.

  • Class: KestenProcessSystem
  • Import: from skcomplex.systems.economics.finance import KestenProcessSystem
  • Field: economics/finance
  • Topics: multiplicative process, power law, agents
  • References:
    • Caiani et al. 2016
    • Thurner et al. 2018
    • Kesten 1973

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 KestenProcessSystem

trajectory = KestenProcessSystem().prepare().simulate()

Parameters

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

Parameter Default
n_firms 200
x 100.0
lambda_low 0.48
lambda_high 1.48
b_low 0.0
b_high 1.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 stochastic
Domains real
Structure variable membership

Class

The source of the class shows how it builds its components from its model parameters.

class KestenProcessSystem(BaseSystem):
    """Firms whose sizes follow Kesten's process.

    It is a random multiplicative factor plus a random positive term. When the factor shrinks sizes on average, the
    additive term reinjects them, and the stationary distribution has a power-law tail. The system has the group
    `firms`, the mean size `mean_size`, and the largest size `max_size`.

    Args:
        n_firms:
            The number of firms.

        x:
            The initial size of every firm.

        lambda_low:
            The lower bound of the multiplicative factor.

        lambda_high:
            The upper bound of the multiplicative factor.

        b_low:
            The lower bound of the additive term.

        b_high:
            The upper bound of the additive term.

        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 KestenProcessSystem
        >>> KestenProcessSystem(10).prepare().system_.elements[0].size
        10
    """

    field = 'economics/finance'
    topics = ('multiplicative process', 'power law', 'agents')
    references = ('Caiani et al. 2016', 'Thurner et al. 2018', 'Kesten 1973')
    until = 100
    observables = tuple(_get_size_observables())

    def __init__(
        self,
        n_firms: int = 200,
        *,
        x: float = 100.0,
        lambda_low: float = 0.48,
        lambda_high: float = 1.48,
        b_low: float = 0.0,
        b_high: float = 1.0,
        label: str = 'system',
        solver: BaseSolver | str = 'auto',
        backend: BaseBackend | str = 'auto',
    ) -> None:
        super().__init__(label, solver=solver, backend=backend)
        self.n_firms = n_firms
        self.x = x
        self.lambda_low = lambda_low
        self.lambda_high = lambda_high
        self.b_low = b_low
        self.b_high = b_high

    def _prepare(self, context: Sequence[Observable] | None = None) -> None:
        """Set the system of the components built from the model parameters."""
        super()._prepare(context)
        firms = KestenFirmElement(
            'firms',
            x=self.x,
            lambda_low=self.lambda_low,
            lambda_high=self.lambda_high,
            b_low=self.b_low,
            b_high=self.b_high,
            size=self.n_firms,
        )
        growth = KestenGrowthInteraction('growth', target='firms')
        self.system_ = System(self.label, elements=[firms], interactions=[growth])

Components

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

Elements:

Interactions:

  • KestenGrowthInteraction, from Interaction
class KestenFirmElement(Element):
    """Firm whose size follows Kesten's process, `x = lambda x + b`.

    The `lambda` and `b` are uniform random.

    Args:
        label:
            The label of the agent or group.

        x:
            The initial size.

        lambda_low:
            The lower bound of the multiplicative factor.

        lambda_high:
            The upper bound of the multiplicative factor.

        b_low:
            The lower bound of the additive term.

        b_high:
            The upper bound of the additive term.

        size:
            The number of members, or `None` for one.

    Examples:
        >>> from skcomplex.systems.economics.finance import KestenFirmElement
        >>> KestenFirmElement('firms', b_high=2.0, size=10).size
        10
    """

    draws = True

    def __init__(
        self,
        label: str,
        *,
        x: Annotated[object, RealSet.closed_open(0, oo)] = 100.0,
        lambda_low: Annotated[object, RealSet.closed_open(0, oo)] = 0.48,
        lambda_high: Annotated[object, RealSet.closed_open(0, oo)] = 1.48,
        b_low: Annotated[object, RealSet.closed_open(0, oo)] = 0.0,
        b_high: Annotated[object, RealSet.closed_open(0, oo)] = 1.0,
        size: int | None = None,
    ) -> None:
        super().__init__(label, size=size)
        self.x = x
        self.lambda_low = lambda_low
        self.lambda_high = lambda_high
        self.b_low = b_low
        self.b_high = b_high

class KestenGrowthInteraction(Interaction):
    """Growth of the sizes of firms by Kesten's process, `x = lambda x + b`.

    Every step every firm multiplies its size by a factor drawn uniformly between `lambda_low` and `lambda_high` and
    adds a term drawn uniformly between `b_low` and `b_high`, all values of the firm.

    Args:
        label:
            The label of the interaction.

        target:
            The firms, with their sizes `x` and the bounds of their factors and terms.

    Examples:
        >>> from skcomplex.systems.economics.finance import KestenGrowthInteraction
        >>> KestenGrowthInteraction('growth').target
        'firms'
    """

    law_classes = (UpdateLaw,)
    draws = True

    def __init__(self, label: str, *, target: Role = 'firms') -> None:
        super().__init__(label)
        self.target = target

    def _prepare(self, context: SimpleNamespace) -> None:
        """Set the growth of the sizes as the rule of the system.

        Args:
            context:
                The namespace of the elements a binding of the roles names.
        """
        super()._prepare(context)
        self.laws_: list[BaseLaw] = [UpdateLaw(context, self._grow)]

    def _grow(self, system: SystemView) -> None:
        """Multiply the size of every firm by a random factor and add a random term."""
        firms = cast(list[KestenFirmView], system.get_agents('target'))
        sizes = []
        for firm in firms:
            factor = float(system.rng.uniform(firm.lambda_low, firm.lambda_high))
            sizes.append(factor * firm.x + float(system.rng.uniform(firm.b_low, firm.b_high)))
        for firm, size in zip(firms, sizes, strict=True):
            firm.x = size

Equations

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