/**
  * Computes the interest rate sensitivity of future price.
  *
  * @param future The future security.
  * @param curves The curves.
  * @return The curve sensitivity.
  */
 @Override
 public InterestRateCurveSensitivity priceCurveSensitivity(
     final FederalFundsFutureSecurity future, final YieldCurveBundle curves) {
   Validate.notNull(future, "Future");
   Validate.notNull(curves, "Curves");
   int nbFixing = future.getFixingPeriodAccrualFactor().length;
   YieldAndDiscountCurve ois = curves.getCurve(future.getOISCurveName());
   double[] df = new double[nbFixing + 1];
   for (int loopfix = 0; loopfix < nbFixing + 1; loopfix++) {
     df[loopfix] = ois.getDiscountFactor(future.getFixingPeriodTime()[loopfix]);
   }
   // Backward sweep
   double priceBar = 1.0;
   double interestBar = -1.0 / future.getFixingTotalAccrualFactor() * priceBar;
   double[] dfBar = new double[nbFixing + 1];
   for (int loopfix = 0; loopfix < nbFixing; loopfix++) {
     dfBar[loopfix] += 1.0 / df[loopfix + 1] * interestBar;
     dfBar[loopfix + 1] += -df[loopfix] / (df[loopfix + 1] * df[loopfix + 1]) * interestBar;
   }
   Map<String, List<DoublesPair>> resultMap = new HashMap<String, List<DoublesPair>>();
   List<DoublesPair> listOIS = new ArrayList<DoublesPair>();
   for (int loopfix = 0; loopfix < nbFixing + 1; loopfix++) {
     listOIS.add(
         new DoublesPair(
             future.getFixingPeriodTime()[loopfix],
             -future.getFixingPeriodTime()[loopfix] * df[loopfix] * dfBar[loopfix]));
   }
   resultMap.put(future.getOISCurveName(), listOIS);
   InterestRateCurveSensitivity result = new InterestRateCurveSensitivity(resultMap);
   return result;
 }
 @Override
 /**
  * Computes the Federal Funds future price using average of forward rates (not convexity
  * adjustment).
  *
  * @param future The future security.
  * @param curves The curves.
  * @return The price.
  */
 public double price(final FederalFundsFutureSecurity future, final YieldCurveBundle curves) {
   Validate.notNull(future, "Future");
   Validate.notNull(curves, "Curves");
   int nbFixing = future.getFixingPeriodAccrualFactor().length;
   YieldAndDiscountCurve ois = curves.getCurve(future.getOISCurveName());
   double[] df = new double[nbFixing + 1];
   for (int loopfix = 0; loopfix < nbFixing + 1; loopfix++) {
     df[loopfix] = ois.getDiscountFactor(future.getFixingPeriodTime()[loopfix]);
   }
   double interest = future.getAccruedInterest();
   for (int loopfix = 0; loopfix < nbFixing; loopfix++) {
     interest += df[loopfix] / df[loopfix + 1] - 1.0;
   }
   return 1.0 - interest / future.getFixingTotalAccrualFactor();
 }
 /**
  * Computes the present value of the future security as the value of one future with a price of 0.
  *
  * @param future The future security.
  * @param curves The curves.
  * @return The present value.
  */
 public CurrencyAmount presentValue(
     final FederalFundsFutureSecurity future, final YieldCurveBundle curves) {
   double price = price(future, curves);
   double pv = price * future.getPaymentAccrualFactor() * future.getNotional();
   return CurrencyAmount.of(future.getCurrency(), pv);
 }