YieldCurveUtils { public static YieldCurve withBucketedShifts(YieldCurve curve, List<DoublesPair> buckets, List<Double> shifts, ShiftType shiftType) { return withBucketedShifts(curve, buckets, shifts, shiftType, BUCKETED_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 testNullCurve2() { YieldCurveUtils.withBucketedShifts(null, new ArrayList<DoublesPair>(), new ArrayList<Double>(), ShiftType.ABSOLUTE); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNullBuckets() { YieldCurveUtils.withBucketedShifts(ORIGINAL_CURVE, null, new ArrayList<Double>(), ShiftType.ABSOLUTE); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNullShifts1() { YieldCurveUtils.withBucketedShifts(ORIGINAL_CURVE, new ArrayList<DoublesPair>(), null, ShiftType.ABSOLUTE); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNullShiftType2() { YieldCurveUtils.withBucketedShifts(ORIGINAL_CURVE, new ArrayList<DoublesPair>(), new ArrayList<Double>(), null); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testDifferentLengthShifts1() { YieldCurveUtils.withBucketedShifts(ORIGINAL_CURVE, Arrays.asList(DoublesPair.of(1., 2.)), new ArrayList<Double>(), ShiftType.ABSOLUTE); }
@Test public void testEmptyBucketedAbsoluteShifts() { final List<DoublesPair> buckets = new ArrayList<>(); final List<Double> shifts = new ArrayList<>(); final YieldCurve shiftedCurve = YieldCurveUtils.withBucketedShifts( ORIGINAL_CURVE, buckets, shifts, ShiftType.ABSOLUTE); assertEquals("ORIGINAL_WithBucketedShifts", shiftedCurve.getName()); assertFalse(ORIGINAL_CURVE.equals(shiftedCurve)); assertCurveEquals(ORIGINAL_CURVE.getCurve(), shiftedCurve.getCurve(), 1e-15); }
@Test public void testEmptyBucketedRelativeShifts() { final List<DoublesPair> buckets = new ArrayList<>(); final List<Double> shifts = new ArrayList<>(); final YieldCurve shiftedCurve = YieldCurveUtils.withBucketedShifts(ORIGINAL_CURVE, buckets, shifts, ShiftType.RELATIVE); assertEquals("ORIGINAL_WithBucketedShifts", shiftedCurve.getName()); assertFalse(ORIGINAL_CURVE.equals(shiftedCurve)); assertCurveEquals(ORIGINAL_CURVE.getCurve(), shiftedCurve.getCurve(), 1e-15); }
@Test public void testZeroBucketedAbsoluteShifts() { final List<DoublesPair> buckets = Arrays.asList(DoublesPair.of(1., 2.), DoublesPair.of(2., 3.), DoublesPair.of(3., 4.)); final List<Double> shifts = Arrays.asList(0., 0., 0.); final YieldCurve shiftedCurve = YieldCurveUtils.withBucketedShifts(ORIGINAL_CURVE, buckets, shifts, ShiftType.ABSOLUTE); assertFalse(ORIGINAL_CURVE.equals(shiftedCurve)); assertCurveEquals(ORIGINAL_CURVE.getCurve(), shiftedCurve.getCurve(), 1e-15); }
@Test public void testZeroBucketedRelativeShifts() { final List<DoublesPair> buckets = Arrays.asList(DoublesPair.of(1., 2.), DoublesPair.of(2., 3.), DoublesPair.of(3., 4.)); final List<Double> shifts = Arrays.asList(0., 0., 0.); final YieldCurve shiftedCurve = YieldCurveUtils.withBucketedShifts(ORIGINAL_CURVE, buckets, shifts, ShiftType.RELATIVE); assertFalse(ORIGINAL_CURVE.equals(shiftedCurve)); assertCurveEquals(ORIGINAL_CURVE.getCurve(), shiftedCurve.getCurve(), 1e-15); }
@Test public void testBucketedAbsoluteShifts1() { final List<DoublesPair> buckets = Arrays.asList(DoublesPair.of(1., 5.), DoublesPair.of(5., 7.5), DoublesPair.of(7.5, 10)); final List<Double> shifts = Arrays.asList(3., 4., 5.); final List<Double> inverseShifts = Arrays.asList(-3., -4., -5.); final DoublesCurve expectedSpreadCurve = InterpolatedDoublesCurve.from( new double[]{0, 1, 5, 7.5, 10}, new double[]{0, 3., 4., 5., 0.}, STEP_INTERPOLATOR); final DoublesCurve expectedCurve = SpreadDoublesCurve.from( ADD_CURVE_FUNCTION, ORIGINAL_CURVE.getCurve(), expectedSpreadCurve); YieldCurve shiftedCurve = YieldCurveUtils.withBucketedShifts(ORIGINAL_CURVE, buckets, shifts, ShiftType.ABSOLUTE); assertCurveEquals(expectedCurve, shiftedCurve.getCurve(), 1e-9); shiftedCurve = YieldCurveUtils.withBucketedShifts(shiftedCurve, buckets, inverseShifts, ShiftType.ABSOLUTE); assertCurveEquals(ORIGINAL_CURVE.getCurve(), shiftedCurve.getCurve(), 1e-9); }
@Test public void testBucketedRelativeShifts1() { final List<DoublesPair> buckets = Arrays.asList(DoublesPair.of(1., 5.), DoublesPair.of(5., 7.5), DoublesPair.of(7.5, 10)); final List<Double> shifts = Arrays.asList(3., 4., 5.); final List<Double> inverseShifts = Arrays.asList(-0.75, -0.8, -5. / 6); final DoublesCurve expectedSpreadCurve = InterpolatedDoublesCurve.from(new double[] {0, 1, 5, 7.5, 10}, new double[] {1, 4., 5., 6., 1.}, STEP_INTERPOLATOR); final DoublesCurve expectedCurve = SpreadDoublesCurve.from(MULTIPLY_CURVE_FUNCTION, ORIGINAL_CURVE.getCurve(), expectedSpreadCurve); YieldCurve shiftedCurve = YieldCurveUtils.withBucketedShifts(ORIGINAL_CURVE, buckets, shifts, ShiftType.RELATIVE); assertCurveEquals(expectedCurve, shiftedCurve.getCurve(), 1e-9); shiftedCurve = YieldCurveUtils.withBucketedShifts(shiftedCurve, buckets, inverseShifts, ShiftType.RELATIVE); assertCurveEquals(ORIGINAL_CURVE.getCurve(), shiftedCurve.getCurve(), 1e-9); }
@Test public void testBucketedAbsoluteShifts2() { final List<DoublesPair> buckets = Arrays.asList(DoublesPair.of(1., 2.), DoublesPair.of(2.5, 3.5), DoublesPair.of(5., 7.5), DoublesPair.of(7.5, 10)); final List<Double> shifts = Arrays.asList(3., 4., 5., 6.); final List<Double> inverseShifts = Arrays.asList(-3., -4., -5., -6.); final DoublesCurve expectedSpreadCurve = InterpolatedDoublesCurve.from(new double[] {0, 1, 2, 2.5, 3.5, 5, 7.5, 10}, new double[] {0, 3., 0, 4., 0., 5., 6., 0.}, STEP_INTERPOLATOR); final DoublesCurve expectedCurve = SpreadDoublesCurve.from(ADD_CURVE_FUNCTION, ORIGINAL_CURVE.getCurve(), expectedSpreadCurve); YieldCurve shiftedCurve = YieldCurveUtils.withBucketedShifts(ORIGINAL_CURVE, buckets, shifts, ShiftType.ABSOLUTE); assertCurveEquals(expectedCurve, shiftedCurve.getCurve(), 1e-9); shiftedCurve = YieldCurveUtils.withBucketedShifts(shiftedCurve, buckets, inverseShifts, ShiftType.ABSOLUTE); assertCurveEquals(ORIGINAL_CURVE.getCurve(), shiftedCurve.getCurve(), 1e-9); }
@Test public void testBucketedRelativeShifts2() { final List<DoublesPair> buckets = Arrays.asList(DoublesPair.of(1., 2.), DoublesPair.of(2.5, 3.5), DoublesPair.of(5., 7.5), DoublesPair.of(7.5, 10)); final List<Double> shifts = Arrays.asList(3., 4., 5., 6.); final List<Double> inverseShifts = Arrays.asList(-0.75, -0.8, -5. / 6, -6. / 7); final DoublesCurve expectedSpreadCurve = InterpolatedDoublesCurve.from(new double[] {0, 1, 2, 2.5, 3.5, 5, 7.5, 10}, new double[] {1, 4., 1, 5., 1., 6., 7., 1.}, STEP_INTERPOLATOR); final DoublesCurve expectedCurve = SpreadDoublesCurve.from(MULTIPLY_CURVE_FUNCTION, ORIGINAL_CURVE.getCurve(), expectedSpreadCurve); YieldCurve shiftedCurve = YieldCurveUtils.withBucketedShifts(ORIGINAL_CURVE, buckets, shifts, ShiftType.RELATIVE); assertCurveEquals(expectedCurve, shiftedCurve.getCurve(), 1e-9); shiftedCurve = YieldCurveUtils.withBucketedShifts(shiftedCurve, buckets, inverseShifts, ShiftType.RELATIVE); assertCurveEquals(ORIGINAL_CURVE.getCurve(), shiftedCurve.getCurve(), 1e-9); }