YieldAndDiscountCurve implements InterestRateModel<Double>, Serializable { public abstract double[] getInterestRateParameterSensitivity(final double time); YieldAndDiscountCurve(final String name); String getName(); double getDiscountFactor(final double t); abstract double getForwardRate(final double t); double getPeriodicInterestRate(final double t, final int compoundingPeriodsPerYear); abstract double[] getInterestRateParameterSensitivity(final double time); abstract int getNumberOfParameters(); abstract List<String> getUnderlyingCurvesNames(); int getNumberOfIntrinsicParameters(final Set<String> curvesNames); @Deprecated YieldAndDiscountCurve withParallelShift(final double shift); YieldAndDiscountCurve withSingleShift(final double t, final double shift);  }
@Test public void interestRateParameterSensitivityYieldPeriodic() { int nbPt = 20; double shift = 1.0E-6; double[] time = new double[nbPt + 1]; double[] rt = new double[nbPt + 1]; double[][] ps = new double[nbPt + 1][]; for (int looppt = 0; looppt <= nbPt; looppt++) { time[looppt] = TIME[0] + looppt * (TIME[TIME.length - 1] - TIME[0]) / nbPt; rt[looppt] = YIELD_PERIODIC.getInterestRate(time[looppt]); ps[looppt] = YIELD_PERIODIC.getInterestRateParameterSensitivity(time[looppt]); } for (int loopr = 0; loopr < RATES.length; loopr++) { double[] rateShift = RATES.clone(); rateShift[loopr] += shift; YieldPeriodicCurve yieldPeriodicShifted = YieldPeriodicCurve.from(COMPOUNDING, InterpolatedDoublesCurve.from(TIME, rateShift, new LinearInterpolator1D())); for (int looppt = 0; looppt <= nbPt; looppt++) { double r = yieldPeriodicShifted.getInterestRate(time[looppt]); assertEquals("ParameterSensitivity - YieldPeriodic", (r - rt[looppt]) / shift, ps[looppt][loopr], TOLERANCE_SENSI); } } }
@Test public void interestRateParameterSensitivityDiscounting() { int nbPt = 20; double shift = 1.0E-6; double[] time = new double[nbPt + 1]; double[] rt = new double[nbPt + 1]; double[][] ps = new double[nbPt + 1][]; for (int looppt = 0; looppt <= nbPt; looppt++) { time[looppt] = TIME[0] + looppt * (TIME[TIME.length - 1] - TIME[0]) / nbPt; rt[looppt] = DISCOUNT.getInterestRate(time[looppt]); ps[looppt] = DISCOUNT.getInterestRateParameterSensitivity(time[looppt]); } for (int loopr = 0; loopr < RATES.length; loopr++) { double[] dfShift = DF_VALUES.clone(); dfShift[loopr] += shift; DiscountCurve discountShift = DiscountCurve.from(InterpolatedDoublesCurve.from(TIME, dfShift, new LinearInterpolator1D())); for (int looppt = 0; looppt <= nbPt; looppt++) { double r = discountShift.getInterestRate(time[looppt]); assertEquals("ParameterSensitivity - YieldPeriodic", (r - rt[looppt]) / shift, ps[looppt][loopr], TOLERANCE_SENSI); } } }