YieldAndDiscountAddZeroSpreadCurve extends YieldAndDiscountCurve { @Override public double getInterestRate(final Double t) { double rate = _curves[0].getInterestRate(t); for (int loopcurve = 1; loopcurve < _curves.length; loopcurve++) { rate += _sign * _curves[loopcurve].getInterestRate(t); } return rate; } YieldAndDiscountAddZeroSpreadCurve(final String name, final boolean subtract, final YieldAndDiscountCurve... curves); @Override double getInterestRate(final Double t); @Override double getForwardRate(final double t); @Override double[] getInterestRateParameterSensitivity(final double time); @Override int getNumberOfParameters(); @Override int getNumberOfIntrinsicParameters(final Set<String> curvesNames); @Override List<String> getUnderlyingCurvesNames(); YieldAndDiscountCurve[] getCurves(); double getSign(); @Override int hashCode(); @Override boolean equals(final Object obj);  }
@Test public void interestRate() { int nbPt = 20; YieldAndDiscountAddZeroSpreadCurve zeroSpreadSubstract = new YieldAndDiscountAddZeroSpreadCurve("Spread substract", true, YIELD, DISCOUNT); for (int looppt = 0; looppt <= nbPt; looppt++) { double time = TIME_YIELD[0] + looppt * (TIME_YIELD[TIME_YIELD.length - 1] - TIME_YIELD[0]) / nbPt; assertEquals("YieldAndDiscountAddZeroSpreadCurve: zc rate ", YIELD.getInterestRate(time) + DISCOUNT.getInterestRate(time), ZERO_ADD_SPREAD.getInterestRate(time), TOLERANCE_RATE); assertEquals("YieldAndDiscountAddZeroSpreadCurve: zc rate ", YIELD.getInterestRate(time) - DISCOUNT.getInterestRate(time), zeroSpreadSubstract.getInterestRate(time), TOLERANCE_RATE); } }