2D Interpolation methods

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

2D Interpolation methods

asavoldi
Hi,

I would like to use 2D interpolation methods available in Quantlib, which are Bilinear and BicubicSpline.
At the moment I use the following code snippet. However I obtain the folowing error:

1>C:\QuantLib-1.3\ql/math/interpolations/bilinearinterpolation.hpp(55): error C2678: '-' binario: non è stato trovato alcun operatore che accetti un operando sinistro di tipo 'QuantLib::Real'. È anche possibile che non vi siano conversioni accettabili.

The problem regards this line of code:

vi = interp2D((int)dayCounter.dayCount(Settings::instance().evaluationDate(), expirations_matrix.at(i)), strikes_matrix.at(j), true);

where vi is a variable of Real type. What should I change in order to fix this issue? Is there a simple example of how to use such function (with the two methods of interpolation)?

Thanks in advance.



//Test bidimensional interpolation
BilinearInterpolation interp2D(expirations.begin(), expirations.end(), strikes.begin(), strikes.end(), vol);
interp2D.enableExtrapolation(true);
       
std::ofstream volSurfaceFileCCG3;
volSurfaceFileCCG3.open("./m3.dat", std::ios::out);

Real vi = 0.0;

for (unsigned int i = 0; i < expirations_matrix.size(); i++){
        for (unsigned int j = 0; j < strikes_matrix.size(); j++){

vi = interp2D((int)dayCounter.dayCount(Settings::instance().evaluationDate(), expirations_matrix.at(i)), strikes_matrix.at(j), true);

volSurfaceFileCCG3 << boost::format("%f %f %f")
% strikes_matrix.at(j)
% dayCounter.dayCount(Settings::instance().evaluationDate(), expirations_matrix.at(i))
% vi
<< std::endl;

}
}
volSurfaceFileCCG3.close();

Reply | Threaded
Open this post in threaded view
|

Re: 2D Interpolation methods

asavoldi
I solved the issue I was dealing with. Now I pass a vector of integers instead of a vector of dates, which caused the compilation problem.

BilinearInterpolation interp2D(time.begin(), time.end(), strikes.begin(), strikes.end(), vol);