InterestRateCurveSensitivityUtils { public static List<DoublesPair> addSensitivity(final List<DoublesPair> sensi1, final List<DoublesPair> sensi2) { final List<DoublesPair> result = new ArrayList<>(sensi1); result.addAll(sensi2); return result; } protected  InterestRateCurveSensitivityUtils(); static Map<String, List<DoublesPair>> clean(final Map<String, List<DoublesPair>> old, final double relTol, final double absTol); static List<DoublesPair> addSensitivity(final List<DoublesPair> sensi1, final List<DoublesPair> sensi2); static Map<String, List<DoublesPair>> addSensitivity(final Map<String, List<DoublesPair>> sensi1, final Map<String, List<DoublesPair>> sensi2); static Map<String, List<DoublesPair>> addSensitivity(final Map<String, List<DoublesPair>> sensi, final String curveName, final List<DoublesPair> list); static Map<String, List<DoublesPair>> addSensitivity(final Map<String, List<DoublesPair>> sensi1, final Map<String, List<DoublesPair>> sensi2, final Map<String, List<DoublesPair>> sensi3); static Map<String, List<DoublesPair>> multiplySensitivity(final Map<String, List<DoublesPair>> sensitivity, final double factor); static List<DoublesPair> multiplySensitivity(final List<DoublesPair> sensitivity, final double factor); static boolean compare(final List<DoublesPair> sensi1, final List<DoublesPair> sensi2, final double tolerance); static boolean compare(final Map<String, List<DoublesPair>> sensi1, final Map<String, List<DoublesPair>> sensi2, final double tolerance);  }
@Test public void testAddSensitivityList() { final List<DoublesPair> l1 = new ArrayList<>(); l1.add(DoublesPair.of(0.23, 12.3)); l1.add(DoublesPair.of(0.23, -2.6)); l1.add(DoublesPair.of(0.35, 2.3)); final List<DoublesPair> l2 = new ArrayList<>(); l2.add(DoublesPair.of(0.35, 12.3)); l2.add(DoublesPair.of(1.23, -2.6)); final List<DoublesPair> res = addSensitivity(l1, l2); final ArrayList<DoublesPair> expected = new ArrayList<>(); expected.add(DoublesPair.of(0.23, 12.3)); expected.add(DoublesPair.of(0.23, -2.6)); expected.add(DoublesPair.of(0.35, 2.3)); expected.add(DoublesPair.of(0.35, 12.3)); expected.add(DoublesPair.of(1.23, -2.6)); assertEquals(expected.size(), res.size()); for (int i = 0; i < expected.size(); i++) { assertEquals(expected.get(i).first, res.get(i).first, 0.0); assertEquals(expected.get(i).second, res.get(i).second, 1e-9); } }
@Test public void testAddSensitivityMap() { final List<DoublesPair> l1 = new ArrayList<>(); l1.add(DoublesPair.of(0.23, 12.3)); l1.add(DoublesPair.of(0.23, -2.6)); l1.add(DoublesPair.of(0.35, 2.3)); final List<DoublesPair> l2 = new ArrayList<>(); l2.add(DoublesPair.of(0.35, 12.3)); l2.add(DoublesPair.of(1.23, -2.6)); final List<DoublesPair> l3 = new ArrayList<>(); l3.add(DoublesPair.of(0.35, 12.3)); l3.add(DoublesPair.of(1.23, -2.6)); final String c1 = "C1"; final String c2 = "C2"; final Map<String, List<DoublesPair>> m1 = new HashMap<>(); m1.put(c1, l1); m1.put(c2, l2); final Map<String, List<DoublesPair>> m2 = new HashMap<>(); m2.put(c2, l2); final Map<String, List<DoublesPair>> res = addSensitivity(m1, m2); assertEquals(2, res.size()); assertSensitivityEquals(l1, res.get(c1), 0.0); assertSensitivityEquals(addSensitivity(l2, l3), res.get(c2), 0.0); }