Stochastic processes are mathematically interesting and practically important for describing problems in finance, statistical physics, and other areas. On the mathematical side, a great deal of theory has been developed to characterize stochastic processes and stochastic integrals, see e.g., Karatzas and Schreve 1991. On the practical side, we are often more interested in, e.g., actually solving particular stochastic differential equations (SDEs) than we are in properties of general classes of SDEs. Numerical methods can be of great use in obtaining solutions to SDEs.

On the other hand, for an advanced undergraduate audience with diverse interests, we should keep the theory accessible with engaging examples. With an abstract and general treatment such as semimartingale integrators (e.g., Protter 1995), students quickly lose interest in the subject. Moreover, the increasing use of a computational approach lowers barriers and encourages students to just "give it a try."

Higham (2001) provides an excellent introduction to numerical simulation of SDEs, with accompanying Matlab programs available to download. For our own use, we have adapted some key elements of Higham's presentation into a set of programs in Python. We took advantage of the greater expressivity of Python to improve upon Higham's programs in several respects:

- We defined two distinct representations of discrete Brownian motion with the same interface and simple conversions between them, allowing us to easily use the most appropriate representation in any case.
- We encapsulated multiple discrete Brownian motion samples into objects, which frequently allows simpler treatment of the samples as atomic units.
- We implemented SDE solvers using first-class functions to define the equations, providing greater modularity to improve reuse of the programs.

References

D. J. Higham. An algorithmic introduction to numerical simulation of stochastic differential equations. SIAM Review, 43(3):525–546, August 2001.

I. Karatzas and S. E. Shreve. Brownian Motion and Stochastic Calculus, 2nd ed., Springer-Verlag, Berlin, 1991.

P. Protter. Stochasic Integration and Differential Equations: A New Approach, Springer-Verlag, 1995.