Book Image

Mastering Python for Finance

Book Image

Mastering Python for Finance

Overview of this book

Table of Contents (17 chapters)
Mastering Python for Finance
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

The Cholesky decomposition


The Cholesky decomposition is another way of solving systems of linear equations. It can be significantly faster and uses a lot of less memory than the LU decomposition by exploiting the property of symmetric matrices. However, it is required that the matrix being decomposed be Hermitian (or real-valued symmetric and thus square) and positive definite. This means that when the matrix A is decomposed as , L is a lower triangular matrix with real and positive numbers on the diagonals, and is the conjugate transpose of L.

Let's consider another example of a system of linear equations where matrix A is both Hermitian and positive definite. Again, the equation is in the form of , where A and B take the following values:

Let's represent these matrices as the NumPy arrays:

""" Cholesky decomposition with NumPy """
import numpy as np

A = np.array([[10., -1., 2., 0.],
              [-1., 11., -1., 3.],
              [2., -1., 10., -1.],
              [0.0, 3., -1., 8.]]...