Skip to content

Geometric Brownian motion

An asset whose price follows geometric Brownian motion.

  • Class: GeometricBrownianMotionSystem
  • Import: from skcomplex.systems.economics.finance import GeometricBrownianMotionSystem
  • Field: economics/finance
  • Topics: asset, sde
  • References:
    • Black and Scholes 1973

The geometric_brownian_motion example

Example

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 GeometricBrownianMotionSystem

trajectory = GeometricBrownianMotionSystem().prepare().simulate()

Parameters

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

Parameter Default
price 100.0
mu 0.05
sigma 0.2
solver 'auto'
backend 'auto'

Tags

The system with its default parameters has these capability tags, which solvers and analyses check.

Tag Values
Time continuous
Space none
Laws noise, rate
Randomness stochastic
Domains real
Structure fixed

Class

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

class GeometricBrownianMotionSystem(BaseSystem):
    """An asset whose price follows geometric Brownian motion.

    The system has the asset `asset`.

    Args:
        price:
            The initial price.

        mu:
            The drift.

        sigma:
            The volatility.

        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 GeometricBrownianMotionSystem
        >>> GeometricBrownianMotionSystem(sigma=0.3).prepare().system_.interactions[0].sigma
        0.3
    """

    field = 'economics/finance'
    topics = ('asset', 'sde')
    references = ('Black and Scholes 1973',)
    until = 1.0
    dt = 0.01

    def __init__(
        self,
        price: float = 100.0,
        *,
        mu: float = 0.05,
        sigma: float = 0.2,
        label: str = 'system',
        solver: BaseSolver | str = 'auto',
        backend: BaseBackend | str = 'auto',
    ) -> None:
        super().__init__(label, solver=solver, backend=backend)
        self.price = price
        self.mu = mu
        self.sigma = sigma

    def _prepare(self, context: Sequence[Observable] | None = None) -> None:
        """Set the system of the components built from the model parameters."""
        super()._prepare(context)
        self.system_ = System(
            self.label,
            elements=[AssetElement('asset', price=self.price)],
            interactions=[GeometricBrownianMotionInteraction('gbm', target='asset', mu=self.mu, sigma=self.sigma)],
        )

Components

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

Elements:

Interactions:

  • GeometricBrownianMotionInteraction, from Interaction
class AssetElement(Element):
    """Traded asset described by its price.

    Args:
        label:
            The label of the asset.

        price:
            The initial price.

    Examples:
        >>> from skcomplex.systems.economics.finance import AssetElement
        >>> AssetElement('stock', price=100.0).price
        100.0
    """

    def __init__(
        self,
        label: str,
        *,
        price: Annotated[float, RealSet.open(0, oo)] = 1.0,
    ) -> None:
        super().__init__(label)
        self.price = price

class GeometricBrownianMotionInteraction(Interaction):
    """Geometric Brownian motion of the price of an asset.

    It follows `dS = mu * S * dt + sigma * S * dW`. The Wiener process `dW` is independent by default, or process
    `index` of a `WienerProcessSpec` that correlates it with the motions of other assets.

    Args:
        label:
            The label of the interaction.

        target:
            The path of the asset.

        mu:
            The drift.

        sigma:
            The volatility.

        process:
            The Wiener processes, one of which drives the price, or `None` for an independent process.

        index:
            The process of `process` that drives the price, or `None` without processes.

    Examples:
        >>> from skcomplex.systems.economics.finance import GeometricBrownianMotionInteraction
        >>> from skcomplex.core.components.interactions import WienerProcessSpec
        >>> GeometricBrownianMotionInteraction('gbm', target='stock', sigma=0.3).sigma
        0.3
        >>> market = WienerProcessSpec('market', dimension=2)
        >>> GeometricBrownianMotionInteraction('gbm', target='stock', process=market, index=1).index
        1
    """

    law_classes = (RateLaw, NoiseLaw)

    def __init__(
        self,
        label: str,
        *,
        target: Role,
        mu: float = 0.05,
        sigma: Annotated[float, RealSet.closed_open(0, oo)] = 0.2,
        process: WienerProcessSpec | None = None,
        index: int | None = None,
    ) -> None:
        super().__init__(label)
        self.target = target
        self.mu = mu
        self.sigma = sigma
        self.process = process
        self.index = index

    def _prepare(self, context: SimpleNamespace) -> None:
        """Set the drift `mu * S` and the noise `sigma * S dW` of the price as the laws.

        Args:
            context:
                The namespace of the elements a binding of the roles names.
        """
        super()._prepare(context)
        price = context.target.price
        process = None
        if self.process is not None:
            process = context.process.dW if self.index is None else context.process.dW[self.index]
        self.laws_: list[BaseLaw] = [
            RateLaw(price, context.mu * price),
            NoiseLaw(price, context.sigma * price, process=process),
        ]

Equations

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

asset.price: diff(price_asset(t), t) == mu_gbm*price_asset(t)