@Override public double yValue(double x) { return shiftType.applyShift(underlyingCurve.yValue(x), shiftAmount); }
@Override public double firstDerivative(double x) { double firstDerivative = underlyingCurve.firstDerivative(x); switch (shiftType) { case ABSOLUTE: // If all Y values have been shifted the same amount the derivative is unaffected return firstDerivative; case RELATIVE: // If all Y values have been scaled by the same factor the first derivative is scaled in the same way return shiftType.applyShift(firstDerivative, shiftAmount); default: throw new IllegalArgumentException("Unsupported shift type " + shiftType); } }
public void test_applyShift() { assertEquals(ShiftType.ABSOLUTE.applyShift(2, 0.1), 2.1); assertEquals(ShiftType.RELATIVE.applyShift(2, 0.1), 2.2); assertEquals(ShiftType.SCALED.applyShift(2, 1.1), 2.2); }
private ParameterizedData applyShifts(int scenarioIndex, ParameterizedData prams) { return prams.withPerturbation((index, value, meta) -> { double shiftAmount = shiftForNode(scenarioIndex, meta); return shiftType.applyShift(value, shiftAmount); }); }
@Override public double yValue(double x) { int i = seasonalityIndex(x); double adjustment = seasonality.get(i); return adjustmentType.applyShift(underlying.yValue(x), adjustment); }
@Override public MarketDataBox<Double> applyTo(MarketDataBox<Double> marketData, ReferenceData refData) { return marketData.mapWithIndex( getScenarioCount(), (value, scenarioIndex) -> shiftType.applyShift(value + spread, shiftAmount.get(scenarioIndex)) - spread); }
public void test_computeShift() { double tol = 1.0e-15; double base = 2.0; double shifted = 2.1; assertEquals(ShiftType.ABSOLUTE.computeShift(base, shifted), 0.1, tol); assertEquals(ShiftType.RELATIVE.computeShift(base, shifted), 0.05, tol); assertEquals(ShiftType.SCALED.computeShift(base, shifted), 1.05, tol); assertEquals( ShiftType.ABSOLUTE.applyShift(base, ShiftType.ABSOLUTE.computeShift(base, shifted)), shifted, tol); assertEquals( ShiftType.RELATIVE.applyShift(base, ShiftType.RELATIVE.computeShift(base, shifted)), shifted, tol); assertEquals( ShiftType.SCALED.applyShift(base, ShiftType.SCALED.computeShift(base, shifted)), shifted, tol); }
@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)))); }
@ImmutableConstructor private InflationNodalCurve( NodalCurve curve, DoubleArray seasonality, ShiftType adjustmentType) { this.underlying = curve; this.seasonality = seasonality; this.xFixing = curve.getXValues().get(0); this.yFixing = curve.getYValues().get(0); int i = seasonalityIndex(xFixing); ArgChecker.isTrue( adjustmentType.applyShift(yFixing, seasonality.get(i)) - yFixing < 1.0E-10, "Fixing value should be unadjusted"); this.adjustmentType = adjustmentType; }
for (int i = 1; i < 12; i++) { int j = (int) ((nbMonth + 12 + 1 + i) % 12); seasonalityCompoundedArray[j] = seasonalityDefinition.getAdjustmentType().applyShift( seasonalityCompoundedArray[(j - 1 + 12) % 12], seasonalityDefinition.getSeasonalityMonthOnMonth().get((lastMonthIndex + i) % 12));