ZSpreadCalculator { public Map<String, List<DoublesPair>> calculatePriceSensitivityToCurve(final Annuity<? extends Payment> annuity, final YieldCurveBundle curves, final double zSpread) { ArgumentChecker.notNull(annuity, "annuity"); ArgumentChecker.notNull(curves, "curves"); final Map<String, List<DoublesPair>> temp = annuity.accept(PV_SENSITIVITY_CALCULATOR, curves); if (Double.doubleToLongBits(zSpread) == 0) { return temp; } final Map<String, List<DoublesPair>> result = new HashMap<>(); for (final Map.Entry<String, List<DoublesPair>> entry : temp.entrySet()) { final List<DoublesPair> unadjusted = entry.getValue(); final ArrayList<DoublesPair> adjusted = new ArrayList<>(unadjusted.size()); for (final DoublesPair pair : unadjusted) { final DoublesPair newPair = DoublesPair.of(pair.first, pair.second * Math.exp(-zSpread * pair.first)); adjusted.add(newPair); } result.put(entry.getKey(), adjusted); } return result; } private  ZSpreadCalculator(); static ZSpreadCalculator getInstance(); double calculateZSpread(final Annuity<? extends Payment> annuity, final YieldCurveBundle curves, final double price); double calculatePriceForZSpread(final Annuity<? extends Payment> annuity, final YieldCurveBundle curves, final double zSpread); double calculatePriceSensitivityToZSpread(final Annuity<? extends Payment> annuity, final YieldCurveBundle curves, final double zSpread); Map<String, List<DoublesPair>> calculatePriceSensitivityToCurve(final Annuity<? extends Payment> annuity, final YieldCurveBundle curves, final double zSpread); Map<String, List<DoublesPair>> calculateZSpreadSensitivityToCurve(final Annuity<? extends Payment> annuity, final YieldCurveBundle curves, final double zSpread);  }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNullAnnuity2() { CALCULATOR.calculatePriceSensitivityToCurve(null, CURVES, 0.04); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNullCurves2() { CALCULATOR.calculatePriceSensitivityToCurve(PAYMENTS, null, 0.04); }