//------------------------------------------------------------------------- /// <summary> /// Converts an FpML 'RelativeDateOffset' to a {@code DaysAdjustment}. /// </summary> /// <param name="baseEl"> the FpML adjustable date element </param> /// <returns> the days adjustment </returns> /// <exception cref="RuntimeException"> if unable to parse </exception> public DaysAdjustment parseRelativeDateOffsetDays(XmlElement baseEl) { // FpML content: ('periodMultiplier', 'period', 'dayType?', // 'businessDayConvention', 'BusinessCentersOrReference.model?' // 'dateRelativeTo', 'adjustedDate') // The 'dateRelativeTo' element is not used here // The 'adjustedDate' element is ignored Period period = parsePeriod(baseEl); if (period.toTotalMonths() != 0) { throw new FpmlParseException("Expected days-based period but found " + period); } Optional <XmlElement> dayTypeEl = baseEl.findChild("dayType"); bool calendarDays = period.Zero || (dayTypeEl.Present && dayTypeEl.get().Content.Equals("Calendar")); BusinessDayConvention fixingBdc = convertBusinessDayConvention(baseEl.getChild("businessDayConvention").Content); HolidayCalendarId calendar = parseBusinessCenters(baseEl); if (calendarDays) { return(DaysAdjustment.ofCalendarDays(period.Days, BusinessDayAdjustment.of(fixingBdc, calendar))); } else { return(DaysAdjustment.ofBusinessDays(period.Days, calendar)); } }
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); }
private static IborIndex parseIborIndex(CsvRow row) { string name = row.getValue(NAME_FIELD); Currency currency = Currency.parse(row.getValue(CURRENCY_FIELD)); bool active = bool.Parse(row.getValue(ACTIVE_FIELD)); DayCount dayCount = DayCount.of(row.getValue(DAY_COUNT_FIELD)); HolidayCalendarId fixingCal = HolidayCalendarId.of(row.getValue(FIXING_CALENDAR_FIELD)); int offsetDays = int.Parse(row.getValue(OFFSET_DAYS_FIELD)); HolidayCalendarId offsetCal = HolidayCalendarId.of(row.getValue(OFFSET_CALENDAR_FIELD)); HolidayCalendarId effectiveCal = HolidayCalendarId.of(row.getValue(EFFECTIVE_DATE_CALENDAR_FIELD)); Tenor tenor = Tenor.parse(row.getValue(TENOR_FIELD)); LocalTime time = LocalTime.parse(row.getValue(FIXING_TIME_FIELD), TIME_FORMAT); ZoneId zoneId = ZoneId.of(row.getValue(FIXING_ZONE_FIELD)); DayCount fixedLegDayCount = DayCount.of(row.getValue(FIXED_LEG_DAY_COUNT)); // interpret CSV DaysAdjustment fixingOffset = DaysAdjustment.ofBusinessDays(-offsetDays, offsetCal, BusinessDayAdjustment.of(PRECEDING, fixingCal)).normalized(); DaysAdjustment effectiveOffset = DaysAdjustment.ofBusinessDays(offsetDays, offsetCal, BusinessDayAdjustment.of(FOLLOWING, effectiveCal)).normalized(); // convention can be two different things PeriodAdditionConvention periodAdditionConvention = PeriodAdditionConvention.extendedEnum().find(row.getField(TENOR_CONVENTION_FIELD)).orElse(PeriodAdditionConventions.NONE); BusinessDayConvention tenorBusinessConvention = BusinessDayConvention.extendedEnum().find(row.getField(TENOR_CONVENTION_FIELD)).orElse(isEndOfMonth(periodAdditionConvention) ? MODIFIED_FOLLOWING : FOLLOWING); BusinessDayAdjustment adj = BusinessDayAdjustment.of(tenorBusinessConvention, effectiveCal); TenorAdjustment tenorAdjustment = TenorAdjustment.of(tenor, periodAdditionConvention, adj); // build result return(ImmutableIborIndex.builder().name(name).currency(currency).active(active).dayCount(dayCount).fixingCalendar(fixingCal).fixingDateOffset(fixingOffset).effectiveDateOffset(effectiveOffset).maturityDateOffset(tenorAdjustment).fixingTime(time).fixingZone(zoneId).defaultFixedLegDayCount(fixedLegDayCount).build()); }
//------------------------------------------------------------------------- /// <summary> /// Converts an FpML 'BusinessDayAdjustments' to a {@code BusinessDayAdjustment}. /// </summary> /// <param name="baseEl"> the FpML business centers or reference element to parse </param> /// <returns> the business day adjustment </returns> /// <exception cref="RuntimeException"> if unable to parse </exception> public BusinessDayAdjustment parseBusinessDayAdjustments(XmlElement baseEl) { // FpML content: ('businessDayConvention', 'BusinessCentersOrReference.model?') BusinessDayConvention bdc = convertBusinessDayConvention(baseEl.getChild("businessDayConvention").Content); Optional <XmlElement> centersEl = baseEl.findChild("businessCenters"); Optional <XmlElement> centersRefEl = baseEl.findChild("businessCentersReference"); HolidayCalendarId calendar = (centersEl.Present || centersRefEl.Present ? parseBusinessCenters(baseEl) : HolidayCalendarIds.NO_HOLIDAYS); return(BusinessDayAdjustment.of(bdc, calendar)); }
// adjustable date, defaulting business day convention and holiday calendar private static Optional <AdjustableDate> parseAdjustableDate(CsvRow row, string leg, string dateField, string cnvField, string calField) { Optional <LocalDate> dateOpt = findValue(row, leg, dateField).map(s => LoaderUtils.parseDate(s)); if (!dateOpt.Present) { return(null); } BusinessDayConvention dateCnv = findValue(row, leg, cnvField).map(s => LoaderUtils.parseBusinessDayConvention(s)).orElse(BusinessDayConventions.MODIFIED_FOLLOWING); HolidayCalendarId cal = findValue(row, leg, calField).map(s => HolidayCalendarId.of(s)).orElse(HolidayCalendarIds.NO_HOLIDAYS); return(AdjustableDate.of(dateOpt.get(), BusinessDayAdjustment.of(dateCnv, cal))); }
public override DaysAdjustment toIborIndexFixingOffset() { DaysAdjustment @base = FloatingRateName.this.toIborIndexFixingOffset(); if (fixingDateOffsetDays == null) { return(@base); } if (fixingDateOffsetDays == 0) { return(DaysAdjustment.ofCalendarDays(0, BusinessDayAdjustment.of(PRECEDING, @base.ResultCalendar))); } return(@base.toBuilder().days(fixingDateOffsetDays.Value).build().normalized()); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @ImmutablePreBuild private static void preBuild(Builder builder) private static void preBuild(Builder builder) { if (builder.index_Renamed != null) { if (string.ReferenceEquals(builder.name_Renamed, null) && builder.dateSequence_Renamed != null) { builder.name_Renamed = builder.index_Renamed.Name + "-" + builder.dateSequence_Renamed.Name; } if (builder.businessDayAdjustment_Renamed == null) { builder.businessDayAdjustment_Renamed = BusinessDayAdjustment.of(FOLLOWING, builder.index_Renamed.EffectiveDateOffset.Calendar); } } }
static CalibrationInflationUsdTest() { DSC_NAMES[DSCON_CURVE_NAME] = USD; ISet <Index> usdFedFundSet = new HashSet <Index>(); usdFedFundSet.Add(USD_FED_FUND); IDX_NAMES[DSCON_CURVE_NAME] = usdFedFundSet; ISet <Index> usdLibor3Set = new HashSet <Index>(); usdLibor3Set.Add(USD_LIBOR_3M); IDX_NAMES[CPI_CURVE_NAME] = usdLibor3Set; for (int i = 0; i < DSC_NB_DEPO_NODES; i++) { BusinessDayAdjustment bda = BusinessDayAdjustment.of(FOLLOWING, USNY); TermDepositConvention convention = ImmutableTermDepositConvention.of("USD-Dep", USD, bda, ACT_360, DaysAdjustment.ofBusinessDays(DSC_DEPO_OFFSET[i], USNY)); DSC_NODES[i] = TermDepositCurveNode.of(TermDepositTemplate.of(Period.ofDays(1), convention), QuoteId.of(StandardId.of(SCHEME, DSC_ID_VALUE[i]))); } for (int i = 0; i < DSC_NB_OIS_NODES; i++) { DSC_NODES[DSC_NB_DEPO_NODES + i] = FixedOvernightSwapCurveNode.of(FixedOvernightSwapTemplate.of(Period.ZERO, Tenor.of(DSC_OIS_TENORS[i]), USD_FIXED_1Y_FED_FUND_OIS), QuoteId.of(StandardId.of(SCHEME, DSC_ID_VALUE[DSC_NB_DEPO_NODES + i]))); } for (int i = 0; i < CPI_NB_NODES; i++) { CPI_NODES[i] = FixedInflationSwapCurveNode.builder().template(FixedInflationSwapTemplate.of(Tenor.of(CPI_TENORS[i]), FixedInflationSwapConventions.USD_FIXED_ZC_US_CPI)).rateId(QuoteId.of(StandardId.of(SCHEME, CPI_ID_VALUE[i]))).date(CurveNodeDate.LAST_FIXING).build(); } ImmutableMarketDataBuilder builder = ImmutableMarketData.builder(VAL_DATE); for (int i = 0; i < DSC_NB_NODES; i++) { builder.addValue(QuoteId.of(StandardId.of(SCHEME, DSC_ID_VALUE[i])), DSC_MARKET_QUOTES[i]); } for (int i = 0; i < CPI_NB_NODES; i++) { builder.addValue(QuoteId.of(StandardId.of(SCHEME, CPI_ID_VALUE[i])), CPI_MARKET_QUOTES[i]); } builder.addTimeSeries(IndexQuoteId.of(US_CPI_U), TS_USD_CPI); ALL_QUOTES = builder.build(); IList <CurveNode[]> groupDsc = new List <CurveNode[]>(); groupDsc.Add(DSC_NODES); CURVES_NODES.Add(groupDsc); IList <CurveNode[]> groupCpi = new List <CurveNode[]>(); groupCpi.Add(CPI_NODES); CURVES_NODES.Add(groupCpi); }
// adjust trade based on additional fields specified private static SwapTrade adjustTrade(SwapTrade trade, Optional <RollConvention> rollConventionOpt, Optional <StubConvention> stubConventionOpt, Optional <LocalDate> firstRegularStartDateOpt, Optional <LocalDate> lastRegEndDateOpt, BusinessDayConvention dateCnv, Optional <HolidayCalendarId> dateCalOpt) { if (!rollConventionOpt.Present && !stubConventionOpt.Present && !firstRegularStartDateOpt.Present && !lastRegEndDateOpt.Present && !dateCalOpt.Present) { return(trade); } ImmutableList.Builder <SwapLeg> legBuilder = ImmutableList.builder(); foreach (SwapLeg leg in trade.Product.Legs) { RateCalculationSwapLeg swapLeg = (RateCalculationSwapLeg)leg; PeriodicSchedule.Builder scheduleBuilder = swapLeg.AccrualSchedule.toBuilder(); rollConventionOpt.ifPresent(rc => scheduleBuilder.rollConvention(rc)); stubConventionOpt.ifPresent(sc => scheduleBuilder.stubConvention(sc)); firstRegularStartDateOpt.ifPresent(date => scheduleBuilder.firstRegularStartDate(date)); lastRegEndDateOpt.ifPresent(date => scheduleBuilder.lastRegularEndDate(date)); dateCalOpt.ifPresent(cal => scheduleBuilder.businessDayAdjustment(BusinessDayAdjustment.of(dateCnv, cal))); legBuilder.add(swapLeg.toBuilder().accrualSchedule(scheduleBuilder.build()).build()); } return(replaceLegs(trade, legBuilder.build())); }
public virtual void test_of() { BusinessDayAdjustment bussAdj = BusinessDayAdjustment.of(FOLLOWING, SAT_SUN); PeriodicSchedule expected = PeriodicSchedule.builder().startDate(START_DATE).endDate(END_DATE).businessDayAdjustment(bussAdj).startDateBusinessDayAdjustment(BusinessDayAdjustment.NONE).endDateBusinessDayAdjustment(BusinessDayAdjustment.NONE).frequency(P3M).rollConvention(RollConventions.NONE).stubConvention(SMART_INITIAL).build(); assertEquals(PRODUCT_STD.PaymentSchedule, expected); assertEquals(PRODUCT_STD.BuySell, BUY); assertEquals(PRODUCT_STD.Currency, USD); assertEquals(PRODUCT_STD.DayCount, ACT_360); assertEquals(PRODUCT_STD.FixedRate, COUPON); assertEquals(PRODUCT_STD.LegalEntityId, LEGAL_ENTITY); assertEquals(PRODUCT_STD.Notional, NOTIONAL); assertEquals(PRODUCT_STD.PaymentOnDefault, ACCRUED_PREMIUM); assertEquals(PRODUCT_STD.ProtectionStart, BEGINNING); assertEquals(PRODUCT_STD.SettlementDateOffset, SETTLE_DAY_ADJ); assertEquals(PRODUCT_STD.StepinDateOffset, STEPIN_DAY_ADJ); Cds test = Cds.of(BUY, LEGAL_ENTITY, USD, NOTIONAL, START_DATE, END_DATE, P3M, SAT_SUN, COUPON); assertEquals(test, PRODUCT_STD); }
//------------------------------------------------------------------------- public override void start(Stage primaryStage) { LocalDate today = LocalDate.now(ZoneId.systemDefault()); // setup GUI elements Label startLbl = new Label("Start date:"); DatePicker startInp = new DatePicker(today); startLbl.LabelFor = startInp; startInp.ShowWeekNumbers = false; Label endLbl = new Label("End date:"); DatePicker endInp = new DatePicker(today.plusYears(1)); endLbl.LabelFor = endInp; endInp.ShowWeekNumbers = false; Label freqLbl = new Label("Frequency:"); ChoiceBox <Frequency> freqInp = new ChoiceBox <Frequency>(FXCollections.observableArrayList(Frequency.P1M, Frequency.P2M, Frequency.P3M, Frequency.P4M, Frequency.P6M, Frequency.P12M)); freqLbl.LabelFor = freqInp; freqInp.Value = Frequency.P3M; Label stubLbl = new Label("Stub:"); ObservableList <StubConvention> stubOptions = FXCollections.observableArrayList(StubConvention.values()); stubOptions.add(0, null); ChoiceBox <StubConvention> stubInp = new ChoiceBox <StubConvention>(stubOptions); stubLbl.LabelFor = stubInp; stubInp.Value = StubConvention.SMART_INITIAL; Label rollLbl = new Label("Roll:"); ChoiceBox <RollConvention> rollInp = new ChoiceBox <RollConvention>(FXCollections.observableArrayList(null, RollConventions.NONE, RollConventions.EOM, RollConventions.IMM, RollConventions.IMMAUD, RollConventions.IMMNZD, RollConventions.SFE)); rollLbl.LabelFor = rollInp; rollInp.Value = RollConventions.NONE; Label bdcLbl = new Label("Adjust:"); ChoiceBox <BusinessDayConvention> bdcInp = new ChoiceBox <BusinessDayConvention>(FXCollections.observableArrayList(BusinessDayConventions.NO_ADJUST, BusinessDayConventions.FOLLOWING, BusinessDayConventions.MODIFIED_FOLLOWING, BusinessDayConventions.PRECEDING, BusinessDayConventions.MODIFIED_PRECEDING, BusinessDayConventions.MODIFIED_FOLLOWING_BI_MONTHLY, BusinessDayConventions.NEAREST)); bdcLbl.LabelFor = bdcInp; bdcInp.Value = BusinessDayConventions.MODIFIED_FOLLOWING; Label holidayLbl = new Label("Holidays:"); ChoiceBox <HolidayCalendarId> holidayInp = new ChoiceBox <HolidayCalendarId>(FXCollections.observableArrayList(HolidayCalendarIds.CHZU, HolidayCalendarIds.GBLO, HolidayCalendarIds.EUTA, HolidayCalendarIds.FRPA, HolidayCalendarIds.JPTO, HolidayCalendarIds.NYFD, HolidayCalendarIds.NYSE, HolidayCalendarIds.USNY, HolidayCalendarIds.USGS, HolidayCalendarIds.NO_HOLIDAYS, HolidayCalendarIds.SAT_SUN)); holidayLbl.LabelFor = holidayInp; holidayInp.Value = HolidayCalendarIds.GBLO; TableView <SchedulePeriod> resultGrid = new TableView <SchedulePeriod>(); TableColumn <SchedulePeriod, LocalDate> unadjustedCol = new TableColumn <SchedulePeriod, LocalDate>("Unadjusted dates"); TableColumn <SchedulePeriod, LocalDate> adjustedCol = new TableColumn <SchedulePeriod, LocalDate>("Adjusted dates"); TableColumn <SchedulePeriod, LocalDate> resultUnadjStartCol = new TableColumn <SchedulePeriod, LocalDate>("Start"); resultUnadjStartCol.CellValueFactory = new TableCallback <>(SchedulePeriod.meta().unadjustedStartDate()); TableColumn <SchedulePeriod, LocalDate> resultUnadjEndCol = new TableColumn <SchedulePeriod, LocalDate>("End"); resultUnadjEndCol.CellValueFactory = new TableCallback <>(SchedulePeriod.meta().unadjustedEndDate()); TableColumn <SchedulePeriod, Period> resultUnadjLenCol = new TableColumn <SchedulePeriod, Period>("Length"); resultUnadjLenCol.CellValueFactory = ReadOnlyCallback.of(sch => Period.between(sch.UnadjustedStartDate, sch.UnadjustedEndDate)); TableColumn <SchedulePeriod, LocalDate> resultStartCol = new TableColumn <SchedulePeriod, LocalDate>("Start"); resultStartCol.CellValueFactory = new TableCallback <>(SchedulePeriod.meta().startDate()); TableColumn <SchedulePeriod, LocalDate> resultEndCol = new TableColumn <SchedulePeriod, LocalDate>("End"); resultEndCol.CellValueFactory = new TableCallback <>(SchedulePeriod.meta().endDate()); TableColumn <SchedulePeriod, Period> resultLenCol = new TableColumn <SchedulePeriod, Period>("Length"); resultLenCol.CellValueFactory = ReadOnlyCallback.of(sch => sch.length()); unadjustedCol.Columns.add(resultUnadjStartCol); unadjustedCol.Columns.add(resultUnadjEndCol); unadjustedCol.Columns.add(resultUnadjLenCol); adjustedCol.Columns.add(resultStartCol); adjustedCol.Columns.add(resultEndCol); adjustedCol.Columns.add(resultLenCol); resultGrid.Columns.add(unadjustedCol); resultGrid.Columns.add(adjustedCol); resultGrid.Placeholder = new Label("Schedule not yet generated"); unadjustedCol.prefWidthProperty().bind(resultGrid.widthProperty().divide(2)); adjustedCol.prefWidthProperty().bind(resultGrid.widthProperty().divide(2)); resultUnadjStartCol.prefWidthProperty().bind(unadjustedCol.widthProperty().divide(3)); resultUnadjEndCol.prefWidthProperty().bind(unadjustedCol.widthProperty().divide(3)); resultUnadjLenCol.prefWidthProperty().bind(unadjustedCol.widthProperty().divide(3)); resultStartCol.prefWidthProperty().bind(adjustedCol.widthProperty().divide(3)); resultEndCol.prefWidthProperty().bind(adjustedCol.widthProperty().divide(3)); resultLenCol.prefWidthProperty().bind(adjustedCol.widthProperty().divide(3)); // setup generation button // this uses the GUI thread which is not the best idea Button btn = new Button(); btn.Text = "Generate"; btn.OnAction = @event => { LocalDate start = startInp.Value; LocalDate end = endInp.Value; Frequency freq = freqInp.Value; StubConvention stub = stubInp.Value; RollConvention roll = rollInp.Value; HolidayCalendarId holCal = holidayInp.Value; BusinessDayConvention bdc = bdcInp.Value; BusinessDayAdjustment bda = BusinessDayAdjustment.of(bdc, holCal); PeriodicSchedule defn = PeriodicSchedule.builder().startDate(start).endDate(end).frequency(freq).businessDayAdjustment(bda).stubConvention(stub).rollConvention(roll).build(); try { Schedule schedule = defn.createSchedule(REF_DATA); Console.WriteLine(schedule); resultGrid.Items = FXCollections.observableArrayList(schedule.Periods); } catch (ScheduleException ex) { resultGrid.Items = FXCollections.emptyObservableList(); resultGrid.Placeholder = new Label(ex.Message); Console.WriteLine(ex.Message); } }; // layout the components GridPane gp = new GridPane(); gp.Hgap = 10; gp.Vgap = 10; gp.Padding = new Insets(0, 10, 0, 10); gp.add(startLbl, 1, 1); gp.add(startInp, 2, 1); gp.add(endLbl, 1, 2); gp.add(endInp, 2, 2); gp.add(freqLbl, 1, 3); gp.add(freqInp, 2, 3); gp.add(bdcLbl, 3, 1); gp.add(bdcInp, 4, 1); gp.add(holidayLbl, 3, 2); gp.add(holidayInp, 4, 2); gp.add(stubLbl, 3, 3); gp.add(stubInp, 4, 3); gp.add(rollLbl, 3, 4); gp.add(rollInp, 4, 4); gp.add(btn, 3, 5, 2, 1); gp.add(resultGrid, 1, 7, 4, 1); BorderPane bp = new BorderPane(gp); Scene scene = new Scene(bp, 600, 600); // launch primaryStage.Title = "Periodic schedule generator"; primaryStage.Scene = scene; primaryStage.show(); }
//------------------------------------------------------------------------- public virtual void coverage() { coverImmutableBean(PRODUCT_STD); Cds other = Cds.builder().buySell(SELL).legalEntityId(StandardId.of("OG", "EFG")).currency(JPY).notional(1d).fixedRate(0.01).dayCount(ACT_365F).paymentSchedule(PeriodicSchedule.builder().businessDayAdjustment(BusinessDayAdjustment.of(BusinessDayConventions.FOLLOWING, JPTO)).startDate(LocalDate.of(2014, 1, 4)).endDate(LocalDate.of(2020, 11, 20)).startDateBusinessDayAdjustment(BusinessDayAdjustment.NONE).endDateBusinessDayAdjustment(BusinessDayAdjustment.NONE).frequency(P6M).rollConvention(RollConventions.NONE).stubConvention(StubConvention.SHORT_FINAL).build()).paymentOnDefault(PaymentOnDefault.NONE).protectionStart(ProtectionStartOfDay.NONE).stepinDateOffset(DaysAdjustment.NONE).settlementDateOffset(DaysAdjustment.NONE).build(); coverBeanEquals(PRODUCT_STD, other); }
static CalibrationZeroRateUsd3OisIrsBsTest() { DSC_NAMES[DSCON_CURVE_NAME] = USD; ISet <Index> usdFedFundSet = new HashSet <Index>(); usdFedFundSet.Add(USD_FED_FUND); IDX_NAMES[DSCON_CURVE_NAME] = usdFedFundSet; ISet <Index> usdLibor3Set = new HashSet <Index>(); usdLibor3Set.Add(USD_LIBOR_3M); IDX_NAMES[FWD3_CURVE_NAME] = usdLibor3Set; ISet <Index> usdLibor6Set = new HashSet <Index>(); usdLibor6Set.Add(USD_LIBOR_6M); IDX_NAMES[FWD6_CURVE_NAME] = usdLibor6Set; for (int i = 0; i < DSC_NB_DEPO_NODES; i++) { BusinessDayAdjustment bda = BusinessDayAdjustment.of(FOLLOWING, USNY); TermDepositConvention convention = ImmutableTermDepositConvention.of("USD-Dep", USD, bda, ACT_360, DaysAdjustment.ofBusinessDays(DSC_DEPO_OFFSET[i], USNY)); DSC_NODES[i] = TermDepositCurveNode.of(TermDepositTemplate.of(Period.ofDays(1), convention), QuoteId.of(StandardId.of(SCHEME, DSC_ID_VALUE[i]))); } for (int i = 0; i < DSC_NB_OIS_NODES; i++) { DSC_NODES[DSC_NB_DEPO_NODES + i] = FixedOvernightSwapCurveNode.of(FixedOvernightSwapTemplate.of(Period.ZERO, Tenor.of(DSC_OIS_TENORS[i]), USD_FIXED_1Y_FED_FUND_OIS), QuoteId.of(StandardId.of(SCHEME, DSC_ID_VALUE[DSC_NB_DEPO_NODES + i]))); } FWD3_NODES[0] = IborFixingDepositCurveNode.of(IborFixingDepositTemplate.of(USD_LIBOR_3M), QuoteId.of(StandardId.of(SCHEME, FWD3_ID_VALUE[0]))); for (int i = 0; i < FWD3_NB_FRA_NODES; i++) { FWD3_NODES[i + 1] = FraCurveNode.of(FraTemplate.of(FWD3_FRA_TENORS[i], USD_LIBOR_3M), QuoteId.of(StandardId.of(SCHEME, FWD3_ID_VALUE[i + 1]))); } for (int i = 0; i < FWD3_NB_IRS_NODES; i++) { FWD3_NODES[i + 1 + FWD3_NB_FRA_NODES] = FixedIborSwapCurveNode.of(FixedIborSwapTemplate.of(Period.ZERO, Tenor.of(FWD3_IRS_TENORS[i]), USD_FIXED_6M_LIBOR_3M), QuoteId.of(StandardId.of(SCHEME, FWD3_ID_VALUE[i + 1 + FWD3_NB_FRA_NODES]))); } FWD6_NODES[0] = IborFixingDepositCurveNode.of(IborFixingDepositTemplate.of(USD_LIBOR_6M), QuoteId.of(StandardId.of(SCHEME, FWD6_ID_VALUE[0]))); for (int i = 0; i < FWD6_NB_FRA_NODES; i++) { FWD6_NODES[i + 1] = FraCurveNode.of(FraTemplate.of(FWD6_FRA_TENORS[i], USD_LIBOR_6M), QuoteId.of(StandardId.of(SCHEME, FWD6_ID_VALUE[i + 1]))); } for (int i = 0; i < FWD6_NB_IRS_NODES; i++) { FWD6_NODES[i + 1 + FWD6_NB_FRA_NODES] = IborIborSwapCurveNode.of(IborIborSwapTemplate.of(Period.ZERO, Tenor.of(FWD6_IRS_TENORS[i]), USD_LIBOR_3M_LIBOR_6M), QuoteId.of(StandardId.of(SCHEME, FWD6_ID_VALUE[i + 1 + FWD6_NB_FRA_NODES]))); } ImmutableMarketDataBuilder builder = ImmutableMarketData.builder(VAL_DATE); for (int i = 0; i < DSC_NB_NODES; i++) { builder.addValue(QuoteId.of(StandardId.of(SCHEME, DSC_ID_VALUE[i])), DSC_MARKET_QUOTES[i]); } for (int i = 0; i < FWD3_NB_NODES; i++) { builder.addValue(QuoteId.of(StandardId.of(SCHEME, FWD3_ID_VALUE[i])), FWD3_MARKET_QUOTES[i]); } for (int i = 0; i < FWD6_NB_NODES; i++) { builder.addValue(QuoteId.of(StandardId.of(SCHEME, FWD6_ID_VALUE[i])), FWD6_MARKET_QUOTES[i]); } ALL_QUOTES = builder.build(); IList <CurveNode[]> groupDsc = new List <CurveNode[]>(); groupDsc.Add(DSC_NODES); CURVES_NODES.Add(groupDsc); IList <CurveNode[]> groupFwd3 = new List <CurveNode[]>(); groupFwd3.Add(FWD3_NODES); CURVES_NODES.Add(groupFwd3); IList <CurveNode[]> groupFwd6 = new List <CurveNode[]>(); groupFwd6.Add(FWD6_NODES); CURVES_NODES.Add(groupFwd6); IList <CurveMetadata> groupDsc = new List <CurveMetadata>(); groupDsc.Add(DefaultCurveMetadata.builder().curveName(DSCON_CURVE_NAME).xValueType(ValueType.YEAR_FRACTION).yValueType(ValueType.ZERO_RATE).dayCount(CURVE_DC).build()); CURVES_METADATA.Add(groupDsc); IList <CurveMetadata> groupFwd3 = new List <CurveMetadata>(); groupFwd3.Add(DefaultCurveMetadata.builder().curveName(FWD3_CURVE_NAME).xValueType(ValueType.YEAR_FRACTION).yValueType(ValueType.ZERO_RATE).dayCount(CURVE_DC).build()); CURVES_METADATA.Add(groupFwd3); IList <CurveMetadata> groupFwd6 = new List <CurveMetadata>(); groupFwd6.Add(DefaultCurveMetadata.builder().curveName(FWD6_CURVE_NAME).xValueType(ValueType.YEAR_FRACTION).yValueType(ValueType.ZERO_RATE).dayCount(CURVE_DC).build()); CURVES_METADATA.Add(groupFwd6); }
// 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()); }
public virtual void test_resolve_unadjustedAccrualAdjustedPayment() { Swap test = Swap.builder().legs(RateCalculationSwapLeg.builder().payReceive(RECEIVE).accrualSchedule(PeriodicSchedule.builder().startDate(date(2016, 1, 3)).endDate(date(2016, 5, 3)).frequency(Frequency.P1M).businessDayAdjustment(BusinessDayAdjustment.NONE).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(Frequency.P1M).businessDayAdjustment(BusinessDayAdjustment.of(FOLLOWING, SAT_SUN)).paymentDateOffset(DaysAdjustment.ofBusinessDays(2, SAT_SUN)).build()).notionalSchedule(NotionalSchedule.of(GBP, NOTIONAL)).calculation(FixedRateCalculation.of(RATE, ACT_360)).build()).build(); RatePaymentPeriod pp1 = RatePaymentPeriod.builder().paymentDate(date(2016, 2, 5)).accrualPeriods(RateAccrualPeriod.builder().startDate(date(2016, 1, 3)).unadjustedStartDate(date(2016, 1, 3)).endDate(date(2016, 2, 3)).unadjustedEndDate(date(2016, 2, 3)).yearFraction(ACT_360.yearFraction(date(2016, 1, 3), date(2016, 2, 3))).rateComputation(FixedRateComputation.of(RATE)).build()).dayCount(ACT_360).currency(GBP).notional(NOTIONAL).build(); RatePaymentPeriod pp2 = RatePaymentPeriod.builder().paymentDate(date(2016, 3, 7)).accrualPeriods(RateAccrualPeriod.builder().startDate(date(2016, 2, 3)).unadjustedStartDate(date(2016, 2, 3)).endDate(date(2016, 3, 3)).unadjustedEndDate(date(2016, 3, 3)).yearFraction(ACT_360.yearFraction(date(2016, 2, 3), date(2016, 3, 3))).rateComputation(FixedRateComputation.of(RATE)).build()).dayCount(ACT_360).currency(GBP).notional(NOTIONAL).build(); RatePaymentPeriod pp3 = RatePaymentPeriod.builder().paymentDate(date(2016, 4, 6)).accrualPeriods(RateAccrualPeriod.builder().startDate(date(2016, 3, 3)).unadjustedStartDate(date(2016, 3, 3)).endDate(date(2016, 4, 3)).unadjustedEndDate(date(2016, 4, 3)).yearFraction(ACT_360.yearFraction(date(2016, 3, 3), date(2016, 4, 3))).rateComputation(FixedRateComputation.of(RATE)).build()).dayCount(ACT_360).currency(GBP).notional(NOTIONAL).build(); RatePaymentPeriod pp4 = RatePaymentPeriod.builder().paymentDate(date(2016, 5, 5)).accrualPeriods(RateAccrualPeriod.builder().startDate(date(2016, 4, 3)).unadjustedStartDate(date(2016, 4, 3)).endDate(date(2016, 5, 3)).unadjustedEndDate(date(2016, 5, 3)).yearFraction(ACT_360.yearFraction(date(2016, 4, 3), date(2016, 5, 3))).rateComputation(FixedRateComputation.of(RATE)).build()).dayCount(ACT_360).currency(GBP).notional(NOTIONAL).build(); ResolvedSwap expected = ResolvedSwap.builder().legs(ResolvedSwapLeg.builder().paymentPeriods(pp1, pp2, pp3, pp4).payReceive(RECEIVE).type(FIXED).build()).build(); assertEqualsBean(test.resolve(REF_DATA), expected); }
// Create a compounding libor 6m vs libor 3m swap private static Trade createCompoundingLibor6mVsLibor3mSwap() { NotionalSchedule notional = NotionalSchedule.of(Currency.USD, 100_000_000); SwapLeg payLeg = RateCalculationSwapLeg.builder().payReceive(PayReceive.PAY).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2014, 8, 27)).endDate(LocalDate.of(2024, 8, 27)).frequency(Frequency.P6M).businessDayAdjustment(BusinessDayAdjustment.of(MODIFIED_FOLLOWING, HolidayCalendarIds.USNY)).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(Frequency.P6M).paymentDateOffset(DaysAdjustment.NONE).build()).notionalSchedule(notional).calculation(IborRateCalculation.of(IborIndices.USD_LIBOR_6M)).build(); SwapLeg receiveLeg = RateCalculationSwapLeg.builder().payReceive(PayReceive.RECEIVE).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2014, 8, 27)).endDate(LocalDate.of(2024, 8, 27)).frequency(Frequency.P3M).businessDayAdjustment(BusinessDayAdjustment.of(MODIFIED_FOLLOWING, HolidayCalendarIds.USNY)).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(Frequency.P6M).paymentDateOffset(DaysAdjustment.NONE).compoundingMethod(CompoundingMethod.STRAIGHT).build()).notionalSchedule(notional).calculation(IborRateCalculation.of(IborIndices.USD_LIBOR_3M)).build(); return(SwapTrade.builder().product(Swap.of(payLeg, receiveLeg)).info(TradeInfo.builder().id(StandardId.of("example", "13")).addAttribute(AttributeType.DESCRIPTION, "Compounding libor 6m vs libor 3m").counterparty(StandardId.of("example", "A")).settlementDate(LocalDate.of(2014, 8, 27)).build()).build()); }
public virtual void test_trade() { IborFixingDepositCurveNode node = IborFixingDepositCurveNode.of(TEMPLATE, QUOTE_ID, SPREAD); LocalDate valuationDate = LocalDate.of(2015, 1, 22); double rate = 0.035; MarketData marketData = ImmutableMarketData.builder(valuationDate).addValue(QUOTE_ID, rate).build(); IborFixingDepositTrade trade = node.trade(1d, marketData, REF_DATA); ImmutableIborFixingDepositConvention conv = (ImmutableIborFixingDepositConvention)TEMPLATE.Convention; LocalDate startDateExpected = conv.SpotDateOffset.adjust(valuationDate, REF_DATA); LocalDate endDateExpected = startDateExpected.plus(TEMPLATE.DepositPeriod); IborFixingDeposit depositExpected = IborFixingDeposit.builder().buySell(BuySell.BUY).index(EUR_LIBOR_3M).startDate(startDateExpected).endDate(endDateExpected).businessDayAdjustment(BusinessDayAdjustment.of(MODIFIED_FOLLOWING, EUR_LIBOR_3M.FixingCalendar)).notional(1.0d).fixedRate(rate + SPREAD).build(); TradeInfo tradeInfoExpected = TradeInfo.builder().tradeDate(valuationDate).build(); assertEquals(trade.Product, depositExpected); assertEquals(trade.Info, tradeInfoExpected); }
//----------------------------------------------------------------------- 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(); }
private static Trade createTrade1() { NotionalSchedule notional = NotionalSchedule.of(Currency.USD, 12_000_000); PeriodicSchedule accrual = PeriodicSchedule.builder().startDate(LocalDate.of(2006, 2, 24)).endDate(LocalDate.of(2011, 2, 24)).frequency(Frequency.P3M).businessDayAdjustment(BusinessDayAdjustment.of(MODIFIED_FOLLOWING, HolidayCalendarIds.USNY)).build(); PaymentSchedule payment = PaymentSchedule.builder().paymentFrequency(Frequency.P3M).paymentDateOffset(DaysAdjustment.ofBusinessDays(2, HolidayCalendarIds.USNY)).build(); SwapLeg payLeg = RateCalculationSwapLeg.builder().payReceive(PayReceive.PAY).accrualSchedule(accrual).paymentSchedule(payment).notionalSchedule(notional).calculation(FixedRateCalculation.of(0.05004, DayCounts.ACT_360)).build(); SwapLeg receiveLeg = RateCalculationSwapLeg.builder().payReceive(PayReceive.RECEIVE).accrualSchedule(accrual).paymentSchedule(payment).notionalSchedule(notional).calculation(IborRateCalculation.of(IborIndices.USD_LIBOR_3M)).build(); return(SwapTrade.builder().product(Swap.builder().legs(payLeg, receiveLeg).build()).info(TradeInfo.builder().id(StandardId.of("mn", "14248")).counterparty(StandardId.of("mn", "Dealer A")).settlementDate(LocalDate.of(2006, 2, 24)).build()).build()); }
static CalibrationDiscountFactorUsd2FomcDatesOisIrsTest() { DSC_NAMES[DSCON_CURVE_NAME] = USD; ISet <Index> usdFedFundSet = new HashSet <Index>(); usdFedFundSet.Add(USD_FED_FUND); IDX_NAMES[DSCON_CURVE_NAME] = usdFedFundSet; ISet <Index> usdLibor3Set = new HashSet <Index>(); usdLibor3Set.Add(USD_LIBOR_3M); IDX_NAMES[FWD3_CURVE_NAME] = usdLibor3Set; double fixingValue = 0.002345; LocalDateDoubleTimeSeries tsBdUsdLibor3M = LocalDateDoubleTimeSeries.builder().put(VAL_DATE_BD, fixingValue).build(); TS_BD_LIBOR3M = ImmutableMarketData.builder(VAL_DATE_BD).addTimeSeries(IndexQuoteId.of(USD_LIBOR_3M), tsBdUsdLibor3M).build(); for (int i = 0; i < DSC_NB_DEPO_NODES; i++) { BusinessDayAdjustment bda = BusinessDayAdjustment.of(FOLLOWING, USNY); TermDepositConvention convention = ImmutableTermDepositConvention.of("USD-Dep", USD, bda, ACT_360, DaysAdjustment.ofBusinessDays(DSC_DEPO_OFFSET[i], USNY)); LocalDate nodeDate = FOMC_NODES[i]; if (nodeDate != null) { DSC_NODES[i] = TermDepositCurveNode.builder().template(TermDepositTemplate.of(Period.ofDays(1), convention)).rateId(QuoteId.of(StandardId.of(SCHEME, DSC_ID_VALUE[i]))).date(CurveNodeDate.of(nodeDate)).build(); } else { DSC_NODES[i] = TermDepositCurveNode.of(TermDepositTemplate.of(Period.ofDays(1), convention), QuoteId.of(StandardId.of(SCHEME, DSC_ID_VALUE[i]))); } } for (int i = 0; i < DSC_NB_OIS_NODES; i++) { LocalDate nodeDate = FOMC_NODES[DSC_NB_DEPO_NODES + i]; if (nodeDate != null) { DSC_NODES[DSC_NB_DEPO_NODES + i] = FixedOvernightSwapCurveNode.builder().template(FixedOvernightSwapTemplate.of(Period.ZERO, Tenor.of(DSC_OIS_TENORS[i]), USD_FIXED_1Y_FED_FUND_OIS)).rateId(QuoteId.of(StandardId.of(SCHEME, DSC_ID_VALUE[DSC_NB_DEPO_NODES + i]))).date(CurveNodeDate.of(nodeDate)).build(); } else { DSC_NODES[DSC_NB_DEPO_NODES + i] = FixedOvernightSwapCurveNode.of(FixedOvernightSwapTemplate.of(Period.ZERO, Tenor.of(DSC_OIS_TENORS[i]), USD_FIXED_1Y_FED_FUND_OIS), QuoteId.of(StandardId.of(SCHEME, DSC_ID_VALUE[DSC_NB_DEPO_NODES + i]))); } } FWD3_NODES[0] = IborFixingDepositCurveNode.of(IborFixingDepositTemplate.of(USD_LIBOR_3M), QuoteId.of(StandardId.of(SCHEME, FWD3_ID_VALUE[0]))); for (int i = 0; i < FWD3_NB_FRA_NODES; i++) { FWD3_NODES[i + 1] = FraCurveNode.of(FraTemplate.of(FWD3_FRA_TENORS[i], USD_LIBOR_3M), QuoteId.of(StandardId.of(SCHEME, FWD3_ID_VALUE[i + 1]))); } for (int i = 0; i < FWD3_NB_IRS_NODES; i++) { FWD3_NODES[i + 1 + FWD3_NB_FRA_NODES] = FixedIborSwapCurveNode.of(FixedIborSwapTemplate.of(Period.ZERO, Tenor.of(FWD3_IRS_TENORS[i]), USD_FIXED_6M_LIBOR_3M), QuoteId.of(StandardId.of(SCHEME, FWD3_ID_VALUE[i + 1 + FWD3_NB_FRA_NODES]))); } ImmutableMarketDataBuilder builder = ImmutableMarketData.builder(VAL_DATE_BD); for (int i = 0; i < FWD3_NB_NODES; i++) { builder.addValue(QuoteId.of(StandardId.of(SCHEME, FWD3_ID_VALUE[i])), FWD3_MARKET_QUOTES[i]); } for (int i = 0; i < DSC_NB_NODES; i++) { builder.addValue(QuoteId.of(StandardId.of(SCHEME, DSC_ID_VALUE[i])), DSC_MARKET_QUOTES[i]); } ALL_QUOTES_BD = builder.build(); IList <CurveNode[]> groupDsc = new List <CurveNode[]>(); groupDsc.Add(DSC_NODES); CURVES_NODES.Add(groupDsc); IList <CurveNode[]> groupFwd3 = new List <CurveNode[]>(); groupFwd3.Add(FWD3_NODES); CURVES_NODES.Add(groupFwd3); IList <CurveMetadata> groupDsc = new List <CurveMetadata>(); groupDsc.Add(DefaultCurveMetadata.builder().curveName(DSCON_CURVE_NAME).xValueType(ValueType.YEAR_FRACTION).yValueType(ValueType.ZERO_RATE).dayCount(CURVE_DC).build()); CURVES_METADATA.Add(groupDsc); IList <CurveMetadata> groupFwd3 = new List <CurveMetadata>(); groupFwd3.Add(DefaultCurveMetadata.builder().curveName(FWD3_CURVE_NAME).xValueType(ValueType.YEAR_FRACTION).yValueType(ValueType.ZERO_RATE).dayCount(CURVE_DC).build()); CURVES_METADATA.Add(groupFwd3); }
//------------------------------------------------------------------------- public virtual void coverage() { coverImmutableBean(PRODUCT); CdsIndex other = CdsIndex.builder().buySell(SELL).cdsIndexId(StandardId.of("OG", "AA-INDEX")).legalEntityIds(ImmutableList.of(StandardId.of("OG", "ABC1"), StandardId.of("OG", "ABC2"))).currency(JPY).notional(1d).paymentSchedule(PeriodicSchedule.of(LocalDate.of(2014, 1, 4), LocalDate.of(2020, 11, 20), P6M, BusinessDayAdjustment.of(BusinessDayConventions.FOLLOWING, JPTO), StubConvention.SHORT_FINAL, RollConventions.NONE)).fixedRate(0.01).dayCount(ACT_365F).paymentOnDefault(PaymentOnDefault.NONE).protectionStart(ProtectionStartOfDay.NONE).settlementDateOffset(DaysAdjustment.NONE).stepinDateOffset(DaysAdjustment.NONE).build(); coverBeanEquals(PRODUCT, other); }
//------------------------------------------------------------------------- //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @ImmutablePreBuild private static void preBuild(Builder builder) private static void preBuild(Builder builder) { if (builder.fixingDateOffset_Renamed == null && builder.fixingCalendar_Renamed != null && builder.maturityDateOffset_Renamed != null) { int days = builder.maturityDateOffset_Renamed.Days; HolidayCalendarId maturityCal = builder.maturityDateOffset_Renamed.Calendar; if (maturityCal.combinedWith(builder.fixingCalendar_Renamed).Equals(maturityCal)) { builder.fixingDateOffset_Renamed = DaysAdjustment.ofBusinessDays(-days, maturityCal); } else { builder.fixingDateOffset_Renamed = DaysAdjustment.ofBusinessDays(-days, maturityCal, BusinessDayAdjustment.of(BusinessDayConventions.PRECEDING, builder.fixingCalendar_Renamed)); } } }
//------------------------------------------------------------------------- // days adjustment, defaulting business day convention private static Optional <BusinessDayAdjustment> parseBusinessDayAdjustment(CsvRow row, string leg, string cnvField, string calField) { BusinessDayConvention dateCnv = findValue(row, leg, cnvField).map(s => LoaderUtils.parseBusinessDayConvention(s)).orElse(BusinessDayConventions.MODIFIED_FOLLOWING); return(findValue(row, leg, calField).map(s => HolidayCalendarId.of(s)).map(cal => BusinessDayAdjustment.of(dateCnv, cal))); }
// create a cross-currency GBP libor 3m vs USD libor 3m swap with spread private static Trade createXCcyGbpLibor3mVsUsdLibor3mSwap() { SwapLeg payLeg = RateCalculationSwapLeg.builder().payReceive(PayReceive.PAY).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.of(Currency.GBP, 61_600_000)).calculation(IborRateCalculation.of(IborIndices.GBP_LIBOR_3M)).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.USNY)).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(Frequency.P3M).paymentDateOffset(DaysAdjustment.NONE).build()).notionalSchedule(NotionalSchedule.of(Currency.USD, 100_000_000)).calculation(IborRateCalculation.builder().index(IborIndices.USD_LIBOR_3M).spread(ValueSchedule.of(0.0091)).build()).build(); return(SwapTrade.builder().product(Swap.of(receiveLeg, payLeg)).info(TradeInfo.builder().id(StandardId.of("example", "14")).addAttribute(AttributeType.DESCRIPTION, "GBP Libor 3m vs USD Libor 3m").counterparty(StandardId.of("example", "A")).settlementDate(LocalDate.of(2014, 1, 24)).build()).build()); }
// Create an overnight averaged vs libor 3m swap with spread private static Trade createOvernightAveragedWithSpreadVsLibor3mSwap() { NotionalSchedule notional = NotionalSchedule.of(Currency.USD, 100_000_000); SwapLeg payLeg = RateCalculationSwapLeg.builder().payReceive(PayReceive.PAY).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2014, 9, 12)).endDate(LocalDate.of(2020, 9, 12)).frequency(Frequency.P3M).businessDayAdjustment(BusinessDayAdjustment.of(MODIFIED_FOLLOWING, HolidayCalendarIds.USNY)).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(Frequency.P3M).paymentDateOffset(DaysAdjustment.NONE).build()).notionalSchedule(notional).calculation(IborRateCalculation.of(IborIndices.USD_LIBOR_3M)).build(); SwapLeg receiveLeg = RateCalculationSwapLeg.builder().payReceive(PayReceive.RECEIVE).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2014, 9, 12)).endDate(LocalDate.of(2020, 9, 12)).frequency(Frequency.P3M).businessDayAdjustment(BusinessDayAdjustment.of(MODIFIED_FOLLOWING, HolidayCalendarIds.USNY)).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(Frequency.P3M).paymentDateOffset(DaysAdjustment.NONE).build()).notionalSchedule(notional).calculation(OvernightRateCalculation.builder().dayCount(DayCounts.ACT_360).index(OvernightIndices.USD_FED_FUND).accrualMethod(OvernightAccrualMethod.AVERAGED).spread(ValueSchedule.of(0.0025)).build()).build(); return(SwapTrade.builder().product(Swap.of(payLeg, receiveLeg)).info(TradeInfo.builder().id(StandardId.of("example", "3")).addAttribute(AttributeType.DESCRIPTION, "Fed Funds averaged + spread vs Libor 3m").counterparty(StandardId.of("example", "A")).settlementDate(LocalDate.of(2014, 9, 12)).build()).build()); }
public virtual void test_createCap() { SurfaceIborCapletFloorletVolatilityBootstrapDefinition @base = SurfaceIborCapletFloorletVolatilityBootstrapDefinition.of(NAME, USD_LIBOR_3M, ACT_ACT_ISDA, TIME_SQUARE, DOUBLE_QUADRATIC); LocalDate startDate = LocalDate.of(2012, 4, 20); LocalDate endDate = LocalDate.of(2017, 4, 20); double strike = 0.01; IborCapFloorLeg expected = IborCapFloorLeg.builder().calculation(IborRateCalculation.of(USD_LIBOR_3M)).capSchedule(ValueSchedule.of(strike)).currency(USD_LIBOR_3M.Currency).notional(ValueSchedule.ALWAYS_1).paymentDateOffset(DaysAdjustment.NONE).paymentSchedule(PeriodicSchedule.of(startDate, endDate, Frequency.of(USD_LIBOR_3M.Tenor.Period), BusinessDayAdjustment.of(BusinessDayConventions.MODIFIED_FOLLOWING, USD_LIBOR_3M.FixingCalendar), StubConvention.NONE, RollConventions.NONE)).payReceive(PayReceive.RECEIVE).build(); IborCapFloorLeg computed = @base.createCap(startDate, endDate, strike); assertEquals(computed, expected); }
//----------------------------------------------------------------------- public virtual void floatingSwapLeg() { // a PeriodicSchedule generates a schedule of accrual periods // - interest is accrued every 6 months from 2014-02-12 to 2014-07-31 // - accrual period dates are adjusted "modified following" using the "GBLO" holiday calendar // - there will be a long initial stub // - the regular accrual period dates will be at the end-of-month PeriodicSchedule accrualSchedule = PeriodicSchedule.builder().startDate(LocalDate.of(2014, 2, 12)).endDate(LocalDate.of(2016, 7, 31)).businessDayAdjustment(BusinessDayAdjustment.of(MODIFIED_FOLLOWING, HolidayCalendarIds.GBLO)).frequency(Frequency.P6M).stubConvention(StubConvention.LONG_INITIAL).rollConvention(RollConventions.EOM).build(); // a PaymentSchedule generates a schedule of payment periods, based on the accrual schedule // - payments are every 6 months // - payments are 2 business days after the end of the period // - no compounding is needed as the payment schedule matches the accrual schedule PaymentSchedule paymentSchedule = PaymentSchedule.builder().paymentFrequency(Frequency.P6M).paymentRelativeTo(PaymentRelativeTo.PERIOD_END).paymentDateOffset(DaysAdjustment.ofBusinessDays(2, HolidayCalendarIds.GBLO)).build(); // a NotionalSchedule generates a schedule of notional amounts, based on the payment schedule // - in this simple case the notional is 1 million GBP and does not change NotionalSchedule notionalSchedule = NotionalSchedule.of(Currency.GBP, 1_000_000); // a RateCalculationSwapLeg can represent a fixed or floating swap leg // - an IborRateCalculation is used to represent a floating Ibor rate // - the "Act/Act ISDA" day count is used // - the index is GBP LIBOR 6M // - fixing is 2 days before the start of the period using the "GBLO" holiday calendar RateCalculationSwapLeg swapLeg = RateCalculationSwapLeg.builder().payReceive(PayReceive.RECEIVE).accrualSchedule(accrualSchedule).paymentSchedule(paymentSchedule).notionalSchedule(notionalSchedule).calculation(IborRateCalculation.builder().dayCount(DayCounts.ACT_ACT_ISDA).index(IborIndices.GBP_LIBOR_6M).fixingRelativeTo(FixingRelativeTo.PERIOD_START).fixingDateOffset(DaysAdjustment.ofBusinessDays(-2, HolidayCalendarIds.GBLO)).build()).build(); // a ResolvedSwapLeg has all the dates of the cash flows // it remains valid so long as the holiday calendar does not change ResolvedSwapLeg resolvedLeg = swapLeg.resolve(ReferenceData.standard()); Console.WriteLine("===== Floating ====="); Console.WriteLine(JodaBeanSer.PRETTY.xmlWriter().write(swapLeg)); Console.WriteLine(); Console.WriteLine("===== Floating resolved ====="); Console.WriteLine(JodaBeanSer.PRETTY.xmlWriter().write(resolvedLeg)); Console.WriteLine(); }
// Create a fixed vs libor 6m swap private static Trade createInterpolatedStub4mFixedVsLibor6mSwap() { NotionalSchedule notional = NotionalSchedule.of(Currency.USD, 100_000_000); SwapLeg payLeg = RateCalculationSwapLeg.builder().payReceive(PayReceive.PAY).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2014, 9, 12)).endDate(LocalDate.of(2016, 7, 12)).frequency(Frequency.P6M).businessDayAdjustment(BusinessDayAdjustment.of(MODIFIED_FOLLOWING, HolidayCalendarIds.USNY)).stubConvention(StubConvention.SHORT_INITIAL).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(Frequency.P6M).paymentDateOffset(DaysAdjustment.NONE).build()).notionalSchedule(notional).calculation(IborRateCalculation.builder().index(IborIndices.USD_LIBOR_6M).initialStub(IborRateStubCalculation.ofIborInterpolatedRate(IborIndices.USD_LIBOR_3M, IborIndices.USD_LIBOR_6M)).build()).build(); SwapLeg receiveLeg = RateCalculationSwapLeg.builder().payReceive(PayReceive.RECEIVE).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2014, 9, 12)).endDate(LocalDate.of(2016, 7, 12)).stubConvention(StubConvention.SHORT_INITIAL).frequency(Frequency.P6M).businessDayAdjustment(BusinessDayAdjustment.of(MODIFIED_FOLLOWING, HolidayCalendarIds.USNY)).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(Frequency.P6M).paymentDateOffset(DaysAdjustment.NONE).build()).notionalSchedule(notional).calculation(FixedRateCalculation.of(0.01, DayCounts.THIRTY_U_360)).build(); return(SwapTrade.builder().product(Swap.of(payLeg, receiveLeg)).info(TradeInfo.builder().id(StandardId.of("example", "9")).addAttribute(AttributeType.DESCRIPTION, "Fixed vs Libor 6m (interpolated 4m short initial stub)").counterparty(StandardId.of("example", "A")).settlementDate(LocalDate.of(2014, 9, 12)).build()).build()); }
//----------------------------------------------------------------------- public virtual void fixedSwapLeg() { // a PeriodicSchedule generates a schedule of accrual periods // - interest is accrued every 3 months from 2014-02-12 to 2014-07-31 // - accrual period dates are adjusted "modified following" using the "GBLO" holiday calendar // - there will be a long initial stub // - the regular accrual period dates will be at the end-of-month PeriodicSchedule accrualSchedule = PeriodicSchedule.builder().startDate(LocalDate.of(2014, 2, 12)).endDate(LocalDate.of(2016, 7, 31)).businessDayAdjustment(BusinessDayAdjustment.of(MODIFIED_FOLLOWING, HolidayCalendarIds.GBLO)).frequency(Frequency.P3M).stubConvention(StubConvention.LONG_INITIAL).rollConvention(RollConventions.EOM).build(); // a PaymentSchedule generates a schedule of payment periods, based on the accrual schedule // - payments are every 6 months // - payments are 2 business days after the end of the period // - straight compounding is used (the payments are less frequent than the accrual, so compounding occurs) PaymentSchedule paymentSchedule = PaymentSchedule.builder().paymentFrequency(Frequency.P6M).paymentRelativeTo(PaymentRelativeTo.PERIOD_END).paymentDateOffset(DaysAdjustment.ofBusinessDays(2, HolidayCalendarIds.GBLO)).compoundingMethod(CompoundingMethod.STRAIGHT).build(); // a NotionalSchedule generates a schedule of notional amounts, based on the payment schedule // - in this simple case the notional is 1 million GBP and does not change NotionalSchedule notionalSchedule = NotionalSchedule.of(Currency.GBP, 1_000_000); // a RateCalculationSwapLeg can represent a fixed or floating swap leg // - a FixedRateCalculation is used to represent a fixed rate // - the "Act/Act ISDA" day count is used // - the rate starts at 0.8% and reduces to 0.7% RateCalculationSwapLeg swapLeg = RateCalculationSwapLeg.builder().payReceive(PayReceive.PAY).accrualSchedule(accrualSchedule).paymentSchedule(paymentSchedule).notionalSchedule(notionalSchedule).calculation(FixedRateCalculation.builder().dayCount(DayCounts.ACT_ACT_ISDA).rate(ValueSchedule.of(0.008, ValueStep.of(LocalDate.of(2015, 1, 31), ValueAdjustment.ofReplace(0.007)))).build()).build(); // a ResolvedSwapLeg has all the dates of the cash flows // it remains valid so long as the holiday calendar does not change ResolvedSwapLeg resolvedLeg = swapLeg.resolve(ReferenceData.standard()); Console.WriteLine("===== Fixed ====="); Console.WriteLine(JodaBeanSer.PRETTY.xmlWriter().write(swapLeg)); Console.WriteLine(); Console.WriteLine("===== Fixed resolved ====="); Console.WriteLine(JodaBeanSer.PRETTY.xmlWriter().write(resolvedLeg)); Console.WriteLine(); }
// Create a compounding fixed vs fed funds swap private static Trade createCompoundingFixedVsFedFundsSwap() { NotionalSchedule notional = NotionalSchedule.of(Currency.USD, 100_000_000); SwapLeg payLeg = RateCalculationSwapLeg.builder().payReceive(PayReceive.PAY).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2014, 2, 5)).endDate(LocalDate.of(2014, 4, 7)).frequency(Frequency.TERM).businessDayAdjustment(BusinessDayAdjustment.of(MODIFIED_FOLLOWING, HolidayCalendarIds.USNY)).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(Frequency.TERM).paymentDateOffset(DaysAdjustment.NONE).build()).notionalSchedule(notional).calculation(FixedRateCalculation.of(0.00123, DayCounts.ACT_360)).build(); SwapLeg receiveLeg = RateCalculationSwapLeg.builder().payReceive(PayReceive.RECEIVE).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2014, 2, 5)).endDate(LocalDate.of(2014, 4, 7)).frequency(Frequency.TERM).businessDayAdjustment(BusinessDayAdjustment.of(MODIFIED_FOLLOWING, HolidayCalendarIds.USNY)).stubConvention(StubConvention.SHORT_INITIAL).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(Frequency.TERM).paymentDateOffset(DaysAdjustment.NONE).build()).notionalSchedule(notional).calculation(OvernightRateCalculation.of(OvernightIndices.USD_FED_FUND)).build(); return(SwapTrade.builder().product(Swap.of(payLeg, receiveLeg)).info(TradeInfo.builder().id(StandardId.of("example", "11")).addAttribute(AttributeType.DESCRIPTION, "Compounding fixed vs fed funds").counterparty(StandardId.of("example", "A")).settlementDate(LocalDate.of(2014, 2, 5)).build()).build()); }