Пример #1
0
        //-------------------------------------------------------------------------
        public virtual void test_compareKey()
        {
            ZeroRateSensitivity a1    = ZeroRateSensitivity.of(GBP, YEARFRAC, 32d);
            ZeroRateSensitivity a2    = ZeroRateSensitivity.of(GBP, YEARFRAC, 32d);
            ZeroRateSensitivity b     = ZeroRateSensitivity.of(USD, YEARFRAC, 32d);
            ZeroRateSensitivity c     = ZeroRateSensitivity.of(GBP, YEARFRAC2, 32d);
            IborRateSensitivity other = IborRateSensitivity.of(IborIndexObservation.of(GBP_LIBOR_3M, date(2014, 6, 30), REF_DATA), 32d);

            assertEquals(a1.compareKey(a2), 0);
            assertEquals(a1.compareKey(b) < 0, true);
            assertEquals(b.compareKey(a1) > 0, true);
            assertEquals(a1.compareKey(c) < 0, true);
            assertEquals(c.compareKey(a1) > 0, true);
            assertEquals(a1.compareKey(other) > 0, true);
            assertEquals(other.compareKey(a1) < 0, true);
        }
        public virtual void test_zeroRatePointSensitivityWithSpread_sensitivityCurrency_smallYearFraction()
        {
            ZeroRatePeriodicDiscountFactors test     = ZeroRatePeriodicDiscountFactors.of(GBP, DATE_VAL, CURVE);
            ZeroRateSensitivity             expected = ZeroRateSensitivity.of(GBP, 0d, USD, 0.0d);
            ZeroRateSensitivity             computed = test.zeroRatePointSensitivityWithSpread(DATE_VAL, USD, SPREAD, CONTINUOUS, 0);

            assertTrue(computed.compareKey(expected) == 0);
            assertEquals(computed.Sensitivity, expected.Sensitivity, TOLERANCE_DELTA_FD);
        }
        public virtual void test_zeroRatePointSensitivityWithSpread_sensitivityCurrency_continous()
        {
            ZeroRatePeriodicDiscountFactors test = ZeroRatePeriodicDiscountFactors.of(GBP, DATE_VAL, CURVE);
            double relativeYearFraction          = ACT_365F.relativeYearFraction(DATE_VAL, DATE_AFTER);
            double df = test.discountFactorWithSpread(DATE_AFTER, SPREAD, CONTINUOUS, 0);
            ZeroRateSensitivity expected = ZeroRateSensitivity.of(GBP, relativeYearFraction, USD, -df * relativeYearFraction);
            ZeroRateSensitivity computed = test.zeroRatePointSensitivityWithSpread(DATE_AFTER, USD, SPREAD, CONTINUOUS, 0);

            assertTrue(computed.compareKey(expected) == 0);
            assertEquals(computed.Sensitivity, expected.Sensitivity, TOLERANCE_DELTA);
        }
        public virtual void test_zeroRatePointSensitivityWithSpread_sensitivityCurrency_periodic()
        {
            int periodPerYear = 4;
            ZeroRatePeriodicDiscountFactors test = ZeroRatePeriodicDiscountFactors.of(GBP, DATE_VAL, CURVE);
            double relativeYearFraction          = ACT_365F.relativeYearFraction(DATE_VAL, DATE_AFTER);
            double df     = test.discountFactor(DATE_AFTER);
            double z      = -1.0 / relativeYearFraction * Math.Log(df);
            double shift  = 1.0E-6;
            double zP     = z + shift;
            double zM     = z - shift;
            double dfSP   = Math.Pow(Math.Pow(Math.Exp(-zP * relativeYearFraction), -1.0 / (relativeYearFraction * periodPerYear)) + SPREAD / periodPerYear, -relativeYearFraction * periodPerYear);
            double dfSM   = Math.Pow(Math.Pow(Math.Exp(-zM * relativeYearFraction), -1.0 / (relativeYearFraction * periodPerYear)) + SPREAD / periodPerYear, -relativeYearFraction * periodPerYear);
            double ddfSdz = (dfSP - dfSM) / (2 * shift);
            ZeroRateSensitivity expected = ZeroRateSensitivity.of(GBP, relativeYearFraction, USD, ddfSdz);
            ZeroRateSensitivity computed = test.zeroRatePointSensitivityWithSpread(DATE_AFTER, USD, SPREAD, PERIODIC, periodPerYear);

            assertTrue(computed.compareKey(expected) == 0);
            assertEquals(computed.Sensitivity, expected.Sensitivity, TOLERANCE_DELTA_FD);
        }