Numerical Methods in Computational Finance. Daniel J. Duffy
Читать онлайн книгу.(0.0554, 0.0559), (0.0556, 0.0559), (0.0558, 0.0559), (0.05589, 0.0559).
For a more complete discussion of Boost odeint, see Duffy (2018).
We complete our discussion of finite difference methods for (3.10). The full problem is (3.11); (3.12) is a coupled system of equations, and it can be solved in different ways. The most effective approach at this stage is to use a production third-party ODE solver in C++.
3.7 MATRIX DIFFERENTIAL EQUATIONS
We have seen what scalar and vector ODEs are. Now we consider matrix ODEs.
The Boost odeint library can be used to solve matrix ODEs, for example:
where A, B and Y are
It can be shown that the solution of system (3.25) can be written as (see Brauer and Nohel (1969)):
(3.26)
A special case is when:
(3.27)
(3.28)
The conclusion is that we can now compute the exponential of a matrix by solving a matrix ODE. We now discuss this topic using C++. To this end, we examine the system:
(3.29)
where C is a given matrix.
We model this system by the following C++ class:
namespace ublas = boost::numeric::ublas; using value_type = double; using state_type = boost::numeric::ublas::matrix<value_type>; class MatrixOde { private: // dB/dt = A*B, B(0) = C; ublas::matrix<value_type> A_; ublas::matrix<value_type> C_; public: MatrixOde(const ublas::matrix<value_type>& A, const ublas::matrix<value_type>& IC) : A_(A), C_(IC) {} void operator()(const state_type &x , state_type &dxdt, double t ) const { for( std::size_t i=0 ; i < x.size1();++i ) { for( std::size_t j=0 ; j < x.size2(); ++j ) { dxdt(i, j) = 0.0; for (std::size_t k = 0; k < x.size2(); ++k) { dxdt(i, j) += A_(i,k)*x(k,j); } } } } };
There are many dubious ways to compute the exponential of a matrix, see Moler and Van Loan (2003), one of which involves the application of ODE solvers. Other methods include:
S1: Series methods (for example, truncating the infinite Taylor series representation for the exponential).
S2: Padé rational approximant. This entails approximating the exponential by a special kind of rational function.
S3: Polynomial methods using the Cayley–Hamilton method.
S4: Inverse Laplace transform.
S5: Matrix decomposition methods.
S6: Splitting methods.
3.7.1 Transition Rate Matrices and Continuous Time Markov Chains
An interesting application of matrices and matrix ODEs is to the modelling of credit rating applications (Wilmott (2006), vol. 2, pp. 665–73). To this end, we define a so-called transition matrix P, which is a table whose elements are probabilities representing migrations from one credit rating to another credit rating. For example, a company having a B rating has a probability 0.07 of getting a BB rating in a small period of time. More generally, we are interested in continuous-time transitions between states using Markov chains, and we have the following Kolmogorov forward equation:
(3.30)
where
The Kolmogorov backward equation is:
(3.31)
The objective is to compute the transition rate matrix Q (that is, states that are in one-to-one correspondence with the integers).
In the case of countable space, the Kolmogorov forward equation is:
(3.32)
where Q(t)