//------------------------------------------------------------------------- // 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()); }
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()); }