BondConstantSpreadHorizonCalculator extends HorizonCalculator<BondTransactionDefinition<?, ?>, IssuerProviderInterface, Double> { @Override public MultipleCurrencyAmount getTheta(final BondTransactionDefinition<?, ?> definition, final ZonedDateTime date, final IssuerProviderInterface data, final int daysForward, final Calendar calendar) { ArgumentChecker.notNull(definition, "definition"); ArgumentChecker.notNull(date, "date"); ArgumentChecker.notNull(data, "data"); ArgumentChecker.isTrue(daysForward == 1 || daysForward == -1, "daysForward must be either 1 or -1"); final InstrumentDerivative instrumentToday = definition.toDerivative(date); final ZonedDateTime horizonDate = date.plusDays(daysForward); final double shiftTime = TimeCalculator.getTimeBetween(date, horizonDate); final InstrumentDerivative instrumentTomorrow = definition.toDerivative(horizonDate); final ParameterIssuerProviderInterface dataTomorrow = (ParameterIssuerProviderInterface) CURVE_ROLLDOWN.rollDown(data, shiftTime); final MultipleCurrencyAmount pvTomorrow = instrumentTomorrow.accept(PV_CALCULATOR, dataTomorrow); final MultipleCurrencyAmount pvToday = instrumentToday.accept(PV_CALCULATOR, data); return subtract(pvTomorrow, pvToday); } private  BondConstantSpreadHorizonCalculator(); static HorizonCalculator<BondTransactionDefinition<?, ?>, IssuerProviderInterface, Double> getInstance(); @Override MultipleCurrencyAmount getTheta(final BondTransactionDefinition<?, ?> definition, final ZonedDateTime date, final IssuerProviderInterface data,
      final int daysForward, final Calendar calendar);  }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNullDefinition() { CALCULATOR.getTheta(null, HORIZON_DATE, FLAT_ISSUER_MULTICURVES, 1, CALENDAR); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNullDate() { CALCULATOR.getTheta(TRANSACTION, null, FLAT_ISSUER_MULTICURVES, 1, CALENDAR); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNullData() { CALCULATOR.getTheta(TRANSACTION, HORIZON_DATE, null, 1, CALENDAR); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testDaysForward1() { CALCULATOR.getTheta(TRANSACTION, HORIZON_DATE, FLAT_ISSUER_MULTICURVES, 2, CALENDAR); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testDaysForward2() { CALCULATOR.getTheta(TRANSACTION, HORIZON_DATE, FLAT_ISSUER_MULTICURVES, -2, CALENDAR); }
@Test public void testConstantCurves() { final BondFixedTransaction today = (BondFixedTransaction) TRANSACTION.toDerivative(HORIZON_DATE); final BondFixedTransaction tomorrow = (BondFixedTransaction) TRANSACTION.toDerivative(HORIZON_DATE.plusDays(1)); final MultipleCurrencyAmount pvToday = today.accept(PV_CALCULATOR, FLAT_ISSUER_MULTICURVES); final MultipleCurrencyAmount pvTomorrow = tomorrow.accept(PV_CALCULATOR, FLAT_ISSUER_MULTICURVES); MultipleCurrencyAmount expected = HorizonCalculator.subtract(pvTomorrow, pvToday); MultipleCurrencyAmount actual = CALCULATOR.getTheta(TRANSACTION, HORIZON_DATE, FLAT_ISSUER_MULTICURVES, 1, CALENDAR, REFERENCE_PRICE); assertMCAEquals(expected, actual); final BondTransaction<?> yesterday = TRANSACTION.toDerivative(HORIZON_DATE.minusDays(1)); final MultipleCurrencyAmount pvYesterday = yesterday.accept(PV_CALCULATOR, FLAT_ISSUER_MULTICURVES); expected = HorizonCalculator.subtract(pvYesterday, pvToday); actual = CALCULATOR.getTheta(TRANSACTION, HORIZON_DATE, FLAT_ISSUER_MULTICURVES, -1, CALENDAR, REFERENCE_PRICE); assertMCAEquals(expected, actual); }