@Test /** Tests the Bermuda swaption getters. */ public void getter() { assertEquals( "Getter: underlying swaps", EXPIRY_SWAP_DEFINITION, BERMUDA_SWAPTION_DEFINITION.getUnderlyingSwap()); assertEquals("Getter: long/short", IS_LONG, BERMUDA_SWAPTION_DEFINITION.isLong()); assertEquals("Getter: expiry dates", EXPIRY_DATE, BERMUDA_SWAPTION_DEFINITION.getExpiryDate()); }
@SuppressWarnings("deprecation") @Test /** Tests the toDerivative method. */ public void toDerivativesDeprecated() { final DayCount actAct = DayCountFactory.INSTANCE.getDayCount("Actual/Actual ISDA"); final String FUNDING_CURVE_NAME = "Funding"; final String FORWARD_CURVE_NAME = "Forward"; final String[] CURVES_NAME = {FUNDING_CURVE_NAME, FORWARD_CURVE_NAME}; final double[] expiryTime = new double[NB_EXPIRY]; final double[] settleTime = new double[NB_EXPIRY]; @SuppressWarnings("unchecked") final SwapFixedCoupon<Coupon>[] underlyingSwap = new SwapFixedCoupon[NB_EXPIRY]; for (int loopexp = 0; loopexp < NB_EXPIRY; loopexp++) { expiryTime[loopexp] = actAct.getDayCountFraction(REFERENCE_DATE, EXPIRY_DATE[loopexp]); underlyingSwap[loopexp] = EXPIRY_SWAP_DEFINITION[loopexp].toDerivative(REFERENCE_DATE, CURVES_NAME); settleTime[loopexp] = actAct.getDayCountFraction( REFERENCE_DATE, EXPIRY_SWAP_DEFINITION[loopexp].getFixedLeg().getNthPayment(0).getAccrualStartDate()); } final SwaptionBermudaFixedIbor swaptionBermuda = new SwaptionBermudaFixedIbor(underlyingSwap, IS_LONG, expiryTime, settleTime); assertEquals( "Swaption Bermuda: to derivatives", swaptionBermuda, BERMUDA_SWAPTION_DEFINITION.toDerivative(REFERENCE_DATE, CURVES_NAME)); }
@Test /** Tests the Bermuda swaption builder from a unique total swap. */ public void from() { final SwaptionBermudaFixedIborDefinition bermuda2 = SwaptionBermudaFixedIborDefinition.from(TOTAL_SWAP_DEFINITION, IS_LONG, EXPIRY_DATE); assertEquals("Bermuda swaption builder", BERMUDA_SWAPTION_DEFINITION, bermuda2); }
@Test /** Tests the equal and hash-code methods. */ public void hashEqual() { final SwaptionBermudaFixedIborDefinition bermuda2 = SwaptionBermudaFixedIborDefinition.from(TOTAL_SWAP_DEFINITION, IS_LONG, EXPIRY_DATE); assertTrue("Bermuda swaption", BERMUDA_SWAPTION_DEFINITION.equals(bermuda2)); assertEquals("Bermuda swaption", BERMUDA_SWAPTION_DEFINITION.hashCode(), bermuda2.hashCode()); SwaptionBermudaFixedIborDefinition modified; modified = new SwaptionBermudaFixedIborDefinition(EXPIRY_SWAP_DEFINITION, !IS_LONG, EXPIRY_DATE); assertFalse("Bermuda swaption", BERMUDA_SWAPTION_DEFINITION.equals(modified)); final ZonedDateTime[] expiry2 = new ZonedDateTime[NB_EXPIRY]; System.arraycopy(EXPIRY_DATE, 0, expiry2, 0, NB_EXPIRY); expiry2[0] = EXPIRY_DATE[0].minusDays(1); modified = new SwaptionBermudaFixedIborDefinition(EXPIRY_SWAP_DEFINITION, IS_LONG, expiry2); assertFalse("Bermuda swaption", BERMUDA_SWAPTION_DEFINITION.equals(modified)); }