Stochastic processes
The gallery’s price model calculates realised prices, conditional moments, and log-price growth.
The model declares \(dS_t=\mu S_t\,dt+\sigma S_t\,dW_t\). Its
ItoProcess law applies Itô’s formula to obtain
Start at 100 with growth rate 0.10 and volatility 0.20:
>>> from sympy import Rational
>>> from examples.gallery.extensions import GeometricDiffusion
>>> price = GeometricDiffusion(
... "price", opening=100, growth=Rational(1, 10), volatility=Rational(1, 5),
... duration=1, wiener_increment=0,
... )
>>> price.log_drift, price.log_diffusion
(2/25, 1/5)
>>> price.closing, price.mean
(100*exp(2/25), 100*exp(1/10))
The log-price drift is 0.08. A zero Wiener increment gives the realised closing price \(100e^{0.08}\); the mean over possible increments is \(100e^{0.10}\).
Declare your own process
Import ItoProcess from modello.contrib.stochastic. For one standard
Wiener driver, ItoProcess(X, a, b, t) declares dX = a*dt + b*dW.
For a sufficiently smooth deterministic function f, its transformed drift
is f_t + a*f_x + b**2*f_xx/2 and diffusion is b*f_x.
State and time remain independent during differentiation; named formulas expand first. The state domain must permit the transform, as positivity permits the logarithm above. Smoothness and adaptedness are model hypotheses. A transform rejects an unmodelled process whose quadratic covariation is undeclared.
generator(f) returns the spatial drift without f_t.
quadratic_variation_rate(f) returns the coefficient of dt in the
transformed quadratic variation.
Supported process queries
exact(initial, elapsed, increment) gives arithmetic or geometric Brownian
values conditional on a supplied Wiener increment. mean and variance
give conditional moments, also supporting affine additive diffusions such as
mean reversion. Elapsed time must be nonnegative; zero time requires a zero
increment and returns the initial value or zero variance, even without a
nonzero-time closed form. Initial values and exact endpoints must satisfy the
state domain.
Recover the coefficients by supplying the log-price drift and diffusion:
>>> fitted = GeometricDiffusion(
... "coefficients", opening=100, duration=1, wiener_increment=0,
... log_drift=Rational(2, 25), log_diffusion=Rational(1, 5),
... )
>>> fitted.growth, fitted.volatility
(1/10, 1/5)
An exact mean-reverting path needs a weighted stochastic integral, not a single increment. Zero diffusion supports deterministic exact paths. Multiple drivers, correlations, arbitrary stochastic integrals, and general SDE boundary problems are unsupported. Declare related processes together: a point observation does not make another process a constant coefficient. These checks do not establish that an entire path stays in its state domain. See Generality and solver boundaries for solver boundaries.
problem.templates exposes scoped, read-only laws. The explorer retains
relative subscripts, histories, differentials, and conditional moment notation;
problem.latex exports the same formulas.
API
- class modello.contrib.stochastic.ItoProcess(state, drift, diffusion, time, driver=None)
Declare
dX = drift*dt + diffusion*dWfor one standard Wiener driver.State and time are independent local calculus coordinates.
drift(f)includes the Itô correction and explicit time derivative;generator(f)gives the spatial generator. Observations and inverse parameter solving use ordinary model fields. No distribution is assigned to a supplied sample.- drift(expression: SymbolicScalar | int | float | complex | str | Decimal | Fraction) Expr
Return
f_t + a*f_x + b**2*f_xx/2, expanding model formulas first.
- diffusion(expression: SymbolicScalar | int | float | complex | str | Decimal | Fraction) Expr
Return the coefficient
b*f_xof this law’s Wiener differential.
- generator(expression: SymbolicScalar | int | float | complex | str | Decimal | Fraction) Expr
Return the spatial generator
a*f_x + b**2*f_xx/2.
- quadratic_variation_rate(expression: SymbolicScalar | int | float | complex | str | Decimal | Fraction | None = None) Expr
Return the
dtcoefficient of the transformed quadratic variation.
- exact(initial: SymbolicScalar | int | float | complex | str | Decimal | Fraction, elapsed: SymbolicScalar | int | float | complex | str | Decimal | Fraction, increment: SymbolicScalar | int | float | complex | str | Decimal | Fraction) Expr
Exact arithmetic/geometric Brownian value conditional on
ΔW.Coefficients must be constant additive or proportional to the state.
incrementdenotes a realised Wiener increment over nonnegativeelapsed; this operation neither samples nor estimates that increment.