public virtual void test_resolve() { BusinessDayAdjustment bussAdj = BusinessDayAdjustment.of(FOLLOWING, SAT_SUN); ResolvedCds test = PRODUCT_STD.resolve(REF_DATA); int nDates = 44; LocalDate[] dates = new LocalDate[nDates]; for (int i = 0; i < nDates; ++i) { dates[i] = START_DATE.plusMonths(3 * i); } IList <CreditCouponPaymentPeriod> payments = new List <CreditCouponPaymentPeriod>(nDates - 1); for (int i = 0; i < nDates - 2; ++i) { LocalDate start = i == 0 ? dates[i] : bussAdj.adjust(dates[i], REF_DATA); LocalDate end = bussAdj.adjust(dates[i + 1], REF_DATA); payments.Add(CreditCouponPaymentPeriod.builder().startDate(start).endDate(end).unadjustedStartDate(dates[i]).unadjustedEndDate(dates[i + 1]).effectiveStartDate(start.minusDays(1)).effectiveEndDate(end.minusDays(1)).paymentDate(end).currency(USD).notional(NOTIONAL).fixedRate(COUPON).yearFraction(ACT_360.relativeYearFraction(start, end)).build()); } LocalDate start = bussAdj.adjust(dates[nDates - 2], REF_DATA); LocalDate end = dates[nDates - 1]; payments.Add(CreditCouponPaymentPeriod.builder().startDate(start).endDate(end.plusDays(1)).unadjustedStartDate(dates[nDates - 2]).unadjustedEndDate(end).effectiveStartDate(start.minusDays(1)).effectiveEndDate(end).paymentDate(bussAdj.adjust(end, REF_DATA)).currency(USD).notional(NOTIONAL).fixedRate(COUPON).yearFraction(ACT_360.relativeYearFraction(start, end.plusDays(1))).build()); ResolvedCds expected = ResolvedCds.builder().buySell(BUY).legalEntityId(LEGAL_ENTITY).dayCount(ACT_360).paymentOnDefault(ACCRUED_PREMIUM).paymentPeriods(payments).protectionStart(BEGINNING).protectionEndDate(END_DATE).settlementDateOffset(SETTLE_DAY_ADJ).stepinDateOffset(STEPIN_DAY_ADJ).build(); assertEquals(test, expected); }
public virtual void test_totoSingleNameCds() { ResolvedCdsIndex @base = ResolvedCdsIndex.builder().buySell(BUY).dayCount(ACT_360).cdsIndexId(INDEX_ID).legalEntityIds(LEGAL_ENTITIES).paymentOnDefault(ACCRUED_PREMIUM).protectionStart(BEGINNING).paymentPeriods(PAYMENTS).protectionEndDate(PAYMENTS[PAYMENTS.Count - 1].EffectiveEndDate).settlementDateOffset(SETTLE_DAY_ADJ).stepinDateOffset(STEPIN_DAY_ADJ).build(); ResolvedCds test = @base.toSingleNameCds(); ResolvedCds expected = ResolvedCds.builder().buySell(BUY).dayCount(ACT_360).legalEntityId(INDEX_ID).paymentOnDefault(ACCRUED_PREMIUM).protectionStart(BEGINNING).paymentPeriods(PAYMENTS).protectionEndDate(PAYMENTS[PAYMENTS.Count - 1].EffectiveEndDate).settlementDateOffset(SETTLE_DAY_ADJ).stepinDateOffset(STEPIN_DAY_ADJ).build(); assertEquals(test, expected); }
//------------------------------------------------------------------------- public virtual void coverage() { ResolvedCds test1 = ResolvedCds.builder().buySell(BUY).dayCount(ACT_360).legalEntityId(LEGAL_ENTITY).paymentOnDefault(ACCRUED_PREMIUM).protectionStart(BEGINNING).paymentPeriods(PAYMENTS).protectionEndDate(PAYMENTS[PAYMENTS.Count - 1].EffectiveEndDate).settlementDateOffset(SETTLE_DAY_ADJ).stepinDateOffset(STEPIN_DAY_ADJ).build(); coverImmutableBean(test1); ResolvedCds test2 = ResolvedCds.builder().buySell(BuySell.SELL).dayCount(DayCounts.ACT_365F).legalEntityId(StandardId.of("OG", "EFG")).paymentOnDefault(PaymentOnDefault.NONE).protectionStart(ProtectionStartOfDay.NONE).paymentPeriods(PAYMENTS[0]).protectionEndDate(PAYMENTS[0].EffectiveEndDate).settlementDateOffset(DaysAdjustment.NONE).stepinDateOffset(DaysAdjustment.NONE).build(); coverBeanEquals(test1, test2); }
public virtual void test_effectiveStartDate() { ResolvedCds test1 = ResolvedCds.builder().buySell(BUY).dayCount(ACT_360).legalEntityId(LEGAL_ENTITY).paymentOnDefault(ACCRUED_PREMIUM).protectionStart(BEGINNING).paymentPeriods(PAYMENTS).protectionEndDate(PAYMENTS[PAYMENTS.Count - 1].EffectiveEndDate).settlementDateOffset(SETTLE_DAY_ADJ).stepinDateOffset(STEPIN_DAY_ADJ).build(); LocalDate date1 = LocalDate.of(2016, 3, 22); assertEquals(test1.calculateEffectiveStartDate(date1), date1.minusDays(1)); LocalDate date2 = LocalDate.of(2013, 9, 22); assertEquals(test1.calculateEffectiveStartDate(date2), START_DATE.minusDays(1)); ResolvedCds test2 = ResolvedCds.builder().buySell(BUY).dayCount(ACT_360).legalEntityId(LEGAL_ENTITY).paymentOnDefault(ACCRUED_PREMIUM).protectionStart(ProtectionStartOfDay.NONE).paymentPeriods(PAYMENTS).protectionEndDate(PAYMENTS[PAYMENTS.Count - 1].EffectiveEndDate).settlementDateOffset(SETTLE_DAY_ADJ).stepinDateOffset(STEPIN_DAY_ADJ).build(); LocalDate date3 = LocalDate.of(2016, 3, 22); assertEquals(test2.calculateEffectiveStartDate(date3), date3); LocalDate date4 = LocalDate.of(2013, 9, 22); assertEquals(test2.calculateEffectiveStartDate(date4), START_DATE); }
public virtual void test_builder() { ResolvedCds test = ResolvedCds.builder().buySell(BUY).dayCount(ACT_360).legalEntityId(LEGAL_ENTITY).paymentOnDefault(ACCRUED_PREMIUM).protectionStart(BEGINNING).paymentPeriods(PAYMENTS).protectionEndDate(PAYMENTS[PAYMENTS.Count - 1].EffectiveEndDate).settlementDateOffset(SETTLE_DAY_ADJ).stepinDateOffset(STEPIN_DAY_ADJ).build(); assertEquals(test.BuySell, BUY); assertEquals(test.Currency, USD); assertEquals(test.AccrualStartDate, PAYMENTS[0].StartDate); assertEquals(test.AccrualEndDate, PAYMENTS[42].EndDate); assertEquals(test.DayCount, ACT_360); assertEquals(test.FixedRate, COUPON); assertEquals(test.LegalEntityId, LEGAL_ENTITY); assertEquals(test.Notional, NOTIONAL); assertEquals(test.PaymentOnDefault, ACCRUED_PREMIUM); assertEquals(test.PaymentPeriods, PAYMENTS); assertEquals(test.ProtectionEndDate, PAYMENTS[42].EffectiveEndDate); assertEquals(test.SettlementDateOffset, SETTLE_DAY_ADJ); assertEquals(test.ProtectionStart, BEGINNING); assertEquals(test.StepinDateOffset, STEPIN_DAY_ADJ); }
public virtual void test_accruedYearFraction() { double eps = 1.0e-15; ResolvedCds test = ResolvedCds.builder().buySell(BUY).dayCount(ACT_360).legalEntityId(LEGAL_ENTITY).paymentOnDefault(ACCRUED_PREMIUM).protectionStart(BEGINNING).paymentPeriods(PAYMENTS).protectionEndDate(PAYMENTS[PAYMENTS.Count - 1].EffectiveEndDate).settlementDateOffset(SETTLE_DAY_ADJ).stepinDateOffset(STEPIN_DAY_ADJ).build(); double accStart = test.accruedYearFraction(START_DATE.minusDays(1)); double accNextMinusOne = test.accruedYearFraction(START_DATE.plusMonths(3).minusDays(1)); double accNext = test.accruedYearFraction(START_DATE.plusMonths(3)); double accNextOne = test.accruedYearFraction(START_DATE.plusMonths(3).plusDays(1)); double accMod = test.accruedYearFraction(START_DATE.plusYears(1)); double accEnd = test.accruedYearFraction(END_DATE); double accEndOne = test.accruedYearFraction(END_DATE.plusDays(1)); assertEquals(accStart, 0d); assertEquals(accNext, 0d); assertEquals(accNextMinusOne, ACT_360.relativeYearFraction(START_DATE, START_DATE.plusMonths(3).minusDays(1)), eps); assertEquals(accNextOne, 1d / 360d, eps); // 2.x assertEquals(accMod, 0.24722222222222223, eps); assertEquals(accEnd, 0.25555555555555554, eps); assertEquals(accEndOne, 0.25833333333333336, eps); }
public virtual void test_serialization() { ResolvedCds test = ResolvedCds.builder().buySell(BUY).dayCount(ACT_360).legalEntityId(LEGAL_ENTITY).paymentOnDefault(ACCRUED_PREMIUM).protectionStart(BEGINNING).paymentPeriods(PAYMENTS).protectionEndDate(PAYMENTS[PAYMENTS.Count - 1].EffectiveEndDate).settlementDateOffset(SETTLE_DAY_ADJ).stepinDateOffset(STEPIN_DAY_ADJ).build(); assertSerialization(test); }