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 therho
parameter. If notNone
, overridesrho
. Ifcorr
is a square matrix of shape(M, M)
, or callable withcorr(t)
evaluating to such matrix, the last dimension of the source values must be of sizeM
(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. Ifrho
is scalar, or callable withrho(t)
evaluating to a scalar,M=2
is assumed, andcorr=((1, rho), (rho, 1))
. Ifrho
is a vector of shape(K,)
, or a callable withrho(t)
evaluating to such vector,M=2*K
is assumed, and theM
source values along the lastvshape
dimension are correlated so thatrho[i]
correlates thei
-th andK+i
-th values, other correlations being zero (corr = array((I, R), (R, I))
whereI = numpy.eye(K)
andR = numpy.diag(rho)
).
Returns: - array
Once instantiated as
dw
,dw(t, dt)
returns a random realization of standard Wiener process increments from timet
to timet + dt
, with shape(t + dt).shape + vshape + (paths,)
. The increments are normal variates with mean 0, either independent with standard deviationsqrt(dt)
, or correlated with covariance matrixcorr*dt
, orcorr(t + dt/2)*dt
(the latter approximates the integral ofcorr(t)
fromt
tot + dt
).
See also
Notes
Realizations across different
t
and/ordt
array elements, and/or across different paths, and/or along axes of the source values other than the last axis ofvshape
, are independent.corr
should be a correlation matrix with unit diagonal elements and off-diagonal correlation coefficients, not a covariance matrix.corr
andrho
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 deterministicprocess
instances (single path processes) to be passed as validcorr
orrho
values. Path dependentcorr
andrho
are not supported.For time-dependent correlations,
dw(t, dt)
approximates the increments of a processw(t)
obeying the SDEdw(t) = D(t)*dz(t)
, wherez(t)
are standard uncorrelated Wiener processes, andD(t)
is a time-dependent matrix such thatD(t) @ (D(t).T) == corr(t)
. Note that, given any two time pointss
andt > s
, by the Ito isometry the expectation value of(w(t)-w(s))[i] * (w(t)-w(s))[j]
, i.e. thei
,j
element of the covariance matrix of increments ofw
froms
tot
, equals the integral ofcorr(u)[i, j]
indu
froms
tot
.For time-independent correlations, as well as for correlations that depend linearly on
t
, the resultingdw(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 enoughdt
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 caserho
was specified.
Methods
__call__
(t, dt)See wiener_source class documentation.