Exemple #1
0
        /// <summary>
        /// Calculates the present value sensitivity of the settlement of the bond trade from the real clean price
        /// with z-spread.
        /// <para>
        /// The present value sensitivity of the settlement is the sensitivity of the present value to
        /// the underlying curves.
        ///
        /// </para>
        /// </summary>
        /// <param name="trade">  the trade </param>
        /// <param name="ratesProvider">  the rates provider, used to determine price index values </param>
        /// <param name="refData">  the reference data used to calculate the settlement date </param>
        /// <param name="discountingProvider">  the discount factors 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>
        /// <param name="cleanRealPrice">  the clean real price </param>
        /// <returns> the present value sensitivity of the settlement </returns>
        public virtual PointSensitivities presentValueSensitivityFromCleanPriceWithZSpread(ResolvedCapitalIndexedBondTrade trade, RatesProvider ratesProvider, LegalEntityDiscountingProvider discountingProvider, ReferenceData refData, double cleanRealPrice, double zSpread, CompoundedRateType compoundedRateType, int periodsPerYear)
        {
            validate(ratesProvider, discountingProvider);
            LocalDate valuationDate          = ratesProvider.ValuationDate;
            ResolvedCapitalIndexedBond bond  = trade.Product;
            LocalDate standardSettlementDate = bond.calculateSettlementDateFromValuation(valuationDate, refData);
            LocalDate tradeSettlementDate    = settlementDate(trade, valuationDate);
            RepoCurveDiscountFactors repoDf  = DiscountingCapitalIndexedBondProductPricer.repoCurveDf(bond, discountingProvider);
            double df = repoDf.discountFactor(standardSettlementDate);
            PointSensitivityBuilder dfSensi         = repoDf.zeroRatePointSensitivity(standardSettlementDate);
            PointSensitivityBuilder pvSensiStandard = forecastValueSensitivityStandardFromCleanPrice(bond, ratesProvider, standardSettlementDate, cleanRealPrice).multipliedBy(df).combinedWith(dfSensi.multipliedBy(forecastValueStandardFromCleanPrice(bond, ratesProvider, standardSettlementDate, cleanRealPrice).Amount));

            if (standardSettlementDate.isEqual(tradeSettlementDate))
            {
                return(presentValueSensitivityFromProductPresentValueSensitivity(trade, ratesProvider, discountingProvider, pvSensiStandard).build());
            }
            // check coupon payment between two settlement dates
            IssuerCurveDiscountFactors issuerDf    = DiscountingCapitalIndexedBondProductPricer.issuerCurveDf(bond, discountingProvider);
            PointSensitivityBuilder    pvSensiDiff = PointSensitivityBuilder.none();

            if (standardSettlementDate.isAfter(tradeSettlementDate))
            {
                pvSensiDiff = pvSensiDiff.combinedWith(productPricer.presentValueSensitivityCouponWithZSpread(bond, ratesProvider, issuerDf, tradeSettlementDate, standardSettlementDate, zSpread, compoundedRateType, periodsPerYear).multipliedBy(-1d));
            }
            else
            {
                pvSensiDiff = pvSensiDiff.combinedWith(productPricer.presentValueSensitivityCouponWithZSpread(bond, ratesProvider, issuerDf, standardSettlementDate, tradeSettlementDate, zSpread, compoundedRateType, periodsPerYear));
            }
            return(presentValueSensitivityFromProductPresentValueSensitivity(trade, ratesProvider, discountingProvider, pvSensiStandard.combinedWith(pvSensiDiff)).build());
        }
Exemple #2
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);
        }
Exemple #3
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);
        }
Exemple #4
0
        // the sensitivity of the present value of the settlement
        private PointSensitivityBuilder presentValueSensitivitySettlement(ResolvedCapitalIndexedBondTrade trade, RatesProvider ratesProvider, LegalEntityDiscountingProvider discountingProvider)
        {
            if (!trade.Settlement.Present)
            {
                // position has no settlement, thus it has no sensitivity
                return(PointSensitivityBuilder.none());
            }
            ResolvedCapitalIndexedBondSettlement settlement = trade.Settlement.get();
            BondPaymentPeriod          settlePeriod         = settlement.Payment;
            ResolvedCapitalIndexedBond product = trade.Product;
            RepoCurveDiscountFactors   repoDf  = DiscountingCapitalIndexedBondProductPricer.repoCurveDf(product, discountingProvider);
            double df        = repoDf.discountFactor(settlePeriod.PaymentDate);
            double netAmount = this.netAmount(trade, ratesProvider).Amount;
            PointSensitivityBuilder dfSensi = repoDf.zeroRatePointSensitivity(settlePeriod.PaymentDate).multipliedBy(netAmount);
            PointSensitivityBuilder naSensi = netAmountSensitivity(settlement, ratesProvider).multipliedBy(df);

            return(dfSensi.combinedWith(naSensi));
        }