public DayCountAnonymousInnerClass(ResolvedCapitalIndexedBondTest outerInstance, com.opengamma.strata.product.bond.ResolvedCapitalIndexedBond @base, com.opengamma.strata.product.bond.CapitalIndexedBondPaymentPeriod period, AtomicBoolean eom)
 {
     this.outerInstance = outerInstance;
     this.@base         = @base;
     this.period        = period;
     this.eom           = eom;
 }
Exemple #2
0
        /// <summary>
        /// Explains the present value of a single payment period with z-spread.
        /// <para>
        /// This adds information to the <seealso cref="ExplainMapBuilder"/> to aid understanding of the calculation.
        ///
        /// </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>
        /// <param name="builder">  the builder to populate </param>
        public virtual void explainPresentValueWithZSpread(CapitalIndexedBondPaymentPeriod period, RatesProvider ratesProvider, IssuerCurveDiscountFactors issuerDiscountFactors, ExplainMapBuilder builder, double zSpread, CompoundedRateType compoundedRateType, int periodsPerYear)
        {
            Currency  currency    = period.Currency;
            LocalDate paymentDate = period.PaymentDate;

            builder.put(ExplainKey.ENTRY_TYPE, "CapitalIndexedBondPaymentPeriod");
            builder.put(ExplainKey.PAYMENT_DATE, paymentDate);
            builder.put(ExplainKey.PAYMENT_CURRENCY, currency);
            builder.put(ExplainKey.START_DATE, period.StartDate);
            builder.put(ExplainKey.UNADJUSTED_START_DATE, period.UnadjustedStartDate);
            builder.put(ExplainKey.END_DATE, period.EndDate);
            builder.put(ExplainKey.UNADJUSTED_END_DATE, period.UnadjustedEndDate);
            builder.put(ExplainKey.DAYS, (int)DAYS.between(period.UnadjustedStartDate, period.UnadjustedEndDate));
            if (paymentDate.isBefore(ratesProvider.ValuationDate))
            {
                builder.put(ExplainKey.COMPLETED, true);
                builder.put(ExplainKey.FORECAST_VALUE, CurrencyAmount.zero(currency));
                builder.put(ExplainKey.PRESENT_VALUE, CurrencyAmount.zero(currency));
            }
            else
            {
                builder.put(ExplainKey.DISCOUNT_FACTOR, issuerDiscountFactors.discountFactor(paymentDate));
                builder.put(ExplainKey.FORECAST_VALUE, CurrencyAmount.of(currency, forecastValue(period, ratesProvider)));
                builder.put(ExplainKey.PRESENT_VALUE, CurrencyAmount.of(currency, presentValueWithZSpread(period, ratesProvider, issuerDiscountFactors, zSpread, compoundedRateType, periodsPerYear)));
            }
        }
Exemple #3
0
        // computes sensitivity with finite difference approximation
        private CurrencyParameterSensitivities fdSensitivityWithZSpread(CapitalIndexedBondPaymentPeriod period, ImmutableRatesProvider ratesProvider, LegalEntityDiscountingProvider issuerRatesProvider, double zSpread, CompoundedRateType compoundedRateType, int periodsPerYear)
        {
            CurrencyParameterSensitivities sensi1 = FD_CAL.sensitivity(issuerRatesProvider, p => CurrencyAmount.of(USD, PRICER.presentValueWithZSpread(period, ratesProvider, p.issuerCurveDiscountFactors(CapitalIndexedBondCurveDataSet.IssuerId, USD), zSpread, compoundedRateType, periodsPerYear)));
            CurrencyParameterSensitivities sensi2 = FD_CAL.sensitivity(ratesProvider, p => CurrencyAmount.of(USD, PRICER.presentValueWithZSpread(period, p, issuerRatesProvider.issuerCurveDiscountFactors(CapitalIndexedBondCurveDataSet.IssuerId, USD), zSpread, compoundedRateType, periodsPerYear)));

            return(sensi1.combinedWith(sensi2));
        }
Exemple #4
0
        /// <summary>
        /// Calculates the forecast value sensitivity of a single payment period.
        /// <para>
        /// The forecast 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>
        /// <returns> the forecast value sensitivity of the period  </returns>
        public virtual PointSensitivityBuilder forecastValueSensitivity(CapitalIndexedBondPaymentPeriod period, RatesProvider ratesProvider)
        {
            if (period.PaymentDate.isBefore(ratesProvider.ValuationDate))
            {
                return(PointSensitivityBuilder.none());
            }
            PointSensitivityBuilder rateSensi = rateComputationFn.rateSensitivity(period.RateComputation, period.StartDate, period.EndDate, ratesProvider);

            return(rateSensi.multipliedBy(period.Notional * period.RealCoupon));
        }
Exemple #5
0
        /// <summary>
        /// Calculates the forecast value of a single payment period.
        /// </summary>
        /// <param name="period">  the period to price </param>
        /// <param name="ratesProvider">  the rates provider, used to determine price index values </param>
        /// <returns> the forecast value of the period  </returns>
        public virtual double forecastValue(CapitalIndexedBondPaymentPeriod period, RatesProvider ratesProvider)
        {
            if (period.PaymentDate.isBefore(ratesProvider.ValuationDate))
            {
                return(0d);
            }
            double rate = rateComputationFn.rate(period.RateComputation, period.StartDate, period.EndDate, ratesProvider);

            return(period.Notional * period.RealCoupon * (rate + 1d));
        }
Exemple #6
0
        public virtual void test_presentValueFromCleanPriceWithZSpread_late()
        {
            CurrencyAmount computed  = PRICER.presentValueFromCleanPriceWithZSpread(TRADE_LATE, RATES_PROVIDER, ISSUER_RATES_PROVIDER, REF_DATA, TRADE_PRICE, Z_SPREAD, CONTINUOUS, 0);
            CurrencyAmount netAmount = PRICER.netAmount(TRADE_LATE, RATES_PROVIDER);
            CapitalIndexedBondPaymentPeriod period = PRODUCT.resolve(REF_DATA).PeriodicPayments.get(17);
            double pvDiff    = PERIOD_PRICER.presentValueWithZSpread(period, RATES_PROVIDER, ISSUER_DISCOUNT_FACTORS, Z_SPREAD, CONTINUOUS, 0) * QUANTITY;
            double df1       = ISSUER_RATES_PROVIDER.repoCurveDiscountFactors(SECURITY_ID, LEGAL_ENTITY, USD).discountFactor(SETTLEMENT_LATE);
            double df2       = ISSUER_RATES_PROVIDER.repoCurveDiscountFactors(SECURITY_ID, LEGAL_ENTITY, USD).discountFactor(SETTLEMENT_STANDARD);
            double expected1 = netAmount.Amount * df1;
            double expected2 = pvDiff + QUANTITY * df2 * PRICER.forecastValueStandardFromCleanPrice(RPRODUCT, RATES_PROVIDER, SETTLEMENT_STANDARD, TRADE_PRICE).Amount;

            assertEquals(computed.Amount, expected1 + expected2, NOTIONAL * QUANTITY * TOL);
        }
Exemple #7
0
        //-------------------------------------------------------------------------
        /// <summary>
        /// Calculates the present value sensitivity of a single 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="ratesProvider">  the rates provider, used to determine price index values </param>
        /// <param name="issuerDiscountFactors">  the discount factor provider </param>
        /// <returns> the present value curve sensitivity of the period </returns>
        public virtual PointSensitivityBuilder presentValueSensitivity(CapitalIndexedBondPaymentPeriod period, RatesProvider ratesProvider, IssuerCurveDiscountFactors issuerDiscountFactors)
        {
            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.discountFactor(period.PaymentDate);
            PointSensitivityBuilder dfSensi = issuerDiscountFactors.zeroRatePointSensitivity(period.PaymentDate);
            double factor = period.Notional * period.RealCoupon;

            return(rateSensi.multipliedBy(df * factor).combinedWith(dfSensi.multipliedBy((rate + 1d) * factor)));
        }
Exemple #8
0
        // the sensitivity of the net amount of the settlement
        private PointSensitivityBuilder netAmountSensitivity(ResolvedCapitalIndexedBondSettlement settlement, RatesProvider ratesProvider)
        {
            BondPaymentPeriod settlePeriod = settlement.Payment;

            if (settlePeriod is KnownAmountBondPaymentPeriod)
            {
                return(PointSensitivityBuilder.none());
            }
            else if (settlePeriod is CapitalIndexedBondPaymentPeriod)
            {
                CapitalIndexedBondPaymentPeriod casted = (CapitalIndexedBondPaymentPeriod)settlePeriod;
                return(productPricer.PeriodPricer.forecastValueSensitivity(casted, ratesProvider));
            }
            throw new System.NotSupportedException("unsupported settlement type");
        }
Exemple #9
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)));
        }
Exemple #10
0
        //-------------------------------------------------------------------------
        /// <summary>
        /// Calculates the net amount of the settlement of the bond trade.
        /// <para>
        /// Since the sign of the settlement notional is opposite to that of the product, negative amount will be returned
        /// for positive quantity of trade.
        ///
        /// </para>
        /// </summary>
        /// <param name="trade">  the trade </param>
        /// <param name="ratesProvider">  the rates provider, used to determine price index values </param>
        /// <returns> the net amount </returns>
        public virtual CurrencyAmount netAmount(ResolvedCapitalIndexedBondTrade trade, RatesProvider ratesProvider)
        {
            if (!trade.Settlement.Present)
            {
                // position has no settlement, thus it has no value
                return(CurrencyAmount.zero(trade.Product.Currency));
            }
            BondPaymentPeriod settlePeriod = trade.Settlement.get().Payment;

            if (settlePeriod is KnownAmountBondPaymentPeriod)
            {
                Payment payment = ((KnownAmountBondPaymentPeriod)settlePeriod).Payment;
                return(payment.Value);
            }
            else if (settlePeriod is CapitalIndexedBondPaymentPeriod)
            {
                CapitalIndexedBondPaymentPeriod casted = (CapitalIndexedBondPaymentPeriod)settlePeriod;
                double netAmount = productPricer.PeriodPricer.forecastValue(casted, ratesProvider);
                return(CurrencyAmount.of(casted.Currency, netAmount));
            }
            throw new System.NotSupportedException("unsupported settlement type");
        }
Exemple #11
0
        /// <summary>
        /// Calculates the present value of a single payment period with z-spread.
        /// <para>
        /// This returns the value of the period with discounting.
        /// If the payment date of the period is in the past, zero is returned.
        ///
        /// </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 of the period </returns>
        public virtual double presentValueWithZSpread(CapitalIndexedBondPaymentPeriod period, RatesProvider ratesProvider, IssuerCurveDiscountFactors issuerDiscountFactors, double zSpread, CompoundedRateType compoundedRateType, int periodsPerYear)
        {
            double df = issuerDiscountFactors.DiscountFactors.discountFactorWithSpread(period.PaymentDate, zSpread, compoundedRateType, periodsPerYear);

            return(df * forecastValue(period, ratesProvider));
        }
Exemple #12
0
        //-------------------------------------------------------------------------
        /// <summary>
        /// Calculates the present value of a single payment period.
        /// <para>
        /// This returns the value of the period with discounting.
        /// If the payment date of the period is in the past, zero is returned.
        ///
        /// </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>
        /// <returns> the present value of the period </returns>
        public virtual double presentValue(CapitalIndexedBondPaymentPeriod period, RatesProvider ratesProvider, IssuerCurveDiscountFactors issuerDiscountFactors)
        {
            double df = issuerDiscountFactors.discountFactor(period.PaymentDate);

            return(df * forecastValue(period, ratesProvider));
        }