//------------------------------------------------------------------------- // notional schedule private static NotionalSchedule parseNotionalSchedule(CsvRow row, string leg) { NotionalSchedule.Builder builder = NotionalSchedule.builder(); // basics Currency currency = Currency.of(getValueWithFallback(row, leg, CURRENCY_FIELD)); builder.currency(currency); builder.amount(ValueSchedule.of(LoaderUtils.parseDouble(getValueWithFallback(row, leg, NOTIONAL_FIELD)))); // fx reset Optional <FxIndex> fxIndexOpt = findValue(row, leg, FX_RESET_INDEX_FIELD).map(s => FxIndex.of(s)); Optional <Currency> notionalCurrencyOpt = findValue(row, leg, NOTIONAL_CURRENCY_FIELD).map(s => Currency.of(s)); Optional <FxResetFixingRelativeTo> fxFixingRelativeToOpt = findValue(row, leg, FX_RESET_RELATIVE_TO_FIELD).map(s => FxResetFixingRelativeTo.of(s)); Optional <DaysAdjustment> fxResetAdjOpt = parseDaysAdjustment(row, leg, FX_RESET_OFFSET_DAYS_FIELD, FX_RESET_OFFSET_CAL_FIELD, FX_RESET_OFFSET_ADJ_CNV_FIELD, FX_RESET_OFFSET_ADJ_CAL_FIELD); if (fxIndexOpt.Present) { FxIndex fxIndex = fxIndexOpt.get(); FxResetCalculation.Builder fxResetBuilder = FxResetCalculation.builder(); fxResetBuilder.index(fxIndex); fxResetBuilder.referenceCurrency(notionalCurrencyOpt.orElse(fxIndex.CurrencyPair.other(currency))); fxFixingRelativeToOpt.ifPresent(v => fxResetBuilder.fixingRelativeTo(v)); fxResetAdjOpt.ifPresent(v => fxResetBuilder.fixingDateOffset(v)); builder.fxReset(fxResetBuilder.build()); } else if (notionalCurrencyOpt.Present || fxFixingRelativeToOpt.Present || fxResetAdjOpt.Present) { throw new System.ArgumentException("Swap trade FX Reset must define field '" + leg + FX_RESET_INDEX_FIELD + "'"); } // optionals findValue(row, leg, NOTIONAL_INITIAL_EXCHANGE_FIELD).map(s => LoaderUtils.parseBoolean(s)).ifPresent(v => builder.initialExchange(v)); findValue(row, leg, NOTIONAL_INTERMEDIATE_EXCHANGE_FIELD).map(s => LoaderUtils.parseBoolean(s)).ifPresent(v => builder.intermediateExchange(v)); findValue(row, leg, NOTIONAL_FINAL_EXCHANGE_FIELD).map(s => LoaderUtils.parseBoolean(s)).ifPresent(v => builder.finalExchange(v)); return(builder.build()); }
// parses the notional schedule private NotionalSchedule parseSwapNotionalSchedule(XmlElement legEl, XmlElement calcEl, FpmlDocument document) { // supported elements: // 'principalExchanges/initialExchange' // 'principalExchanges/finalExchange' // 'principalExchanges/intermediateExchange' // 'calculationPeriodAmount/calculation/notionalSchedule/notionalStepSchedule' // 'calculationPeriodAmount/calculation/notionalSchedule/notionalStepParameters' NotionalSchedule.Builder notionalScheduleBuilder = NotionalSchedule.builder(); // exchanges legEl.findChild("principalExchanges").ifPresent(el => { notionalScheduleBuilder.initialExchange(bool.Parse(el.getChild("initialExchange").Content)); notionalScheduleBuilder.intermediateExchange(bool.Parse(el.getChild("intermediateExchange").Content)); notionalScheduleBuilder.finalExchange(bool.Parse(el.getChild("finalExchange").Content)); }); // notional schedule XmlElement notionalEl = calcEl.getChild("notionalSchedule"); XmlElement stepScheduleEl = notionalEl.getChild("notionalStepSchedule"); Optional <XmlElement> paramScheduleElOpt = notionalEl.findChild("notionalStepParameters"); double initialValue = document.parseDecimal(stepScheduleEl.getChild("initialValue")); ValueStepSequence seq = paramScheduleElOpt.map(el => parseAmountSchedule(el, initialValue, document)).orElse(null); notionalScheduleBuilder.amount(parseSchedule(stepScheduleEl, initialValue, seq, document)); notionalScheduleBuilder.currency(document.parseCurrency(stepScheduleEl.getChild("currency"))); return(notionalScheduleBuilder.build()); }
//----------------------------------------------------------------------- public virtual void vanillaFixedVsLibor3mSwap() { // we are paying a fixed rate every 3 months at 1.5% with a 100 million notional RateCalculationSwapLeg payLeg = RateCalculationSwapLeg.builder().payReceive(PayReceive.PAY).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2014, 9, 12)).endDate(LocalDate.of(2021, 9, 12)).frequency(Frequency.P3M).businessDayAdjustment(BusinessDayAdjustment.of(MODIFIED_FOLLOWING, HolidayCalendarIds.USNY)).startDateBusinessDayAdjustment(BusinessDayAdjustment.NONE).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(Frequency.P3M).paymentDateOffset(DaysAdjustment.NONE).build()).notionalSchedule(NotionalSchedule.builder().currency(Currency.USD).amount(ValueSchedule.of(100_000_000)).build()).calculation(FixedRateCalculation.of(0.015, DayCounts.THIRTY_U_360)).build(); // we are receiving USD LIBOR 3M every 3 months with a 100 million notional RateCalculationSwapLeg receiveLeg = RateCalculationSwapLeg.builder().payReceive(PayReceive.RECEIVE).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2014, 9, 12)).endDate(LocalDate.of(2021, 9, 12)).frequency(Frequency.P3M).businessDayAdjustment(BusinessDayAdjustment.of(MODIFIED_FOLLOWING, HolidayCalendarIds.USNY)).startDateBusinessDayAdjustment(BusinessDayAdjustment.NONE).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(Frequency.P3M).paymentDateOffset(DaysAdjustment.NONE).build()).notionalSchedule(NotionalSchedule.builder().currency(Currency.USD).amount(ValueSchedule.of(100_000_000)).build()).calculation(IborRateCalculation.of(IborIndices.USD_LIBOR_3M)).build(); // a SwapTrade combines the two legs SwapTrade trade = SwapTrade.builder().info(TradeInfo.builder().id(StandardId.of("OG-Trade", "1")).tradeDate(LocalDate.of(2014, 9, 10)).build()).product(Swap.of(payLeg, receiveLeg)).build(); Console.WriteLine("===== Vanilla fixed vs Libor3m ====="); Console.WriteLine(JodaBeanSer.PRETTY.xmlWriter().write(trade)); Console.WriteLine(); Console.WriteLine("===== Vanilla fixed vs Libor3m pay leg ====="); Console.WriteLine(JodaBeanSer.PRETTY.xmlWriter().write(payLeg.resolve(ReferenceData.standard()))); Console.WriteLine(); Console.WriteLine("===== Vanilla fixed vs Libor3m receive leg ====="); Console.WriteLine(JodaBeanSer.PRETTY.xmlWriter().write(receiveLeg.resolve(ReferenceData.standard()))); Console.WriteLine(); }
// create a cross-currency USD fixed vs GBP libor 3m swap with initial and final notional exchange private static SwapTrade createNotionalExchangeSwap() { SwapLeg payLeg = RateCalculationSwapLeg.builder().payReceive(PayReceive.PAY).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2014, 1, 24)).endDate(LocalDate.of(2021, 1, 24)).frequency(Frequency.P6M).businessDayAdjustment(BusinessDayAdjustment.of(MODIFIED_FOLLOWING, HolidayCalendarIds.GBLO)).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(Frequency.P6M).paymentDateOffset(DaysAdjustment.NONE).build()).notionalSchedule(NotionalSchedule.builder().currency(Currency.USD).amount(ValueSchedule.of(100_000_000)).initialExchange(true).finalExchange(true).build()).calculation(FixedRateCalculation.of(0.03, DayCounts.THIRTY_U_360)).build(); SwapLeg receiveLeg = RateCalculationSwapLeg.builder().payReceive(PayReceive.RECEIVE).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2014, 1, 24)).endDate(LocalDate.of(2021, 1, 24)).frequency(Frequency.P3M).businessDayAdjustment(BusinessDayAdjustment.of(MODIFIED_FOLLOWING, HolidayCalendarIds.GBLO)).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(Frequency.P3M).paymentDateOffset(DaysAdjustment.NONE).build()).notionalSchedule(NotionalSchedule.builder().currency(Currency.GBP).amount(ValueSchedule.of(61_600_000)).initialExchange(true).finalExchange(true).build()).calculation(IborRateCalculation.of(IborIndices.GBP_LIBOR_3M)).build(); return(SwapTrade.builder().product(Swap.of(payLeg, receiveLeg)).info(TradeInfo.builder().id(StandardId.of("example", "16")).addAttribute(AttributeType.DESCRIPTION, "USD fixed vs GBP Libor 3m (notional exchange)").counterparty(StandardId.of("example", "A")).settlementDate(LocalDate.of(2014, 1, 24)).build()).build()); }
//----------------------------------------------------------------------- // XCcy swap with exchange of notional public virtual void test_XCcyEur3MSpreadVsUSD3M() { SwapLeg payLeg = RateCalculationSwapLeg.builder().payReceive(PAY).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2014, 1, 24)).endDate(LocalDate.of(2016, 1, 24)).frequency(P3M).businessDayAdjustment(BDA_MF).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(P3M).paymentDateOffset(DaysAdjustment.NONE).build()).notionalSchedule(NotionalSchedule.builder().finalExchange(true).initialExchange(true).amount(ValueSchedule.of(NOTIONAL_EUR)).currency(EUR).build()).calculation(IborRateCalculation.builder().index(EUR_EURIBOR_3M).fixingDateOffset(DaysAdjustment.ofBusinessDays(-2, CalendarUSD.NYC, BDA_P)).spread(ValueSchedule.of(0.0020)).build()).build(); SwapLeg receiveLeg = RateCalculationSwapLeg.builder().payReceive(RECEIVE).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2014, 1, 24)).endDate(LocalDate.of(2016, 1, 24)).frequency(P3M).businessDayAdjustment(BDA_MF).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(P3M).paymentDateOffset(DaysAdjustment.NONE).build()).notionalSchedule(NotionalSchedule.builder().finalExchange(true).initialExchange(true).amount(ValueSchedule.of(NOTIONAL_USD)).currency(USD).build()).calculation(IborRateCalculation.builder().index(USD_LIBOR_3M).fixingDateOffset(DaysAdjustment.ofBusinessDays(-2, CalendarUSD.NYC, BDA_P)).build()).build(); ResolvedSwapTrade trade = SwapTrade.builder().info(TradeInfo.builder().tradeDate(LocalDate.of(2014, 9, 10)).build()).product(Swap.of(payLeg, receiveLeg)).build().resolve(REF_DATA); double pvUsdExpected = 431944.6868; double pvEurExpected = -731021.1778; DiscountingSwapTradePricer pricer = swapPricer(); MultiCurrencyAmount pv = pricer.presentValue(trade, provider()); assertEquals(pv.getAmount(USD).Amount, pvUsdExpected, TOLERANCE_PV); assertEquals(pv.getAmount(EUR).Amount, pvEurExpected, TOLERANCE_PV); }
private SwapTrade getMtmTrade(bool initialExchange, bool intermediateExchange, bool finalExchange, double?initialNotional) { SwapLeg payLeg = RateCalculationSwapLeg.builder().payReceive(PAY).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2014, 1, 24)).endDate(LocalDate.of(2016, 1, 24)).frequency(P3M).businessDayAdjustment(BDA_MF).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(P3M).paymentDateOffset(DaysAdjustment.NONE).build()).notionalSchedule(NotionalSchedule.builder().finalExchange(finalExchange).initialExchange(initialExchange).amount(ValueSchedule.of(NOTIONAL_EUR)).currency(EUR).build()).calculation(IborRateCalculation.builder().index(EUR_EURIBOR_3M).fixingDateOffset(DaysAdjustment.ofBusinessDays(-2, CalendarUSD.NYC, BDA_P)).spread(ValueSchedule.of(0.0020)).build()).build(); SwapLeg receiveLeg = RateCalculationSwapLeg.builder().payReceive(RECEIVE).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2014, 1, 24)).endDate(LocalDate.of(2016, 1, 24)).frequency(P3M).businessDayAdjustment(BDA_MF).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(P3M).paymentDateOffset(DaysAdjustment.NONE).build()).notionalSchedule(NotionalSchedule.builder().finalExchange(finalExchange).initialExchange(initialExchange).intermediateExchange(intermediateExchange).amount(ValueSchedule.of(NOTIONAL_USD)).currency(USD).fxReset(FxResetCalculation.builder().fixingDateOffset(DaysAdjustment.ofBusinessDays(-2, CalendarUSD.NYC, BDA_P)).referenceCurrency(EUR).index(EUR_USD_WM).initialNotionalValue(initialNotional).build()).build()).calculation(IborRateCalculation.builder().index(USD_LIBOR_3M).fixingDateOffset(DaysAdjustment.ofBusinessDays(-2, CalendarUSD.NYC, BDA_P)).build()).build(); return(SwapTrade.builder().info(TradeInfo.builder().tradeDate(LocalDate.of(2014, 9, 10)).build()).product(Swap.of(payLeg, receiveLeg)).build()); }