@Override public MarketDataBox<Curve> applyTo(MarketDataBox<Curve> curve, ReferenceData refData) { return curve.mapWithIndex(getScenarioCount(), this::applyShift); }
@Override public MarketDataBox<ParameterizedData> applyTo( MarketDataBox<ParameterizedData> marketData, ReferenceData refData) { log.debug("Applying {} point shift to ParameterizedData '{}'", shiftType, marketData.getValue(0).toString()); return marketData.mapWithIndex( shifts.rowCount(), (prams, scenarioIndex) -> applyShifts(scenarioIndex, prams)); }
@Override public MarketDataBox<Double> applyTo(MarketDataBox<Double> marketData, ReferenceData refData) { return marketData.mapWithIndex( getScenarioCount(), (value, scenarioIndex) -> shiftType.applyShift(value + spread, shiftAmount.get(scenarioIndex)) - spread); }
/** * Tests that applying a function multiple times to the value creates a box of scenario values. */ public void mapWithIndex() { MarketDataBox<Integer> box = MarketDataBox.ofScenarioValues(27, 28, 29); MarketDataBox<Integer> scenarioBox = box.mapWithIndex(3, (v, idx) -> v + idx); assertThat(scenarioBox.isScenarioValue()).isTrue(); assertThat(scenarioBox.getScenarioCount()).isEqualTo(3); assertThat(scenarioBox.getValue(0)).isEqualTo(27); assertThat(scenarioBox.getValue(1)).isEqualTo(29); assertThat(scenarioBox.getValue(2)).isEqualTo(31); }
/** * Tests that applying a function multiple times to the value creates a box of scenario values. */ public void mapWithIndex() { MarketDataBox<Integer> box = MarketDataBox.ofSingleValue(27); MarketDataBox<Integer> scenarioBox = box.mapWithIndex(3, (v, idx) -> v + idx); assertThat(scenarioBox.isScenarioValue()).isTrue(); assertThat(scenarioBox.getScenarioCount()).isEqualTo(3); assertThat(scenarioBox.getValue(0)).isEqualTo(27); assertThat(scenarioBox.getValue(1)).isEqualTo(28); assertThat(scenarioBox.getValue(2)).isEqualTo(29); }
/** * Tests that an exception is thrown when trying to apply a function multiple times with a scenario count * that doesn't match the scenario count of the box. */ public void mapWithIndexWrongNumberOfScenarios() { MarketDataBox<Integer> box = MarketDataBox.ofScenarioValues(27, 28, 29); assertThrows(() -> box.mapWithIndex(4, (v, idx) -> v + idx), IllegalArgumentException.class); }
@Override public MarketDataBox<FxRate> applyTo(MarketDataBox<FxRate> marketData, ReferenceData refData) { log.debug("Applying {} shift to FX rate '{}'", shiftType, marketData.getValue(0).getPair().toString()); return marketData.mapWithIndex( getScenarioCount(), (fxRate, scenarioIndex) -> FxRate.of( currencyPair, shiftType.applyShift(fxRate.fxRate(currencyPair), shiftAmount.get(scenarioIndex)))); }