@Test /** Tests the present value with an explicit computation. */ public void presentValue() { double strikeM = STRIKE * (1 - STANDARD_SPREAD); double strikeP = STRIKE * (1 + STANDARD_SPREAD); Forex forexM = new Forex( FOREX.getPaymentCurrency1().withAmount(1.0), FOREX.getPaymentCurrency2().withAmount(-strikeM)); Forex forexP = new Forex( FOREX.getPaymentCurrency1().withAmount(1.0), FOREX.getPaymentCurrency2().withAmount(-strikeP)); ForexOptionVanilla vanillaM = new ForexOptionVanilla(forexM, FOREX_CALL_OPTION.getExpirationTime(), IS_CALL, IS_LONG); ForexOptionVanilla vanillaP = new ForexOptionVanilla(forexP, FOREX_CALL_OPTION.getExpirationTime(), IS_CALL, IS_LONG); MultipleCurrencyAmount pvP = METHOD_VANILLA_BLACK.presentValue(vanillaP, SMILE_BUNDLE); MultipleCurrencyAmount pvM = METHOD_VANILLA_BLACK.presentValue(vanillaM, SMILE_BUNDLE); MultipleCurrencyAmount pvExpected = pvM.plus(pvP.multipliedBy(-1.0)) .multipliedBy( 1.0 / (strikeP - strikeM) * Math.abs(FOREX.getPaymentCurrency2().getAmount())); MultipleCurrencyAmount pvComputed = METHOD_DIGITAL_SPREAD.presentValue(FOREX_CALL_OPTION, SMILE_BUNDLE); assertEquals( "Forex Digital option: call spread method - present value", pvExpected.getAmount(USD), pvComputed.getAmount(USD), TOLERANCE_PRICE); }
@Test /** Tests the currency exposure with an explicit computation. */ public void currencyExposure() { double spread = 0.0001; // Relative spread. double strikeM = STRIKE * (1 - spread); double strikeP = STRIKE * (1 + spread); Forex forexM = new Forex( FOREX.getPaymentCurrency1().withAmount(1.0), FOREX.getPaymentCurrency2().withAmount(-strikeM)); Forex forexP = new Forex( FOREX.getPaymentCurrency1().withAmount(1.0), FOREX.getPaymentCurrency2().withAmount(-strikeP)); ForexOptionVanilla vanillaM = new ForexOptionVanilla(forexM, FOREX_CALL_OPTION.getExpirationTime(), IS_CALL, IS_LONG); ForexOptionVanilla vanillaP = new ForexOptionVanilla(forexP, FOREX_CALL_OPTION.getExpirationTime(), IS_CALL, IS_LONG); MultipleCurrencyAmount ceP = METHOD_VANILLA_BLACK.currencyExposure(vanillaP, SMILE_BUNDLE); MultipleCurrencyAmount ceM = METHOD_VANILLA_BLACK.currencyExposure(vanillaM, SMILE_BUNDLE); MultipleCurrencyAmount ceExpected = ceM.plus(ceP.multipliedBy(-1.0)) .multipliedBy( 1.0 / (strikeP - strikeM) * Math.abs(FOREX.getPaymentCurrency2().getAmount())); MultipleCurrencyAmount ceComputed = METHOD_DIGITAL_SPREAD.currencyExposure(FOREX_CALL_OPTION, SMILE_BUNDLE); assertEquals( "Forex Digital option: call spread method - currency exposure", ceExpected.getAmount(USD), ceComputed.getAmount(USD), TOLERANCE_PRICE); assertEquals( "Forex Digital option: call spread method - currency exposure", ceExpected.getAmount(EUR), ceComputed.getAmount(EUR), TOLERANCE_PRICE); }
@Test public void testMultipleCashFlowsNoNetting() { for (final InstrumentDefinition<?> definition : NO_NETTING_MULTIPLE_CASHFLOWS) { final TreeMap<LocalDate, MultipleCurrencyAmount> pay = new TreeMap<LocalDate, MultipleCurrencyAmount>( definition.accept(PAY_CASH_FLOWS, IBOR_FIXING_SERIES)); final TreeMap<LocalDate, MultipleCurrencyAmount> receive = new TreeMap<LocalDate, MultipleCurrencyAmount>( definition.accept(RECEIVE_CASH_FLOWS, IBOR_FIXING_SERIES)); final TreeMap<LocalDate, MultipleCurrencyAmount> netted = new TreeMap<LocalDate, MultipleCurrencyAmount>( definition.accept(VISITOR, IBOR_FIXING_SERIES)); final Set<LocalDate> combinedDates = new HashSet<LocalDate>(); combinedDates.addAll(pay.keySet()); combinedDates.addAll(receive.keySet()); assertEquals(combinedDates.size(), netted.size()); for (final Map.Entry<LocalDate, MultipleCurrencyAmount> entry : netted.entrySet()) { final LocalDate date = entry.getKey(); final MultipleCurrencyAmount payAmount = pay.get(date); final MultipleCurrencyAmount receiveAmount = receive.get(date); MultipleCurrencyAmount combinedAmountForDate = null; if (payAmount != null) { combinedAmountForDate = payAmount.multipliedBy(-1); if (receiveAmount != null) { combinedAmountForDate = combinedAmountForDate.plus(receiveAmount); } } else { if (receiveAmount != null) { combinedAmountForDate = receiveAmount; } } assertNotNull(combinedAmountForDate); assertEquals(combinedAmountForDate, entry.getValue()); } } }