Пример #1
0
        //-------------------------------------------------------------------------
        public virtual void noLeftTest()
        {
            BoundCurveInterpolator bci = PRODUCT_LINEAR.bind(X_VALUES, Y_VALUES, DISCOUNT_FACTOR_LINEAR_RIGHT_ZERO_RATE, DISCOUNT_FACTOR_LINEAR_RIGHT_ZERO_RATE);

            assertThrowsIllegalArg(() => bci.interpolate(0.2d));
            assertThrowsIllegalArg(() => bci.firstDerivative(0.3d));
            assertThrowsIllegalArg(() => bci.parameterSensitivity(0.6d));
        }
Пример #2
0
        public virtual void derivativeTest()
        {
            BoundCurveInterpolator bci = PRODUCT_LINEAR.bind(X_VALUES, Y_VALUES, LINEAR, DISCOUNT_FACTOR_LINEAR_RIGHT_ZERO_RATE);

            for (int i = 0; i < NUM_KEYS; ++i)
            {
                double key      = X_KEYS.get(i);
                double computed = bci.firstDerivative(key);
                double expected = 0.5d * (bci.interpolate(key + EPS) - bci.interpolate(key - EPS)) / EPS;
                assertEquals(computed, expected, EPS);
            }
        }
Пример #3
0
        public virtual void interpolateTest()
        {
            BoundCurveInterpolator bci = PRODUCT_LINEAR.bind(X_VALUES, Y_VALUES, LINEAR, DISCOUNT_FACTOR_LINEAR_RIGHT_ZERO_RATE);
            double grad = -Y_VALUES.get(NUM_DATA - 1) * DSC_VALUES.get(NUM_DATA - 1) - X_VALUES.get(NUM_DATA - 1) * DSC_VALUES.get(NUM_DATA - 1) * bci.firstDerivative(X_VALUES.get(NUM_DATA - 1));

            for (int i = 0; i < NUM_KEYS; ++i)
            {
                double key = X_KEYS.get(i);
                double df  = grad * (key - X_VALUES.get(NUM_DATA - 1)) + DSC_VALUES.get(NUM_DATA - 1);
                assertEquals(bci.interpolate(key), -Math.Log(df) / key, TOL);
            }
        }
Пример #4
0
        public virtual void parameterSensitivityTest()
        {
            BoundCurveInterpolator bci = PRODUCT_LINEAR.bind(X_VALUES, Y_VALUES, LINEAR, DISCOUNT_FACTOR_LINEAR_RIGHT_ZERO_RATE);

            for (int i = 0; i < NUM_KEYS; ++i)
            {
                double      key      = X_KEYS.get(i);
                DoubleArray computed = bci.parameterSensitivity(key);
                for (int j = 0; j < NUM_DATA; ++j)
                {
                    double[] yValuesUp = Y_VALUES.toArray();
                    double[] yValuesDw = Y_VALUES.toArray();
                    yValuesUp[j] += EPS;
                    yValuesDw[j] -= EPS;
                    BoundCurveInterpolator bciUp = PRODUCT_LINEAR.bind(X_VALUES, DoubleArray.copyOf(yValuesUp), LINEAR, DISCOUNT_FACTOR_LINEAR_RIGHT_ZERO_RATE);
                    BoundCurveInterpolator bciDw = PRODUCT_LINEAR.bind(X_VALUES, DoubleArray.copyOf(yValuesDw), LINEAR, DISCOUNT_FACTOR_LINEAR_RIGHT_ZERO_RATE);
                    double expected = 0.5 * (bciUp.interpolate(key) - bciDw.interpolate(key)) / EPS;
                    assertEquals(computed.get(j), expected, EPS * 10d);
                }
            }
        }