Numerical Methods in Computational Finance. Daniel J. Duffy
Читать онлайн книгу.example, theorem 5.2.1 in Øksendal (1998) addresses these issues. We discuss SDEs in more detail in Chapter 13.
3.5 NUMERICAL METHODS FOR ODES
In this section we introduce a class of one-step methods to approximate the solution of ODE system (3.1).
The first step is to replace continuous time by discrete time. To this end, we divide the interval [0, T] into a number of subintervals. We define mesh points as follows:
In this case we define a set of subintervals of size
,
.
In general, we speak of a non-uniform mesh when the sizes of the subintervals are not necessarily the same. However, in this book we consider in the main a class of finite difference schemes where the N subintervals have the same length (we then speak of a uniform mesh), namely . The variable
is also used to denote the uniform mesh size.
In general, we define to be the approximate solution at time
and we write the functional dependence of
on
and h by:
where is called the increment function. For example, in the case of the explicit Euler method, this function is:
The increment function represents the increment of the approximate solution. In general, the goal is to produce a formula for that agrees with a certain exact relative increment with an error of
where
without making it necessary to compute the derivative of f (Henrici (1962)). A special case of (3.21) is the fourth-order Runge–Kutta method:
where:
Other methods are:
Second-order Ralston method:
and Heun's (improved Euler) method:
This is a predictor-corrector method that also has applications to stochastic differential equations.
In general, explicit Runge–Kutta methods are unsuitable for stiff ODEs.
3.5.1 Code Samples in Python
We show hand-crafted code for the explicit Euler method as well as the schemes (3.22), (3.23) and (3.24). The main reason is to get hands-on experience with coding solvers for ODEs before using production solvers (for example, Python's or Boost C++ odeint libraries), especially for readers for whom numerical ODEs are new, for example readers with an economics or econometrics background. A good strategy is 1) get it working (write your own code and examples), then 2) get it right (use a library with the same examples) and then and only then get it optimised (use a library in a larger application).
The following code is for the methods:
Explicit Euler
Fourth-order Runge–Kutta (RK4)
Second-order Ralston.
Heun