final double referencePrice = 0.99;
final String name = "ERU2";
final LocalDate REFERENCE_DATE = LocalDate.of(2010, 8, 18);
final ZonedDateTime REFERENCE_DATE_ZONED = ZonedDateTime.of(LocalDateTime.of(REFERENCE_DATE, LocalTime.MIDNIGHT), ZoneOffset.UTC);
final InterestRateFutureSecurityDefinition eru2Definition = new InterestRateFutureSecurityDefinition(LAST_TRADING_DATE, EURIBOR3M, noitonal, futuresAccrualFactor, name, calendar);
final InterestRateFutureSecurity eru2 = eru2Definition.toDerivative(REFERENCE_DATE_ZONED, referencePrice);
final double factor = MODEL.futuresConvexityFactor(MODEL_PARAMETERS, eru2.getLastTradingTime(), eru2.getFixingPeriodStartTime(), eru2.getFixingPeriodEndTime());
final double expectedFactor = 1.000079130767980;
assertEquals("Hull-White one factor: future convexity adjusment factor", expectedFactor, factor, TOLERANCE_RATE);
// Derivative with respect to volatility parameters
final int nbSigma = MODEL_PARAMETERS.getVolatility().length;
final double[] sigmaBar = new double[nbSigma];
final double factor2 = MODEL.futuresConvexityFactor(MODEL_PARAMETERS, eru2.getLastTradingTime(), eru2.getFixingPeriodStartTime(), eru2.getFixingPeriodEndTime(), sigmaBar);
assertEquals("Hull-White one factor: future convexity adjusment factor", factor, factor2, TOLERANCE_RATE);
final double[] sigmaBarExpected = new double[nbSigma];
final double shift = 1E-6;
for (int loops = 0; loops < nbSigma; loops++) {
double[] volBumped = VOLATILITY.clone();
volBumped[loops] += shift;
HullWhiteOneFactorPiecewiseConstantParameters parametersBumped = new HullWhiteOneFactorPiecewiseConstantParameters(MEAN_REVERSION, volBumped, VOLATILITY_TIME);
double factorPlus = MODEL.futuresConvexityFactor(parametersBumped, eru2.getLastTradingTime(), eru2.getFixingPeriodStartTime(), eru2.getFixingPeriodEndTime());
volBumped[loops] -= 2 * shift;
parametersBumped = new HullWhiteOneFactorPiecewiseConstantParameters(MEAN_REVERSION, volBumped, VOLATILITY_TIME);
double factorMinus = MODEL.futuresConvexityFactor(parametersBumped, eru2.getLastTradingTime(), eru2.getFixingPeriodStartTime(), eru2.getFixingPeriodEndTime());
sigmaBarExpected[loops] = (factorPlus - factorMinus) / (2 * shift);
assertEquals("Hull-White one factor: future convexity adjusment factor", sigmaBarExpected[loops], sigmaBar[loops], TOLERANCE_RATE);
}
}