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 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_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));
        }
        //-------------------------------------------------------------------------
        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_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));
        }
Пример #10
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);
        }
        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);
        }
        /// <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);
        }
Пример #15
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);
        }
        /// <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));
        }
        public virtual void test_serialization()
        {
            IssuerCurveZeroRateSensitivity test = IssuerCurveZeroRateSensitivity.of(CURRENCY, YEARFRAC, GROUP, VALUE);

            assertSerialization(test);
        }