Ejemplo n.º 1
0
        public virtual void test_zeroRatePointSensitivity_sensitivityCurrency()
        {
            LegalEntitySurvivalProbabilities test     = LegalEntitySurvivalProbabilities.of(LEGAL_ENTITY, DFS);
            CreditCurveZeroRateSensitivity   expected = CreditCurveZeroRateSensitivity.of(LEGAL_ENTITY, DFS.zeroRatePointSensitivity(DATE_AFTER, GBP));

            assertEquals(test.zeroRatePointSensitivity(DATE_AFTER, GBP), expected);
        }
Ejemplo n.º 2
0
        //-------------------------------------------------------------------------
        public virtual void test_build()
        {
            CreditCurveZeroRateSensitivity @base = CreditCurveZeroRateSensitivity.of(LEGAL_ENTITY, GBP, YEAR_FRACTION, 32d);
            PointSensitivities             test  = @base.build();

            assertEquals(test.Sensitivities, ImmutableList.of(@base));
        }
Ejemplo n.º 3
0
        //-------------------------------------------------------------------------
        public virtual void test_cloned()
        {
            CreditCurveZeroRateSensitivity @base = CreditCurveZeroRateSensitivity.of(LEGAL_ENTITY, GBP, YEAR_FRACTION, 32d);
            CreditCurveZeroRateSensitivity test  = @base.cloned();

            assertSame(test, @base);
        }
Ejemplo n.º 4
0
        //-------------------------------------------------------------------------
        public virtual void test_withCurrency()
        {
            CreditCurveZeroRateSensitivity @base = CreditCurveZeroRateSensitivity.of(LEGAL_ENTITY, USD, YEAR_FRACTION, VALUE);

            assertSame(@base.withCurrency(USD), @base);
            assertEquals(@base.withCurrency(GBP), CreditCurveZeroRateSensitivity.of(LEGAL_ENTITY, USD, YEAR_FRACTION, GBP, VALUE));
        }
Ejemplo n.º 5
0
        //-------------------------------------------------------------------------
        // proper end-to-end FD tests are in pricer test
        public virtual void test_parameterSensitivity()
        {
            LegalEntitySurvivalProbabilities test  = LegalEntitySurvivalProbabilities.of(LEGAL_ENTITY, DFS);
            CreditCurveZeroRateSensitivity   point = CreditCurveZeroRateSensitivity.of(LEGAL_ENTITY, ZeroRateSensitivity.of(USD, 1d, 1d));

            assertEquals(test.parameterSensitivity(point).size(), 1);
        }
Ejemplo n.º 6
0
        //-------------------------------------------------------------------------
        public virtual void test_unitParameterSensitivity()
        {
            LegalEntitySurvivalProbabilities test     = LegalEntitySurvivalProbabilities.of(LEGAL_ENTITY, DFS);
            CreditCurveZeroRateSensitivity   sens     = test.zeroRatePointSensitivity(DATE_AFTER);
            CurrencyParameterSensitivities   expected = DFS.parameterSensitivity(DFS.zeroRatePointSensitivity(DATE_AFTER));

            assertEquals(test.parameterSensitivity(sens), expected);
        }
Ejemplo n.º 7
0
        public virtual void test_zeroRatePointSensitivity_sensitivityCurrency_yearFraction()
        {
            double yearFraction = DFS.relativeYearFraction(DATE_AFTER);
            LegalEntitySurvivalProbabilities test     = LegalEntitySurvivalProbabilities.of(LEGAL_ENTITY, DFS);
            CreditCurveZeroRateSensitivity   expected = CreditCurveZeroRateSensitivity.of(LEGAL_ENTITY, DFS.zeroRatePointSensitivity(yearFraction, GBP));

            assertEquals(test.zeroRatePointSensitivity(yearFraction, GBP), expected);
        }
Ejemplo n.º 8
0
        //-------------------------------------------------------------------------
        public virtual void test_withSensitivity()
        {
            CreditCurveZeroRateSensitivity @base    = CreditCurveZeroRateSensitivity.of(LEGAL_ENTITY, USD, YEAR_FRACTION, VALUE);
            CreditCurveZeroRateSensitivity expected = CreditCurveZeroRateSensitivity.of(LEGAL_ENTITY, USD, YEAR_FRACTION, 20d);
            CreditCurveZeroRateSensitivity test     = @base.withSensitivity(20d);

            assertEquals(test, expected);
        }
Ejemplo n.º 9
0
        //-------------------------------------------------------------------------
        public virtual void test_mapSensitivity()
        {
            CreditCurveZeroRateSensitivity @base    = CreditCurveZeroRateSensitivity.of(LEGAL_ENTITY, GBP, YEAR_FRACTION, 32d);
            CreditCurveZeroRateSensitivity expected = CreditCurveZeroRateSensitivity.of(LEGAL_ENTITY, GBP, YEAR_FRACTION, 1 / 32d);
            CreditCurveZeroRateSensitivity test     = @base.mapSensitivity(s => 1 / s);

            assertEquals(test, expected);
        }
Ejemplo n.º 10
0
        //-------------------------------------------------------------------------
        public virtual void test_multipliedBy()
        {
            CreditCurveZeroRateSensitivity @base    = CreditCurveZeroRateSensitivity.of(LEGAL_ENTITY, GBP, YEAR_FRACTION, 32d);
            CreditCurveZeroRateSensitivity expected = CreditCurveZeroRateSensitivity.of(LEGAL_ENTITY, GBP, YEAR_FRACTION, 32d * 3.5d);
            CreditCurveZeroRateSensitivity test     = @base.multipliedBy(3.5d);

            assertEquals(test, expected);
        }
Ejemplo n.º 11
0
        //-------------------------------------------------------------------------
        public virtual void test_buildInto()
        {
            CreditCurveZeroRateSensitivity @base = CreditCurveZeroRateSensitivity.of(LEGAL_ENTITY, GBP, YEAR_FRACTION, 32d);
            MutablePointSensitivities      combo = new MutablePointSensitivities();
            MutablePointSensitivities      test  = @base.buildInto(combo);

            assertSame(test, combo);
            assertEquals(test.Sensitivities, ImmutableList.of(@base));
        }
Ejemplo n.º 12
0
        //-------------------------------------------------------------------------
        public virtual void coverage()
        {
            CreditCurveZeroRateSensitivity test = CreditCurveZeroRateSensitivity.of(LEGAL_ENTITY, GBP, YEAR_FRACTION, 32d);

            coverImmutableBean(test);
            CreditCurveZeroRateSensitivity test2 = CreditCurveZeroRateSensitivity.of(StandardId.of("OG", "AAA"), USD, YEAR_FRACTION, 16d);

            coverBeanEquals(test, test2);
        }
Ejemplo n.º 13
0
 public int compareKey(PointSensitivity other)
 {
     if (other is CreditCurveZeroRateSensitivity)
     {
         CreditCurveZeroRateSensitivity otherZero = (CreditCurveZeroRateSensitivity)other;
         return(ComparisonChain.start().compare(zeroRateSensitivity.YearFraction, otherZero.zeroRateSensitivity.YearFraction).compare(zeroRateSensitivity.Currency, otherZero.zeroRateSensitivity.Currency).compare(zeroRateSensitivity.CurveCurrency, otherZero.zeroRateSensitivity.CurveCurrency).compare(legalEntityId, otherZero.legalEntityId).result());
     }
     return(this.GetType().Name.CompareTo(other.GetType().Name));
 }
Ejemplo n.º 14
0
        public virtual void test_combinedWith_mutable()
        {
            CreditCurveZeroRateSensitivity @base    = CreditCurveZeroRateSensitivity.of(LEGAL_ENTITY, GBP, YEAR_FRACTION, 32d);
            MutablePointSensitivities      expected = new MutablePointSensitivities();

            expected.add(@base);
            PointSensitivityBuilder test = @base.combinedWith(new MutablePointSensitivities());

            assertEquals(test, expected);
        }
Ejemplo n.º 15
0
        public virtual void test_of()
        {
            CreditCurveZeroRateSensitivity test = CreditCurveZeroRateSensitivity.of(LEGAL_ENTITY, USD, YEAR_FRACTION, VALUE);

            assertEquals(test.Currency, USD);
            assertEquals(test.CurveCurrency, USD);
            assertEquals(test.LegalEntityId, LEGAL_ENTITY);
            assertEquals(test.Sensitivity, VALUE);
            assertEquals(test.YearFraction, YEAR_FRACTION);
        }
Ejemplo n.º 16
0
        //-------------------------------------------------------------------------
        public virtual void test_combinedWith()
        {
            CreditCurveZeroRateSensitivity base1    = CreditCurveZeroRateSensitivity.of(LEGAL_ENTITY, GBP, YEAR_FRACTION, 32d);
            CreditCurveZeroRateSensitivity base2    = CreditCurveZeroRateSensitivity.of(LEGAL_ENTITY, GBP, YEAR_FRACTION, 22d);
            MutablePointSensitivities      expected = new MutablePointSensitivities();

            expected.add(base1).add(base2);
            PointSensitivityBuilder test = base1.combinedWith(base2);

            assertEquals(test, expected);
        }
        public virtual void test_singleDiscountCurveParameterSensitivity()
        {
            ZeroRateSensitivity            zeroPt   = ZeroRateSensitivity.of(USD, 10d, 5d);
            CreditCurveZeroRateSensitivity creditPt = CreditCurveZeroRateSensitivity.of(LEGAL_ENTITY_ABC, JPY, 2d, 3d);
            FxForwardSensitivity           fxPt     = FxForwardSensitivity.of(CurrencyPair.of(JPY, USD), USD, LocalDate.of(2017, 2, 14), 15d);
            CreditRatesProvider            test     = ImmutableCreditRatesProvider.builder().creditCurves(ImmutableMap.of(Pair.of(LEGAL_ENTITY_ABC, USD), LegalEntitySurvivalProbabilities.of(LEGAL_ENTITY_ABC, CRD_ABC_USD), Pair.of(LEGAL_ENTITY_ABC, JPY), LegalEntitySurvivalProbabilities.of(LEGAL_ENTITY_ABC, CRD_ABC_JPY), Pair.of(LEGAL_ENTITY_DEF, JPY), LegalEntitySurvivalProbabilities.of(LEGAL_ENTITY_DEF, CRD_DEF))).discountCurves(ImmutableMap.of(USD, DSC_USD, JPY, DSC_JPY)).recoveryRateCurves(ImmutableMap.of(LEGAL_ENTITY_ABC, RR_ABC, LEGAL_ENTITY_DEF, RR_DEF)).valuationDate(VALUATION).build();
            CurrencyParameterSensitivities computed = CurrencyParameterSensitivities.of(test.singleDiscountCurveParameterSensitivity(zeroPt.combinedWith(creditPt).combinedWith(fxPt).build(), USD));
            CurrencyParameterSensitivities expected = DSC_USD.parameterSensitivity(zeroPt);

            assertTrue(computed.equalWithTolerance(expected, 1.0e-14));
        }
Ejemplo n.º 18
0
        public virtual void test_of_ZeroRateSensitivity()
        {
            ZeroRateSensitivity            zeroPoint = ZeroRateSensitivity.of(USD, YEAR_FRACTION, GBP, VALUE);
            CreditCurveZeroRateSensitivity test      = CreditCurveZeroRateSensitivity.of(LEGAL_ENTITY, zeroPoint);

            assertEquals(test.Currency, GBP);
            assertEquals(test.CurveCurrency, USD);
            assertEquals(test.LegalEntityId, LEGAL_ENTITY);
            assertEquals(test.Sensitivity, VALUE);
            assertEquals(test.YearFraction, YEAR_FRACTION);
            assertEquals(test.toZeroRateSensitivity(), zeroPoint);
        }
Ejemplo n.º 19
0
 //-----------------------------------------------------------------------
 public override bool Equals(object obj)
 {
     if (obj == this)
     {
         return(true);
     }
     if (obj != null && obj.GetType() == this.GetType())
     {
         CreditCurveZeroRateSensitivity other = (CreditCurveZeroRateSensitivity)obj;
         return(JodaBeanUtils.equal(legalEntityId, other.legalEntityId) && JodaBeanUtils.equal(zeroRateSensitivity, other.zeroRateSensitivity));
     }
     return(false);
 }
Ejemplo n.º 20
0
        //-------------------------------------------------------------------------
        public virtual void test_convertedTo()
        {
            double sensi = 32d;
            CreditCurveZeroRateSensitivity @base = CreditCurveZeroRateSensitivity.of(LEGAL_ENTITY, GBP, YEAR_FRACTION, sensi);
            double   rate   = 1.5d;
            FxMatrix matrix = FxMatrix.of(CurrencyPair.of(GBP, USD), rate);
            CreditCurveZeroRateSensitivity test1    = @base.convertedTo(USD, matrix);
            CreditCurveZeroRateSensitivity expected = CreditCurveZeroRateSensitivity.of(LEGAL_ENTITY, GBP, YEAR_FRACTION, USD, rate * sensi);

            assertEquals(test1, expected);
            CreditCurveZeroRateSensitivity test2 = @base.convertedTo(GBP, matrix);

            assertEquals(test2, @base);
        }
Ejemplo n.º 21
0
        //-------------------------------------------------------------------------
        public virtual void test_compareKey()
        {
            CreditCurveZeroRateSensitivity a1    = CreditCurveZeroRateSensitivity.of(LEGAL_ENTITY, GBP, YEAR_FRACTION, 32d);
            CreditCurveZeroRateSensitivity a2    = CreditCurveZeroRateSensitivity.of(LEGAL_ENTITY, GBP, YEAR_FRACTION, 32d);
            CreditCurveZeroRateSensitivity b     = CreditCurveZeroRateSensitivity.of(LEGAL_ENTITY, GBP, 10d, 32d);
            CreditCurveZeroRateSensitivity c     = CreditCurveZeroRateSensitivity.of(LEGAL_ENTITY, USD, YEAR_FRACTION, 32d);
            CreditCurveZeroRateSensitivity d     = CreditCurveZeroRateSensitivity.of(LEGAL_ENTITY, USD, YEAR_FRACTION, GBP, 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(a1.compareKey(d) < 0, true);
            assertEquals(c.compareKey(a1) > 0, true);
            assertEquals(a1.compareKey(other) < 0, true);
            assertEquals(other.compareKey(a1) > 0, true);
        }
Ejemplo n.º 22
0
        public CurrencyParameterSensitivity singleCreditCurveParameterSensitivity(PointSensitivities pointSensitivities, StandardId legalEntityId, Currency currency)
        {
            CurrencyParameterSensitivities sens = CurrencyParameterSensitivities.empty();

            foreach (PointSensitivity point in pointSensitivities.Sensitivities)
            {
                if (point is CreditCurveZeroRateSensitivity)
                {
                    CreditCurveZeroRateSensitivity pt = (CreditCurveZeroRateSensitivity)point;
                    if (pt.LegalEntityId.Equals(legalEntityId) && pt.Currency.Equals(currency))
                    {
                        LegalEntitySurvivalProbabilities factors = survivalProbabilities(pt.LegalEntityId, pt.CurveCurrency);
                        sens = sens.combinedWith(factors.parameterSensitivity(pt));
                    }
                }
            }
            ArgChecker.isTrue(sens.size() == 1, "sensitivity must be unique");
            return(sens.Sensitivities.get(0));
        }
Ejemplo n.º 23
0
        //-------------------------------------------------------------------------
        public CurrencyParameterSensitivities parameterSensitivity(PointSensitivities pointSensitivities)
        {
            CurrencyParameterSensitivities sens = CurrencyParameterSensitivities.empty();

            foreach (PointSensitivity point in pointSensitivities.Sensitivities)
            {
                if (point is CreditCurveZeroRateSensitivity)
                {
                    CreditCurveZeroRateSensitivity   pt      = (CreditCurveZeroRateSensitivity)point;
                    LegalEntitySurvivalProbabilities factors = survivalProbabilities(pt.LegalEntityId, pt.CurveCurrency);
                    sens = sens.combinedWith(factors.parameterSensitivity(pt));
                }
                else if (point is ZeroRateSensitivity)
                {
                    ZeroRateSensitivity   pt      = (ZeroRateSensitivity)point;
                    CreditDiscountFactors factors = discountFactors(pt.CurveCurrency);
                    sens = sens.combinedWith(factors.parameterSensitivity(pt));
                }
            }
            return(sens);
        }
Ejemplo n.º 24
0
        /// <summary>
        /// Calculates the zero rate point sensitivity at the specified date specifying the currency of the sensitivity.
        /// <para>
        /// This returns a sensitivity instance referring to the zero hazard rate sensitivity of the
        /// points that were queried in the market data.
        /// The sensitivity typically has the value {@code (-survivalProbability * yearFraction)}.
        /// The sensitivity refers to the result of <seealso cref="#survivalProbability(LocalDate)"/>.
        /// </para>
        /// <para>
        /// This method allows the currency of the sensitivity to differ from the currency of the market data.
        ///
        /// </para>
        /// </summary>
        /// <param name="date">  the date </param>
        /// <param name="sensitivityCurrency">  the currency of the sensitivity </param>
        /// <returns> the point sensitivity of the zero rate </returns>
        /// <exception cref="RuntimeException"> if the result cannot be calculated </exception>
        public CreditCurveZeroRateSensitivity zeroRatePointSensitivity(LocalDate date, Currency sensitivityCurrency)
        {
            ZeroRateSensitivity zeroRateSensitivity = survivalProbabilities.zeroRatePointSensitivity(date, sensitivityCurrency);

            return(CreditCurveZeroRateSensitivity.of(legalEntityId, zeroRateSensitivity));
        }
Ejemplo n.º 25
0
 /// <summary>
 /// Calculates the parameter sensitivity from the point sensitivity.
 /// <para>
 /// This is used to convert a single point sensitivity to parameter sensitivity.
 /// The calculation typically involves multiplying the point and unit sensitivities.
 ///
 /// </para>
 /// </summary>
 /// <param name="pointSensitivity">  the point sensitivity to convert </param>
 /// <returns> the parameter sensitivity </returns>
 /// <exception cref="RuntimeException"> if the result cannot be calculated </exception>
 public CurrencyParameterSensitivities parameterSensitivity(CreditCurveZeroRateSensitivity pointSensitivity)
 {
     return(survivalProbabilities.parameterSensitivity(pointSensitivity.toZeroRateSensitivity()));
 }
Ejemplo n.º 26
0
        public virtual void test_serialization()
        {
            CreditCurveZeroRateSensitivity test = CreditCurveZeroRateSensitivity.of(LEGAL_ENTITY, GBP, YEAR_FRACTION, 32d);

            assertSerialization(test);
        }
Ejemplo n.º 27
0
        /// <summary>
        /// Calculates the zero rate point sensitivity at the specified year fraction specifying the currency of the sensitivity.
        /// <para>
        /// This returns a sensitivity instance referring to the zero hazard rate sensitivity of the
        /// points that were queried in the market data.
        /// The sensitivity typically has the value {@code (-survivalProbability * yearFraction)}.
        /// The sensitivity refers to the result of <seealso cref="#survivalProbability(LocalDate)"/>.
        /// </para>
        /// <para>
        /// This method allows the currency of the sensitivity to differ from the currency of the market data.
        ///
        /// </para>
        /// </summary>
        /// <param name="yearFraction">  the year fraction </param>
        /// <param name="sensitivityCurrency">  the currency of the sensitivity </param>
        /// <returns> the point sensitivity of the zero rate </returns>
        /// <exception cref="RuntimeException"> if the result cannot be calculated </exception>
        public CreditCurveZeroRateSensitivity zeroRatePointSensitivity(double yearFraction, Currency sensitivityCurrency)
        {
            ZeroRateSensitivity zeroRateSensitivity = survivalProbabilities.zeroRatePointSensitivity(yearFraction, sensitivityCurrency);

            return(CreditCurveZeroRateSensitivity.of(legalEntityId, zeroRateSensitivity));
        }