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 LU decomposition


The LU decomposition, or also known as lower upper factorization, is one of the methods of solving square systems of linear equations. As its name implies, the LU factorization decomposes matrix A into a product of two matrices: a lower triangular matrix L and an upper triangular matrix U. The decomposition can be represented as follows:

Here, we can see , , and so on. A lower triangular matrix is a matrix that contains values in its lower triangle with the remaining upper triangle populated with zeros. The converse is true for an upper triangular matrix.

The definite advantage of the LU decomposition method over the Cholesky decomposition method is that it works for any square matrices. The latter method only works for symmetric and positive definite matrices.

Remember the previous example of a 3 by 3 matrix A. This time, though, we will use the linalg package of the SciPy module for the LU decomposition:

""" LU decomposition with SciPy """
import scipy.linalg as linalg...