@Override public ValueAdjustment toValueAdjustment(double shiftAmount) { return ValueAdjustment.ofDeltaMultiplier(shiftAmount); }
public void equals() { ValueAdjustment a1 = ValueAdjustment.ofReplace(200); ValueAdjustment a2 = ValueAdjustment.ofReplace(200); ValueAdjustment b = ValueAdjustment.ofDeltaMultiplier(200); ValueAdjustment c = ValueAdjustment.ofDeltaMultiplier(0.1); assertEquals(a1.equals(a2), true); assertEquals(a1.equals(b), false); assertEquals(a1.equals(c), false); }
public void test_ofDeltaMultiplier() { ValueAdjustment test = ValueAdjustment.ofDeltaMultiplier(0.1); assertEquals(test.getModifyingValue(), 0.1, TOLERANCE); assertEquals(test.getType(), ValueAdjustmentType.DELTA_MULTIPLIER); assertEquals(test.adjust(100), 110, TOLERANCE); assertEquals(test.toString(), "ValueAdjustment[result = input + input * 0.1]"); }
private ValueStepSequence parseAmountSchedule(XmlElement scheduleEl, double initialValue, FpmlDocument document) { Frequency freq = document.parseFrequency(scheduleEl.getChild("stepFrequency")); LocalDate start = document.parseDate(scheduleEl.getChild("firstNotionalStepDate")); LocalDate end = document.parseDate(scheduleEl.getChild("lastNotionalStepDate")); Optional<XmlElement> amountElOpt = scheduleEl.findChild("notionalStepAmount"); if (amountElOpt.isPresent()) { double amount = document.parseDecimal(amountElOpt.get()); return ValueStepSequence.of(start, end, freq, ValueAdjustment.ofDeltaAmount(amount)); } double rate = document.parseDecimal(scheduleEl.getChild("notionalStepRate")); String relativeTo = scheduleEl.findChild("stepRelativeTo").map(el -> el.getContent()).orElse("Previous"); if (relativeTo.equals("Previous")) { return ValueStepSequence.of(start, end, freq, ValueAdjustment.ofDeltaMultiplier(rate)); } else if (relativeTo.equals("Initial")) { // data model does not support 'relative to initial' but can calculate amount here double amount = initialValue * rate; return ValueStepSequence.of(start, end, freq, ValueAdjustment.ofDeltaAmount(amount)); } else { throw new FpmlParseException(Messages.format( "Unknown 'stepRelativeTo' value '{}', expected 'Initial' or 'Previous'", relativeTo)); } }