public void test_collectIndices() { FixedRateCalculation test = FixedRateCalculation.builder() .dayCount(ACT_365F) .rate(ValueSchedule.of(0.025d)) .build(); ImmutableSet.Builder<Index> builder = ImmutableSet.builder(); test.collectIndices(builder); assertEquals(builder.build(), ImmutableSet.of()); }
}); fixedRateBuilder.rate(parseSchedule(fixedEl, document)); fixedRateBuilder.dayCount(document.parseDayCountFraction(calcEl.getChild("dayCountFraction")));
public void test_builder() { FixedRateCalculation test = FixedRateCalculation.builder() .dayCount(ACT_365F) .rate(ValueSchedule.of(0.025d)) .initialStub(FixedRateStubCalculation.ofFixedRate(0.1d)) .finalStub(FixedRateStubCalculation.ofFixedRate(0.2d)) .futureValueNotional(FutureValueNotional.autoCalculate()) .build(); assertEquals(test.getRate(), ValueSchedule.of(0.025d)); assertEquals(test.getDayCount(), ACT_365F); assertEquals(test.getInitialStub(), Optional.of(FixedRateStubCalculation.ofFixedRate(0.1d))); assertEquals(test.getFinalStub(), Optional.of(FixedRateStubCalculation.ofFixedRate(0.2d))); assertEquals(test.getFutureValueNotional(), Optional.of(FutureValueNotional.autoCalculate())); }
.calculation(FixedRateCalculation.builder() .rate(ValueSchedule.of(fixedRate)) .dayCount(dayCount) .futureValueNotional( accrualMethod == OVERNIGHT_COMPOUNDED_ANNUAL_RATE ? FutureValueNotional.autoCalculate() : null)
.notionalSchedule(NotionalSchedule.of(GBP, 1000d)) .calculation(FixedRateCalculation.builder() .dayCount(ACT_365F) .rate(ValueSchedule.of(0.025d)) .build()) .notionalSchedule(NotionalSchedule.of(GBP, 2000d)) .calculation(FixedRateCalculation.builder() .dayCount(ACT_360) .rate(ValueSchedule.of(0.025d)) .build())
.calculation(FixedRateCalculation.builder() .rate(ValueSchedule.of(0.1)) .dayCount(DayCount.ofBus252(BRBD)) .futureValueNotional(FutureValueNotional.of(12345670)) .build())
.calculation(FixedRateCalculation.builder() .rate(ValueSchedule.of(0.25d)) .dayCount(ACT_365F) .futureValueNotional(FutureValueNotional.autoCalculate()) .build())
public void test_expand_distinctValues() { FixedRateCalculation test = FixedRateCalculation.builder() .dayCount(ACT_365F) .rate(ValueSchedule.of( 0.025d,
.calculation(FixedRateCalculation.builder() .rate(ValueSchedule.of(parRateComputed)) .dayCount(DayCounts.ONE_ONE) // year fraction is always 1. .build()) .build()
.build(); FixedRateCalculation rateCalc = FixedRateCalculation.builder() .dayCount(DayCounts.ACT_365F) .rate(ValueSchedule.of(0.025d)) .build();
private static SwapLeg fixedLeg( LocalDate start, LocalDate end, Frequency frequency, PayReceive payReceive, NotionalSchedule notional, double fixedRate, StubConvention stubConvention) { return RateCalculationSwapLeg.builder() .payReceive(payReceive) .accrualSchedule(PeriodicSchedule.builder() .startDate(start) .endDate(end) .frequency(frequency) .businessDayAdjustment(BDA_MF) .stubConvention(stubConvention) .build()) .paymentSchedule(PaymentSchedule.builder() .paymentFrequency(frequency) .paymentDateOffset(DaysAdjustment.NONE) .build()) .notionalSchedule(notional) .calculation(FixedRateCalculation.builder() .dayCount(THIRTY_U_360) .rate(ValueSchedule.of(fixedRate)) .build()) .build(); }
public void test_expand_oneValue() { FixedRateCalculation test = FixedRateCalculation.builder() .dayCount(ACT_365F) .rate(ValueSchedule.of(0.025d)) .build(); SchedulePeriod period1 = SchedulePeriod.of(date(2014, 1, 6), date(2014, 2, 5), date(2014, 1, 5), date(2014, 2, 5)); SchedulePeriod period2 = SchedulePeriod.of(date(2014, 1, 5), date(2014, 2, 5), date(2014, 2, 5), date(2014, 3, 5)); SchedulePeriod period3 = SchedulePeriod.of(date(2014, 3, 5), date(2014, 4, 7), date(2014, 3, 5), date(2014, 4, 5)); Schedule schedule = Schedule.builder() .periods(period1, period2, period3) .frequency(Frequency.P1M) .rollConvention(RollConventions.DAY_5) .build(); RateAccrualPeriod rap1 = RateAccrualPeriod.builder(period1) .yearFraction(period1.yearFraction(ACT_365F, schedule)) .rateComputation(FixedRateComputation.of(0.025d)) .build(); RateAccrualPeriod rap2 = RateAccrualPeriod.builder(period2) .yearFraction(period2.yearFraction(ACT_365F, schedule)) .rateComputation(FixedRateComputation.of(0.025d)) .build(); RateAccrualPeriod rap3 = RateAccrualPeriod.builder(period3) .yearFraction(period3.yearFraction(ACT_365F, schedule)) .rateComputation(FixedRateComputation.of(0.025d)) .build(); ImmutableList<RateAccrualPeriod> periods = test.createAccrualPeriods(schedule, schedule, REF_DATA); assertEquals(periods, ImmutableList.of(rap1, rap2, rap3)); }
private static SwapLeg fixedLeg( LocalDate start, LocalDate end, Frequency frequency, PayReceive payReceive, NotionalSchedule notional, double fixedRate, StubConvention stubConvention) { return RateCalculationSwapLeg.builder() .payReceive(payReceive) .accrualSchedule(PeriodicSchedule.builder() .startDate(start) .endDate(end) .frequency(frequency) .businessDayAdjustment(BDA_MF) .stubConvention(stubConvention) .build()) .paymentSchedule(PaymentSchedule.builder() .paymentFrequency(frequency) .paymentDateOffset(DaysAdjustment.NONE) .build()) .notionalSchedule(notional) .calculation(FixedRateCalculation.builder() .dayCount(THIRTY_U_360) .rate(ValueSchedule.of(fixedRate)) .build()) .build(); }
private static SwapLeg fixedLeg( LocalDate start, LocalDate end, Frequency frequency, PayReceive payReceive, NotionalSchedule notional, double fixedRate, StubConvention stubConvention) { return RateCalculationSwapLeg.builder() .payReceive(payReceive) .accrualSchedule(PeriodicSchedule.builder() .startDate(start) .endDate(end) .frequency(frequency) .businessDayAdjustment(BDA_MF) .stubConvention(stubConvention) .build()) .paymentSchedule(PaymentSchedule.builder() .paymentFrequency(frequency) .paymentDateOffset(DaysAdjustment.NONE) .build()) .notionalSchedule(notional) .calculation(FixedRateCalculation.builder() .dayCount(THIRTY_U_360) .rate(ValueSchedule.of(fixedRate)) .build()) .build(); }
public void test_serialization() { RateCalculationSwapLeg test = RateCalculationSwapLeg.builder() .payReceive(PAY) .accrualSchedule(PeriodicSchedule.builder() .startDate(DATE_01_05) .endDate(DATE_04_05) .frequency(P1M) .businessDayAdjustment(BusinessDayAdjustment.of(FOLLOWING, GBLO)) .build()) .paymentSchedule(PaymentSchedule.builder() .paymentFrequency(P1M) .paymentDateOffset(PLUS_TWO_DAYS) .build()) .notionalSchedule(NotionalSchedule.of(GBP, 1000d)) .calculation(FixedRateCalculation.builder() .dayCount(DayCounts.ACT_365F) .rate(ValueSchedule.of(0.025d)) .build()) .build(); assertSerialization(test); }
public void test_expand_onePeriod_with_futureValueNotional() { FixedRateCalculation test = FixedRateCalculation.builder() .dayCount(ACT_365F) .rate(ValueSchedule.of(0.025d)) .futureValueNotional(FutureValueNotional.of(1000d)) .build(); SchedulePeriod period = SchedulePeriod.of(date(2014, 1, 6), date(2014, 2, 5), date(2014, 1, 5), date(2014, 2, 5)); Schedule schedule = Schedule.builder() .periods(period) .frequency(Frequency.TERM) .rollConvention(RollConventions.NONE) .build(); double yearFraction = period.yearFraction(ACT_365F, schedule); RateAccrualPeriod rap = RateAccrualPeriod.builder(period) .yearFraction(period.yearFraction(ACT_365F, schedule)) .rateComputation(FixedOvernightCompoundedAnnualRateComputation.of(0.025d, yearFraction)) .build(); ImmutableList<RateAccrualPeriod> periods = test.createAccrualPeriods(schedule, schedule, REF_DATA); assertEquals(periods, ImmutableList.of(rap)); }
/** * Obtains a rate calculation for the specified day count and rate. * <p> * The rate specified here does not vary during the life of the swap. * If this method provides insufficient control, use the {@linkplain #builder() builder}. * * @param rate the rate * @param dayCount the day count * @return the calculation */ public static FixedRateCalculation of(double rate, DayCount dayCount) { return FixedRateCalculation.builder() .dayCount(dayCount) .rate(ValueSchedule.of(rate)) .build(); }
public void test_expand_multiplePeriod_with_futureValueNotional() { FixedRateCalculation test = FixedRateCalculation.builder() .dayCount(ACT_365F) .rate(ValueSchedule.of(0.025d)) .futureValueNotional(FutureValueNotional.of(1000d)) .build(); SchedulePeriod period1 = SchedulePeriod.of(date(2014, 1, 6), date(2014, 2, 5), date(2014, 1, 5), date(2014, 2, 5)); SchedulePeriod period2 = SchedulePeriod.of(date(2014, 1, 5), date(2014, 2, 5), date(2014, 2, 5), date(2014, 3, 5)); SchedulePeriod period3 = SchedulePeriod.of(date(2014, 3, 5), date(2014, 4, 7), date(2014, 3, 5), date(2014, 4, 5)); Schedule schedule = Schedule.builder() .periods(period1, period2, period3) .frequency(Frequency.P1M) .rollConvention(RollConventions.DAY_5) .build(); assertThrowsIllegalArg(() -> test.createAccrualPeriods(schedule, schedule, REF_DATA)); }
public void coverage() { FixedRateCalculation test = FixedRateCalculation.builder() .dayCount(ACT_365F) .rate(ValueSchedule.of(0.025d)) .build(); coverImmutableBean(test); FixedRateCalculation test2 = FixedRateCalculation.builder() .dayCount(ACT_360) .rate(ValueSchedule.of(0.030d)) .build(); coverBeanEquals(test, test2); }
public void test_serialization() { FixedRateCalculation test = FixedRateCalculation.builder() .dayCount(ACT_365F) .rate(ValueSchedule.of(0.025d)) .build(); assertSerialization(test); }