public virtual void test_createTrade_withFee() { TenorCdsTemplate base1 = TenorCdsTemplate.of(TENOR_10Y, CONV1); TenorCdsTemplate base2 = TenorCdsTemplate.of(AccrualStart.NEXT_DAY, TENOR_2Y, CONV2); LocalDate tradeDate = LocalDate.of(2015, 5, 5); AdjustablePayment payment1 = AdjustablePayment.of(EUR, NOTIONAL_2M, CONV1.SettlementDateOffset.adjust(tradeDate, REF_DATA)); AdjustablePayment payment2 = AdjustablePayment.of(USD, NOTIONAL_2M, CONV2.SettlementDateOffset.adjust(tradeDate, REF_DATA)); LocalDate startDate1 = date(2015, 3, 20); LocalDate endDate1 = date(2025, 6, 20); LocalDate startDate2 = date(2015, 5, 6); LocalDate endDate2 = date(2017, 6, 20); CdsTrade test1 = base1.createTrade(LEGAL_ENTITY, tradeDate, BUY, NOTIONAL_2M, 0.05d, payment1, REF_DATA); CdsTrade test2 = base2.createTrade(LEGAL_ENTITY, tradeDate, BUY, NOTIONAL_2M, 0.05d, payment2, REF_DATA); Cds expected1 = Cds.of(BUY, LEGAL_ENTITY, CONV1.Currency, NOTIONAL_2M, startDate1, endDate1, Frequency.P3M, CONV1.SettlementDateOffset.Calendar, 0.05d); PeriodicSchedule sch1 = expected1.PaymentSchedule; expected1 = expected1.toBuilder().paymentSchedule(sch1.toBuilder().startDateBusinessDayAdjustment(sch1.BusinessDayAdjustment).rollConvention(RollConventions.DAY_20).build()).build(); Cds expected2 = Cds.of(BUY, LEGAL_ENTITY, CONV2.Currency, NOTIONAL_2M, startDate2, endDate2, Frequency.P3M, CONV2.SettlementDateOffset.Calendar, 0.05d); PeriodicSchedule sch2 = expected2.PaymentSchedule; expected2 = expected2.toBuilder().paymentSchedule(sch2.toBuilder().startDateBusinessDayAdjustment(sch2.BusinessDayAdjustment).rollConvention(RollConventions.DAY_20).build()).build(); assertEquals(test1.Info.TradeDate, tradeDate); assertEquals(test1.UpfrontFee, payment1); assertEquals(test1.Product, expected1); assertEquals(test2.Info.TradeDate, tradeDate); assertEquals(test2.UpfrontFee, payment2); assertEquals(test2.Product, expected2); }
private AdjustablePayment parsePremium(XmlElement swaptionEl, FpmlDocument document, TradeInfoBuilder tradeInfoBuilder) { XmlElement premiumEl = swaptionEl.getChild("premium"); PayReceive payReceive = document.parsePayerReceiver(premiumEl, tradeInfoBuilder); XmlElement paymentAmountEl = premiumEl.getChild("paymentAmount"); CurrencyAmount ccyAmount = document.parseCurrencyAmount(paymentAmountEl); ccyAmount = payReceive.Pay ? ccyAmount.negated() : ccyAmount; AdjustableDate paymentDate = premiumEl.findChild("paymentDate").map(el => document.parseAdjustableDate(el)).get(); return(AdjustablePayment.of(ccyAmount, paymentDate)); }
//------------------------------------------------------------------------- public Trade parseTrade(FpmlDocument document, XmlElement tradeEl) { // supported elements: // 'swaption' // 'swaption/buyerPartyReference' // 'swaption/sellerPartyReference' // 'swaption/premium/payerPartyReference' // 'swaption/premium/receiverPartyReference' // 'swaption/premium/paymentAmount' // 'swaption/premium/paymentDate' // 'swaption/europeanExercise' // 'swaption/europeanExercise/expirationDate' // 'swaption/europeanExercise/expirationDate/adjustableDate' // 'swaption/europeanExercise/expirationDate/adjustableDate/unadjustedDate' // 'swaption/europeanExercise/expirationDate/adjustableDate/dateAdjustments' // 'swaption/europeanExercise/expirationTime // 'swaption/swap' // ignored elements: // 'Product.model?' // 'swaption/calculationAgent' // 'swaption/assetClass' // 'swaption/primaryAssestClass' // 'swaption/productId' // 'swaption/productType' // 'swaption/secondaryAssetClass' // 'swaption/sellerAccountReference' // 'swaption/sellerPartyReference' // 'swaption/swaptionAdjustedDates' // 'swaption/swaptionStraddle' TradeInfoBuilder tradeInfoBuilder = document.parseTradeInfo(tradeEl); XmlElement swaptionEl = tradeEl.getChild("swaption"); XmlElement europeanExerciseEl = swaptionEl.getChild("europeanExercise"); XmlElement expirationTimeEl = europeanExerciseEl.getChild("expirationTime"); // Parse the premium, expiry date, expiry time and expiry zone, longShort and swaption settlement. AdjustablePayment premium = parsePremium(swaptionEl, document, tradeInfoBuilder); AdjustableDate expiryDate = parseExpiryDate(europeanExerciseEl, document); LocalTime expiryTime = parseExpiryTime(expirationTimeEl, document); ZoneId expiryZone = parseExpiryZone(expirationTimeEl, document); LongShort longShort = parseLongShort(swaptionEl, document, tradeInfoBuilder); SwaptionSettlement swaptionSettlement = parseSettlement(swaptionEl, document); //Re use the Swap FpML parser to parse the underlying swap on this swaption. SwapFpmlParserPlugin swapParser = SwapFpmlParserPlugin.INSTANCE; Swap swap = swapParser.parseSwap(document, swaptionEl, tradeInfoBuilder); Swaption swaption = Swaption.builder().expiryDate(expiryDate).expiryZone(expiryZone).expiryTime(expiryTime).longShort(longShort).swaptionSettlement(swaptionSettlement).underlying(swap).build(); return(SwaptionTrade.builder().info(tradeInfoBuilder.build()).product(swaption).premium(premium).build()); }
public virtual void test_createTrade_withFee() { DatesCdsTemplate @base = DatesCdsTemplate.of(START, END, CONV1); LocalDate tradeDate = LocalDate.of(2015, 5, 5); AdjustablePayment payment = AdjustablePayment.of(EUR, NOTIONAL_2M, CONV1.SettlementDateOffset.adjust(tradeDate, REF_DATA)); CdsTrade test = @base.createTrade(LEGAL_ENTITY, tradeDate, BUY, NOTIONAL_2M, 0.05d, payment, REF_DATA); Cds expected = Cds.of(BUY, LEGAL_ENTITY, CONV1.Currency, NOTIONAL_2M, START, END, Frequency.P3M, CONV1.SettlementDateOffset.Calendar, 0.05d); PeriodicSchedule sch1 = expected.PaymentSchedule; expected = expected.toBuilder().paymentSchedule(sch1.toBuilder().startDateBusinessDayAdjustment(sch1.BusinessDayAdjustment).rollConvention(RollConventions.DAY_20).build()).build(); assertEquals(test.Info.TradeDate, tradeDate); assertEquals(test.UpfrontFee, payment); assertEquals(test.Product, expected); }
//------------------------------------------------------------------------- public virtual void test_toTrade() { LocalDate tradeDate = LocalDate.of(2015, 12, 21); // 19, 20 weekend LocalDate startDate = LocalDate.of(2015, 12, 20); LocalDate endDate = LocalDate.of(2020, 12, 20); LocalDate settlementDate = LocalDate.of(2015, 12, 24); TradeInfo info = TradeInfo.builder().tradeDate(tradeDate).settlementDate(settlementDate).build(); Tenor tenor = Tenor.TENOR_5Y; ImmutableCdsConvention @base = ImmutableCdsConvention.of(NAME, GBP, ACT_360, P3M, BUSI_ADJ_STD, SETTLE_DAY_ADJ_STD); Cds product = Cds.builder().legalEntityId(LEGAL_ENTITY).paymentSchedule(PeriodicSchedule.builder().startDate(startDate).endDate(endDate).frequency(P3M).businessDayAdjustment(BUSI_ADJ_STD).startDateBusinessDayAdjustment(BUSI_ADJ_STD).endDateBusinessDayAdjustment(BusinessDayAdjustment.NONE).stubConvention(StubConvention.SMART_INITIAL).rollConvention(RollConventions.DAY_20).build()).buySell(BUY).currency(GBP).dayCount(ACT_360).notional(NOTIONAL).fixedRate(COUPON).paymentOnDefault(PaymentOnDefault.ACCRUED_PREMIUM).protectionStart(ProtectionStartOfDay.BEGINNING).stepinDateOffset(STEPIN_DAY_ADJ).settlementDateOffset(SETTLE_DAY_ADJ_STD).build(); CdsTrade expected = CdsTrade.builder().info(info).product(product).build(); CdsTrade test1 = @base.createTrade(LEGAL_ENTITY, tradeDate, tenor, BUY, NOTIONAL, COUPON, REF_DATA); assertEquals(test1, expected); CdsTrade test2 = @base.createTrade(LEGAL_ENTITY, tradeDate, startDate, tenor, BUY, NOTIONAL, COUPON, REF_DATA); assertEquals(test2, expected); CdsTrade test3 = @base.createTrade(LEGAL_ENTITY, tradeDate, startDate, endDate, BUY, NOTIONAL, COUPON, REF_DATA); assertEquals(test3, expected); CdsTrade test4 = @base.toTrade(LEGAL_ENTITY, info, startDate, endDate, BUY, NOTIONAL, COUPON); assertEquals(test4, expected); AdjustablePayment upfront = AdjustablePayment.of(CurrencyAmount.of(GBP, 0.1 * NOTIONAL), settlementDate); CdsTrade expectedWithUf = CdsTrade.builder().info(info).product(product).upfrontFee(upfront).build(); CdsTrade test5 = @base.createTrade(LEGAL_ENTITY, tradeDate, tenor, BUY, NOTIONAL, COUPON, upfront, REF_DATA); assertEquals(test5, expectedWithUf); CdsTrade test6 = @base.createTrade(LEGAL_ENTITY, tradeDate, startDate, tenor, BUY, NOTIONAL, COUPON, upfront, REF_DATA); assertEquals(test6, expectedWithUf); CdsTrade test7 = @base.createTrade(LEGAL_ENTITY, tradeDate, startDate, endDate, BUY, NOTIONAL, COUPON, upfront, REF_DATA); assertEquals(test7, expectedWithUf); CdsTrade test8 = @base.toTrade(LEGAL_ENTITY, info, startDate, endDate, BUY, NOTIONAL, COUPON, upfront); assertEquals(test8, expectedWithUf); }
public virtual void test_positive_notional() { assertThrows(() => Bill.builder().dayCount(DAY_COUNT).legalEntityId(LEGAL_ENTITY).notional(AdjustablePayment.of(CurrencyAmount.of(CCY, -10), MATURITY_DATE_ADJ)).securityId(SECURITY_ID).settlementDateOffset(SETTLE).yieldConvention(YIELD_CONVENTION).build()); }
//------------------------------------------------------------------------- public virtual void coverage() { BillSecurity test1 = BillSecurity.builder().dayCount(DAY_COUNT).info(INFO).legalEntityId(LEGAL_ENTITY).notional(NOTIONAL).settlementDateOffset(SETTLE).yieldConvention(YIELD_CONVENTION).build(); coverImmutableBean(test1); BillSecurity test2 = BillSecurity.builder().dayCount(DayCounts.ACT_365F).info(SecurityInfo.of(SecurityId.of("OG-Test", "ID2"), PRICE_INFO)).legalEntityId(LegalEntityId.of("OG-Ticker", "LE2")).notional(AdjustablePayment.of(CurrencyAmount.of(CCY, 10), MATURITY_DATE_ADJ)).settlementDateOffset(DaysAdjustment.ofBusinessDays(2, EUTA, BUSINESS_ADJUST)).yieldConvention(BillYieldConvention.INTEREST_AT_MATURITY).build(); coverBeanEquals(test1, test2); }
internal static FxVanillaOptionTrade sut2() { AdjustablePayment premium = AdjustablePayment.of(CurrencyAmount.of(EUR, NOTIONAL * 0.01), date(2014, 11, 13)); return(FxVanillaOptionTrade.builder().product(PRODUCT2).premium(premium).build()); }
internal static SwaptionTrade sut2() { return(SwaptionTrade.builder().premium(AdjustablePayment.of(CurrencyAmount.of(Currency.USD, -3050000d), LocalDate.of(2014, 3, 17))).product(SwaptionTest.sut2()).build()); }
// parses the CDS internal Trade parseCds(FpmlDocument document, XmlElement tradeEl, TradeInfoBuilder tradeInfoBuilder) { XmlElement cdsEl = tradeEl.getChild("creditDefaultSwap"); XmlElement generalTermsEl = cdsEl.getChild("generalTerms"); XmlElement feeLegEl = cdsEl.getChild("feeLeg"); document.validateNotPresent(generalTermsEl, "basketReferenceInformation"); document.validateNotPresent(feeLegEl, "singlePayment"); BuySell buySell = document.parseBuyerSeller(generalTermsEl, tradeInfoBuilder); // effective and termination date are optional in FpML but mandatory for Strata AdjustableDate effectiveDate = document.parseAdjustableDate(generalTermsEl.getChild("effectiveDate")); AdjustableDate terminationDate = document.parseAdjustableDate(generalTermsEl.getChild("scheduledTerminationDate")); BusinessDayAdjustment bda = generalTermsEl.findChild("dateAdjustments").map(el => document.parseBusinessDayAdjustments(el)).orElse(BusinessDayAdjustment.NONE); PeriodicSchedule.Builder scheduleBuilder = PeriodicSchedule.builder().startDate(effectiveDate.Unadjusted).startDateBusinessDayAdjustment(effectiveDate.Adjustment).endDate(terminationDate.Unadjusted).endDateBusinessDayAdjustment(terminationDate.Adjustment).businessDayAdjustment(bda); // an upfront fee Optional <XmlElement> initialPaymentOptEl = feeLegEl.findChild("initialPayment"); AdjustablePayment upfrontFee = null; if (initialPaymentOptEl.Present) { XmlElement initialPaymentEl = initialPaymentOptEl.get(); PayReceive payRec = document.parsePayerReceiver(initialPaymentEl, tradeInfoBuilder); CurrencyAmount amount = document.parseCurrencyAmount(initialPaymentEl.getChild("paymentAmount")); LocalDate date = initialPaymentEl.findChild("adjustablePaymentDate").map(el => document.parseDate(el)).orElse(effectiveDate.Unadjusted); AdjustableDate adjDate = AdjustableDate.of(date, bda); upfrontFee = payRec.Pay ? AdjustablePayment.ofPay(amount, adjDate) : AdjustablePayment.ofReceive(amount, adjDate); } // we require a periodicPayment and fixedAmountCalculation XmlElement periodicPaymentEl = feeLegEl.getChild("periodicPayment"); scheduleBuilder.frequency(periodicPaymentEl.findChild("paymentFrequency").map(el => document.parseFrequency(el)).orElse(Frequency.P3M)); periodicPaymentEl.findChild("firstPaymentDate").ifPresent(el => scheduleBuilder.firstRegularStartDate(document.parseDate(el))); periodicPaymentEl.findChild("firstPeriodStartDate").ifPresent(el => scheduleBuilder.overrideStartDate(AdjustableDate.of(document.parseDate(el)))); periodicPaymentEl.findChild("lastRegularPaymentDate").ifPresent(el => scheduleBuilder.lastRegularEndDate(document.parseDate(el))); scheduleBuilder.rollConvention(periodicPaymentEl.findChild("rollConvention").map(el => document.convertRollConvention(el.Content)).orElse(null)); XmlElement fixedAmountCalcEl = periodicPaymentEl.getChild("fixedAmountCalculation"); double fixedRate = document.parseDecimal(fixedAmountCalcEl.getChild("fixedRate")); DayCount dayCount = fixedAmountCalcEl.findChild("dayCountFraction").map(el => document.parseDayCountFraction(el)).orElse(DayCounts.ACT_360); // handle a single protectionTerms element XmlElement protectionTermEl = cdsEl.getChild("protectionTerms"); CurrencyAmount notional = document.parseCurrencyAmount(protectionTermEl.getChild("calculationAmount")); // single name CDS Optional <XmlElement> singleOptEl = generalTermsEl.findChild("referenceInformation"); if (singleOptEl.Present) { // we require a single entityId XmlElement referenceEntityEl = singleOptEl.get().getChild("referenceEntity"); XmlElement entityIdEl = referenceEntityEl.getChild("entityId"); string scheme = entityIdEl.findAttribute("entityIdScheme").orElse("http://www.fpml.org/coding-scheme/external/entity-id-RED-1-0"); string value = entityIdEl.Content; StandardId entityId = StandardId.of(scheme, value); Cds cds = Cds.builder().buySell(buySell).legalEntityId(entityId).currency(notional.Currency).notional(notional.Amount).paymentSchedule(scheduleBuilder.build()).fixedRate(fixedRate).dayCount(dayCount).build(); return(CdsTrade.builder().info(tradeInfoBuilder.build()).product(cds).upfrontFee(upfrontFee).build()); } // CDS index Optional <XmlElement> indexOptEl = generalTermsEl.findChild("indexReferenceInformation"); if (indexOptEl.Present) { string indexName = indexOptEl.get().getChild("indexName").Content; CdsIndex cdsIndex = CdsIndex.builder().buySell(buySell).cdsIndexId(StandardId.of("CDX-Name", indexName)).currency(notional.Currency).notional(notional.Amount).paymentSchedule(scheduleBuilder.build()).fixedRate(fixedRate).dayCount(dayCount).build(); return(CdsIndexTrade.builder().info(tradeInfoBuilder.build()).product(cdsIndex).upfrontFee(upfrontFee).build()); } // unknown type throw new FpmlParseException("FpML CDS must be single name or index"); }
//------------------------------------------------------------------------- public virtual void coverage() { FxSingleBarrierOptionTrade test1 = sut(); FxSingleBarrierOptionTrade test2 = FxSingleBarrierOptionTrade.builder().product(FxSingleBarrierOption.of(VANILLA_OPTION, BARRIER)).premium(AdjustablePayment.of(CurrencyAmount.of(EUR, NOTIONAL * 0.01), date(2014, 11, 13))).build(); coverImmutableBean(test1); coverBeanEquals(test1, test2); }