YieldSensitivityCalculator { public double calculateNthOrderSensitivityFromYield(final Annuity<? extends PaymentFixed> annuity, final double yield, final int order) { Validate.notNull(annuity, "annuity"); Validate.isTrue(order >= 0, "order must be positive"); double sum = 0; double t; double tPower; final int n = annuity.getNumberOfPayments(); PaymentFixed temp; for (int i = 0; i < n; i++) { temp = annuity.getNthPayment(i); t = temp.getPaymentTime(); tPower = Math.pow(t, order); sum += temp.getAmount() * tPower * Math.exp(-yield * t); } return sum; } private  YieldSensitivityCalculator(); static YieldSensitivityCalculator getInstance(); double calculateYield(final Annuity<? extends PaymentFixed> annuity, final double pv); double calculateYield(final AnnuityCouponFixed annuity, final double pv); double calculatePriceForYield(final Annuity<? extends PaymentFixed> annuity, final double yield); double calculatePriceForYield(final AnnuityCouponFixed annuity, final double yield); double calculateNthOrderSensitivity(final Annuity<? extends PaymentFixed> annuity, final double pv, final int order); double calculateNthOrderSensitivity(final AnnuityCouponFixed annuity, final double pv, final int order); double calculateNthOrderSensitivityFromYield(final Annuity<? extends PaymentFixed> annuity, final double yield, final int order); double calculateNthOrderSensitivityFromYield(final AnnuityCouponFixed annuity, final double yield, final int order);  }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNullAnnuity4() { YSC.calculateNthOrderSensitivityFromYield((AnnuityCouponFixed) null, 0.04, 1); }