Esempio n. 1
0
        public virtual void test_cloned()
        {
            RepoCurveZeroRateSensitivity @base = RepoCurveZeroRateSensitivity.of(CURRENCY, YEARFRAC, GROUP, VALUE);
            RepoCurveZeroRateSensitivity test  = @base.cloned();

            assertEquals(test, @base);
        }
Esempio n. 2
0
        public virtual void test_createZeroRateSensitivity()
        {
            RepoCurveZeroRateSensitivity @base    = RepoCurveZeroRateSensitivity.of(CURRENCY, YEARFRAC, GBP, GROUP, VALUE);
            ZeroRateSensitivity          expected = ZeroRateSensitivity.of(CURRENCY, YEARFRAC, GBP, VALUE);
            ZeroRateSensitivity          test     = @base.createZeroRateSensitivity();

            assertEquals(test, expected);
        }
Esempio n. 3
0
        public virtual void test_mapSensitivity()
        {
            RepoCurveZeroRateSensitivity @base    = RepoCurveZeroRateSensitivity.of(CURRENCY, YEARFRAC, GROUP, VALUE);
            RepoCurveZeroRateSensitivity expected = RepoCurveZeroRateSensitivity.of(CURRENCY, YEARFRAC, GROUP, 1d / VALUE);
            RepoCurveZeroRateSensitivity test     = @base.mapSensitivity(s => 1d / s);

            assertEquals(test, expected);
        }
Esempio n. 4
0
        public virtual void test_zeroRatePointSensitivity_USD()
        {
            RepoCurveDiscountFactors     @base    = RepoCurveDiscountFactors.of(DSC_FACTORS, GROUP);
            RepoCurveZeroRateSensitivity expected = RepoCurveZeroRateSensitivity.of(DSC_FACTORS.zeroRatePointSensitivity(DATE_AFTER, USD), GROUP);
            RepoCurveZeroRateSensitivity computed = @base.zeroRatePointSensitivity(DATE_AFTER, USD);

            assertEquals(computed, expected);
        }
Esempio n. 5
0
        public virtual void test_buildInto()
        {
            RepoCurveZeroRateSensitivity @base = RepoCurveZeroRateSensitivity.of(CURRENCY, YEARFRAC, GROUP, VALUE);
            MutablePointSensitivities    combo = new MutablePointSensitivities();
            MutablePointSensitivities    test  = @base.buildInto(combo);

            assertSame(test, combo);
            assertEquals(test.Sensitivities, ImmutableList.of(@base));
        }
Esempio n. 6
0
        //-------------------------------------------------------------------------
        public virtual void test_multipliedBy()
        {
            RepoCurveZeroRateSensitivity @base = RepoCurveZeroRateSensitivity.of(CURRENCY, YEARFRAC, GROUP, VALUE);
            double rate = 2.4d;
            RepoCurveZeroRateSensitivity test     = @base.multipliedBy(rate);
            RepoCurveZeroRateSensitivity expected = RepoCurveZeroRateSensitivity.of(CURRENCY, YEARFRAC, GROUP, VALUE * rate);

            assertEquals(test, expected);
        }
Esempio n. 7
0
 public int compareKey(PointSensitivity other)
 {
     if (other is RepoCurveZeroRateSensitivity)
     {
         RepoCurveZeroRateSensitivity otherZero = (RepoCurveZeroRateSensitivity)other;
         return(ComparisonChain.start().compare(curveCurrency, otherZero.curveCurrency).compare(currency, otherZero.currency).compare(yearFraction, otherZero.yearFraction).compare(repoGroup, otherZero.repoGroup).result());
     }
     return(this.GetType().Name.CompareTo(other.GetType().Name));
 }
Esempio n. 8
0
        public virtual void test_parameterSensitivity()
        {
            RepoCurveDiscountFactors       @base    = RepoCurveDiscountFactors.of(DSC_FACTORS, GROUP);
            RepoCurveZeroRateSensitivity   sensi    = @base.zeroRatePointSensitivity(DATE_AFTER, USD);
            CurrencyParameterSensitivities computed = @base.parameterSensitivity(sensi);
            CurrencyParameterSensitivities expected = DSC_FACTORS.parameterSensitivity(DSC_FACTORS.zeroRatePointSensitivity(DATE_AFTER, USD));

            assertEquals(computed, expected);
        }
Esempio n. 9
0
        //-------------------------------------------------------------------------
        public virtual void coverage()
        {
            RepoCurveZeroRateSensitivity test1 = RepoCurveZeroRateSensitivity.of(CURRENCY, YEARFRAC, GROUP, VALUE);

            coverImmutableBean(test1);
            RepoCurveZeroRateSensitivity test2 = RepoCurveZeroRateSensitivity.of(GBP, YEARFRAC2, RepoGroup.of("ISSUER2 BND 5Y"), 12d);

            coverBeanEquals(test1, test2);
        }
Esempio n. 10
0
        public virtual void test_of_withoutSensitivityCurrency()
        {
            RepoCurveZeroRateSensitivity test = RepoCurveZeroRateSensitivity.of(CURRENCY, YEARFRAC, GROUP, VALUE);

            assertEquals(test.RepoGroup, GROUP);
            assertEquals(test.CurveCurrency, CURRENCY);
            assertEquals(test.Currency, CURRENCY);
            assertEquals(test.YearFraction, YEARFRAC);
            assertEquals(test.Sensitivity, VALUE);
        }
Esempio n. 11
0
        //-------------------------------------------------------------------------
        private PointSensitivities presentValueSensitivitySettlement(Payment settlement, RepoCurveDiscountFactors repoDf)
        {
            PointSensitivityBuilder pointSettle = paymentPricer.presentValueSensitivity(settlement, repoDf.DiscountFactors);

            if (pointSettle is ZeroRateSensitivity)
            {
                return(RepoCurveZeroRateSensitivity.of((ZeroRateSensitivity)pointSettle, repoDf.RepoGroup).build());
            }
            return(pointSettle.build());    // NoPointSensitivity
        }
Esempio n. 12
0
        public virtual void test_withSensitivity()
        {
            RepoCurveZeroRateSensitivity @base = RepoCurveZeroRateSensitivity.of(CURRENCY, YEARFRAC, GROUP, VALUE);
            double newValue = 53d;
            RepoCurveZeroRateSensitivity test = @base.withSensitivity(newValue);

            assertEquals(test.RepoGroup, GROUP);
            assertEquals(test.CurveCurrency, CURRENCY);
            assertEquals(test.Currency, CURRENCY);
            assertEquals(test.YearFraction, YEARFRAC);
            assertEquals(test.Sensitivity, newValue);
        }
Esempio n. 13
0
        private PointSensitivityBuilder presentValueSensitivityPayment(ResolvedFixedCouponBondTrade trade, LegalEntityDiscountingProvider provider)
        {
            RepoCurveDiscountFactors repoDf = DiscountingFixedCouponBondProductPricer.repoCurveDf(trade.Product, provider);
            Payment upfrontPayment          = this.upfrontPayment(trade);
            PointSensitivityBuilder pt      = paymentPricer.presentValueSensitivity(upfrontPayment, repoDf.DiscountFactors);

            if (pt is ZeroRateSensitivity)
            {
                return(RepoCurveZeroRateSensitivity.of((ZeroRateSensitivity)pt, repoDf.RepoGroup));
            }
            return(pt);    // NoPointSensitivity
        }
Esempio n. 14
0
        public virtual void test_curveParameterSensitivity()
        {
            ImmutableLegalEntityDiscountingProvider test = ImmutableLegalEntityDiscountingProvider.builder().issuerCurves(ImmutableMap.of(Pair.of(GROUP_ISSUER, GBP), DSC_FACTORS_ISSUER)).issuerCurveGroups(ImmutableMap.of(ID_ISSUER, GROUP_ISSUER)).repoCurves(ImmutableMap.of(Pair.of(GROUP_REPO_ISSUER, GBP), DSC_FACTORS_REPO)).repoCurveGroups(ImmutableMap.of(ID_ISSUER, GROUP_REPO_ISSUER)).valuationDate(DATE).build();
            LocalDate refDate = date(2018, 11, 24);
            IssuerCurveZeroRateSensitivity sensi1   = test.issuerCurveDiscountFactors(ID_ISSUER, GBP).zeroRatePointSensitivity(refDate, GBP);
            RepoCurveZeroRateSensitivity   sensi2   = test.repoCurveDiscountFactors(ID_SECURITY, ID_ISSUER, GBP).zeroRatePointSensitivity(refDate, GBP);
            PointSensitivities             sensi    = PointSensitivities.of(sensi1, sensi2);
            CurrencyParameterSensitivities computed = test.parameterSensitivity(sensi);
            CurrencyParameterSensitivities expected = DSC_FACTORS_ISSUER.parameterSensitivity(sensi1.createZeroRateSensitivity()).combinedWith(DSC_FACTORS_REPO.parameterSensitivity(sensi2.createZeroRateSensitivity()));

            assertTrue(computed.equalWithTolerance(expected, 1.0e-12));
        }
Esempio n. 15
0
        public virtual void test_of_zeroRateSensitivity()
        {
            Currency                     sensiCurrency = GBP;
            ZeroRateSensitivity          zeroSensi     = ZeroRateSensitivity.of(CURRENCY, YEARFRAC, sensiCurrency, VALUE);
            RepoCurveZeroRateSensitivity test          = RepoCurveZeroRateSensitivity.of(zeroSensi, GROUP);

            assertEquals(test.RepoGroup, GROUP);
            assertEquals(test.CurveCurrency, CURRENCY);
            assertEquals(test.Currency, sensiCurrency);
            assertEquals(test.YearFraction, YEARFRAC);
            assertEquals(test.Sensitivity, VALUE);
        }
Esempio n. 16
0
 //-----------------------------------------------------------------------
 public override bool Equals(object obj)
 {
     if (obj == this)
     {
         return(true);
     }
     if (obj != null && obj.GetType() == this.GetType())
     {
         RepoCurveZeroRateSensitivity other = (RepoCurveZeroRateSensitivity)obj;
         return(JodaBeanUtils.equal(curveCurrency, other.curveCurrency) && JodaBeanUtils.equal(yearFraction, other.yearFraction) && JodaBeanUtils.equal(currency, other.currency) && JodaBeanUtils.equal(repoGroup, other.repoGroup) && JodaBeanUtils.equal(sensitivity, other.sensitivity));
     }
     return(false);
 }
Esempio n. 17
0
        public virtual void test_convertedTo()
        {
            RepoCurveZeroRateSensitivity @base = RepoCurveZeroRateSensitivity.of(CURRENCY, YEARFRAC, GROUP, VALUE);
            double   rate   = 1.5d;
            FxMatrix matrix = FxMatrix.of(CurrencyPair.of(GBP, USD), rate);
            RepoCurveZeroRateSensitivity test1 = @base.convertedTo(USD, matrix);

            assertEquals(test1, @base);
            RepoCurveZeroRateSensitivity test2    = @base.convertedTo(GBP, matrix);
            RepoCurveZeroRateSensitivity expected = RepoCurveZeroRateSensitivity.of(CURRENCY, YEARFRAC, GBP, GROUP, VALUE / rate);

            assertEquals(test2, expected);
        }
Esempio n. 18
0
        public virtual void test_compareKey()
        {
            RepoCurveZeroRateSensitivity a1    = RepoCurveZeroRateSensitivity.of(CURRENCY, YEARFRAC, GROUP, VALUE);
            RepoCurveZeroRateSensitivity a2    = RepoCurveZeroRateSensitivity.of(CURRENCY, YEARFRAC, GROUP, VALUE);
            RepoCurveZeroRateSensitivity b     = RepoCurveZeroRateSensitivity.of(GBP, YEARFRAC, GROUP, VALUE);
            RepoCurveZeroRateSensitivity c     = RepoCurveZeroRateSensitivity.of(CURRENCY, YEARFRAC2, GROUP, VALUE);
            RepoCurveZeroRateSensitivity d     = RepoCurveZeroRateSensitivity.of(CURRENCY, YEARFRAC, RepoGroup.of("ISSUER1 BND 3Y"), VALUE);
            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(d) < 0, true);
            assertEquals(d.compareKey(a1) > 0, true);
            assertEquals(a1.compareKey(other) > 0, true);
            assertEquals(other.compareKey(a1) < 0, true);
        }
        //-------------------------------------------------------------------------
        public CurrencyParameterSensitivities parameterSensitivity(PointSensitivities pointSensitivities)
        {
            CurrencyParameterSensitivities sens = CurrencyParameterSensitivities.empty();

            foreach (PointSensitivity point in pointSensitivities.Sensitivities)
            {
                if (point is RepoCurveZeroRateSensitivity)
                {
                    RepoCurveZeroRateSensitivity pt      = (RepoCurveZeroRateSensitivity)point;
                    RepoCurveDiscountFactors     factors = repoCurveDiscountFactors(pt.RepoGroup, pt.CurveCurrency);
                    sens = sens.combinedWith(factors.parameterSensitivity(pt));
                }
                else if (point is IssuerCurveZeroRateSensitivity)
                {
                    IssuerCurveZeroRateSensitivity pt      = (IssuerCurveZeroRateSensitivity)point;
                    IssuerCurveDiscountFactors     factors = issuerCurveDiscountFactors(pt.LegalEntityGroup, pt.CurveCurrency);
                    sens = sens.combinedWith(factors.parameterSensitivity(pt));
                }
            }
            return(sens);
        }
Esempio n. 20
0
        public virtual void test_pvsensiZSpread_settle_after_val()
        {
            PointSensitivities pvsensiComputed = PRICER_TRADE.presentValueSensitivityWithZSpread(BILL_TRADE_SETTLE_AFTER_VAL, PROVIDER, Z_SPREAD, CompoundedRateType.CONTINUOUS, 0);
            PointSensitivities pvsensiExpected = PRICER_PRODUCT.presentValueSensitivityWithZSpread(BILL_PRODUCT.resolve(REF_DATA), PROVIDER, Z_SPREAD, CompoundedRateType.CONTINUOUS, 0).multipliedBy(QUANTITY).combinedWith(RepoCurveZeroRateSensitivity.of((ZeroRateSensitivity)PRICER_PAYMENT.presentValueSensitivity(BILL_TRADE_SETTLE_AFTER_VAL.Settlement.get(), PROVIDER.repoCurveDiscountFactors(BILL_PRODUCT.SecurityId, BILL_PRODUCT.LegalEntityId, BILL_PRODUCT.Currency).DiscountFactors), GROUP_REPO).build());

            assertTrue(pvsensiComputed.equalWithTolerance(pvsensiExpected, TOLERANCE_PVSENSI));
            CurrencyParameterSensitivities paramSensiComputed = PROVIDER.parameterSensitivity(pvsensiComputed);
            CurrencyParameterSensitivities paramSensiExpected = FD_CALC.sensitivity(PROVIDER, p => PRICER_TRADE.presentValueWithZSpread(BILL_TRADE_SETTLE_AFTER_VAL, p, Z_SPREAD, CompoundedRateType.CONTINUOUS, 0));

            assertTrue(paramSensiComputed.equalWithTolerance(paramSensiExpected, EPS * NOTIONAL_AMOUNT * QUANTITY));
        }
Esempio n. 21
0
 /// <summary>
 /// Calculates the curve parameter sensitivity from the point sensitivity.
 /// <para>
 /// This is used to convert a single point sensitivity to curve 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(RepoCurveZeroRateSensitivity pointSensitivity)
 {
     return(discountFactors.parameterSensitivity(pointSensitivity.createZeroRateSensitivity()));
 }
Esempio n. 22
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 rate sensitivity of the curve
        /// used to determine the discount factor.
        /// The sensitivity typically has the value {@code (-discountFactor * relativeYearFraction)}.
        /// The sensitivity refers to the result of <seealso cref="#discountFactor(LocalDate)"/>.
        /// </para>
        /// <para>
        /// This method allows the currency of the sensitivity to differ from the currency of the curve.
        ///
        /// </para>
        /// </summary>
        /// <param name="date">  the date to discount to </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 RepoCurveZeroRateSensitivity zeroRatePointSensitivity(LocalDate date, Currency sensitivityCurrency)
        {
            ZeroRateSensitivity zeroRateSensitivity = discountFactors.zeroRatePointSensitivity(date, sensitivityCurrency);

            return(RepoCurveZeroRateSensitivity.of(zeroRateSensitivity, repoGroup));
        }
Esempio n. 23
0
        public virtual void test_serialization()
        {
            RepoCurveZeroRateSensitivity test = RepoCurveZeroRateSensitivity.of(CURRENCY, YEARFRAC, GROUP, VALUE);

            assertSerialization(test);
        }