Linear interpolation with QuantLib

QuantLib includes numerous mathematical and function-related tools. And, it often makes the things very easy for us. As an illustration, we implement the linear interpolation function.

In the example code below, we compute linearly interpolated f(x) values for the corresponding x = 1,5 and 3,5.

x 0 1 1.5 2 3 3,5 4
f(x) 2 3.5 ? 3 2.75 ? 5

using namespace QuantLib;
using std::vector;
using std::cout;
using std::endl;

int main (int, char*[]){

	// Vector creation
	double xVectorData[]= {0, 1, 2, 3, 4};
	double yVectorData[]= {2, 3.5, 3, 2.75, 6};
	vector<double>xVector(xVectorData, xVectorData+5);
	vector<double>yVector(yVectorData, yVectorData+5);

	// Implementation of the Linear interpolation function
	LinearInterpolation linInt (

	// Outputting
	cout << "Linearly interpolated value for :" << endl;
	cout << "x = 1.5 is " << linInt (1.5) << endl;
	cout << "x = 3.5 is " << linInt (3.5) << endl;

	return 0;

4 pensamientos en “Linear interpolation with QuantLib

  1. édouard Autor de la entrada

    I wish to thank Will Smith for a comment he made. There were “extrapolation” meanings here and there in my post instead of “interpolation” . Will owns a brilliant website on commodity modelling. You may want to have a look at it :

    1. édouard Autor de la entrada

      One can certainly implement an interpolation scheme to get more option values. Then, one first have to think of the nature of that interpolation.
      As regards the sort of error that might happen, one could expect some mispricing due to the convexity of the option price. Does that make sense?
      Esta pregunta ahora parece como la mientras una entrevista para una puesto como análista cuantitativo jejejejeje 🙂



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

Logo de

Estás comentando usando tu cuenta de 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