HestonVolatilityFunction extends VolatilityFunctionProvider<HestonModelData> { @Override public Function1D<HestonModelData, double[]> getVolatilityAdjointFunction(final EuropeanVanillaOption option, final double forward) { final Function1D<HestonModelData, double[][]> func = getVolatilityAdjointFunction(forward, new double[] {option.getStrike() }, option.getTimeToExpiry()); return new Function1D<HestonModelData, double[]>() { @Override public double[] evaluate(final HestonModelData x) { final double[][] temp = func.evaluate(x); Validate.isTrue(temp.length == 1); return temp[0]; } }; } HestonVolatilityFunction(); @Override Function1D<HestonModelData, Double> getVolatilityFunction(final EuropeanVanillaOption option, final double forward); @Override Function1D<HestonModelData, double[]> getVolatilityFunction(final double forward, final double[] strikes, final double timeToExpiry); @ExternalFunction double getVolatility(final double forward, final double strike, final double timeToExpiry, final double kappa, final double theta, final double vol0, final double omega,
      final double rho); @ExternalFunction double[] getVolatilitySet(final double forward, final double[] strikes, final double timeToExpiry, final double kappa, final double theta, final double vol0, final double omega,
      final double rho); @Override Function1D<HestonModelData, double[]> getVolatilityAdjointFunction(final EuropeanVanillaOption option, final double forward); @Override Function1D<HestonModelData, double[][]> getVolatilityAdjointFunction(final double forward, final double[] strikes,
      final double timeToExpiry); @Override Function1D<HestonModelData, double[]> getModelAdjointFunction(final EuropeanVanillaOption option, final double forward); @Override Function1D<HestonModelData, double[][]> getModelAdjointFunction(final double forward, final double[] strikes,
      final double timeToExpiry); @Override int hashCode(); @Override boolean equals(final Object obj); @Override String toString();  }
@Test public void tesVolFunctionAdjoint() { final int n = STRIKES.length; final Function1D<HestonModelData, double[][]> adjointSetFunc = VOL_FUNC_PROVIDER.getVolatilityAdjointFunction(FORWARD, STRIKES, TIME); final Function1D<HestonModelData, double[][]> adjointSetFuncFD = VOL_FUNC_PROVIDER_FD.getVolatilityAdjointFunction(FORWARD, STRIKES, TIME); final double[][] adjointSet = adjointSetFunc.evaluate(DATA); final double[][] adjointSetFD = adjointSetFuncFD.evaluate(DATA); assertEquals(adjointSet.length, n, "#strikes"); assertEquals(adjointSetFD.length, n, "#strikes FD"); assertEquals(adjointSet[0].length, 8, "#parameters"); assertEquals(adjointSetFD[0].length, 8, "#parameters FD"); for (int i = 0; i < n; i++) { for (int pIndex = 3; pIndex < 8; pIndex++) { assertEquals(adjointSetFD[i][pIndex], adjointSet[i][pIndex], 5e-3, "parameter: " + pIndex + ". strike: " + i); } } }