Matrix decomposition with QuantLib

QuantLib includes several matrix decomposition as well as Eigen values/vectors finding tools. If your memory needs a simple refresh in this area of linear algebra, you should visit the Wikipedia’s page on matrix decomposition. For more advanced discussions and other matrix-related topics, Math World reads numerous valuable pages.

In the code below, we shall implement some of these tools. As you will see, it’s quite straightforward. The matrix we work with is the standard square matrix :

#include<ql\quantlib.hpp>
using namespace QuantLib;

using std::endl;
using std::cout;

int main(int, char*[]){

	// Matrix declaration and population
	Matrix A(3,3);
	A[0][0] = 1.0; A[0][1] = 0.5; A[0][2] = 0.2;
	A[1][0] = 0.5; A[1][1] = 1.0; A[1][2] = 0.3;
	A[2][0] = 0.2; A[2][1] = 0.3; A[2][2] = 1.0;

	SymmetricSchurDecomposition schurDec(A);
	SVD SVDDec(A);

	// Outputting
	cout << "Matrix A : " << endl << A << endl;
	cout << "Eigen values (Schur): " << endl;
	schurDec.eigenvalues() << endl;
	cout << "Eigen vector (Schur) : " << endl;
	schurDec.eigenvectors() << endl;
	cout << "Cholesky decomposition : " << endl;
	CholeskyDecomposition(A) << endl;
	cout << "SVD U-matrix : " << endl;
	SVDDec.U() << endl;
	cout << "SVD V-matrix : ";
	endl << SVDDec.V() << endl;

	return 0;
}
About these ads

Un pensamiento en “Matrix decomposition with QuantLib

  1. Pingback: Generation of correlated random numbers: recommended article | Quant Corner

Deja un comentario

Por favor, inicia sesión con uno de estos métodos para publicar tu comentario:

Logo de WordPress.com

Estás comentando usando tu cuenta de WordPress.com. Cerrar sesión / Cambiar )

Imagen de Twitter

Estás comentando usando tu cuenta de Twitter. Cerrar sesión / Cambiar )

Foto de Facebook

Estás comentando usando tu cuenta de Facebook. Cerrar sesión / Cambiar )

Google+ photo

Estás comentando usando tu cuenta de Google+. Cerrar sesión / Cambiar )

Conectando a %s