/** * 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_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())); }
public void test_of() { FixedRateCalculation test = FixedRateCalculation.of(0.025d, ACT_365F); assertEquals(test.getType(), SwapLegType.FIXED); assertEquals(test.getRate(), ValueSchedule.of(0.025d)); assertEquals(test.getDayCount(), ACT_365F); assertEquals(test.getInitialStub(), Optional.empty()); assertEquals(test.getFinalStub(), Optional.empty()); assertEquals(test.getFutureValueNotional(), Optional.empty()); }
/** * Restricted copy constructor. * @param beanToCopy the bean to copy from, not null */ private Builder(FixedRateCalculation beanToCopy) { this.dayCount = beanToCopy.getDayCount(); this.rate = beanToCopy.getRate(); this.initialStub = beanToCopy.initialStub; this.finalStub = beanToCopy.finalStub; this.futureValueNotional = beanToCopy.futureValueNotional; }
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()); }
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)); }
private static SwapTrade parseVariableRates(SwapTrade trade, List<CsvRow> variableRows) { ImmutableList.Builder<ValueStep> stepBuilder = ImmutableList.builder(); for (CsvRow row : variableRows) { LocalDate date = LoaderUtils.parseDate(row.getValue(START_DATE_FIELD)); row.findValue(FIXED_RATE_FIELD) .map(str -> LoaderUtils.parseDoublePercent(str)) .ifPresent(fixedRate -> stepBuilder.add(ValueStep.of(date, ValueAdjustment.ofReplace(fixedRate)))); } ImmutableList<ValueStep> varRates = stepBuilder.build(); if (varRates.isEmpty()) { return trade; } // adjust the trade, inserting the variable rates ImmutableList.Builder<SwapLeg> legBuilder = ImmutableList.builder(); for (SwapLeg swapLeg : trade.getProduct().getLegs()) { RateCalculationSwapLeg leg = (RateCalculationSwapLeg) swapLeg; if (leg.getCalculation() instanceof FixedRateCalculation) { FixedRateCalculation baseCalc = (FixedRateCalculation) leg.getCalculation(); FixedRateCalculation calc = baseCalc.toBuilder() .rate(ValueSchedule.of(baseCalc.getRate().getInitialValue(), varRates)) .build(); legBuilder.add(leg.toBuilder().calculation(calc).build()); } else { legBuilder.add(leg); } } return replaceLegs(trade, legBuilder.build()); }
public void test_toLeg1() { FixedRateSwapLegConvention base = FixedRateSwapLegConvention.of(GBP, ACT_365F, P3M, BDA_MOD_FOLLOW); 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) .stubConvention(StubConvention.SMART_INITIAL) .build()) .paymentSchedule(PaymentSchedule.builder() .paymentFrequency(P3M) .paymentDateOffset(DaysAdjustment.NONE) .build()) .notionalSchedule(NotionalSchedule.of(GBP, NOTIONAL_2M)) .calculation(FixedRateCalculation.of(0.25d, ACT_365F)) .build(); assertEquals(test, expected); }
if (calculation instanceof FixedRateCalculation) { FixedRateCalculation calc = (FixedRateCalculation) calculation; String vary = !calc.getRate().getSteps().isEmpty() || calc.getRate().getStepSequence().isPresent() ? " variable" : ""; return SummarizerUtils.percent(calc.getRate().getInitialValue()) + vary;
if (getFutureValueNotional().isPresent()) { if (accrualSchedule.size() != 1) { throw new IllegalArgumentException(
@Override public FixedRateCalculation build() { return new FixedRateCalculation( dayCount, rate, initialStub, finalStub, futureValueNotional); }
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)); }
@Override protected Object propertyGet(Bean bean, String propertyName, boolean quiet) { switch (propertyName.hashCode()) { case 1905311443: // dayCount return ((FixedRateCalculation) bean).getDayCount(); case 3493088: // rate return ((FixedRateCalculation) bean).getRate(); case 1233359378: // initialStub return ((FixedRateCalculation) bean).initialStub; case 355242820: // finalStub return ((FixedRateCalculation) bean).finalStub; case -282775858: // futureValueNotional return ((FixedRateCalculation) bean).futureValueNotional; } return super.propertyGet(bean, propertyName, quiet); }
.accrualSchedule(accSchedule) .calculation( FixedRateCalculation.of(fixedRate, ACT_360)) .paymentSchedule( PaymentSchedule.builder().paymentFrequency(frequency).paymentDateOffset(DaysAdjustment.NONE).build())
DayCount defaultFixedLegDayCount) { FixedRateCalculation.Builder builder = FixedRateCalculation.builder();
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)); }
.build()) .notionalSchedule(NotionalSchedule.of(GBP, NOTIONAL)) .calculation(FixedRateCalculation.of(RATE, ACT_360)) .build()) .build();
FixedRateCalculation.Builder fixedRateBuilder = FixedRateCalculation.builder(); calcEl.findChild("futureValueNotional").ifPresent(fvnEl -> { FutureValueNotional notional = FutureValueNotional.builder()
public void test_expand_distinctValues() { FixedRateCalculation test = FixedRateCalculation.builder() .dayCount(ACT_365F) .rate(ValueSchedule.of( .rateComputation(FixedRateComputation.of(0.015d)) .build(); ImmutableList<RateAccrualPeriod> periods = test.createAccrualPeriods(schedule, schedule, REF_DATA); assertEquals(periods, ImmutableList.of(rap1, rap2, rap3));
public void test_serialization() { FixedRateCalculation test = FixedRateCalculation.builder() .dayCount(ACT_365F) .rate(ValueSchedule.of(0.025d)) .build(); assertSerialization(test); }