コード例 #1
0
        //-------------------------------------------------------------------------
        // proper end-to-end FD tests are elsewhere
        public virtual void test_parameterSensitivity()
        {
            ZeroRateDiscountFactors test  = ZeroRateDiscountFactors.of(GBP, DATE_VAL, CURVE);
            ZeroRateSensitivity     point = ZeroRateSensitivity.of(GBP, 1d, 1d);

            assertEquals(test.parameterSensitivity(point).size(), 1);
        }
コード例 #2
0
        public virtual void test_zeroRatePointSensitivityWithSpread_smallYearFraction()
        {
            ZeroRateDiscountFactors test     = ZeroRateDiscountFactors.of(GBP, DATE_VAL, CURVE);
            ZeroRateSensitivity     expected = ZeroRateSensitivity.of(GBP, 0d, -0d);

            assertEquals(test.zeroRatePointSensitivityWithSpread(DATE_VAL, SPREAD, CONTINUOUS, 0), expected);
        }
コード例 #3
0
        public virtual void test_zeroRatePointSensitivityWithSpread_sensitivityCurrency_smallYearFraction()
        {
            ZeroRateDiscountFactors test     = ZeroRateDiscountFactors.of(GBP, DATE_VAL, CURVE);
            ZeroRateSensitivity     expected = ZeroRateSensitivity.of(GBP, 0d, USD, -0d);

            assertEquals(test.zeroRatePointSensitivityWithSpread(DATE_VAL, USD, SPREAD, PERIODIC, 2), expected);
        }
コード例 #4
0
        //-------------------------------------------------------------------------
        public virtual void test_discountFactorWithSpread_continuous()
        {
            ZeroRateDiscountFactors test = ZeroRateDiscountFactors.of(GBP, DATE_VAL, CURVE);
            double relativeYearFraction  = ACT_365F.relativeYearFraction(DATE_VAL, DATE_AFTER);
            double expected = Math.Exp(-relativeYearFraction * (CURVE.yValue(relativeYearFraction) + SPREAD));

            assertEquals(test.discountFactorWithSpread(DATE_AFTER, SPREAD, CONTINUOUS, 0), expected, TOL);
        }
コード例 #5
0
        //-------------------------------------------------------------------------
        public virtual void test_discountFactor()
        {
            ZeroRateDiscountFactors test = ZeroRateDiscountFactors.of(GBP, DATE_VAL, CURVE);
            double relativeYearFraction  = ACT_365F.relativeYearFraction(DATE_VAL, DATE_AFTER);
            double expected = Math.Exp(-relativeYearFraction * CURVE.yValue(relativeYearFraction));

            assertEquals(test.discountFactor(DATE_AFTER), expected);
        }
コード例 #6
0
        //-------------------------------------------------------------------------
        public virtual void test_createParameterSensitivity()
        {
            ZeroRateDiscountFactors        test          = ZeroRateDiscountFactors.of(GBP, DATE_VAL, CURVE);
            DoubleArray                    sensitivities = DoubleArray.of(0.12, 0.15);
            CurrencyParameterSensitivities sens          = test.createParameterSensitivity(USD, sensitivities);

            assertEquals(sens.Sensitivities.get(0), CURVE.createParameterSensitivity(USD, sensitivities));
        }
コード例 #7
0
        //-------------------------------------------------------------------------
        public virtual void coverage()
        {
            ZeroRateDiscountFactors test = ZeroRateDiscountFactors.of(GBP, DATE_VAL, CURVE);

            coverImmutableBean(test);
            ZeroRateDiscountFactors test2 = ZeroRateDiscountFactors.of(USD, DATE_VAL.plusDays(1), CURVE2);

            coverBeanEquals(test, test2);
        }
コード例 #8
0
        //-------------------------------------------------------------------------
        public virtual void test_zeroRate()
        {
            ZeroRateDiscountFactors test = ZeroRateDiscountFactors.of(GBP, DATE_VAL, CURVE);
            double relativeYearFraction  = ACT_365F.relativeYearFraction(DATE_VAL, DATE_AFTER);
            double discountFactor        = test.discountFactor(DATE_AFTER);
            double zeroRate = test.zeroRate(DATE_AFTER);

            assertEquals(Math.Exp(-zeroRate * relativeYearFraction), discountFactor);
        }
コード例 #9
0
        public virtual void test_zeroRatePointSensitivityWithSpread_sensitivityCurrency_continous()
        {
            ZeroRateDiscountFactors test = ZeroRateDiscountFactors.of(GBP, DATE_VAL, CURVE);
            double relativeYearFraction  = ACT_365F.relativeYearFraction(DATE_VAL, DATE_AFTER);
            double df = Math.Exp(-relativeYearFraction * (CURVE.yValue(relativeYearFraction) + SPREAD));
            ZeroRateSensitivity expected = ZeroRateSensitivity.of(GBP, relativeYearFraction, USD, -df * relativeYearFraction);

            assertEquals(test.zeroRatePointSensitivityWithSpread(DATE_AFTER, USD, SPREAD, CONTINUOUS, 0), expected);
        }
コード例 #10
0
        public virtual void test_zeroRatePointSensitivity_sensitivityCurrency()
        {
            ZeroRateDiscountFactors test = ZeroRateDiscountFactors.of(GBP, DATE_VAL, CURVE);
            double relativeYearFraction  = ACT_365F.relativeYearFraction(DATE_VAL, DATE_AFTER);
            double df = Math.Exp(-relativeYearFraction * CURVE.yValue(relativeYearFraction));
            ZeroRateSensitivity expected = ZeroRateSensitivity.of(GBP, relativeYearFraction, USD, -df * relativeYearFraction);

            assertEquals(test.zeroRatePointSensitivity(DATE_AFTER, USD), expected);
        }
コード例 #11
0
        //-------------------------------------------------------------------------
        public virtual void test_unitParameterSensitivity()
        {
            ZeroRateDiscountFactors test = ZeroRateDiscountFactors.of(GBP, DATE_VAL, CURVE);
            ZeroRateSensitivity     sens = test.zeroRatePointSensitivity(DATE_AFTER);

            double relativeYearFraction             = ACT_365F.relativeYearFraction(DATE_VAL, DATE_AFTER);
            CurrencyParameterSensitivities expected = CurrencyParameterSensitivities.of(CURVE.yValueParameterSensitivity(relativeYearFraction).multipliedBy(sens.Currency, sens.Sensitivity));

            assertEquals(test.parameterSensitivity(sens), expected);
        }
コード例 #12
0
        public virtual void test_of_badCurve()
        {
            InterpolatedNodalCurve notYearFraction    = InterpolatedNodalCurve.of(Curves.prices(NAME), DoubleArray.of(0, 10), DoubleArray.of(1, 2), INTERPOLATOR);
            InterpolatedNodalCurve notZeroRate        = InterpolatedNodalCurve.of(Curves.discountFactors(NAME, ACT_365F), DoubleArray.of(0, 10), DoubleArray.of(1, 2), INTERPOLATOR);
            CurveMetadata          noDayCountMetadata = DefaultCurveMetadata.builder().curveName(NAME).xValueType(ValueType.YEAR_FRACTION).yValueType(ValueType.ZERO_RATE).build();
            InterpolatedNodalCurve notDayCount        = InterpolatedNodalCurve.of(noDayCountMetadata, DoubleArray.of(0, 10), DoubleArray.of(1, 2), INTERPOLATOR);

            assertThrowsIllegalArg(() => ZeroRateDiscountFactors.of(GBP, DATE_VAL, notYearFraction));
            assertThrowsIllegalArg(() => ZeroRateDiscountFactors.of(GBP, DATE_VAL, notZeroRate));
            assertThrowsIllegalArg(() => ZeroRateDiscountFactors.of(GBP, DATE_VAL, notDayCount));
        }
コード例 #13
0
        public virtual void test_discountFactorWithSpread_periodic()
        {
            int periodPerYear            = 4;
            ZeroRateDiscountFactors test = ZeroRateDiscountFactors.of(GBP, DATE_VAL, CURVE);
            double relativeYearFraction  = ACT_365F.relativeYearFraction(DATE_VAL, DATE_AFTER);
            double discountFactorBase    = test.discountFactor(DATE_AFTER);
            double rate     = (Math.Pow(discountFactorBase, -1d / periodPerYear / relativeYearFraction) - 1d) * periodPerYear;
            double expected = discountFactorFromPeriodicallyCompoundedRate(rate + SPREAD, periodPerYear, relativeYearFraction);

            assertEquals(test.discountFactorWithSpread(DATE_AFTER, SPREAD, PERIODIC, periodPerYear), expected, TOL);
        }
コード例 #14
0
 //-----------------------------------------------------------------------
 public override bool Equals(object obj)
 {
     if (obj == this)
     {
         return(true);
     }
     if (obj != null && obj.GetType() == this.GetType())
     {
         ZeroRateDiscountFactors other = (ZeroRateDiscountFactors)obj;
         return(JodaBeanUtils.equal(currency, other.currency) && JodaBeanUtils.equal(valuationDate, other.valuationDate) && JodaBeanUtils.equal(curve, other.curve));
     }
     return(false);
 }
コード例 #15
0
        //-------------------------------------------------------------------------
        public virtual void test_of()
        {
            ZeroRateDiscountFactors test = ZeroRateDiscountFactors.of(GBP, DATE_VAL, CURVE);

            assertEquals(test.Currency, GBP);
            assertEquals(test.ValuationDate, DATE_VAL);
            assertEquals(test.Curve, CURVE);
            assertEquals(test.ParameterCount, CURVE.ParameterCount);
            assertEquals(test.getParameter(0), CURVE.getParameter(0));
            assertEquals(test.getParameterMetadata(0), CURVE.getParameterMetadata(0));
            assertEquals(test.withParameter(0, 1d).Curve, CURVE.withParameter(0, 1d));
            assertEquals(test.withPerturbation((i, v, m) => v + 1d).Curve, CURVE.withPerturbation((i, v, m) => v + 1d));
            assertEquals(test.findData(CURVE.Name), CURVE);
            assertEquals(test.findData(CurveName.of("Rubbish")), null);
        }
コード例 #16
0
        public virtual void test_zeroRatePointSensitivityWithSpread_sensitivityCurrency_periodic()
        {
            int periodPerYear            = 4;
            ZeroRateDiscountFactors test = ZeroRateDiscountFactors.of(GBP, DATE_VAL, CURVE);
            double relativeYearFraction  = ACT_365F.relativeYearFraction(DATE_VAL, DATE_AFTER);
            double discountFactorUp      = Math.Exp(-(CURVE.yValue(relativeYearFraction) + EPS) * relativeYearFraction);
            double discountFactorDw      = Math.Exp(-(CURVE.yValue(relativeYearFraction) - EPS) * relativeYearFraction);
            double rateUp                = (Math.Pow(discountFactorUp, -1d / periodPerYear / relativeYearFraction) - 1d) * periodPerYear;
            double rateDw                = (Math.Pow(discountFactorDw, -1d / periodPerYear / relativeYearFraction) - 1d) * periodPerYear;
            double expectedValue         = 0.5 / EPS * (discountFactorFromPeriodicallyCompoundedRate(rateUp + SPREAD, periodPerYear, relativeYearFraction) - discountFactorFromPeriodicallyCompoundedRate(rateDw + SPREAD, periodPerYear, relativeYearFraction));
            ZeroRateSensitivity computed = test.zeroRatePointSensitivityWithSpread(DATE_AFTER, USD, SPREAD, PERIODIC, periodPerYear);

            assertEquals(computed.Sensitivity, expectedValue, EPS);
            assertEquals(computed.Currency, USD);
            assertEquals(computed.CurveCurrency, GBP);
            assertEquals(computed.YearFraction, relativeYearFraction);
        }
コード例 #17
0
        //-------------------------------------------------------------------------
        public virtual void test_withCurve()
        {
            ZeroRateDiscountFactors test = ZeroRateDiscountFactors.of(GBP, DATE_VAL, CURVE).withCurve(CURVE2);

            assertEquals(test.Curve, CURVE2);
        }
コード例 #18
0
        public virtual void test_discountFactorWithSpread_smallYearFraction()
        {
            ZeroRateDiscountFactors test = ZeroRateDiscountFactors.of(GBP, DATE_VAL, CURVE);

            assertEquals(test.discountFactorWithSpread(DATE_VAL, SPREAD, PERIODIC, 1), 1d, TOL);
        }