ISDACompliantCurve extends DoublesCurve { public double getRT(final double t) { if (t <= _t[0]) { return _rt[0] * t / _t[0]; } final int n = _t.length; if (t > _t[n - 1]) { return getRT(t, n - 1); } final int index = Arrays.binarySearch(_t, t); if (index >= 0) { return _rt[index]; } final int insertionPoint = -(1 + index); return getRT(t, insertionPoint); } protected  ISDACompliantCurve();  ISDACompliantCurve(final double t, final double r);  ISDACompliantCurve(final double[] t, final double[] r); protected  ISDACompliantCurve(final double[][] tAndRt); protected  ISDACompliantCurve(final ISDACompliantCurve from); protected  ISDACompliantCurve(final double[] timesFromBaseDate, final double[] r, final double newBaseFromOriginalBase); static ISDACompliantCurve makeFromForwardRates(final double[] t, final double[] fwd); static ISDACompliantCurve makeFromRT(final double[] t, final double[] rt); double[] getKnotTimes(); double[] getKnotZeroRates(); double getDiscountFactor(final double t); double getTimeAtIndex(final int index); double getZeroRateAtIndex(final int index); double getRTAtIndex(final int index); double getZeroRate(final double t); double getRT(final double t); double[] getRTandSensitivity(final double t, final int nodeIndex); double getForwardRate(final double t); int getNumberOfKnots(); double[] getNodeSensitivity(final double t); double getSingleNodeSensitivity(final double t, final int nodeIndex); double getSingleNodeRTSensitivity(final double t, final int nodeIndex); double getSingleNodeDiscountFactorSensitivity(final double t, final int nodeIndex); ISDACompliantCurve withOffset(final double newBaseFromOriginalBase); ISDACompliantCurve withRates(final double[] r); ISDACompliantCurve withRate(final double rate, final int index); void setRate(final double rate, final int index); ISDACompliantCurve withDiscountFactor(final double discountFactor, final int index); double[] getT(); double[] getRt(); @Override int hashCode(); @Override boolean equals(final Object obj); @Override Double[] getYValueParameterSensitivity(final Double x); @Override double getDyDx(final double x); @Override Double[] getXData(); @Override Double[] getYData(); @Override int size(); @Override Double getYValue(final Double x); static ISDACompliantCurve.Meta meta(); @Override ISDACompliantCurve.Meta metaBean(); final Property<double[]> t(); final Property<double[]> rt(); @Override ISDACompliantCurve clone(); @Override String toString();  }
@Test public void getRTTest() { final double[] t = new double[] {0.1, 0.2, 0.5, 0.7, 1.0, 2.0, 3.0, 3.4, 10.0 }; final double[] r = new double[] {1.0, 0.8, 0.7, 1.2, 1.2, 1.3, 1.2, 1.0, 0.9 }; final int n = t.length; final double[] rt = new double[n]; for (int i = 0; i < n; i++) { rt[i] = r[i] * t[i]; } final ISDACompliantCurve curve = new ISDACompliantCurve(t, r); double rTCalculatedi = 0.0; double ti = 0.0; final int iterationMax = 1000000; for (int i = 0; i < iterationMax; i++) { ti = ti + i / iterationMax * 100; if (ti <= t[0]) { rTCalculatedi = ti * r[0]; } else if (ti >= t[t.length - 1]) { rTCalculatedi = ti * r[t.length - 1]; } else { int indexpointi = Arrays.binarySearch(t, ti); if (indexpointi >= 0) { rTCalculatedi = t[indexpointi] * r[indexpointi]; } else { indexpointi = -(1 + indexpointi); if (indexpointi == 0) { rTCalculatedi = ti * r[0]; } else if (indexpointi == n) { rTCalculatedi = ti * r[n - 1]; } else { final double t1 = t[indexpointi - 1]; final double t2 = t[indexpointi]; final double dt = t2 - t1; rTCalculatedi = ((t2 - ti) * r[indexpointi - 1] * t[indexpointi - 1] + (ti - t1) * r[indexpointi] * t[indexpointi]) / dt; } } } final double rTexpectedi = curve.getRT(ti); assertEquals("Time: " + ti, rTexpectedi, rTCalculatedi, 1e-10); } }