DiscreteVolatilityFunctionProviderFromInterpolatedTermStructure extends DiscreteVolatilityFunctionProvider { @Override public DiscreteVolatilityFunction from(final DoublesPair[] expiryStrikePoints) { ArgumentChecker.noNulls(expiryStrikePoints, "expiryStrikePoints"); final int n = expiryStrikePoints.length; final Double[] expiries = new Double[n]; for (int i = 0; i < n; i++) { expiries[i] = expiryStrikePoints[i].first; } final VectorFunction vf = _funcPro.from(expiries); return new DiscreteVolatilityFunction() { @Override public int getLengthOfRange() { return vf.getLengthOfRange(); } @Override public int getLengthOfDomain() { return vf.getLengthOfDomain(); } @Override public DoubleMatrix2D calculateJacobian(final DoubleMatrix1D x) { return vf.calculateJacobian(x); } @Override public DoubleMatrix1D evaluate(final DoubleMatrix1D x) { return vf.evaluate(x); } }; } DiscreteVolatilityFunctionProviderFromInterpolatedTermStructure(final double[] knotPoints, final Interpolator1D interpolator); @Override DiscreteVolatilityFunction from(final DoublesPair[] expiryStrikePoints);  }
@Test public void test() { final DiscreteVolatilityFunctionProvider discPro = new DiscreteVolatilityFunctionProviderFromInterpolatedTermStructure(KNOTS, INTERPOLATOR); final List<DoublesPair> points = new ArrayList<>(); points.add(DoublesPair.of(3.4, 0.05)); points.add(DoublesPair.of(0.1, 0.06)); points.add(DoublesPair.of(12.0, 0.05)); points.add(DoublesPair.of(5.0, 0.12)); final DiscreteVolatilityFunction func = discPro.from(points); assertEquals(KNOTS.length, func.getLengthOfDomain()); assertEquals(points.size(), func.getLengthOfRange()); final DoubleMatrix1D knotValues = new DoubleMatrix1D(0.7, 0.6, 0.55, 0.7, 1.2, 1.0, 0.8); final DoubleMatrix1D vols1 = func.evaluate(knotValues); final VectorFunctionProvider<Double> vfp = new InterpolatedVectorFunctionProvider(INTERPOLATOR, KNOTS); final VectorFunction vf = vfp.from(new Double[] {3.4, 0.1, 12.0, 5.0 }); final DoubleMatrix1D vols2 = vf.evaluate(knotValues); AssertMatrix.assertEqualsVectors(vols2, vols1, 1e-13); final DoubleMatrix2D jac1 = func.calculateJacobian(knotValues); final DoubleMatrix2D jac2 = vf.calculateJacobian(knotValues); AssertMatrix.assertEqualsMatrix(jac2, jac1, 1e-14); }