2.4.4. sdepy.SDEs¶
-
class
sdepy.SDEs(*, paths=1, vshape=(), dtype=None, steps=None, i0=0, info=None, getinfo=True, method='euler', **args)[source]¶ Class representation of a user defined system of Stochastic Differential Equations (SDEs), intended for subclassing.
The parent
SDEclass represents a single SDE, scalar or multidimensional: by an appropriate choice of thevshapeparameter, and composition of equation values, it suffices to describe any system of SDEs.Its
SDEssubclass is added for convenience of representation: it allows to state each equation separately and to retrieve separate processes as a result. The number of equations must be stated as theqattribute. Thevshapeparameter is taken as the common shape of values in each equation in the system.A minimal definition of a lognormal process
xwith stochastic volatilityyis as follows:>>> from sdepy import SDEs, integrator >>> class my_process(SDEs, integrator): ... q = 2 ... def sde(self, t, x, y, mu=0., sigma=1., xi=1.): ... return ({'dt': mu*x, 'dw': y*x}, ... {'dt': 0, 'dw': xi*y}) >>> P = my_process(x0=(1., 2.), xi=0.5, vshape=5, ... paths=100*1000, steps=100, ) >>> x, y = P(timeline=(0., 0.5, 1.)) >>> x.shape, y.shape ((3, 5, 100000), (3, 5, 100000))
See also
Notes
By default, the stochasticity sources of each component equation are realized independently, even if represented in the
sdeoutput by the same key ('dw'in the example above).The way stochasticity sources are instantiated and dispatched to each equation, and how correlations of the Wiener source are set via the
corrparameter, depend on the value of theaddaxisattribute:- If
True, source values have shapevshape + (q,), and the[kk, i]component of source values is dispatched to thekkcomponent of equationi(kkis a multiindex spanning shapevshape). If given,corrmust be of shape(q, q)and correlates corresponding components across equations. - If
addaxisisFalse(default) andNis the size of the last axis ofvshape, the values of the sources have shapevshape[:-1] + (N*q,), and the[kk, i*N + h]component of the source values is dispatched to the[kk, h]component of equationi(kkis a multiindex spanning shapevshape[:-1], andhis inrange(N)). If given,corrmust be of shape(N*q, N*q), and correlates all last components of all equations to each other.
After instantiation, stochasticity sources and correlation matrices may be inspected as follows:
>>> P = my_process(vshape=(), rho=0.5) >>> P.sources['dw'].vshape (2,) >>> P.sources['dw'].corr.shape (2, 2) >>> P.sources['dw'].corr[0, 1] 0.5
Attributes: - q : int
Number of equations.
- addaxis : bool
Affects the internal representation of the equations: if
True, a last axis of sizeqis added tovshape, ifFalse, components are stacked onto the last axis ofvshape. Defaults toFalse. It is forced toTrueif the process components have scalar values.
Methods
pack(xs)Packs the given arrays (one per equation) into a single array. unpack(X)Unpacks the given array into multiple arrays (one per equation). - If