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


The QR decomposition, also known as the QR factorization, is another method of solving linear systems of equations using matrices, very much like the LU decomposition. The equation to solve is in the form of , where matrix . Except in this case, A is a product of an orthogonal matrix Q and upper triangular matrix R. The QR algorithm is commonly used to solve the linear least squares problem.

An orthogonal matrix exhibits the following properties:

  • It is a square matrix

  • Multiplying an orthogonal matrix by its transpose returns the identity matrix:

  • The inverse of an orthogonal matrix equals its transpose:

An identity matrix is also a square matrix with its main diagonal containing ones and zeros elsewhere.

We can now restate the problem as follows:

Using the same variables in the LU decomposition example, we will use the qr function of scipy.linalg to compute our values of Q and R, and let the variable y represent our value of with the following code:

""" QR decomposition with...