/// <summary>
        /// Calculates the present value of the bond future trade with z-spread.
        /// <para>
        /// The present value of the product is the value on the valuation date.
        /// </para>
        /// <para>
        /// The z-spread is a parallel shift applied to continuously compounded rates or periodic compounded rates
        /// of the issuer discounting curve.
        /// </para>
        /// <para>
        /// This method calculates based on the difference between the model price and the
        /// last settlement price, or the trade price if traded on the valuation date.
        ///
        /// </para>
        /// </summary>
        /// <param name="trade">  the trade </param>
        /// <param name="discountingProvider">  the discounting provider </param>
        /// <param name="lastSettlementPrice">  the last settlement price used for margining, in decimal form </param>
        /// <param name="zSpread">  the z-spread </param>
        /// <param name="compoundedRateType">  the compounded rate type </param>
        /// <param name="periodPerYear">  the number of periods per year </param>
        /// <returns> the present value </returns>
        public CurrencyAmount presentValueWithZSpread(ResolvedBondFutureTrade trade, LegalEntityDiscountingProvider discountingProvider, double lastSettlementPrice, double zSpread, CompoundedRateType compoundedRateType, int periodPerYear)
        {
            double price          = priceWithZSpread(trade, discountingProvider, zSpread, compoundedRateType, periodPerYear);
            double referencePrice = this.referencePrice(trade, discountingProvider.ValuationDate, lastSettlementPrice);

            return(presentValue(trade, price, referencePrice));
        }
        //-------------------------------------------------------------------------
        /// <summary>
        /// Calculates the currency exposure of the bond future trade.
        /// <para>
        /// This method calculates based on the difference between the model price and the
        /// last settlement price, or the trade price if traded on the valuation date.
        ///
        /// </para>
        /// </summary>
        /// <param name="trade">  the trade </param>
        /// <param name="discountingProvider">  the discounting provider </param>
        /// <param name="lastSettlementPrice">  the last settlement price used for margining, in decimal form </param>
        /// <returns> the currency exposure of the bond future trade </returns>
        public MultiCurrencyAmount currencyExposure(ResolvedBondFutureTrade trade, LegalEntityDiscountingProvider discountingProvider, double lastSettlementPrice)
        {
            double price          = this.price(trade, discountingProvider);
            double referencePrice = this.referencePrice(trade, discountingProvider.ValuationDate, lastSettlementPrice);

            return(MultiCurrencyAmount.of(presentValue(trade, price, referencePrice)));
        }
        //-------------------------------------------------------------------------
        /// <summary>
        /// Calculates the price sensitivity of the bond future product.
        /// <para>
        /// The price sensitivity of the product is the sensitivity of the price to the underlying curves.
        /// </para>
        /// <para>
        /// Note that the price sensitivity should be no currency.
        ///
        /// </para>
        /// </summary>
        /// <param name="future">  the future </param>
        /// <param name="discountingProvider">  the discounting provider </param>
        /// <returns> the price curve sensitivity of the product </returns>
        public PointSensitivities priceSensitivity(ResolvedBondFuture future, LegalEntityDiscountingProvider discountingProvider)
        {
            ImmutableList <ResolvedFixedCouponBond> basket = future.DeliveryBasket;
            int size = basket.size();

            double[] priceBonds = new double[size];
            int      indexCTD   = 0;
            double   priceMin   = 2d;

            for (int i = 0; i < size; i++)
            {
                ResolvedFixedCouponBond bond = basket.get(i);
                double dirtyPrice            = bondPricer.dirtyPriceFromCurves(bond, discountingProvider, future.LastDeliveryDate);
                priceBonds[i] = bondPricer.cleanPriceFromDirtyPrice(bond, future.LastDeliveryDate, dirtyPrice) / future.ConversionFactors.get(i);
                if (priceBonds[i] < priceMin)
                {
                    priceMin = priceBonds[i];
                    indexCTD = i;
                }
            }
            ResolvedFixedCouponBond bond       = basket.get(indexCTD);
            PointSensitivityBuilder pointSensi = bondPricer.dirtyPriceSensitivity(bond, discountingProvider, future.LastDeliveryDate);

            return(pointSensi.multipliedBy(1d / future.ConversionFactors.get(indexCTD)).build());
        }
Beispiel #4
0
        //-------------------------------------------------------------------------
        /// <summary>
        /// Computes the first order sensitivities of a function of a LegalEntityDiscountingProvider to a double by finite difference.
        /// <para>
        /// The finite difference is computed by forward type.
        /// The function should return a value in the same currency for any rates provider of LegalEntityDiscountingProvider.
        ///
        /// </para>
        /// </summary>
        /// <param name="provider">  the rates provider </param>
        /// <param name="valueFn">  the function from a rate provider to a currency amount for which the sensitivity should be computed </param>
        /// <returns> the curve sensitivity </returns>
        public virtual CurrencyParameterSensitivities sensitivity(LegalEntityDiscountingProvider provider, System.Func <ImmutableLegalEntityDiscountingProvider, CurrencyAmount> valueFn)
        {
            ImmutableLegalEntityDiscountingProvider immProv = provider.toImmutableLegalEntityDiscountingProvider();
            CurrencyAmount valueInit = valueFn(immProv);
            CurrencyParameterSensitivities discounting = sensitivity(immProv, valueFn, ImmutableLegalEntityDiscountingProvider.meta().repoCurves(), valueInit);
            CurrencyParameterSensitivities forward     = sensitivity(immProv, valueFn, ImmutableLegalEntityDiscountingProvider.meta().issuerCurves(), valueInit);

            return(discounting.combinedWith(forward));
        }
        /// <summary>
        /// Calculates the theta of the bond future option product based on the price of the underlying future.
        /// <para>
        /// The theta of the product is minus of the option price sensitivity to the time to expiry.
        /// The volatility is unchanged for a fixed strike in the sensitivity computation, hence the "StickyStrike" name.
        ///
        /// </para>
        /// </summary>
        /// <param name="futureOption">  the option product </param>
        /// <param name="discountingProvider">  the discounting provider </param>
        /// <param name="volatilities">  the volatilities </param>
        /// <param name="futurePrice">  the price of the underlying future </param>
        /// <returns> the price curve sensitivity of the product </returns>
        public double theta(ResolvedBondFutureOption futureOption, LegalEntityDiscountingProvider discountingProvider, BlackBondFutureVolatilities volatilities, double futurePrice)
        {
            ArgChecker.isTrue(futureOption.PremiumStyle.Equals(FutureOptionPremiumStyle.DAILY_MARGIN), "Premium style should be DAILY_MARGIN");
            double             strike       = futureOption.StrikePrice;
            ResolvedBondFuture future       = futureOption.UnderlyingFuture;
            double             volatility   = volatilities.volatility(futureOption.Expiry, future.LastTradeDate, strike, futurePrice);
            double             timeToExpiry = volatilities.relativeTime(futureOption.Expiry);
            double             theta        = BlackFormulaRepository.driftlessTheta(futurePrice, strike, timeToExpiry, volatility);

            return(theta);
        }
        /// <summary>
        /// Calculates the present value of a bill product with z-spread.
        /// <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 of the bill product </returns>
        public virtual CurrencyAmount presentValueWithZSpread(ResolvedBill bill, LegalEntityDiscountingProvider provider, double zSpread, CompoundedRateType compoundedRateType, int periodsPerYear)
        {
            if (provider.ValuationDate.isAfter(bill.Notional.Date))
            {
                return(CurrencyAmount.of(bill.Currency, 0.0d));
            }
            IssuerCurveDiscountFactors issuerDf = issuerCurveDf(bill, provider);
            double dfMaturity = issuerDf.DiscountFactors.discountFactorWithSpread(bill.Notional.Date, zSpread, compoundedRateType, periodsPerYear);

            return(bill.Notional.Value.multipliedBy(dfMaturity));
        }
        //-------------------------------------------------------------------------
        /// <summary>
        /// Calculates the present value of the bill product.
        /// <para>
        /// The present value of the product is the value on the valuation date.
        /// The result is expressed using the payment currency of the bill.
        /// </para>
        /// <para>
        /// Coupon payments of the product are considered based on the valuation date.
        ///
        /// </para>
        /// </summary>
        /// <param name="bill">  the product </param>
        /// <param name="provider">  the discounting provider </param>
        /// <returns> the present value of the bill product </returns>
        public virtual CurrencyAmount presentValue(ResolvedBill bill, LegalEntityDiscountingProvider provider)
        {
            if (provider.ValuationDate.isAfter(bill.Notional.Date))
            {
                return(CurrencyAmount.of(bill.Currency, 0.0d));
            }
            IssuerCurveDiscountFactors issuerDf = issuerCurveDf(bill, provider);
            double dfMaturity = issuerDf.discountFactor(bill.Notional.Date);

            return(bill.Notional.Value.multipliedBy(dfMaturity));
        }
        /// <summary>
        /// Calculates the price for settlement at a given settlement date using curves with z-spread.
        /// <para>
        /// The z-spread is a parallel shift applied to continuously compounded rates or
        /// periodic compounded rates of the issuer discounting curve.
        /// </para>
        /// <para>
        /// The z-spread is applied only on the legal entity curve, not on the repo curve.
        ///
        /// </para>
        /// </summary>
        /// <param name="bill">  the bill </param>
        /// <param name="provider">  the discounting provider </param>
        /// <param name="settlementDate">  the settlement date </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 price </returns>
        public virtual double priceFromCurvesWithZSpread(ResolvedBill bill, LegalEntityDiscountingProvider provider, LocalDate settlementDate, double zSpread, CompoundedRateType compoundedRateType, int periodsPerYear)
        {
            ArgChecker.inOrderNotEqual(settlementDate, bill.Notional.Date, "settlementDate", "endDate");
            ArgChecker.inOrderOrEqual(provider.ValuationDate, settlementDate, "valuationDate", "settlementDate");
            IssuerCurveDiscountFactors issuerDf = issuerCurveDf(bill, provider);
            double dfMaturity = issuerDf.DiscountFactors.discountFactorWithSpread(bill.Notional.Date, zSpread, compoundedRateType, periodsPerYear);
            RepoCurveDiscountFactors repoDf = repoCurveDf(bill, provider);
            double dfRepoSettle             = repoDf.discountFactor(settlementDate);

            return(dfMaturity / dfRepoSettle);
        }
        //-------------------------------------------------------------------------
        /// <summary>
        /// Calculates the price for settlement at a given settlement date using curves.
        /// </summary>
        /// <param name="bill">  the bill </param>
        /// <param name="provider">  the discounting provider </param>
        /// <param name="settlementDate">  the settlement date </param>
        /// <returns> the price </returns>
        public virtual double priceFromCurves(ResolvedBill bill, LegalEntityDiscountingProvider provider, LocalDate settlementDate)
        {
            ArgChecker.inOrderNotEqual(settlementDate, bill.Notional.Date, "settlementDate", "endDate");
            ArgChecker.inOrderOrEqual(provider.ValuationDate, settlementDate, "valuationDate", "settlementDate");
            IssuerCurveDiscountFactors issuerDf = issuerCurveDf(bill, provider);
            double dfMaturity = issuerDf.discountFactor(bill.Notional.Date);
            RepoCurveDiscountFactors repoDf = repoCurveDf(bill, provider);
            double dfRepoSettle             = repoDf.discountFactor(settlementDate);

            return(dfMaturity / dfRepoSettle);
        }
        //-------------------------------------------------------------------------
        /// <summary>
        /// Calculates the present value sensitivity of the bill product.
        /// <para>
        /// The present value sensitivity of the product is the sensitivity of the present value to
        /// the underlying curves.
        ///
        /// </para>
        /// </summary>
        /// <param name="bill">  the product </param>
        /// <param name="provider">  the discounting provider </param>
        /// <returns> the present value curve sensitivity of the product </returns>
        public virtual PointSensitivities presentValueSensitivity(ResolvedBill bill, LegalEntityDiscountingProvider provider)
        {
            if (provider.ValuationDate.isAfter(bill.Notional.Date))
            {
                return(PointSensitivities.empty());
            }
            IssuerCurveDiscountFactors issuerDf = issuerCurveDf(bill, provider);
            double dfEndBar = bill.Notional.Amount;
            PointSensitivityBuilder sensMaturity = issuerDf.zeroRatePointSensitivity(bill.Notional.Date).multipliedBy(dfEndBar);

            return(sensMaturity.build());
        }
Beispiel #11
0
        public virtual void test_simpleMeasures()
        {
            BondFutureOptionTradeCalculationFunction <BondFutureOptionTrade> function = BondFutureOptionTradeCalculationFunction.TRADE;
            ScenarioMarketData                       md       = marketData();
            LegalEntityDiscountingProvider           provider = LED_LOOKUP.marketDataView(md.scenario(0)).discountingProvider();
            BlackBondFutureOptionMarginedTradePricer pricer   = BlackBondFutureOptionMarginedTradePricer.DEFAULT;
            CurrencyAmount      expectedPv = pricer.presentValue(RTRADE, provider, VOLS, SETTLE_PRICE);
            MultiCurrencyAmount expectedCurrencyExposure = pricer.currencyExposure(RTRADE, provider, VOLS, SETTLE_PRICE);

            ISet <Measure> measures = ImmutableSet.of(Measures.PRESENT_VALUE, Measures.CURRENCY_EXPOSURE, Measures.RESOLVED_TARGET);

            assertThat(function.calculate(TRADE, measures, PARAMS, md, REF_DATA)).containsEntry(Measures.PRESENT_VALUE, Result.success(CurrencyScenarioArray.of(ImmutableList.of(expectedPv)))).containsEntry(Measures.CURRENCY_EXPOSURE, Result.success(MultiCurrencyScenarioArray.of(ImmutableList.of(expectedCurrencyExposure)))).containsEntry(Measures.RESOLVED_TARGET, Result.success(RTRADE));
        }
        //-------------------------------------------------------------------------
        /// <summary>
        /// Calculates the price of the bond future product.
        /// <para>
        /// The price of the product is the price on the valuation date.
        /// </para>
        /// <para>
        /// Strata uses <i>decimal prices</i> for bond futures. This is coherent with the pricing of <seealso cref="FixedCouponBond"/>.
        /// For example, a price of 99.32% is represented in Strata by 0.9932.
        ///
        /// </para>
        /// </summary>
        /// <param name="future">  the future </param>
        /// <param name="discountingProvider">  the discounting provider </param>
        /// <returns> the price of the product, in decimal form </returns>
        public double price(ResolvedBondFuture future, LegalEntityDiscountingProvider discountingProvider)
        {
            ImmutableList <ResolvedFixedCouponBond> basket = future.DeliveryBasket;
            int size = basket.size();

            double[] priceBonds = new double[size];
            for (int i = 0; i < size; ++i)
            {
                ResolvedFixedCouponBond bond = basket.get(i);
                double dirtyPrice            = bondPricer.dirtyPriceFromCurves(bond, discountingProvider, future.LastDeliveryDate);
                priceBonds[i] = bondPricer.cleanPriceFromDirtyPrice(bond, future.LastDeliveryDate, dirtyPrice) / future.ConversionFactors.get(i);
            }
            return(Doubles.min(priceBonds));
        }
        public virtual void test_pv01_quote()
        {
            BillTradeCalculationFunction <BillTrade> function = BillTradeCalculationFunction.TRADE;
            ScenarioMarketData             md                      = marketData();
            LegalEntityDiscountingProvider provider                = LOOKUP.marketDataView(md.scenario(0)).discountingProvider();
            DiscountingBillTradePricer     pricer                  = DiscountingBillTradePricer.DEFAULT;
            PointSensitivities             pvPointSens             = pricer.presentValueSensitivity(RTRADE, provider);
            CurrencyParameterSensitivities pvParamSens             = provider.parameterSensitivity(pvPointSens);
            CurrencyParameterSensitivities expectedPv01CalBucketed = MQ_CALC.sensitivity(pvParamSens, provider).multipliedBy(1e-4);
            MultiCurrencyAmount            expectedPv01Cal         = expectedPv01CalBucketed.total();

            ISet <Measure> measures = ImmutableSet.of(Measures.PV01_MARKET_QUOTE_SUM, Measures.PV01_MARKET_QUOTE_BUCKETED);

            assertThat(function.calculate(TRADE, measures, PARAMS, md, REF_DATA)).containsEntry(Measures.PV01_MARKET_QUOTE_SUM, Result.success(MultiCurrencyScenarioArray.of(ImmutableList.of(expectedPv01Cal)))).containsEntry(Measures.PV01_MARKET_QUOTE_BUCKETED, Result.success(ScenarioArray.of(ImmutableList.of(expectedPv01CalBucketed))));
        }
Beispiel #14
0
        public virtual void test_simpleMeasures()
        {
            CapitalIndexedBondTradeCalculationFunction <CapitalIndexedBondTrade> function = CapitalIndexedBondTradeCalculationFunction.TRADE;
            ScenarioMarketData                       md                       = marketData();
            RatesProvider                            ratesProvider            = RATES_LOOKUP.marketDataView(md.scenario(0)).ratesProvider();
            LegalEntityDiscountingProvider           ledProvider              = LED_LOOKUP.marketDataView(md.scenario(0)).discountingProvider();
            DiscountingCapitalIndexedBondTradePricer pricer                   = DiscountingCapitalIndexedBondTradePricer.DEFAULT;
            CurrencyAmount                           expectedPv               = pricer.presentValue(RTRADE, ratesProvider, ledProvider);
            MultiCurrencyAmount                      expectedCurrencyExposure = pricer.currencyExposure(RTRADE, ratesProvider, ledProvider);
            CurrencyAmount                           expectedCurrentCash      = pricer.currentCash(RTRADE, ratesProvider);

            ISet <Measure> measures = ImmutableSet.of(Measures.PRESENT_VALUE, Measures.CURRENCY_EXPOSURE, Measures.CURRENT_CASH, Measures.RESOLVED_TARGET);

            assertThat(function.calculate(TRADE, measures, PARAMS, md, REF_DATA)).containsEntry(Measures.PRESENT_VALUE, Result.success(CurrencyScenarioArray.of(ImmutableList.of(expectedPv)))).containsEntry(Measures.CURRENCY_EXPOSURE, Result.success(MultiCurrencyScenarioArray.of(ImmutableList.of(expectedCurrencyExposure)))).containsEntry(Measures.CURRENT_CASH, Result.success(CurrencyScenarioArray.of(ImmutableList.of(expectedCurrentCash)))).containsEntry(Measures.RESOLVED_TARGET, Result.success(RTRADE));
        }
Beispiel #15
0
        public virtual void test_pv01()
        {
            BondFutureOptionTradeCalculationFunction <BondFutureOptionTrade> function = BondFutureOptionTradeCalculationFunction.TRADE;
            ScenarioMarketData                       md                      = marketData();
            LegalEntityDiscountingProvider           provider                = LED_LOOKUP.marketDataView(md.scenario(0)).discountingProvider();
            BlackBondFutureOptionMarginedTradePricer pricer                  = BlackBondFutureOptionMarginedTradePricer.DEFAULT;
            PointSensitivities                       pvPointSens             = pricer.presentValueSensitivityRates(RTRADE, provider, VOLS);
            CurrencyParameterSensitivities           pvParamSens             = provider.parameterSensitivity(pvPointSens);
            MultiCurrencyAmount                      expectedPv01Cal         = pvParamSens.total().multipliedBy(1e-4);
            CurrencyParameterSensitivities           expectedPv01CalBucketed = pvParamSens.multipliedBy(1e-4);

            ISet <Measure> measures = ImmutableSet.of(Measures.PV01_CALIBRATED_SUM, Measures.PV01_CALIBRATED_BUCKETED);

            assertThat(function.calculate(TRADE, measures, PARAMS, md, REF_DATA)).containsEntry(Measures.PV01_CALIBRATED_SUM, Result.success(MultiCurrencyScenarioArray.of(ImmutableList.of(expectedPv01Cal)))).containsEntry(Measures.PV01_CALIBRATED_BUCKETED, Result.success(ScenarioArray.of(ImmutableList.of(expectedPv01CalBucketed))));
        }
Beispiel #16
0
        /// <summary>
        /// Calculates the present value of a bill trade.
        /// <para>
        /// If the settlement details are provided, the present value is the sum of the underlying product's present value
        /// multiplied by the quantity and the present value of the settlement payment if still due at the valuation date.
        /// If not it is the underlying product's present value multiplied by the quantity.
        ///
        /// </para>
        /// </summary>
        /// <param name="trade">  the trade </param>
        /// <param name="provider">  the discounting provider </param>
        /// <returns> the present value </returns>
        public virtual CurrencyAmount presentValue(ResolvedBillTrade trade, LegalEntityDiscountingProvider provider)
        {
            if (provider.ValuationDate.isAfter(trade.Product.Notional.Date))
            {
                return(CurrencyAmount.of(trade.Product.Currency, 0.0d));
            }
            CurrencyAmount pvProduct = productPricer.presentValue(trade.Product, provider).multipliedBy(trade.Quantity);

            if (trade.Settlement.Present)
            {
                RepoCurveDiscountFactors repoDf   = DiscountingBillProductPricer.repoCurveDf(trade.Product, provider);
                CurrencyAmount           pvSettle = paymentPricer.presentValue(trade.Settlement.get(), repoDf.DiscountFactors);
                return(pvProduct.plus(pvSettle));
            }
            return(pvProduct);
        }
Beispiel #17
0
        public virtual void test_pv01_quote()
        {
            FixedCouponBondTradeCalculationFunction <FixedCouponBondTrade> function = FixedCouponBondTradeCalculationFunction.TRADE;
            ScenarioMarketData                    md                      = marketData();
            LegalEntityDiscountingProvider        provider                = LOOKUP.marketDataView(md.scenario(0)).discountingProvider();
            DiscountingFixedCouponBondTradePricer pricer                  = DiscountingFixedCouponBondTradePricer.DEFAULT;
            PointSensitivities                    pvPointSens             = pricer.presentValueSensitivity(RTRADE, provider);
            CurrencyParameterSensitivities        pvParamSens             = provider.parameterSensitivity(pvPointSens);
            CurrencyParameterSensitivities        expectedPv01CalBucketed = MQ_CALC.sensitivity(pvParamSens, provider).multipliedBy(1e-4);
            MultiCurrencyAmount                   expectedPv01Cal         = expectedPv01CalBucketed.total();

            ISet <Measure> measures = ImmutableSet.of(Measures.PV01_MARKET_QUOTE_SUM, Measures.PV01_MARKET_QUOTE_BUCKETED);
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: java.util.Map<com.opengamma.strata.calc.Measure, com.opengamma.strata.collect.result.Result<?>> computed = function.calculate(TRADE, measures, PARAMS, md, REF_DATA);
            IDictionary <Measure, Result <object> > computed = function.calculate(TRADE, measures, PARAMS, md, REF_DATA);
            MultiCurrencyScenarioArray sumComputed           = (MultiCurrencyScenarioArray)computed[Measures.PV01_MARKET_QUOTE_SUM].Value;
            ScenarioArray <CurrencyParameterSensitivities> bucketedComputed = (ScenarioArray <CurrencyParameterSensitivities>)computed[Measures.PV01_MARKET_QUOTE_BUCKETED].Value;

            assertEquals(sumComputed.ScenarioCount, 1);
            assertEquals(sumComputed.get(0).Currencies, ImmutableSet.of(GBP));
            assertTrue(DoubleMath.fuzzyEquals(sumComputed.get(0).getAmount(GBP).Amount, expectedPv01Cal.getAmount(GBP).Amount, 1.0e-10));
            assertEquals(bucketedComputed.ScenarioCount, 1);
            assertTrue(bucketedComputed.get(0).equalWithTolerance(expectedPv01CalBucketed, 1.0e-10));
        }
Beispiel #18
0
        //-------------------------------------------------------------------------
        /// <summary>
        /// Calculates the present value of the bond trade.
        /// <para>
        /// The present value of the trade is the value on the valuation date.
        /// The result is expressed using the payment currency of the bond.
        /// </para>
        /// <para>
        /// Coupon payments of the underlying product are considered based on the settlement date of the trade.
        ///
        /// </para>
        /// </summary>
        /// <param name="trade">  the trade </param>
        /// <param name="ratesProvider">  the rates provider, used to determine price index values </param>
        /// <param name="discountingProvider">  the discount factors provider </param>
        /// <returns> the present value of the bond trade </returns>
        public virtual CurrencyAmount presentValue(ResolvedCapitalIndexedBondTrade trade, RatesProvider ratesProvider, LegalEntityDiscountingProvider discountingProvider)
        {
            validate(ratesProvider, discountingProvider);
            LocalDate      settlementDate = this.settlementDate(trade, ratesProvider.ValuationDate);
            CurrencyAmount pvProduct      = productPricer.presentValue(trade.Product, ratesProvider, discountingProvider, settlementDate);

            return(presentValueFromProductPresentValue(trade, ratesProvider, discountingProvider, pvProduct));
        }
Beispiel #19
0
 private void validate(RatesProvider ratesProvider, LegalEntityDiscountingProvider discountingProvider)
 {
     ArgChecker.isTrue(ratesProvider.ValuationDate.isEqual(discountingProvider.ValuationDate), "the rates providers should be for the same date");
 }
Beispiel #20
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));
        }
Beispiel #21
0
        //-------------------------------------------------------------------------
        // the sensitivity of the product plus settlement
        private PointSensitivityBuilder presentValueSensitivityFromProductPresentValueSensitivity(ResolvedCapitalIndexedBondTrade trade, RatesProvider ratesProvider, LegalEntityDiscountingProvider discountingProvider, PointSensitivityBuilder productPresnetValueSensitivity)
        {
            PointSensitivityBuilder sensiProduct = productPresnetValueSensitivity.multipliedBy(trade.Quantity);
            PointSensitivityBuilder sensiPayment = presentValueSensitivitySettlement(trade, ratesProvider, discountingProvider);

            return(sensiProduct.combinedWith(sensiPayment));
        }
Beispiel #22
0
        private CurrencyAmount presentValueFromProductPresentValue(ResolvedCapitalIndexedBondTrade trade, RatesProvider ratesProvider, LegalEntityDiscountingProvider discountingProvider, CurrencyAmount productPresentValue)
        {
            CurrencyAmount pvProduct = productPresentValue.multipliedBy(trade.Quantity);
            CurrencyAmount pvPayment = presentValueSettlement(trade, ratesProvider, discountingProvider);

            return(pvProduct.plus(pvPayment));
        }
Beispiel #23
0
        //-------------------------------------------------------------------------
        private CurrencyAmount presentValueSettlement(ResolvedCapitalIndexedBondTrade trade, RatesProvider ratesProvider, LegalEntityDiscountingProvider discountingProvider)
        {
            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;
            ResolvedCapitalIndexedBond product      = trade.Product;
            CurrencyAmount             netAmount    = this.netAmount(trade, ratesProvider);
            RepoCurveDiscountFactors   repoDf       = DiscountingCapitalIndexedBondProductPricer.repoCurveDf(product, discountingProvider);

            return(netAmount.multipliedBy(repoDf.discountFactor(settlePeriod.PaymentDate)));
        }
Beispiel #24
0
        /// <summary>
        /// Calculates the currency exposure of the bond trade with z-spread.
        /// </summary>
        /// <param name="trade">  the trade </param>
        /// <param name="ratesProvider">  the rates provider, used to determine price index values </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>
        /// <returns> the currency exposure of the trade </returns>
        public virtual MultiCurrencyAmount currencyExposureWithZSpread(ResolvedCapitalIndexedBondTrade trade, RatesProvider ratesProvider, LegalEntityDiscountingProvider discountingProvider, double zSpread, CompoundedRateType compoundedRateType, int periodsPerYear)
        {
            CurrencyAmount pv = presentValueWithZSpread(trade, ratesProvider, discountingProvider, zSpread, compoundedRateType, periodsPerYear);

            return(MultiCurrencyAmount.of(pv));
        }
Beispiel #25
0
        /// <summary>
        /// Calculates the currency exposure of the bond trade.
        /// </summary>
        /// <param name="trade">  the trade </param>
        /// <param name="ratesProvider">  the rates provider, used to determine price index values </param>
        /// <param name="discountingProvider">  the discount factors provider </param>
        /// <returns> the currency exposure of the trade </returns>
        public virtual MultiCurrencyAmount currencyExposure(ResolvedCapitalIndexedBondTrade trade, RatesProvider ratesProvider, LegalEntityDiscountingProvider discountingProvider)
        {
            CurrencyAmount pv = presentValue(trade, ratesProvider, discountingProvider);

            return(MultiCurrencyAmount.of(pv));
        }
Beispiel #26
0
        //-------------------------------------------------------------------------
        /// <summary>
        /// Calculates the currency exposure of the bond trade.
        /// </summary>
        /// <param name="trade">  the trade </param>
        /// <param name="ratesProvider">  the rates provider, used to determine price index values </param>
        /// <param name="discountingProvider">  the discount factors provider </param>
        /// <param name="refData">  the reference data used to calculate the settlement date </param>
        /// <param name="cleanRealPrice">  the clean real price </param>
        /// <returns> the currency exposure of the trade </returns>
        public virtual MultiCurrencyAmount currencyExposureFromCleanPrice(ResolvedCapitalIndexedBondTrade trade, RatesProvider ratesProvider, LegalEntityDiscountingProvider discountingProvider, ReferenceData refData, double cleanRealPrice)
        {
            CurrencyAmount pv = presentValueFromCleanPrice(trade, ratesProvider, discountingProvider, refData, cleanRealPrice);

            return(MultiCurrencyAmount.of(pv));
        }
Beispiel #27
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());
        }
Beispiel #28
0
        /// <summary>
        /// Calculates the present value of the settlement of the bond trade from the clean price with z-spread.
        /// <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>
        /// <para>
        /// The z-spread is a parallel shift applied to continuously compounded rates or periodic
        /// compounded rates of the discounting curve.
        ///
        /// </para>
        /// </summary>
        /// <param name="trade">  the trade </param>
        /// <param name="ratesProvider">  the rates provider, used to determine price index values </param>
        /// <param name="discountingProvider">  the discount factors provider </param>
        /// <param name="refData">  the reference data used to calculate the settlement date </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 of the settlement </returns>
        public virtual CurrencyAmount presentValueFromCleanPriceWithZSpread(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);
            CurrencyAmount pvStandard = forecastValueStandardFromCleanPrice(bond, ratesProvider, standardSettlementDate, cleanRealPrice).multipliedBy(df);

            if (standardSettlementDate.isEqual(tradeSettlementDate))
            {
                return(presentValueFromProductPresentValue(trade, ratesProvider, discountingProvider, pvStandard));
            }
            // check coupon payment between two settlement dates
            IssuerCurveDiscountFactors issuerDf = DiscountingCapitalIndexedBondProductPricer.issuerCurveDf(bond, discountingProvider);
            double pvDiff = 0d;

            if (standardSettlementDate.isAfter(tradeSettlementDate))
            {
                pvDiff = -productPricer.presentValueCouponWithZSpread(bond, ratesProvider, issuerDf, tradeSettlementDate, standardSettlementDate, zSpread, compoundedRateType, periodsPerYear);
            }
            else
            {
                pvDiff = productPricer.presentValueCouponWithZSpread(bond, ratesProvider, issuerDf, standardSettlementDate, tradeSettlementDate, zSpread, compoundedRateType, periodsPerYear);
            }
            return(presentValueFromProductPresentValue(trade, ratesProvider, discountingProvider, pvStandard.plus(pvDiff)));
        }
Beispiel #29
0
        /// <summary>
        /// Calculates the present value sensitivity of the bond trade with z-spread.
        /// <para>
        /// The present value sensitivity of the trade is the sensitivity of the present value to
        /// the underlying curves.
        /// </para>
        /// <para>
        /// Coupon payments of the underlying product are considered based on the settlement date of the trade.
        ///
        /// </para>
        /// </summary>
        /// <param name="trade">  the trade </param>
        /// <param name="ratesProvider">  the rates provider, used to determine price index values </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>
        /// <returns> the present value sensitivity of the bond trade </returns>
        public virtual PointSensitivities presentValueSensitivityWithZSpread(ResolvedCapitalIndexedBondTrade trade, RatesProvider ratesProvider, LegalEntityDiscountingProvider discountingProvider, double zSpread, CompoundedRateType compoundedRateType, int periodsPerYear)
        {
            validate(ratesProvider, discountingProvider);
            LocalDate settlementDate             = this.settlementDate(trade, ratesProvider.ValuationDate);
            PointSensitivityBuilder productSensi = productPricer.presentValueSensitivityWithZSpread(trade.Product, ratesProvider, discountingProvider, settlementDate, zSpread, compoundedRateType, periodsPerYear);

            return(presentValueSensitivityFromProductPresentValueSensitivity(trade, ratesProvider, discountingProvider, productSensi).build());
        }
Beispiel #30
0
        //-------------------------------------------------------------------------
        /// <summary>
        /// Calculates the present value sensitivity of the bond trade.
        /// <para>
        /// The present value sensitivity of the trade is the sensitivity of the present value to
        /// the underlying curves.
        /// </para>
        /// <para>
        /// Coupon payments of the underlying product are considered based on the settlement date of the trade.
        ///
        /// </para>
        /// </summary>
        /// <param name="trade">  the trade </param>
        /// <param name="ratesProvider">  the rates provider, used to determine price index values </param>
        /// <param name="discountingProvider">  the discount factors provider </param>
        /// <returns> the present value sensitivity of the bond trade </returns>
        public virtual PointSensitivities presentValueSensitivity(ResolvedCapitalIndexedBondTrade trade, RatesProvider ratesProvider, LegalEntityDiscountingProvider discountingProvider)
        {
            validate(ratesProvider, discountingProvider);
            LocalDate settlementDate             = this.settlementDate(trade, ratesProvider.ValuationDate);
            PointSensitivityBuilder productSensi = productPricer.presentValueSensitivity(trade.Product, ratesProvider, discountingProvider, settlementDate);

            return(presentValueSensitivityFromProductPresentValueSensitivity(trade, ratesProvider, discountingProvider, productSensi).build());
        }