Stochastic Calculus
Mathematical foundations of stochastic calculus in Asgard. The Runtime page covers the API; this page covers the underlying mathematics.
Stochastic Processes
A one-dimensional stochastic process $X_t$ is defined by a stochastic differential equation (SDE):
$$dX_t = a(t, X_t),dt + b(t, X_t),dW_t$$
where:
- $a(t, X_t)$ is the drift coefficient (deterministic tendency)
- $b(t, X_t)$ is the diffusion coefficient (noise intensity)
- $W_t$ is a Wiener process (standard Brownian motion)
Equivalently, in integral form:
$$X_t = X_0 + \int_0^t a(s, X_s),ds + \int_0^t b(s, X_s),dW_s$$
The first integral is the standard Riemann integral. The definition of the stochastic integral $\int f,dW_t$ determines which stochastic calculus we are working in. There are two viable choices: Itô and Stratonovich.
Itô Calculus
The Itô integral evaluates the integrand at the left endpoint of each partition interval. This makes it non-anticipating (the integrand does not "look ahead" to future values of $W_t$), which gives the integral the martingale property: the conditional expectation of future values equals the current value.
Itô Lemma
The Itô Lemma is the chain rule of stochastic calculus. For a twice differentiable function $f$ and an $m$-dimensional continuous semimartingale $X = \langle X^1, \ldots, X^m \rangle$:
$$f(X_t) = f(X_0) + \sum_{i=1}^{m} \int_0^t \frac{\partial f}{\partial x_i}(X_s),dX_s^i + \frac{1}{2}\sum_{i,j=1}^{m} \int_0^t \frac{\partial^2 f}{\partial x_i \partial x_j}(X_s),d[X^i, X^j]_s$$
where $[X^i, X^j]_s$ is the quadratic covariation of processes $X^i$ and $X^j$.
The extra second-order term $\frac{1}{2}\sum \frac{\partial^2 f}{\partial x_i \partial x_j},d[X^i, X^j]$ is what distinguishes Itô calculus from classical calculus. It arises because Brownian motion paths have non-zero quadratic variation ($[W, W]_t = t$).
For the common scalar case $dX_t = a,dt + b,dW_t$ and a function $g(t, X_t)$:
$$dg = \frac{\partial g}{\partial t},dt + \frac{\partial g}{\partial x},dX_t + \frac{1}{2}\frac{\partial^2 g}{\partial x^2},b^2,dt$$
Stratonovich Calculus
The Stratonovich integral evaluates the integrand at the midpoint of each partition interval. The key advantage: it preserves the classical chain rule from ordinary calculus. If $f$ is a smooth function and $X_t$ satisfies an SDE, then:
$$df(X_t) = f'(X_t),dX_t \quad \text{(Stratonovich)}$$
with no correction term. This makes Stratonovich calculus the natural choice when modelling continuous physical systems where the classical rules of calculus should hold.
However, the Stratonovich integral is not a martingale and does not satisfy the Fokker-Planck equation directly.
Itô-Stratonovich Conversion
The two integrals are related by a correction term. For a function $h$ of Brownian motion:
$$\int_0^T h(W_t) \circ dW_t = \int_0^T h(W_t),dW_t + \frac{1}{2}\int_0^T h'(W_t),dt$$
where $\circ,dW_t$ denotes the Stratonovich integral and $dW_t$ denotes the Itô integral.
For SDEs, the conversion works through a drift correction. An SDE in Stratonovich form:
$$dX_t = a(t, X_t),dt + b(t, X_t) \circ dW_t$$
is equivalent to the Itô SDE:
$$dX_t = \bar{a}(t, X_t),dt + b(t, X_t),dW_t$$
where the corrected drift is:
$$\bar{a}(t, X) = a(t, X) + \frac{1}{2},b(t, X),\frac{\partial b}{\partial X}(t, X)$$
The correction term $\frac{1}{2}b\frac{\partial b}{\partial X}$ is called the noise-induced drift or Stratonovich correction. It vanishes when the diffusion coefficient $b$ is constant (additive noise), in which case both calculi agree.
When to Use Which
| Criterion | Itô | Stratonovich |
|---|---|---|
| Chain rule | Itô Lemma (extra term) | Classical chain rule |
| Martingale | Yes | No |
| Fokker-Planck | Directly applicable | Requires conversion |
| Moment equations | Clean expressions | More complex |
| Physical systems | Less natural | Natural (classical rules) |
| Discrete models | Better fit | Less natural |
| Numerical schemes | Euler-Maruyama is $O(\sqrt{\Delta t})$ strong | Euler-Heun needed |
| Convergence | Standard discretization | Brownian bridge convergence |
Rules of thumb:
- Use Itô for financial models, discrete systems, and when you need martingale properties or Fokker-Planck equations
- Use Stratonovich for continuous physical systems where classical calculus rules should apply, and when simulating via Brownian bridge sample paths
Since the two formulations are always interconvertible via the drift correction formula, the choice is one of convenience rather than correctness.
Taylor Expansions
Both calculi have stochastic generalizations of the Taylor expansion, used in higher-order numerical schemes.
The Itô-Taylor expansion of a function $f(X_t)$ involves iterated stochastic integrals $I_\alpha$ indexed by multi-indices $\alpha$. Truncating to order $m$ gives schemes of increasing accuracy:
- Order 0.5: Euler-Maruyama (simplest)
- Order 1.0: Milstein (includes $\int W,dW$ term)
- Higher orders: require iterated stochastic integrals
The Stratonovich-Taylor expansion has similar structure but uses Stratonovich iterated integrals, which satisfy simpler algebraic identities due to the classical chain rule.
Connection to Asgard
Asgard implements both calculi through StochasticCalculus (parameters) and
StochasticCircuitExecutor (execution):
from gimle.asgard.circuit.circuit import Circuit
from gimle.asgard.runtime.stochastic_circuit_executor import (
StochasticCircuitExecutor,
)
from gimle.asgard.runtime.stream_evaluator import StochasticCalculus
# Define the calculus (drift, diffusion, Monte Carlo settings)
calculus = StochasticCalculus(
drift=0.0,
diffusion=1.0,
n_paths=1000,
dt=0.01,
)
# Compile and execute a circuit
circuit = Circuit.from_string("composition(var(noise), register(t))")
executor = StochasticCircuitExecutor(circuit)
paths = executor.execute(
input_streams=[noise_stream],
stochastic_dims={"t": calculus},
t_start=0.0,
t_end=2.0,
)
The stochastic circuit executor:
- Generates Brownian paths via
jax.randomwith configurable seed - Applies Euler-Maruyama (Itô) or Euler-Heun (Stratonovich) time-stepping
- Computes ensemble statistics (mean, variance, quantiles) across paths
- Handles Itô-Stratonovich conversion internally when needed
Circuit operations like register and deregister adapt their behaviour
based on the calculus: under stochastic semantics, register implements
stochastic integration rather than deterministic coefficient shifting.
Next Steps
- Runtime — API for configuring and running stochastic simulations
- Approximation Theory — The deterministic polynomial semantics that stochastic calculus extends