/// <summary> /// Tests that applying a function multiple times to the value creates a box of scenario values. /// </summary> public virtual void mapWithIndex() { MarketDataBox <int> box = MarketDataBox.ofScenarioValues(27, 28, 29); MarketDataBox <int> scenarioBox = box.mapWithIndex(3, (v, idx) => v + idx); assertThat(scenarioBox.ScenarioValue).True; assertThat(scenarioBox.ScenarioCount).isEqualTo(3); assertThat(scenarioBox.getValue(0)).isEqualTo(27); assertThat(scenarioBox.getValue(1)).isEqualTo(29); assertThat(scenarioBox.getValue(2)).isEqualTo(31); }
//------------------------------------------------------------------------- public MarketDataBox <Curve> applyTo(MarketDataBox <Curve> curve, ReferenceData refData) { return(curve.mapWithIndex(ScenarioCount, this.applyShift)); }
//------------------------------------------------------------------------- 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))); }
//------------------------------------------------------------------------- public MarketDataBox <double> applyTo(MarketDataBox <double> marketData, ReferenceData refData) { return(marketData.mapWithIndex(ScenarioCount, (value, scenarioIndex) => shiftType.applyShift(value + spread, shiftAmount.get(scenarioIndex)) - spread)); }
//------------------------------------------------------------------------- public MarketDataBox <FxRate> applyTo(MarketDataBox <FxRate> marketData, ReferenceData refData) { log.debug("Applying {} shift to FX rate '{}'", shiftType, marketData.getValue(0).Pair.ToString()); return(marketData.mapWithIndex(ScenarioCount, (fxRate, scenarioIndex) => FxRate.of(currencyPair, shiftType.applyShift(fxRate.fxRate(currencyPair), shiftAmount.get(scenarioIndex))))); }
/// <summary> /// 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. /// </summary> public virtual void mapWithIndexWrongNumberOfScenarios() { MarketDataBox <int> box = MarketDataBox.ofScenarioValues(27, 28, 29); assertThrows(() => box.mapWithIndex(4, (v, idx) => v + idx), typeof(System.ArgumentException)); }