Construct a BiCubicInterpolation curve


#1

Hi,

I would like to try on the BiCubicInterpolation method in OG but found some difficulties to implement it.
Sorry for this stupid question and not sure if anyone of you could help?

Thanks and Regards,
Tomy

import com.opengamma.analytics.math.*;
import com.opengamma.analytics.math.interpolation.PiecewisePolynomialInterpolator;
import com.opengamma.analytics.math.interpolation.BicubicSplineInterpolator;
import com.opengamma.analytics.math.interpolation.PiecewisePolynomialResult2D;

public class Test {

public static void main(String[] args) {
	
	double[] tenors = new double[6] ;
	double[] deltas = new double[5];
	double[][] volList = new double[6][5];
	deltas[0] = 0.1;
	deltas[1] = 0.25;
	deltas[2] = 0.5;
	deltas[3] = 0.75;
	deltas[4] = 0.9;
	
	tenors[0] = 7;
	tenors[1] = 14;
	tenors[2] = 21;
	tenors[3] = 30;
	tenors[4] = 60;
	tenors[5] = 90;
	//tenors[6] = 180;
		
	volList[0][0] = 7.102473086508976;
	volList[0][1] = 7.362197030337733;
	volList[0][2] = 6.889999999999999;
	volList[0][3] = 6.27019703033773;
	volList[0][4] = 5.3974730865089775;
	
	volList[1][0] = 8.038942408982622;
	volList[1][1] = 7.930665974897735;
	volList[1][2] = 7.244999999999999;
	volList[1][3] = 6.560665974897731;
	volList[1][4] = 5.753942408982631;
	
	volList[2][0] = 8.923409040107146;
	volList[2][1] = 8.50395462249152;
	volList[2][2] = 7.6205;
	volList[2][3] = 6.960954622491518;
	volList[2][4] = 6.248409040107146;
	
	volList[3][0] = 9.327911731456267;
	volList[3][1] = 8.852134919457745;
	volList[3][2] = 7.784999999999999;
	volList[3][3] = 7.090134919457744;
	volList[3][4] = 6.397911731456256;
	
	volList[4][0] = 9.75922873898433;
	volList[4][1] = 9.062496375629301;
	volList[4][2] = 7.959499999999999;
	volList[4][3] = 7.165496375629301;
	volList[4][4] = 6.4292287389843334;
	
	volList[5][0] = 10.402911731456259;
	volList[5][1] = 9.484634919457745;
	volList[5][2] = 8.165;
	volList[5][3] = 7.297634919457745;
	volList[5][4] = 6.642911731456259;
	
	PiecewisePolynomialInterpolator[] pInterpolator = new PiecewisePolynomialInterpolator[2];
	BicubicSplineInterpolator spline = new BicubicSplineInterpolator(pInterpolator);
	
	PiecewisePolynomialResult2D result = spline.interpolate(tenors, deltas, volList);

}

}


#2

Just found there are sample code in each folder. Thanks!


#3

Just for clarification,

Two subclasses of PiecewisePolynomialInterpolator have to be instantiated to specify derivative values at knot points.

Instead of

PiecewisePolynomialInterpolator[] pInterpolator = new PiecewisePolynomialInterpolator[2];

for example,

PiecewisePolynomialInterpolator[] pInterpolator = new PiecewisePolynomialInterpolator[] {new CubicSplineInterpolator(), new CubicSplineInterpolator() };