public virtual void test_cloned()
        {
            IssuerCurveZeroRateSensitivity @base = IssuerCurveZeroRateSensitivity.of(CURRENCY, YEARFRAC, GROUP, VALUE);
            IssuerCurveZeroRateSensitivity test  = @base.cloned();

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

            assertEquals(test, expected);
        }
        public virtual void test_zeroRatePointSensitivity_USD()
        {
            IssuerCurveDiscountFactors     @base    = IssuerCurveDiscountFactors.of(DSC_FACTORS, GROUP);
            IssuerCurveZeroRateSensitivity expected = IssuerCurveZeroRateSensitivity.of(DSC_FACTORS.zeroRatePointSensitivity(DATE_AFTER, USD), GROUP);
            IssuerCurveZeroRateSensitivity computed = @base.zeroRatePointSensitivity(DATE_AFTER, USD);

            assertEquals(computed, expected);
        }
        public virtual void test_createZeroRateSensitivity()
        {
            IssuerCurveZeroRateSensitivity @base    = IssuerCurveZeroRateSensitivity.of(CURRENCY, YEARFRAC, GBP, GROUP, VALUE);
            ZeroRateSensitivity            expected = ZeroRateSensitivity.of(CURRENCY, YEARFRAC, GBP, VALUE);
            ZeroRateSensitivity            test     = @base.createZeroRateSensitivity();

            assertEquals(test, expected);
        }
        public virtual void test_buildInto()
        {
            IssuerCurveZeroRateSensitivity @base = IssuerCurveZeroRateSensitivity.of(CURRENCY, YEARFRAC, GROUP, VALUE);
            MutablePointSensitivities      combo = new MutablePointSensitivities();
            MutablePointSensitivities      test  = @base.buildInto(combo);

            assertSame(test, combo);
            assertEquals(test.Sensitivities, ImmutableList.of(@base));
        }
Example #6
0
 public int compareKey(PointSensitivity other)
 {
     if (other is IssuerCurveZeroRateSensitivity)
     {
         IssuerCurveZeroRateSensitivity otherZero = (IssuerCurveZeroRateSensitivity)other;
         return(ComparisonChain.start().compare(curveCurrency, otherZero.curveCurrency).compare(currency, otherZero.currency).compare(yearFraction, otherZero.yearFraction).compare(legalEntityGroup, otherZero.legalEntityGroup).result());
     }
     return(this.GetType().Name.CompareTo(other.GetType().Name));
 }
        //-------------------------------------------------------------------------
        public virtual void coverage()
        {
            IssuerCurveZeroRateSensitivity test1 = IssuerCurveZeroRateSensitivity.of(CURRENCY, YEARFRAC, GROUP, VALUE);

            coverImmutableBean(test1);
            IssuerCurveZeroRateSensitivity test2 = IssuerCurveZeroRateSensitivity.of(GBP, YEARFRAC2, LegalEntityGroup.of("ISSUER1"), 12d);

            coverBeanEquals(test1, test2);
        }
        //-------------------------------------------------------------------------
        public virtual void test_multipliedBy()
        {
            IssuerCurveZeroRateSensitivity @base = IssuerCurveZeroRateSensitivity.of(CURRENCY, YEARFRAC, GROUP, VALUE);
            double rate = 2.4d;
            IssuerCurveZeroRateSensitivity test     = @base.multipliedBy(rate);
            IssuerCurveZeroRateSensitivity expected = IssuerCurveZeroRateSensitivity.of(CURRENCY, YEARFRAC, GROUP, VALUE * rate);

            assertEquals(test, expected);
        }
        public virtual void test_parameterSensitivity()
        {
            IssuerCurveDiscountFactors     @base    = IssuerCurveDiscountFactors.of(DSC_FACTORS, GROUP);
            IssuerCurveZeroRateSensitivity 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);
        }
        //-------------------------------------------------------------------------
        /// <summary>
        /// Calculates the present value sensitivity of a single fixed coupon payment period.
        /// <para>
        /// The present value sensitivity of the period is the sensitivity of the present value to
        /// the underlying curves.
        ///
        /// </para>
        /// </summary>
        /// <param name="period">  the period to price </param>
        /// <param name="discountFactors">  the discount factor provider </param>
        /// <returns> the present value curve sensitivity of the period </returns>
        public virtual PointSensitivityBuilder presentValueSensitivity(FixedCouponBondPaymentPeriod period, IssuerCurveDiscountFactors discountFactors)
        {
            if (period.PaymentDate.isBefore(discountFactors.ValuationDate))
            {
                return(PointSensitivityBuilder.none());
            }
            IssuerCurveZeroRateSensitivity dscSensi = discountFactors.zeroRatePointSensitivity(period.PaymentDate);

            return(dscSensi.multipliedBy(period.FixedRate * period.Notional * period.YearFraction));
        }
        public virtual void test_of_withoutSensitivityCurrency()
        {
            IssuerCurveZeroRateSensitivity test = IssuerCurveZeroRateSensitivity.of(CURRENCY, YEARFRAC, GROUP, VALUE);

            assertEquals(test.LegalEntityGroup, GROUP);
            assertEquals(test.CurveCurrency, CURRENCY);
            assertEquals(test.Currency, CURRENCY);
            assertEquals(test.YearFraction, YEARFRAC);
            assertEquals(test.Sensitivity, VALUE);
        }
        /// <summary>
        /// Calculates the present value sensitivity of a single fixed coupon payment period with z-spread.
        /// <para>
        /// The z-spread is a parallel shift applied to continuously compounded rates or periodic
        /// compounded rates of the discounting curve.
        /// </para>
        /// <para>
        /// The present value sensitivity of the period is the sensitivity of the present value to
        /// the underlying curves.
        ///
        /// </para>
        /// </summary>
        /// <param name="period">  the period to price </param>
        /// <param name="discountFactors">  the discount factor provider </param>
        /// <param name="zSpread">  the z-spread </param>
        /// <param name="compoundedRateType">  the compounded rate type </param>
        /// <param name="periodsPerYear">  the number of periods per year </param>
        /// <returns> the present value curve sensitivity of the period </returns>
        public virtual PointSensitivityBuilder presentValueSensitivityWithSpread(FixedCouponBondPaymentPeriod period, IssuerCurveDiscountFactors discountFactors, double zSpread, CompoundedRateType compoundedRateType, int periodsPerYear)
        {
            if (period.PaymentDate.isBefore(discountFactors.ValuationDate))
            {
                return(PointSensitivityBuilder.none());
            }
            ZeroRateSensitivity            zeroSensi = discountFactors.DiscountFactors.zeroRatePointSensitivityWithSpread(period.PaymentDate, zSpread, compoundedRateType, periodsPerYear);
            IssuerCurveZeroRateSensitivity dscSensi  = IssuerCurveZeroRateSensitivity.of(zeroSensi, discountFactors.LegalEntityGroup);

            return(dscSensi.multipliedBy(period.FixedRate * period.Notional * period.YearFraction));
        }
Example #13
0
        public virtual void presentValueSensitivity_zspread()
        {
            PointSensitivities sensiComputed = PRICER.presentValueSensitivityWithZSpread(BILL, PROVIDER, Z_SPREAD, CompoundedRateType.CONTINUOUS, 0);
            PointSensitivities sensiExpected = IssuerCurveZeroRateSensitivity.of(DSC_FACTORS_ISSUER.zeroRatePointSensitivityWithSpread(MATURITY_DATE, Z_SPREAD, CompoundedRateType.CONTINUOUS, 0), GROUP_ISSUER).multipliedBy(NOTIONAL.Amount).build();

            assertTrue(sensiComputed.equalWithTolerance(sensiExpected, TOLERANCE_PV));
            CurrencyParameterSensitivities paramSensiComputed = PROVIDER.parameterSensitivity(sensiComputed);
            CurrencyParameterSensitivities paramSensiExpected = FD_CALC.sensitivity(PROVIDER, p => PRICER.presentValueWithZSpread(BILL, p, Z_SPREAD, CompoundedRateType.CONTINUOUS, 0));

            assertTrue(paramSensiComputed.equalWithTolerance(paramSensiExpected, EPS * NOTIONAL_AMOUNT));
        }
        public virtual void test_withSensitivity()
        {
            IssuerCurveZeroRateSensitivity @base = IssuerCurveZeroRateSensitivity.of(CURRENCY, YEARFRAC, GROUP, VALUE);
            double newValue = 53d;
            IssuerCurveZeroRateSensitivity test = @base.withSensitivity(newValue);

            assertEquals(test.LegalEntityGroup, GROUP);
            assertEquals(test.CurveCurrency, CURRENCY);
            assertEquals(test.Currency, CURRENCY);
            assertEquals(test.YearFraction, YEARFRAC);
            assertEquals(test.Sensitivity, newValue);
        }
Example #15
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));
        }
        public virtual void test_of_zeroRateSensitivity()
        {
            Currency                       sensiCurrency = GBP;
            ZeroRateSensitivity            zeroSensi     = ZeroRateSensitivity.of(CURRENCY, YEARFRAC, sensiCurrency, VALUE);
            IssuerCurveZeroRateSensitivity test          = IssuerCurveZeroRateSensitivity.of(zeroSensi, GROUP);

            assertEquals(test.LegalEntityGroup, GROUP);
            assertEquals(test.CurveCurrency, CURRENCY);
            assertEquals(test.Currency, sensiCurrency);
            assertEquals(test.YearFraction, YEARFRAC);
            assertEquals(test.Sensitivity, VALUE);
        }
Example #17
0
 //-----------------------------------------------------------------------
 public override bool Equals(object obj)
 {
     if (obj == this)
     {
         return(true);
     }
     if (obj != null && obj.GetType() == this.GetType())
     {
         IssuerCurveZeroRateSensitivity other = (IssuerCurveZeroRateSensitivity)obj;
         return(JodaBeanUtils.equal(curveCurrency, other.curveCurrency) && JodaBeanUtils.equal(yearFraction, other.yearFraction) && JodaBeanUtils.equal(currency, other.currency) && JodaBeanUtils.equal(legalEntityGroup, other.legalEntityGroup) && JodaBeanUtils.equal(sensitivity, other.sensitivity));
     }
     return(false);
 }
        /// <summary>
        /// Calculates the present value sensitivity of the bill product with z-spread.
        /// <para>
        /// The present value sensitivity of the product is the sensitivity of the present value to
        /// the underlying curves.
        /// </para>
        /// <para>
        /// The z-spread is a parallel shift applied to continuously compounded rates or
        /// periodic compounded rates of the issuer discounting curve.
        ///
        /// </para>
        /// </summary>
        /// <param name="bill">  the product </param>
        /// <param name="provider">  the discounting provider </param>
        /// <param name="zSpread">  the z-spread </param>
        /// <param name="compoundedRateType">  the compounded rate type </param>
        /// <param name="periodsPerYear">  the number of periods per year </param>
        /// <returns> the present value curve sensitivity of the product </returns>
        public virtual PointSensitivities presentValueSensitivityWithZSpread(ResolvedBill bill, LegalEntityDiscountingProvider provider, double zSpread, CompoundedRateType compoundedRateType, int periodsPerYear)
        {
            if (provider.ValuationDate.isAfter(bill.Notional.Date))
            {
                return(PointSensitivities.empty());
            }
            IssuerCurveDiscountFactors issuerDf = issuerCurveDf(bill, provider);
            double dfEndBar = bill.Notional.Amount;
            ZeroRateSensitivity            zeroSensMaturity = issuerDf.DiscountFactors.zeroRatePointSensitivityWithSpread(bill.Notional.Date, zSpread, compoundedRateType, periodsPerYear);
            IssuerCurveZeroRateSensitivity dscSensMaturity  = IssuerCurveZeroRateSensitivity.of(zeroSensMaturity, issuerDf.LegalEntityGroup).multipliedBy(dfEndBar);

            return(dscSensMaturity.build());
        }
        public virtual void test_convertedTo()
        {
            IssuerCurveZeroRateSensitivity @base = IssuerCurveZeroRateSensitivity.of(CURRENCY, YEARFRAC, GROUP, VALUE);
            double   rate   = 1.5d;
            FxMatrix matrix = FxMatrix.of(CurrencyPair.of(GBP, USD), rate);
            IssuerCurveZeroRateSensitivity test1 = @base.convertedTo(USD, matrix);

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

            assertEquals(test2, expected);
        }
Example #20
0
        /// <summary>
        /// Calculates the present value sensitivity of a single payment period with z-spread.
        /// <para>
        /// The present value sensitivity of the period is the sensitivity of the present value to
        /// the underlying curves.
        ///
        /// </para>
        /// </summary>
        /// <param name="period">  the period to price </param>
        /// <param name="ratesProvider">  the rates provider, used to determine price index values </param>
        /// <param name="issuerDiscountFactors">  the discount factor provider </param>
        /// <param name="zSpread">  the z-spread </param>
        /// <param name="compoundedRateType">  the compounded rate type </param>
        /// <param name="periodsPerYear">  the number of periods per year </param>
        /// <returns> the present value curve sensitivity of the period </returns>
        public virtual PointSensitivityBuilder presentValueSensitivityWithZSpread(CapitalIndexedBondPaymentPeriod period, RatesProvider ratesProvider, IssuerCurveDiscountFactors issuerDiscountFactors, double zSpread, CompoundedRateType compoundedRateType, int periodsPerYear)
        {
            if (period.PaymentDate.isBefore(ratesProvider.ValuationDate))
            {
                return(PointSensitivityBuilder.none());
            }
            double rate = rateComputationFn.rate(period.RateComputation, period.StartDate, period.EndDate, ratesProvider);
            PointSensitivityBuilder rateSensi = rateComputationFn.rateSensitivity(period.RateComputation, period.StartDate, period.EndDate, ratesProvider);
            double df = issuerDiscountFactors.DiscountFactors.discountFactorWithSpread(period.PaymentDate, zSpread, compoundedRateType, periodsPerYear);
            ZeroRateSensitivity            zeroSensi = issuerDiscountFactors.DiscountFactors.zeroRatePointSensitivityWithSpread(period.PaymentDate, zSpread, compoundedRateType, periodsPerYear);
            IssuerCurveZeroRateSensitivity dfSensi   = IssuerCurveZeroRateSensitivity.of(zeroSensi, issuerDiscountFactors.LegalEntityGroup);
            double factor = period.Notional * period.RealCoupon;

            return(rateSensi.multipliedBy(df * factor).combinedWith(dfSensi.multipliedBy((rate + 1d) * factor)));
        }
        public virtual void test_compareKey()
        {
            IssuerCurveZeroRateSensitivity a1    = IssuerCurveZeroRateSensitivity.of(CURRENCY, YEARFRAC, GROUP, VALUE);
            IssuerCurveZeroRateSensitivity a2    = IssuerCurveZeroRateSensitivity.of(CURRENCY, YEARFRAC, GROUP, VALUE);
            IssuerCurveZeroRateSensitivity b     = IssuerCurveZeroRateSensitivity.of(GBP, YEARFRAC, GROUP, VALUE);
            IssuerCurveZeroRateSensitivity c     = IssuerCurveZeroRateSensitivity.of(CURRENCY, YEARFRAC2, GROUP, VALUE);
            IssuerCurveZeroRateSensitivity d     = IssuerCurveZeroRateSensitivity.of(CURRENCY, YEARFRAC, LegalEntityGroup.of("ISSUER2"), VALUE);
            IborRateSensitivity            other = IborRateSensitivity.of(IborIndexObservation.of(GBP_LIBOR_3M, date(2015, 8, 27), 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);
        }
        public virtual void test_serialization()
        {
            IssuerCurveZeroRateSensitivity test = IssuerCurveZeroRateSensitivity.of(CURRENCY, YEARFRAC, GROUP, VALUE);

            assertSerialization(test);
        }
        /// <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 IssuerCurveZeroRateSensitivity zeroRatePointSensitivity(LocalDate date, Currency sensitivityCurrency)
        {
            ZeroRateSensitivity zeroRateSensitivity = discountFactors.zeroRatePointSensitivity(date, sensitivityCurrency);

            return(IssuerCurveZeroRateSensitivity.of(zeroRateSensitivity, legalEntityGroup));
        }
 /// <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(IssuerCurveZeroRateSensitivity pointSensitivity)
 {
     return(discountFactors.parameterSensitivity(pointSensitivity.createZeroRateSensitivity()));
 }