Cobweb
A market whose price converges to or oscillates around equilibrium.
- Class:
CobwebSystem - Import:
from skcomplex.systems.economics.markets import CobwebSystem - Field:
economics/markets - Topics:
market,discrete map - References:
- Ezekiel 1938
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.markets import CobwebSystem
trajectory = CobwebSystem().prepare().simulate()
Parameters
The model parameters take these defaults, and set_params changes them.
| Parameter | Default |
|---|---|
price |
1.0 |
a |
10.0 |
b |
2.0 |
c |
1.0 |
d |
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 | deterministic |
| Domains | real |
| Structure | fixed |
Class
The source of the class shows how it builds its components from its model parameters.
class CobwebSystem(BaseSystem):
"""A market whose price converges to or oscillates around equilibrium.
Supply lags the price. The system has the market `market`.
Args:
price:
The initial price.
a:
The demand intercept.
b:
The demand slope.
c:
The supply intercept.
d:
The supply slope.
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.markets import CobwebSystem
>>> CobwebSystem(price=2.0).prepare().simulate(until=2).get_values('market.price').tolist()
[2.0, 3.5, 2.75]
"""
field = 'economics/markets'
topics = ('market', 'discrete map')
references = ('Ezekiel 1938',)
until = 30
dt = 1
def __init__(
self,
price: float = 1.0,
*,
a: float = 10.0,
b: float = 2.0,
c: float = 1.0,
d: float = 1.0,
label: str = 'system',
solver: BaseSolver | str = 'auto',
backend: BaseBackend | str = 'auto',
) -> None:
super().__init__(label, solver=solver, backend=backend)
self.price = price
self.a = a
self.b = b
self.c = c
self.d = d
def _prepare(self, context: Sequence[Observable] | None = None) -> None:
"""Set the system of the market and its cobweb."""
super()._prepare(context)
self.system_ = System(
self.label,
elements=[MarketElement('market', price=self.price)],
interactions=[CobwebInteraction('cobweb', target='market', a=self.a, b=self.b, c=self.c, d=self.d)],
)
Components
The system uses these element and interaction classes, each with its nearest class of the core.
Elements:
MarketElement, fromElement
Interactions:
CobwebInteraction, fromInteraction
class MarketElement(Element):
"""Market of one good described by its price.
Args:
label:
The label of the market.
price:
The initial price.
Examples:
>>> from skcomplex.systems.economics.markets import MarketElement
>>> MarketElement('wheat', price=2.0).price
2.0
"""
def __init__(
self,
label: str,
*,
price: float = 1.0,
) -> None:
super().__init__(label)
self.price = price
class CobwebInteraction(Interaction):
"""Cobweb system, where supply reacts to the previous price.
Demand clears the market. Demand is `a - b * price` and supply is `c + d * previous price`, so the next price is
`(a - c - d * price) / b`, a map of the state `price` of the market.
Args:
label:
The label of the interaction.
target:
The path of the market.
a:
The demand intercept.
b:
The demand slope.
c:
The supply intercept.
d:
The supply slope.
Examples:
>>> from skcomplex.systems.economics.markets import CobwebInteraction
>>> CobwebInteraction('cobweb', target='wheat', a=10, b=2, c=1, d=1).b
2
"""
law_classes = (UpdateLaw,)
def __init__(
self,
label: str,
*,
target: Role = 'market',
a: float = 10.0,
b: Annotated[float, RealSet.open(0, oo)] = 2.0,
c: float = 1.0,
d: Annotated[float, RealSet.open(0, oo)] = 1.0,
) -> None:
super().__init__(label)
self.target = target
self.a = a
self.b = b
self.c = c
self.d = d
def _prepare(self, context: SimpleNamespace) -> None:
"""Set the next price `(a - c - d * price) / b`, at which demand buys the supply of the last price.
Args:
context:
The namespace of the elements a binding of the roles names.
"""
super()._prepare(context)
s = context
self.laws_: list[BaseLaw] = [UpdateLaw(s.target.price, (s.a - s.c - s.d * s.target.price) / s.b)]
Equations
The equations are those that symbolic returns for the system with its default parameters.
market.price: price_market(t + 1) == -(d_cobweb*price_market(t) - a_cobweb + c_cobweb)/b_cobweb