//------------------------------------------------------------------------- // ibor rate calculation private static RateCalculation parseIborRateCalculation(CsvRow row, string leg, IborIndex iborIndex, BusinessDayAdjustment bda, Currency currency) { IborRateCalculation.Builder builder = IborRateCalculation.builder(); // basics builder.index(iborIndex); // reset Optional <Frequency> resetFrequencyOpt = findValue(row, leg, RESET_FREQUENCY_FIELD).map(v => Frequency.parse(v)); IborRateResetMethod resetMethod = findValue(row, leg, RESET_METHOD_FIELD).map(v => IborRateResetMethod.of(v)).orElse(IborRateResetMethod.WEIGHTED); BusinessDayAdjustment resetDateAdj = parseBusinessDayAdjustment(row, leg, RESET_DATE_CNV_FIELD, RESET_DATE_CAL_FIELD).orElse(bda); resetFrequencyOpt.ifPresent(freq => builder.resetPeriods(ResetSchedule.builder().resetFrequency(freq).resetMethod(resetMethod).businessDayAdjustment(resetDateAdj).build())); // optionals, no ability to set firstFixingDateOffset findValue(row, leg, DAY_COUNT_FIELD).map(s => LoaderUtils.parseDayCount(s)).ifPresent(v => builder.dayCount(v)); findValue(row, leg, FIXING_RELATIVE_TO_FIELD).map(s => FixingRelativeTo.of(s)).ifPresent(v => builder.fixingRelativeTo(v)); Optional <DaysAdjustment> fixingAdjOpt = parseDaysAdjustment(row, leg, FIXING_OFFSET_DAYS_FIELD, FIXING_OFFSET_CAL_FIELD, FIXING_OFFSET_ADJ_CNV_FIELD, FIXING_OFFSET_ADJ_CAL_FIELD); fixingAdjOpt.ifPresent(v => builder.fixingDateOffset(v)); findValue(row, leg, NEGATIVE_RATE_METHOD_FIELD).map(s => NegativeRateMethod.of(s)).ifPresent(v => builder.negativeRateMethod(v)); findValue(row, leg, FIRST_RATE_FIELD).map(s => LoaderUtils.parseDoublePercent(s)).ifPresent(v => builder.firstRate(v)); findValue(row, leg, GEARING_FIELD).map(s => LoaderUtils.parseDouble(s)).ifPresent(v => builder.gearing(ValueSchedule.of(v))); findValue(row, leg, SPREAD_FIELD).map(s => LoaderUtils.parseDoublePercent(s)).ifPresent(v => builder.spread(ValueSchedule.of(v))); // initial stub Optional <IborRateStubCalculation> initialStub = parseIborStub(row, leg, currency, builder, INITIAL_STUB_RATE_FIELD, INITIAL_STUB_AMOUNT_FIELD, INITIAL_STUB_INDEX_FIELD, INITIAL_STUB_INTERPOLATED_INDEX_FIELD); initialStub.ifPresent(stub => builder.initialStub(stub)); // final stub Optional <IborRateStubCalculation> finalStub = parseIborStub(row, leg, currency, builder, FINAL_STUB_RATE_FIELD, FINAL_STUB_AMOUNT_FIELD, FINAL_STUB_INDEX_FIELD, FINAL_STUB_INTERPOLATED_INDEX_FIELD); finalStub.ifPresent(stub => builder.finalStub(stub)); return(builder.build()); }
public virtual void test_collectIndices_stubCalcsTwoStubs_interpolated() { IborRateCalculation test = IborRateCalculation.builder().dayCount(ACT_365F).index(GBP_LIBOR_1M).fixingDateOffset(MINUS_TWO_DAYS).initialStub(IborRateStubCalculation.ofIborInterpolatedRate(GBP_LIBOR_1W, GBP_LIBOR_1M)).finalStub(IborRateStubCalculation.ofIborInterpolatedRate(GBP_LIBOR_3M, GBP_LIBOR_1M)).build(); ImmutableSet.Builder <Index> builder = ImmutableSet.builder(); test.collectIndices(builder); assertEquals(builder.build(), ImmutableSet.of(GBP_LIBOR_1M, GBP_LIBOR_1W, GBP_LIBOR_3M)); }
public virtual void test_expand_singlePeriod_stubCalcsInitialStub_interpolated() { IborRateCalculation test = IborRateCalculation.builder().dayCount(ACT_365F).index(GBP_LIBOR_2M).fixingDateOffset(MINUS_TWO_DAYS).initialStub(IborRateStubCalculation.ofIborInterpolatedRate(GBP_LIBOR_1W, GBP_LIBOR_1M)).build(); RateAccrualPeriod rap1 = RateAccrualPeriod.builder(ACCRUAL1STUB).yearFraction(ACCRUAL1STUB.yearFraction(ACT_365F, ACCRUAL_SCHEDULE_STUBS)).rateComputation(IborInterpolatedRateComputation.of(GBP_LIBOR_1W, GBP_LIBOR_1M, DATE_01_06, REF_DATA)).build(); ImmutableList <RateAccrualPeriod> periods = test.createAccrualPeriods(SINGLE_ACCRUAL_SCHEDULE_STUB, SINGLE_ACCRUAL_SCHEDULE_STUB, REF_DATA); assertEquals(periods, ImmutableList.of(rap1)); }
//------------------------------------------------------------------------- public virtual void test_collectIndices_simple() { IborRateCalculation test = IborRateCalculation.builder().dayCount(ACT_365F).index(GBP_LIBOR_1M).fixingDateOffset(MINUS_TWO_DAYS).build(); ImmutableSet.Builder <Index> builder = ImmutableSet.builder(); test.collectIndices(builder); assertEquals(builder.build(), ImmutableSet.of(GBP_LIBOR_1M)); }
//------------------------------------------------------------------------- public virtual void coverage() { IborCapFloorLeg test1 = IborCapFloorLeg.builder().calculation(RATE_CALCULATION).floorSchedule(FLOOR).notional(NOTIONAL).paymentSchedule(SCHEDULE).payReceive(RECEIVE).build(); coverImmutableBean(test1); IborCapFloorLeg test2 = IborCapFloorLeg.builder().calculation(IborRateCalculation.of(GBP_LIBOR_6M)).capSchedule(CAP).notional(ValueSchedule.of(1000)).paymentDateOffset(PAYMENT_OFFSET).paymentSchedule(PeriodicSchedule.builder().startDate(START).endDate(END).frequency(Frequency.P6M).businessDayAdjustment(BUSS_ADJ).build()).payReceive(PAY).build(); coverBeanEquals(test1, test2); }
//------------------------------------------------------------------------- public virtual void coverage() { IborRateCalculation test = IborRateCalculation.builder().dayCount(ACT_365F).index(GBP_LIBOR_3M).fixingDateOffset(MINUS_TWO_DAYS).build(); coverImmutableBean(test); IborRateCalculation test2 = IborRateCalculation.builder().dayCount(ACT_360).index(GBP_LIBOR_6M).resetPeriods(ResetSchedule.builder().resetFrequency(P3M).resetMethod(IborRateResetMethod.UNWEIGHTED).businessDayAdjustment(BusinessDayAdjustment.NONE).build()).fixingDateOffset(MINUS_THREE_DAYS).fixingRelativeTo(PERIOD_END).negativeRateMethod(NOT_NEGATIVE).firstRegularRate(0.028d).initialStub(IborRateStubCalculation.NONE).finalStub(IborRateStubCalculation.NONE).gearing(ValueSchedule.of(2d)).spread(ValueSchedule.of(-0.025d)).build(); coverBeanEquals(test, test2); }
//------------------------------------------------------------------------- public virtual void test_expand_firstFixingDateOffsetNoStub() { IborRateCalculation test = IborRateCalculation.builder().dayCount(ACT_365F).index(GBP_LIBOR_1M).fixingDateOffset(MINUS_TWO_DAYS).firstFixingDateOffset(MINUS_ONE_DAY).build(); RateAccrualPeriod rap1 = RateAccrualPeriod.builder(ACCRUAL1).yearFraction(ACCRUAL1.yearFraction(ACT_365F, ACCRUAL_SCHEDULE)).rateComputation(IborRateComputation.of(GBP_LIBOR_1M, DATE_01_03, REF_DATA)).build(); RateAccrualPeriod rap2 = RateAccrualPeriod.builder(ACCRUAL2).yearFraction(ACCRUAL2.yearFraction(ACT_365F, ACCRUAL_SCHEDULE)).rateComputation(IborRateComputation.of(GBP_LIBOR_1M, DATE_02_03, REF_DATA)).build(); RateAccrualPeriod rap3 = RateAccrualPeriod.builder(ACCRUAL3).yearFraction(ACCRUAL3.yearFraction(ACT_365F, ACCRUAL_SCHEDULE)).rateComputation(IborRateComputation.of(GBP_LIBOR_1M, DATE_03_03, REF_DATA)).build(); ImmutableList <RateAccrualPeriod> periods = test.createAccrualPeriods(ACCRUAL_SCHEDULE, ACCRUAL_SCHEDULE, REF_DATA); assertEquals(periods, ImmutableList.of(rap1, rap2, rap3)); }
//------------------------------------------------------------------------- public virtual void test_expand_gearingSpreadEverythingElse() { IborRateCalculation test = IborRateCalculation.builder().dayCount(ACT_360).index(GBP_LIBOR_3M).fixingDateOffset(MINUS_THREE_DAYS).fixingRelativeTo(PERIOD_END).negativeRateMethod(NOT_NEGATIVE).gearing(ValueSchedule.of(1d, ValueStep.of(2, ValueAdjustment.ofReplace(2d)))).spread(ValueSchedule.of(0d, ValueStep.of(1, ValueAdjustment.ofReplace(-0.025d)))).build(); RateAccrualPeriod rap1 = RateAccrualPeriod.builder(ACCRUAL1).yearFraction(ACCRUAL1.yearFraction(ACT_360, ACCRUAL_SCHEDULE)).rateComputation(IborRateComputation.of(GBP_LIBOR_3M, DATE_01_31, REF_DATA)).negativeRateMethod(NOT_NEGATIVE).build(); RateAccrualPeriod rap2 = RateAccrualPeriod.builder(ACCRUAL2).yearFraction(ACCRUAL2.yearFraction(ACT_360, ACCRUAL_SCHEDULE)).rateComputation(IborRateComputation.of(GBP_LIBOR_3M, DATE_02_28, REF_DATA)).negativeRateMethod(NOT_NEGATIVE).spread(-0.025d).build(); RateAccrualPeriod rap3 = RateAccrualPeriod.builder(ACCRUAL3).yearFraction(ACCRUAL3.yearFraction(ACT_360, ACCRUAL_SCHEDULE)).rateComputation(IborRateComputation.of(GBP_LIBOR_3M, DATE_04_02, REF_DATA)).negativeRateMethod(NOT_NEGATIVE).gearing(2d).spread(-0.025d).build(); ImmutableList <RateAccrualPeriod> periods = test.createAccrualPeriods(ACCRUAL_SCHEDULE, ACCRUAL_SCHEDULE, REF_DATA); assertEquals(periods, ImmutableList.of(rap1, rap2, rap3)); }
public virtual void test_expand_firstRateFixedInitialStubSpecified() { IborRateCalculation test = IborRateCalculation.builder().dayCount(ACT_365F).index(GBP_LIBOR_1M).fixingDateOffset(MINUS_TWO_DAYS).initialStub(IborRateStubCalculation.ofIborRate(GBP_LIBOR_1W)).firstRate(0.024d).build(); RateAccrualPeriod rap1 = RateAccrualPeriod.builder(ACCRUAL1STUB).yearFraction(ACCRUAL1STUB.yearFraction(ACT_365F, ACCRUAL_SCHEDULE_INITIAL_STUB)).rateComputation(IborRateComputation.of(GBP_LIBOR_1W, DATE_01_06, REF_DATA)).build(); RateAccrualPeriod rap2 = RateAccrualPeriod.builder(ACCRUAL2).yearFraction(ACCRUAL2.yearFraction(ACT_365F, ACCRUAL_SCHEDULE_INITIAL_STUB)).rateComputation(IborRateComputation.of(GBP_LIBOR_1M, DATE_02_03, REF_DATA)).build(); RateAccrualPeriod rap3 = RateAccrualPeriod.builder(ACCRUAL3).yearFraction(ACCRUAL3.yearFraction(ACT_365F, ACCRUAL_SCHEDULE_INITIAL_STUB)).rateComputation(IborRateComputation.of(GBP_LIBOR_1M, DATE_03_03, REF_DATA)).build(); ImmutableList <RateAccrualPeriod> periods = test.createAccrualPeriods(ACCRUAL_SCHEDULE_INITIAL_STUB, ACCRUAL_SCHEDULE_INITIAL_STUB, REF_DATA); assertEquals(periods, ImmutableList.of(rap1, rap2, rap3)); }
public virtual void test_expand_firstRegularRateFixedTwoStubs() { IborRateCalculation test = IborRateCalculation.builder().dayCount(ACT_365F).index(GBP_LIBOR_1M).fixingDateOffset(MINUS_TWO_DAYS).firstRegularRate(0.028d).build(); RateAccrualPeriod rap1 = RateAccrualPeriod.builder(ACCRUAL1STUB).yearFraction(ACCRUAL1STUB.yearFraction(ACT_365F, ACCRUAL_SCHEDULE_STUBS)).rateComputation(IborRateComputation.of(GBP_LIBOR_1M, DATE_01_06, REF_DATA)).build(); RateAccrualPeriod rap2 = RateAccrualPeriod.builder(ACCRUAL2).yearFraction(ACCRUAL2.yearFraction(ACT_365F, ACCRUAL_SCHEDULE_STUBS)).rateComputation(FixedRateComputation.of(0.028d)).build(); RateAccrualPeriod rap3 = RateAccrualPeriod.builder(ACCRUAL3STUB).yearFraction(ACCRUAL3STUB.yearFraction(ACT_365F, ACCRUAL_SCHEDULE_STUBS)).rateComputation(IborRateComputation.of(GBP_LIBOR_1M, DATE_03_03, REF_DATA)).build(); ImmutableList <RateAccrualPeriod> periods = test.createAccrualPeriods(ACCRUAL_SCHEDULE_STUBS, ACCRUAL_SCHEDULE_STUBS, REF_DATA); assertEquals(periods, ImmutableList.of(rap1, rap2, rap3)); }
/// <summary> /// Restricted copy constructor. </summary> /// <param name="beanToCopy"> the bean to copy from, not null </param> internal Builder(IborCapFloorLeg beanToCopy) { this.payReceive_Renamed = beanToCopy.PayReceive; this.paymentSchedule_Renamed = beanToCopy.PaymentSchedule; this.paymentDateOffset_Renamed = beanToCopy.PaymentDateOffset; this.currency_Renamed = beanToCopy.Currency; this.notional_Renamed = beanToCopy.Notional; this.calculation_Renamed = beanToCopy.Calculation; this.capSchedule_Renamed = beanToCopy.capSchedule; this.floorSchedule_Renamed = beanToCopy.floorSchedule; }
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); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @ImmutableConstructor private IborCapFloorLeg(com.opengamma.strata.product.common.PayReceive payReceive, com.opengamma.strata.basics.schedule.PeriodicSchedule paymentSchedule, com.opengamma.strata.basics.date.DaysAdjustment paymentDateOffset, com.opengamma.strata.basics.currency.Currency currency, com.opengamma.strata.basics.value.ValueSchedule notional, com.opengamma.strata.product.swap.IborRateCalculation calculation, com.opengamma.strata.basics.value.ValueSchedule capSchedule, com.opengamma.strata.basics.value.ValueSchedule floorSchedule) private IborCapFloorLeg(PayReceive payReceive, PeriodicSchedule paymentSchedule, DaysAdjustment paymentDateOffset, Currency currency, ValueSchedule notional, IborRateCalculation calculation, ValueSchedule capSchedule, ValueSchedule floorSchedule) { this.payReceive = ArgChecker.notNull(payReceive, "payReceive"); this.paymentSchedule = ArgChecker.notNull(paymentSchedule, "paymentSchedule"); this.paymentDateOffset = ArgChecker.notNull(paymentDateOffset, "paymentDateOffset"); this.currency = currency != null ? currency : calculation.Index.Currency; this.notional = notional; this.calculation = ArgChecker.notNull(calculation, "calculation"); this.capSchedule = capSchedule; this.floorSchedule = floorSchedule; ArgChecker.isTrue(!this.PaymentSchedule.StubConvention.Present || this.PaymentSchedule.StubConvention.get().Equals(StubConvention.NONE), "Stub period is not allowed"); ArgChecker.isFalse(this.CapSchedule.Present == this.FloorSchedule.Present, "One of cap schedule and floor schedule should be empty"); ArgChecker.isTrue(this.Calculation.Index.Tenor.Period.Equals(this.PaymentSchedule.Frequency.Period), "Payment frequency period should be the same as index tenor period"); }
public virtual void test_builder_ensureDefaults() { IborRateCalculation test = IborRateCalculation.builder().index(GBP_LIBOR_3M).build(); assertEquals(test.DayCount, ACT_365F); assertEquals(test.Index, GBP_LIBOR_3M); assertEquals(test.ResetPeriods, null); assertEquals(test.FixingRelativeTo, PERIOD_START); assertEquals(test.FixingDateOffset, GBP_LIBOR_3M.FixingDateOffset); assertEquals(test.NegativeRateMethod, ALLOW_NEGATIVE); assertEquals(test.FirstRegularRate, double?.empty()); assertEquals(test.InitialStub, null); assertEquals(test.FinalStub, null); assertEquals(test.Gearing, null); assertEquals(test.Spread, null); }
public virtual void test_builder_ensureOptionalDouble() { IborRateCalculation test = IborRateCalculation.builder().dayCount(ACT_365F).index(GBP_LIBOR_3M).fixingDateOffset(MINUS_TWO_DAYS).firstRegularRate(0.028d).build(); assertEquals(test.DayCount, ACT_365F); assertEquals(test.Index, GBP_LIBOR_3M); assertEquals(test.ResetPeriods, null); assertEquals(test.FixingRelativeTo, PERIOD_START); assertEquals(test.FixingDateOffset, MINUS_TWO_DAYS); assertEquals(test.NegativeRateMethod, ALLOW_NEGATIVE); assertEquals(test.FirstRegularRate, double?.of(0.028d)); assertEquals(test.InitialStub, null); assertEquals(test.FinalStub, null); assertEquals(test.Gearing, null); assertEquals(test.Spread, null); }
//------------------------------------------------------------------------- public virtual void test_of() { IborRateCalculation test = IborRateCalculation.of(GBP_LIBOR_3M); assertEquals(test.Type, SwapLegType.IBOR); assertEquals(test.DayCount, ACT_365F); assertEquals(test.Index, GBP_LIBOR_3M); assertEquals(test.ResetPeriods, null); assertEquals(test.FixingRelativeTo, PERIOD_START); assertEquals(test.FixingDateOffset, GBP_LIBOR_3M.FixingDateOffset); assertEquals(test.NegativeRateMethod, ALLOW_NEGATIVE); assertEquals(test.FirstRegularRate, double?.empty()); assertEquals(test.InitialStub, null); assertEquals(test.FinalStub, null); assertEquals(test.Gearing, null); assertEquals(test.Spread, null); }
public virtual void test_expand_initialStubAndResetPeriods_weighted_firstFixed() { IborRateCalculation test = IborRateCalculation.builder().dayCount(ACT_360).index(GBP_LIBOR_3M).fixingDateOffset(MINUS_TWO_DAYS).resetPeriods(ResetSchedule.builder().resetFrequency(P1M).businessDayAdjustment(BusinessDayAdjustment.of(FOLLOWING, GBLO)).resetMethod(WEIGHTED).build()).firstRegularRate(0.028d).initialStub(IborRateStubCalculation.ofFixedRate(0.030d)).build(); SchedulePeriod accrual1 = SchedulePeriod.of(DATE_02_05, DATE_04_07, DATE_02_05, DATE_04_05); SchedulePeriod accrual2 = SchedulePeriod.of(DATE_04_07, DATE_07_07, DATE_04_05, DATE_07_05); Schedule schedule = Schedule.builder().periods(accrual1, accrual2).frequency(P3M).rollConvention(DAY_5).build(); RateAccrualPeriod rap1 = RateAccrualPeriod.builder(accrual1).yearFraction(accrual1.yearFraction(ACT_360, schedule)).rateComputation(FixedRateComputation.of(0.030d)).build(); IborIndexObservation obs4 = IborIndexObservation.of(GBP_LIBOR_3M, DATE_04_03, REF_DATA); IborIndexObservation obs5 = IborIndexObservation.of(GBP_LIBOR_3M, DATE_05_01, REF_DATA); IborIndexObservation obs6 = IborIndexObservation.of(GBP_LIBOR_3M, DATE_06_03, REF_DATA); ImmutableList <IborAveragedFixing> fixings2 = ImmutableList.of(IborAveragedFixing.ofDaysInResetPeriod(obs4, DATE_04_07, DATE_05_06, 0.028d), IborAveragedFixing.ofDaysInResetPeriod(obs5, DATE_05_06, DATE_06_05), IborAveragedFixing.ofDaysInResetPeriod(obs6, DATE_06_05, DATE_07_07)); RateAccrualPeriod rap2 = RateAccrualPeriod.builder(accrual2).yearFraction(accrual2.yearFraction(ACT_360, schedule)).rateComputation(IborAveragedRateComputation.of(fixings2)).build(); ImmutableList <RateAccrualPeriod> periods = test.createAccrualPeriods(schedule, schedule, REF_DATA); assertEquals(periods, ImmutableList.of(rap1, rap2)); }
// a summary of the leg private string legSummary(SwapLeg leg) { if (leg is RateCalculationSwapLeg) { RateCalculationSwapLeg rcLeg = (RateCalculationSwapLeg)leg; RateCalculation calculation = rcLeg.Calculation; if (calculation is FixedRateCalculation) { FixedRateCalculation calc = (FixedRateCalculation)calculation; string vary = calc.Rate.Steps.Count > 0 || calc.Rate.StepSequence.Present ? " variable" : ""; return(SummarizerUtils.percent(calc.Rate.InitialValue) + vary); } if (calculation is IborRateCalculation) { IborRateCalculation calc = (IborRateCalculation)calculation; string gearing = calc.Gearing.map(g => " * " + SummarizerUtils.value(g.InitialValue)).orElse(""); string spread = calc.Spread.map(s => " + " + SummarizerUtils.percent(s.InitialValue)).orElse(""); return(calc.Index.Name + gearing + spread); } if (calculation is OvernightRateCalculation) { OvernightRateCalculation calc = (OvernightRateCalculation)calculation; string avg = calc.AccrualMethod == OvernightAccrualMethod.AVERAGED ? " avg" : ""; string gearing = calc.Gearing.map(g => " * " + SummarizerUtils.value(g.InitialValue)).orElse(""); string spread = calc.Spread.map(s => " + " + SummarizerUtils.percent(s.InitialValue)).orElse(""); return(calc.Index.Name + avg + gearing + spread); } if (calculation is InflationRateCalculation) { InflationRateCalculation calc = (InflationRateCalculation)calculation; string gearing = calc.Gearing.map(g => " * " + SummarizerUtils.value(g.InitialValue)).orElse(""); return(calc.Index.Name + gearing); } } if (leg is KnownAmountSwapLeg) { KnownAmountSwapLeg kaLeg = (KnownAmountSwapLeg)leg; string vary = kaLeg.Amount.Steps.Count > 0 || kaLeg.Amount.StepSequence.Present ? " variable" : ""; return(SummarizerUtils.amount(kaLeg.Currency, kaLeg.Amount.InitialValue) + vary); } ImmutableSet <Index> allIndices = leg.allIndices(); return(allIndices.Empty ? "Fixed" : allIndices.ToString()); }
public virtual void test_resolve_cap() { IborRateCalculation rateCalc = IborRateCalculation.builder().index(EUR_EURIBOR_3M).fixingRelativeTo(FixingRelativeTo.PERIOD_END).fixingDateOffset(EUR_EURIBOR_3M.FixingDateOffset).build(); IborCapFloorLeg @base = IborCapFloorLeg.builder().calculation(rateCalc).capSchedule(CAP).notional(NOTIONAL).paymentDateOffset(PAYMENT_OFFSET).paymentSchedule(SCHEDULE).payReceive(RECEIVE).build(); LocalDate[] unadjustedDates = new LocalDate[] { START, START.plusMonths(3), START.plusMonths(6), START.plusMonths(9), START.plusMonths(12) }; IborCapletFloorletPeriod[] periods = new IborCapletFloorletPeriod[4]; for (int i = 0; i < 4; ++i) { LocalDate start = BUSS_ADJ.adjust(unadjustedDates[i], REF_DATA); LocalDate end = BUSS_ADJ.adjust(unadjustedDates[i + 1], REF_DATA); double yearFraction = EUR_EURIBOR_3M.DayCount.relativeYearFraction(start, end); periods[i] = IborCapletFloorletPeriod.builder().caplet(CAP.InitialValue).currency(EUR).startDate(start).endDate(end).unadjustedStartDate(unadjustedDates[i]).unadjustedEndDate(unadjustedDates[i + 1]).paymentDate(PAYMENT_OFFSET.adjust(end, REF_DATA)).notional(NOTIONALS[i]).iborRate(IborRateComputation.of(EUR_EURIBOR_3M, rateCalc.FixingDateOffset.adjust(end, REF_DATA), REF_DATA)).yearFraction(yearFraction).build(); } ResolvedIborCapFloorLeg expected = ResolvedIborCapFloorLeg.builder().capletFloorletPeriods(periods).payReceive(RECEIVE).build(); ResolvedIborCapFloorLeg computed = @base.resolve(REF_DATA); assertEquals(computed, expected); }
static CapletStrippingSetup() { LocalDate startDate = BASE_DATE.plus(USD_LIBOR_3M.Tenor); for (int i = 0; i < NUM_BLACK_MATURITIES; ++i) { for (int j = 0; j < NUM_BLACK_STRIKES; ++j) { CAPS_BLACK[j][i] = IborCapFloorLeg.builder().calculation(IborRateCalculation.of(USD_LIBOR_3M)).capSchedule(ValueSchedule.of(CAP_BLACK_STRIKES[j])).notional(ValueSchedule.ALWAYS_1).paymentSchedule(PeriodicSchedule.of(startDate, BASE_DATE.plusYears(CAP_BLACK_END_TIMES[i]), Frequency.P3M, BusinessDayAdjustment.of(BusinessDayConventions.MODIFIED_FOLLOWING, USD_LIBOR_3M.FixingCalendar), StubConvention.NONE, RollConventions.NONE)).payReceive(PayReceive.RECEIVE).build().resolve(REF_DATA); } } for (int i = 0; i < NUM_NORMAL_MATURITIES; ++i) { for (int j = 0; j < NUM_NORMAL_STRIKES; ++j) { CAPS_NORMAL[j][i] = IborCapFloorLeg.builder().calculation(IborRateCalculation.of(USD_LIBOR_3M)).capSchedule(ValueSchedule.of(CAP_NORMAL_STRIKES[j])).notional(ValueSchedule.ALWAYS_1).paymentSchedule(PeriodicSchedule.of(startDate, BASE_DATE.plusYears(CAP_NORMAL_END_TIMES[i]), Frequency.P3M, BusinessDayAdjustment.of(BusinessDayConventions.MODIFIED_FOLLOWING, USD_LIBOR_3M.FixingCalendar), StubConvention.NONE, RollConventions.NONE)).payReceive(PayReceive.RECEIVE).build().resolve(REF_DATA); } } }
public override Builder set(string propertyName, object newValue) { switch (propertyName.GetHashCode()) { case -885469925: // payReceive this.payReceive_Renamed = (PayReceive)newValue; break; case -1499086147: // paymentSchedule this.paymentSchedule_Renamed = (PeriodicSchedule)newValue; break; case -716438393: // paymentDateOffset this.paymentDateOffset_Renamed = (DaysAdjustment)newValue; break; case 575402001: // currency this.currency_Renamed = (Currency)newValue; break; case 1585636160: // notional this.notional_Renamed = (ValueSchedule)newValue; break; case -934682935: // calculation this.calculation_Renamed = (IborRateCalculation)newValue; break; case -596212599: // capSchedule this.capSchedule_Renamed = (ValueSchedule)newValue; break; case -1562227005: // floorSchedule this.floorSchedule_Renamed = (ValueSchedule)newValue; break; default: throw new NoSuchElementException("Unknown property: " + propertyName); } return(this); }
public virtual void test_expand_resetPeriods_weighted_firstFixingDateOffset() { // only the fixing date of the first reset period is changed, everything else stays the same IborRateCalculation test = IborRateCalculation.builder().dayCount(ACT_365F).index(GBP_LIBOR_3M).fixingDateOffset(MINUS_TWO_DAYS).resetPeriods(ResetSchedule.builder().resetFrequency(P1M).businessDayAdjustment(BusinessDayAdjustment.of(FOLLOWING, GBLO)).resetMethod(WEIGHTED).build()).firstFixingDateOffset(MINUS_ONE_DAY).build(); SchedulePeriod accrual1 = SchedulePeriod.of(DATE_01_06, DATE_04_07, DATE_01_05, DATE_04_05); SchedulePeriod accrual2 = SchedulePeriod.of(DATE_04_07, DATE_07_07, DATE_04_05, DATE_07_05); Schedule schedule = Schedule.builder().periods(accrual1, accrual2).frequency(P3M).rollConvention(DAY_5).build(); IborIndexObservation obs1 = IborIndexObservation.of(GBP_LIBOR_3M, DATE_01_03, REF_DATA); IborIndexObservation obs2 = IborIndexObservation.of(GBP_LIBOR_3M, DATE_02_03, REF_DATA); IborIndexObservation obs3 = IborIndexObservation.of(GBP_LIBOR_3M, DATE_03_03, REF_DATA); ImmutableList <IborAveragedFixing> fixings1 = ImmutableList.of(IborAveragedFixing.ofDaysInResetPeriod(obs1, DATE_01_06, DATE_02_05), IborAveragedFixing.ofDaysInResetPeriod(obs2, DATE_02_05, DATE_03_05), IborAveragedFixing.ofDaysInResetPeriod(obs3, DATE_03_05, DATE_04_07)); RateAccrualPeriod rap1 = RateAccrualPeriod.builder(accrual1).yearFraction(accrual1.yearFraction(ACT_365F, schedule)).rateComputation(IborAveragedRateComputation.of(fixings1)).build(); IborIndexObservation obs4 = IborIndexObservation.of(GBP_LIBOR_3M, DATE_04_03, REF_DATA); IborIndexObservation obs5 = IborIndexObservation.of(GBP_LIBOR_3M, DATE_05_01, REF_DATA); IborIndexObservation obs6 = IborIndexObservation.of(GBP_LIBOR_3M, DATE_06_03, REF_DATA); ImmutableList <IborAveragedFixing> fixings2 = ImmutableList.of(IborAveragedFixing.ofDaysInResetPeriod(obs4, DATE_04_07, DATE_05_06), IborAveragedFixing.ofDaysInResetPeriod(obs5, DATE_05_06, DATE_06_05), IborAveragedFixing.ofDaysInResetPeriod(obs6, DATE_06_05, DATE_07_07)); RateAccrualPeriod rap2 = RateAccrualPeriod.builder(accrual2).yearFraction(accrual2.yearFraction(ACT_365F, schedule)).rateComputation(IborAveragedRateComputation.of(fixings2)).build(); ImmutableList <RateAccrualPeriod> periods = test.createAccrualPeriods(schedule, schedule, REF_DATA); assertEquals(periods, ImmutableList.of(rap1, rap2)); }
//----------------------------------------------------------------------- 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(); }
//----------------------------------------------------------------------- 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(); }
/// <summary> /// Sets the interest rate accrual calculation. /// <para> /// The interest rate accrual is based on Ibor index. /// </para> /// </summary> /// <param name="calculation"> the new value, not null </param> /// <returns> this, for chaining, not null </returns> public Builder calculation(IborRateCalculation calculation) { JodaBeanUtils.notNull(calculation, "calculation"); this.calculation_Renamed = calculation; return(this); }
// 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()); }
// 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 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_toLeg_withSpread() { IborRateSwapLegConvention @base = IborRateSwapLegConvention.builder().index(GBP_LIBOR_3M).build(); LocalDate startDate = LocalDate.of(2015, 5, 5); LocalDate endDate = LocalDate.of(2020, 5, 5); RateCalculationSwapLeg test = @base.toLeg(startDate, endDate, PAY, NOTIONAL_2M, 0.25d); RateCalculationSwapLeg expected = RateCalculationSwapLeg.builder().payReceive(PAY).accrualSchedule(PeriodicSchedule.builder().frequency(P3M).startDate(startDate).endDate(endDate).businessDayAdjustment(BDA_MOD_FOLLOW).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(P3M).paymentDateOffset(DaysAdjustment.NONE).build()).notionalSchedule(NotionalSchedule.of(GBP, NOTIONAL_2M)).calculation(IborRateCalculation.builder().index(GBP_LIBOR_3M).spread(ValueSchedule.of(0.25d)).build()).build(); assertEquals(test, expected); }
public virtual void test_summarize_irs_weird() { PeriodicSchedule accrual = PeriodicSchedule.of(date(2018, 2, 12), date(2020, 2, 12), Frequency.P3M, BusinessDayAdjustment.NONE, SHORT_INITIAL, false); PaymentSchedule payment = PaymentSchedule.builder().paymentFrequency(Frequency.P3M).paymentDateOffset(DaysAdjustment.NONE).build(); NotionalSchedule notional = NotionalSchedule.of(GBP, ValueSchedule.builder().initialValue(1_000_000).stepSequence(ValueStepSequence.of(date(2018, 8, 12), date(2019, 8, 12), Frequency.P6M, ofDeltaAmount(-50_000))).build()); RateCalculationSwapLeg payLeg = RateCalculationSwapLeg.builder().payReceive(PAY).accrualSchedule(accrual).paymentSchedule(payment).notionalSchedule(notional).calculation(FixedRateCalculation.builder().dayCount(ACT_360).rate(ValueSchedule.builder().initialValue(0.0012).stepSequence(ValueStepSequence.of(date(2018, 8, 12), date(2019, 8, 12), Frequency.P6M, ofDeltaAmount(0.0001))).build()).build()).build(); RateCalculationSwapLeg recLeg = RateCalculationSwapLeg.builder().payReceive(RECEIVE).accrualSchedule(accrual).paymentSchedule(payment).notionalSchedule(notional).calculation(IborRateCalculation.builder().index(IborIndices.GBP_LIBOR_3M).gearing(ValueSchedule.of(1.1)).spread(ValueSchedule.of(0.002)).build()).build(); Swap test = Swap.of(payLeg, recLeg); assertEquals(test.summaryDescription(), "2Y GBP 1mm variable Rec GBP-LIBOR-3M * 1.1 + 0.2% / Pay 0.12% variable : 12Feb18-12Feb20"); }