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