YieldCurveUtils { public static YieldCurve withParallelShift(YieldCurve curve, double shift, ShiftType shiftType) { return withParallelShift(curve, shift, shiftType, PARALLEL_SHIFT_NAME); }  static YieldCurve withParallelShift(YieldCurve curve, double shift, ShiftType shiftType); static YieldCurve withParallelShift(YieldCurve curve, double shift, ShiftType shiftType, String nameSuffix); static YieldCurve withBucketedShifts(YieldCurve curve,
                                              List<DoublesPair> buckets,
                                              List<Double> shifts,
                                              ShiftType shiftType); static YieldCurve withBucketedShifts(YieldCurve curve,
                                              List<DoublesPair> buckets,
                                              List<Double> shifts,
                                              ShiftType shiftType,
                                              String nameSuffix); static YieldCurve withPointShifts(YieldCurve curve, List<Double> t, List<Double> shifts, ShiftType shiftType); static YieldCurve withPointShifts(YieldCurve curve,
                                           List<Double> t,
                                           List<Double> shifts,
                                           ShiftType shiftType,
                                           String nameSuffix); static final String PARALLEL_SHIFT_NAME; static final String BUCKETED_SHIFT_NAME; static final String POINT_SHIFT_NAME; }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNullCurve1() { YieldCurveUtils.withParallelShift(null, 100, ShiftType.ABSOLUTE); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNullShiftType1() { YieldCurveUtils.withParallelShift(ORIGINAL_CURVE, 100, null); }
@Test public void testZeroAbsoluteParallelShift() { final YieldCurve shiftedCurve = YieldCurveUtils.withParallelShift(ORIGINAL_CURVE, 0, ShiftType.ABSOLUTE); assertEquals("ORIGINAL_WithParallelShift", shiftedCurve.getName()); assertFalse(shiftedCurve.getCurve().equals(ORIGINAL_CURVE.getCurve())); assertTrue(shiftedCurve.getCurve() instanceof SpreadDoublesCurve); assertCurveEquals(ORIGINAL_CURVE.getCurve(), shiftedCurve.getCurve(), 1e-15); }
@Test public void testZeroRelativeParallelShift() { final YieldCurve shiftedCurve = YieldCurveUtils.withParallelShift(ORIGINAL_CURVE, 0, ShiftType.RELATIVE); assertEquals("ORIGINAL_WithParallelShift", shiftedCurve.getName()); assertFalse(shiftedCurve.getCurve().equals(ORIGINAL_CURVE.getCurve())); assertTrue(shiftedCurve.getCurve() instanceof SpreadDoublesCurve); assertCurveEquals(ORIGINAL_CURVE.getCurve(), shiftedCurve.getCurve(), 1e-15); }
@Test public void testAbsoluteParallelShift() { final double shift = 0.03; YieldCurve shiftedCurve = YieldCurveUtils.withParallelShift(ORIGINAL_CURVE, shift, ShiftType.ABSOLUTE); final double[] y = new double[T.length]; for (int i = 0; i < y.length; i++) { y[i] = Y[i] + shift; } final DoublesCurve expectedCurve = InterpolatedDoublesCurve.from(T, y, INTERPOLATOR); assertCurveEquals(expectedCurve, shiftedCurve.getCurve(), 1e-9); shiftedCurve = YieldCurveUtils.withParallelShift(shiftedCurve, -shift, ShiftType.ABSOLUTE); assertCurveEquals(ORIGINAL_CURVE.getCurve(), shiftedCurve.getCurve(), 1e-9); }
@Test public void testRelativeParallelShift() { final double shift = 0.03; YieldCurve shiftedCurve = YieldCurveUtils.withParallelShift(ORIGINAL_CURVE, shift, ShiftType.RELATIVE); final double[] y = new double[T.length]; for (int i = 0; i < y.length; i++) { y[i] = Y[i] * (1 + shift); } final DoublesCurve expectedCurve = InterpolatedDoublesCurve.from(T, y, INTERPOLATOR); assertCurveEquals(expectedCurve, shiftedCurve.getCurve(), 1e-9); shiftedCurve = YieldCurveUtils.withParallelShift(shiftedCurve, -shift / (1 + shift), ShiftType.RELATIVE); assertCurveEquals(ORIGINAL_CURVE.getCurve(), shiftedCurve.getCurve(), 1e-9); }