2.3.2. sdepy.wiener_source

class sdepy.wiener_source(*, paths=1, vshape=(), dtype=None, corr=None, rho=None)[source]

dw, a source of standard Wiener process (Brownian motion) increments.

Parameters:
paths : int

Number of paths (last dimension) of the source realizations.

vshape : tuple of int

Shape of source values.

dtype : data-type

Data type of source values. Defaults to None.

corr : array-like, or callable, or None

Correlation matrix of the standard Wiener process increments, possibly time-dependent, or None for no correlations, or for correlations specified by the rho parameter. If not None, overrides rho. If corr is a square matrix of shape (M, M), or callable with corr(t) evaluating to such matrix, the last dimension of the source values must be of size M (vshape[-1] == M), and increments along the last axis of the source values will be correlated accordingly.

rho : array-like, or callable, or None

Correlations of the standard Wiener process increments, possibly time-dependent, or None for no correlations. If rho is scalar, or callable with rho(t) evaluating to a scalar, M=2 is assumed, and corr=((1, rho), (rho, 1)). If rho is a vector of shape (K,), or a callable with rho(t) evaluating to such vector, M=2*K is assumed, and the M source values along the last vshape dimension are correlated so that rho[i] correlates the i-th and K+i-th values, other correlations being zero (corr = array((I, R), (R, I)) where I = numpy.eye(K) and R = numpy.diag(rho)).

Returns:
array

Once instantiated as dw, dw(t, dt) returns a random realization of standard Wiener process increments from time t to time t + dt, with shape (t + dt).shape + vshape + (paths,). The increments are normal variates with mean 0, either independent with standard deviation sqrt(dt), or correlated with covariance matrix corr*dt, or corr(t + dt/2)*dt (the latter approximates the integral of corr(t) from t to t + dt).

See also

source

Notes

Realizations across different t and/or dt array elements, and/or across different paths, and/or along axes of the source values other than the last axis of vshape, are independent. corr should be a correlation matrix with unit diagonal elements and off-diagonal correlation coefficients, not a covariance matrix.

corr and rho values with a trailing one-dimensional paths axis are accepted, of shape (M, M, 1) or (M/2, 1) respectively. This last axis is ignored: this allows for deterministic process instances (single path processes) to be passed as valid corr or rho values. Path dependent corr and rho are not supported.

For time-dependent correlations, dw(t, dt) approximates the increments of a process w(t) obeying the SDE dw(t) = D(t)*dz(t), where z(t) are standard uncorrelated Wiener processes, and D(t) is a time-dependent matrix such that D(t) @ (D(t).T) == corr(t). Note that, given any two time points s and t > s, by the Ito isometry the expectation value of (w(t)-w(s))[i] * (w(t)-w(s))[j], i.e. the i, j element of the covariance matrix of increments of w from s to t, equals the integral of corr(u)[i, j] in du from s to t.

For time-independent correlations, as well as for correlations that depend linearly on t, the resulting dw(t, dt) is exact, as far as it can be within the accuracy of the pseudo-random normal variate generator of NumPy. Otherwise, mind using small enough dt intervals.

Attributes:
corr : array, or callable

Stores the correlation matrix used computing increments. May expose either a reference to corr, if provided explicitly, or an appropriate object, in case rho was specified.

Methods

__call__(t, dt) See wiener_source class documentation.