2.4.2. sdepy.integrator

class sdepy.integrator(*, paths=1, xshape=(), wshape=(), dtype=None, steps=None, i0=0, info=None, getinfo=True, method='euler')[source]

Step by step numerical integration of Ito Stochastic Differential Equations (SDEs), intended for subclassing.

For usage, see the SDE class documentation.

This class encapsulates SDE integration methods, and cooperates with the SDE class, that should always have precedence in method resolution order. As long as the respective APIs are complied with, a new integrator stated as an integrator subclass will interoperate with existing SDEs (as described by SDE subclasses), and a new SDE will interoperate with existing integrators.

Parameters:
paths, xshape, wshape, dtype, steps, i0, info, getinfo

See paths_generator class documentation.

method : string

Integration method. Defaults to 'euler', for the Euler-Maruyama method (at present, this single method is supported). It is stored as an attribute of the same name.

Returns:
process

Once instantiated as p, p(timeline) performs the integration along the given timeline, based on parameters of instantiation, returning the resulting process as determined by the cooperating SDE subclass and the chosen integration method. Defaults to a process of numpy.nan along the given timeline.

Notes

The equation to be integrated is exposed to the integration algorithm in a standardized form, via methods A and dZ delegated to a cooperating SDE class. The latter should take care of equation parameters, initial conditions, expected paths and shapes, and should instantiate all necessary stochasticity sources.

The integration method is exposed as the next method to the paths_generator parent class.

If the getinfo attribute is set to True, at each integration step the following items are added to the itervars dictionary, made available to subclasses to track the integration progress:

  • last_t: starting time point of the last integration step.
  • last_dt: time increment of the last integration step.
  • last_x : starting value of the process, at time last_t.
  • last_A: dictionary of the last computed values of the SDE terms, at time last_t.
  • last_dZ: dictionary of the last realized SDE stochasticity source values, cumulated in the interval from last_t to last_t + last_dt.
  • new_x : computed value of the process, at time last_t + last_dt.

This becomes relevant in case the output timeline is coarse (e.g. just the initial and final time) but diagnostic information is needed about all integration steps performed (e.g., to track how often the process has changed sign, or to count the number of realized jumps).

Methods

A(t, x) Value of the SDE terms at time t and process value x.
dZ(t, dt) Value of the SDE differentials at time t, for time increment dt.
next() Perform an integration step with the requested method.
euler_next() Euler-Maruyama integration step.