public void test_builder_validFull() { ValueStepSequence seq = ValueStepSequence.of( date(2016, 4, 20), date(2016, 10, 20), Frequency.P3M, ValueAdjustment.ofDeltaAmount(-100)); ValueSchedule test = ValueSchedule.builder() .initialValue(2000d) .steps(STEP1, STEP2) .stepSequence(seq) .build(); assertEquals(test.getInitialValue(), 2000d, TOLERANCE); assertEquals(test.getSteps(), ImmutableList.of(STEP1, STEP2)); assertEquals(test.getStepSequence(), Optional.of(seq)); }
.currency(EUR) .amount(ValueSchedule.builder() .initialValue(50000000d) .steps( ValueStep.of(date(1995, 12, 14), ValueAdjustment.ofReplace(40000000d)), ValueStep.of(date(1996, 12, 14), ValueAdjustment.ofReplace(30000000d)), ValueStep.of(date(1997, 12, 14), ValueAdjustment.ofReplace(20000000d)), ValueStep.of(date(1998, 12, 14), ValueAdjustment.ofReplace(10000000d))) .build()) .build(); RateCalculationSwapLeg payLeg = RateCalculationSwapLeg.builder()
.currency(EUR) .amount(ValueSchedule.builder() .initialValue(50000000d) .steps( ValueStep.of(date(1995, 12, 14), ValueAdjustment.ofReplace(40000000d)), ValueStep.of(date(1996, 12, 14), ValueAdjustment.ofReplace(30000000d)), ValueStep.of(date(1997, 12, 14), ValueAdjustment.ofReplace(20000000d)), ValueStep.of(date(1998, 12, 14), ValueAdjustment.ofReplace(10000000d))) .build()) .build(); RateCalculationSwapLeg payLeg = RateCalculationSwapLeg.builder()
.currency(EUR) .amount(ValueSchedule.builder() .initialValue(50000000d) .stepSequence(ValueStepSequence.of( date(1995, 12, 14), date(1998, 12, 14), Frequency.P12M, ValueAdjustment.ofDeltaAmount(-10000000d))) .build()) .build(); RateCalculationSwapLeg payLeg = RateCalculationSwapLeg.builder()
.build()) .amount(ValueSchedule.builder() .initialValue(123d) .steps(ValueStep.of(1, ValueAdjustment.ofReplace(234d))) .build()) .currency(GBP) .build();
@Override public ValueSchedule.Builder builder() { return new ValueSchedule.Builder(); }
/** * Returns a builder that allows this bean to be mutated. * @return the mutable builder, not null */ public Builder toBuilder() { return new Builder(this); }
/** * Returns a builder used to create an instance of the bean. * @return the builder, not null */ public static ValueSchedule.Builder builder() { return new ValueSchedule.Builder(); }
public void test_resolveValues_sequenceAndSteps() { ValueStepSequence seq = ValueStepSequence.of( date(2014, 2, 1), date(2014, 3, 1), Frequency.P1M, ValueAdjustment.ofDeltaAmount(100)); ValueStep step1 = ValueStep.of(date(2014, 1, 1), ValueAdjustment.ofReplace(350d)); ValueSchedule test = ValueSchedule.builder().initialValue(200d).steps(step1).stepSequence(seq).build(); assertEquals(test.resolveValues(SCHEDULE), DoubleArray.of(350d, 450d, 550d)); }
public void test_builder_validEmpty() { ValueSchedule test = ValueSchedule.builder().build(); assertEquals(test.getInitialValue(), 0d, TOLERANCE); assertEquals(test.getSteps(), ImmutableList.of()); }
private ValueSchedule parseSchedule(XmlElement scheduleEl, double initialValue, ValueStepSequence seq, FpmlDocument document) { List<XmlElement> stepEls = scheduleEl.getChildren("step"); ImmutableList.Builder<ValueStep> stepBuilder = ImmutableList.builder(); for (XmlElement stepEl : stepEls) { LocalDate stepDate = document.parseDate(stepEl.getChild("stepDate")); double stepValue = document.parseDecimal(stepEl.getChild("stepValue")); stepBuilder.add(ValueStep.of(stepDate, ValueAdjustment.ofReplace(stepValue))); } return ValueSchedule.builder().initialValue(initialValue).steps(stepBuilder.build()).stepSequence(seq).build(); }
public void test_resolveValues_sequenceAndStepClash() { ValueStepSequence seq = ValueStepSequence.of( date(2014, 2, 1), date(2014, 3, 1), Frequency.P1M, ValueAdjustment.ofDeltaAmount(100)); ValueStep step1 = ValueStep.of(date(2014, 2, 1), ValueAdjustment.ofReplace(350d)); ValueSchedule test = ValueSchedule.builder().initialValue(200d).steps(step1).stepSequence(seq).build(); assertThrowsIllegalArg(() -> test.resolveValues(SCHEDULE)); }
/** * Sets the {@code steps} property in the builder * from an array of objects. * @param steps the new value, not null * @return this, for chaining, not null */ public Builder steps(ValueStep... steps) { return steps(ImmutableList.copyOf(steps)); }