Esempio n. 1
0
        //-------------------------------------------------------------------------
        /// <summary>
        /// Calculates the present value sensitivity of the fixed coupon 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="provider">  the discounting provider </param>
        /// <returns> the present value curve sensitivity of the trade </returns>
        public virtual PointSensitivities presentValueSensitivity(ResolvedFixedCouponBondTrade trade, LegalEntityDiscountingProvider provider)
        {
            LocalDate settlementDate             = this.settlementDate(trade, provider.ValuationDate);
            PointSensitivityBuilder sensiProduct = productPricer.presentValueSensitivity(trade.Product, provider, settlementDate);

            return(presentValueSensitivityFromProductPresentValueSensitivity(trade, provider, sensiProduct).build());
        }
Esempio n. 2
0
        /// <summary>
        /// Calculates the present value sensitivity of the fixed coupon 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>
        /// The z-spread is a parallel shift applied to continuously compounded rates or periodic
        /// compounded rates of the discounting curve.
        /// </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="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 trade </returns>
        public virtual PointSensitivities presentValueSensitivityWithZSpread(ResolvedFixedCouponBondTrade trade, LegalEntityDiscountingProvider provider, double zSpread, CompoundedRateType compoundedRateType, int periodsPerYear)
        {
            LocalDate settlementDate             = this.settlementDate(trade, provider.ValuationDate);
            PointSensitivityBuilder sensiProduct = productPricer.presentValueSensitivityWithZSpread(trade.Product, provider, zSpread, compoundedRateType, periodsPerYear, settlementDate);

            return(presentValueSensitivityFromProductPresentValueSensitivity(trade, provider, sensiProduct).build());
        }
Esempio n. 3
0
        /// <summary>
        /// Calculates the present value of the fixed coupon bond trade with z-spread from the
        /// clean price of the underlying product.
        /// <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>
        /// The z-spread is a parallel shift applied to continuously compounded rates or periodic
        /// compounded rates of the discounting curve.
        /// </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="provider">  the discounting provider </param>
        /// <param name="refData">  the reference data used to calculate the settlement date </param>
        /// <param name="cleanPrice">  the clean price </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 fixed coupon bond trade </returns>
        public virtual CurrencyAmount presentValueFromCleanPriceWithZSpread(ResolvedFixedCouponBondTrade trade, LegalEntityDiscountingProvider provider, ReferenceData refData, double cleanPrice, double zSpread, CompoundedRateType compoundedRateType, int periodsPerYear)
        {
            ResolvedFixedCouponBond product  = trade.Product;
            LocalDate standardSettlementDate = this.standardSettlementDate(product, provider, refData);
            LocalDate tradeSettlementDate    = settlementDate(trade, provider.ValuationDate);
            Currency  currency = product.Currency;
            RepoCurveDiscountFactors repoDf = DiscountingFixedCouponBondProductPricer.repoCurveDf(product, provider);
            double df         = repoDf.discountFactor(standardSettlementDate);
            double pvStandard = (cleanPrice * product.Notional + productPricer.accruedInterest(product, standardSettlementDate)) * df;

            if (standardSettlementDate.isEqual(tradeSettlementDate))
            {
                return(presentValueFromProductPresentValue(trade, provider, CurrencyAmount.of(currency, pvStandard)));
            }
            // check coupon payment between two settlement dates
            IssuerCurveDiscountFactors issuerDf = DiscountingFixedCouponBondProductPricer.issuerCurveDf(product, provider);
            double pvDiff = 0d;

            if (standardSettlementDate.isAfter(tradeSettlementDate))
            {
                pvDiff = productPricer.presentValueCouponWithZSpread(product, issuerDf, tradeSettlementDate, standardSettlementDate, zSpread, compoundedRateType, periodsPerYear);
            }
            else
            {
                pvDiff = -productPricer.presentValueCouponWithZSpread(product, issuerDf, standardSettlementDate, tradeSettlementDate, zSpread, compoundedRateType, periodsPerYear);
            }
            return(presentValueFromProductPresentValue(trade, provider, CurrencyAmount.of(currency, pvStandard + pvDiff)));
        }
Esempio n. 4
0
        //-------------------------------------------------------------------------
        /// <summary>
        /// Calculates the present value of the fixed coupon 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="provider">  the discounting provider </param>
        /// <returns> the present value of the fixed coupon bond trade </returns>
        public virtual CurrencyAmount presentValue(ResolvedFixedCouponBondTrade trade, LegalEntityDiscountingProvider provider)
        {
            LocalDate      settlementDate = this.settlementDate(trade, provider.ValuationDate);
            CurrencyAmount pvProduct      = productPricer.presentValue(trade.Product, provider, settlementDate);

            return(presentValueFromProductPresentValue(trade, provider, pvProduct));
        }
Esempio n. 5
0
        /// <summary>
        /// Calculates the present value of the fixed coupon bond trade with z-spread.
        /// <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>
        /// The z-spread is a parallel shift applied to continuously compounded rates or periodic
        /// compounded rates of the discounting curve.
        /// </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="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 fixed coupon bond trade </returns>
        public virtual CurrencyAmount presentValueWithZSpread(ResolvedFixedCouponBondTrade trade, LegalEntityDiscountingProvider provider, double zSpread, CompoundedRateType compoundedRateType, int periodsPerYear)
        {
            LocalDate      settlementDate = this.settlementDate(trade, provider.ValuationDate);
            CurrencyAmount pvProduct      = productPricer.presentValueWithZSpread(trade.Product, provider, zSpread, compoundedRateType, periodsPerYear, settlementDate);

            return(presentValueFromProductPresentValue(trade, provider, pvProduct));
        }
Esempio n. 6
0
        //-------------------------------------------------------------------------
        private CurrencyAmount presentValuePayment(ResolvedFixedCouponBondTrade trade, LegalEntityDiscountingProvider provider)
        {
            RepoCurveDiscountFactors repoDf = DiscountingFixedCouponBondProductPricer.repoCurveDf(trade.Product, provider);
            Payment upfrontPayment          = this.upfrontPayment(trade);

            return(paymentPricer.presentValue(upfrontPayment, repoDf.DiscountFactors));
        }
        // market quote bucketed PV01 for one scenario
        internal CurrencyParameterSensitivities pv01MarketQuoteBucketed(ResolvedFixedCouponBondTrade trade, LegalEntityDiscountingProvider ratesProvider)
        {
            PointSensitivities             pointSensitivity     = tradePricer.presentValueSensitivity(trade, ratesProvider);
            CurrencyParameterSensitivities parameterSensitivity = ratesProvider.parameterSensitivity(pointSensitivity);

            return(MARKET_QUOTE_SENS.sensitivity(parameterSensitivity, ratesProvider).multipliedBy(ONE_BASIS_POINT));
        }
Esempio n. 8
0
        private CurrencyAmount presentValueFromProductPresentValue(ResolvedFixedCouponBondTrade trade, LegalEntityDiscountingProvider provider, CurrencyAmount productPresentValue)
        {
            CurrencyAmount pvProduct = productPresentValue.multipliedBy(trade.Quantity);
            CurrencyAmount pvPayment = presentValuePayment(trade, provider);

            return(pvProduct.plus(pvPayment));
        }
Esempio n. 9
0
        private PointSensitivityBuilder presentValueSensitivityPayment(ResolvedFixedCouponBondTrade trade, LegalEntityDiscountingProvider provider)
        {
            RepoCurveDiscountFactors repoDf = DiscountingFixedCouponBondProductPricer.repoCurveDf(trade.Product, provider);
            Payment upfrontPayment          = this.upfrontPayment(trade);
            PointSensitivityBuilder pt      = paymentPricer.presentValueSensitivity(upfrontPayment, repoDf.DiscountFactors);

            if (pt is ZeroRateSensitivity)
            {
                return(RepoCurveZeroRateSensitivity.of((ZeroRateSensitivity)pt, repoDf.RepoGroup));
            }
            return(pt);    // NoPointSensitivity
        }
Esempio n. 10
0
        //-------------------------------------------------------------------------
        /// <summary>
        /// Calculates the payment that was made for the trade.
        /// <para>
        /// This is the payment that was made on the settlement date, based on the quantity and clean price.
        ///
        /// </para>
        /// </summary>
        /// <param name="trade">  the trade </param>
        /// <returns> the payment that was made </returns>
        public virtual Payment upfrontPayment(ResolvedFixedCouponBondTrade trade)
        {
            ResolvedFixedCouponBond product = trade.Product;
            Currency currency = product.Currency;

            if (!trade.Settlement.Present)
            {
                return(Payment.of(CurrencyAmount.zero(currency), product.StartDate));  // date doesn't matter as it is zero
            }
            // payment is based on the dirty price
            ResolvedFixedCouponBondSettlement settlement = trade.Settlement.get();
            LocalDate settlementDate = settlement.SettlementDate;
            double    cleanPrice     = settlement.Price;
            double    dirtyPrice     = productPricer.dirtyPriceFromCleanPrice(product, settlementDate, cleanPrice);
            // calculate payment
            double quantity = trade.Quantity;
            double notional = product.Notional;

            return(Payment.of(CurrencyAmount.of(currency, -quantity * notional * dirtyPrice), settlementDate));
        }
Esempio n. 11
0
        /// <summary>
        /// Calculates the current cash of the fixed coupon bond trade.
        /// </summary>
        /// <param name="trade">  the trade </param>
        /// <param name="valuationDate">  the valuation date </param>
        /// <returns> the current cash amount </returns>
        public virtual CurrencyAmount currentCash(ResolvedFixedCouponBondTrade trade, LocalDate valuationDate)
        {
            Payment        upfrontPayment = this.upfrontPayment(trade);
            Currency       currency       = upfrontPayment.Currency; // assumes single currency is involved in trade
            CurrencyAmount currentCash    = CurrencyAmount.zero(currency);

            if (upfrontPayment.Date.Equals(valuationDate))
            {
                currentCash = currentCash.plus(upfrontPayment.Value);
            }
            if (trade.Settlement.Present)
            {
                LocalDate settlementDate        = trade.Settlement.get().SettlementDate;
                ResolvedFixedCouponBond product = trade.Product;
                if (!settlementDate.isAfter(valuationDate))
                {
                    double  cashCoupon  = product.hasExCouponPeriod() ? 0d : currentCashCouponPayment(product, valuationDate);
                    Payment payment     = product.NominalPayment;
                    double  cashNominal = payment.Date.isEqual(valuationDate) ? payment.Amount : 0d;
                    currentCash = currentCash.plus(CurrencyAmount.of(currency, (cashCoupon + cashNominal) * trade.Quantity));
                }
            }
            return(currentCash);
        }
 //-------------------------------------------------------------------------
 /// <summary>
 /// Calculates present value across one or more scenarios.
 /// </summary>
 /// <param name="trade">  the trade </param>
 /// <param name="lookup">  the lookup used to query the market data </param>
 /// <param name="marketData">  the market data </param>
 /// <returns> the present value, one entry per scenario </returns>
 public virtual CurrencyScenarioArray presentValue(ResolvedFixedCouponBondTrade trade, LegalEntityDiscountingMarketDataLookup lookup, ScenarioMarketData marketData)
 {
     return(calc.presentValue(trade, lookup.marketDataView(marketData)));
 }
 /// <summary>
 /// Calculates current cash for a single set of market data.
 /// <para>
 /// The sum of all cash flows paid on the valuation date.
 ///
 /// </para>
 /// </summary>
 /// <param name="trade">  the trade </param>
 /// <param name="ratesProvider">  the market data </param>
 /// <returns> the current cash </returns>
 public virtual CurrencyAmount currentCash(ResolvedFixedCouponBondTrade trade, LegalEntityDiscountingProvider ratesProvider)
 {
     return(calc.currentCash(trade, ratesProvider));
 }
 //-------------------------------------------------------------------------
 /// <summary>
 /// Calculates currency exposure across one or more scenarios.
 /// <para>
 /// The currency risk, expressed as the equivalent amount in each currency.
 ///
 /// </para>
 /// </summary>
 /// <param name="trade">  the trade </param>
 /// <param name="lookup">  the lookup used to query the market data </param>
 /// <param name="marketData">  the market data </param>
 /// <returns> the currency exposure, one entry per scenario </returns>
 public virtual MultiCurrencyScenarioArray currencyExposure(ResolvedFixedCouponBondTrade trade, LegalEntityDiscountingMarketDataLookup lookup, ScenarioMarketData marketData)
 {
     return(calc.currencyExposure(trade, lookup.marketDataView(marketData)));
 }
 /// <summary>
 /// Calculates present value sensitivity for a single set of market data.
 /// <para>
 /// This is the sensitivity of
 /// <seealso cref="#presentValue(ResolvedFixedCouponBondTrade, LegalEntityDiscountingMarketDataLookup, ScenarioMarketData) present value"/>
 /// to a one basis point shift in the market quotes used to calibrate the curves.
 /// The result is provided for each affected curve and currency, bucketed by curve node.
 ///
 /// </para>
 /// </summary>
 /// <param name="trade">  the trade </param>
 /// <param name="ratesProvider">  the market data </param>
 /// <returns> the present value sensitivity </returns>
 public virtual CurrencyParameterSensitivities pv01MarketQuoteBucketed(ResolvedFixedCouponBondTrade trade, LegalEntityDiscountingProvider ratesProvider)
 {
     return(calc.pv01MarketQuoteBucketed(trade, ratesProvider));
 }
Esempio n. 16
0
 //-------------------------------------------------------------------------
 /// <summary>
 /// Calculates the currency exposure of the fixed coupon bond trade.
 /// </summary>
 /// <param name="trade">  the trade </param>
 /// <param name="provider">  the discounting provider </param>
 /// <returns> the currency exposure of the fixed coupon bond trade </returns>
 public virtual MultiCurrencyAmount currencyExposure(ResolvedFixedCouponBondTrade trade, LegalEntityDiscountingProvider provider)
 {
     return(MultiCurrencyAmount.of(presentValue(trade, provider)));
 }
 // current cash for one scenario
 internal CurrencyAmount currentCash(ResolvedFixedCouponBondTrade trade, LegalEntityDiscountingProvider discountingProvider)
 {
     return(tradePricer.currentCash(trade, discountingProvider.ValuationDate));
 }
Esempio n. 18
0
 //-------------------------------------------------------------------------
 // calculate the settlement date
 private LocalDate settlementDate(ResolvedFixedCouponBondTrade trade, LocalDate valuationDate)
 {
     return(trade.Settlement.map(settle => settle.SettlementDate).orElse(valuationDate));
 }
Esempio n. 19
0
 /// <summary>
 /// Calculates the currency exposure of the fixed coupon bond trade with z-spread.
 /// </summary>
 /// <param name="trade">  the trade </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 currency exposure of the fixed coupon bond trade </returns>
 public virtual MultiCurrencyAmount currencyExposureWithZSpread(ResolvedFixedCouponBondTrade trade, LegalEntityDiscountingProvider provider, double zSpread, CompoundedRateType compoundedRateType, int periodsPerYear)
 {
     return(MultiCurrencyAmount.of(presentValueWithZSpread(trade, provider, zSpread, compoundedRateType, periodsPerYear)));
 }
 /// <summary>
 /// Calculates present value for a single set of market data.
 /// </summary>
 /// <param name="trade">  the trade </param>
 /// <param name="ratesProvider">  the market data </param>
 /// <returns> the present value </returns>
 public virtual CurrencyAmount presentValue(ResolvedFixedCouponBondTrade trade, LegalEntityDiscountingProvider ratesProvider)
 {
     return(calc.presentValue(trade, ratesProvider));
 }
 //-------------------------------------------------------------------------
 /// <summary>
 /// Calculates present value sensitivity across one or more scenarios.
 /// <para>
 /// This is the sensitivity of
 /// <seealso cref="#presentValue(ResolvedFixedCouponBondTrade, LegalEntityDiscountingMarketDataLookup, ScenarioMarketData) present value"/>
 /// to a one basis point shift in the calibrated curves.
 /// The result is the sum of the sensitivities of all affected curves.
 ///
 /// </para>
 /// </summary>
 /// <param name="trade">  the trade </param>
 /// <param name="lookup">  the lookup used to query the market data </param>
 /// <param name="marketData">  the market data </param>
 /// <returns> the present value sensitivity, one entry per scenario </returns>
 public virtual MultiCurrencyScenarioArray pv01CalibratedSum(ResolvedFixedCouponBondTrade trade, LegalEntityDiscountingMarketDataLookup lookup, ScenarioMarketData marketData)
 {
     return(calc.pv01CalibratedSum(trade, lookup.marketDataView(marketData)));
 }
 // present value for one scenario
 internal CurrencyAmount presentValue(ResolvedFixedCouponBondTrade trade, LegalEntityDiscountingProvider discountingProvider)
 {
     return(tradePricer.presentValue(trade, discountingProvider));
 }
 // currency exposure for one scenario
 internal MultiCurrencyAmount currencyExposure(ResolvedFixedCouponBondTrade trade, LegalEntityDiscountingProvider discountingProvider)
 {
     return(tradePricer.currencyExposure(trade, discountingProvider));
 }
 //-------------------------------------------------------------------------
 // calculates calibrated bucketed PV01 for all scenarios
 internal ScenarioArray <CurrencyParameterSensitivities> pv01CalibratedBucketed(ResolvedFixedCouponBondTrade trade, LegalEntityDiscountingScenarioMarketData marketData)
 {
     return(ScenarioArray.of(marketData.ScenarioCount, i => pv01CalibratedBucketed(trade, marketData.scenario(i).discountingProvider())));
 }
 //-------------------------------------------------------------------------
 // calculates present value for all scenarios
 internal CurrencyScenarioArray presentValue(ResolvedFixedCouponBondTrade trade, LegalEntityDiscountingScenarioMarketData marketData)
 {
     return(CurrencyScenarioArray.of(marketData.ScenarioCount, i => presentValue(trade, marketData.scenario(i).discountingProvider())));
 }
Esempio n. 26
0
        private PointSensitivityBuilder presentValueSensitivityFromProductPresentValueSensitivity(ResolvedFixedCouponBondTrade trade, LegalEntityDiscountingProvider provider, PointSensitivityBuilder productPresnetValueSensitivity)
        {
            PointSensitivityBuilder sensiProduct = productPresnetValueSensitivity.multipliedBy(trade.Quantity);
            PointSensitivityBuilder sensiPayment = presentValueSensitivityPayment(trade, provider);

            return(sensiProduct.combinedWith(sensiPayment));
        }
 //-------------------------------------------------------------------------
 // calculates calibrated sum PV01 for all scenarios
 internal MultiCurrencyScenarioArray pv01CalibratedSum(ResolvedFixedCouponBondTrade trade, LegalEntityDiscountingScenarioMarketData marketData)
 {
     return(MultiCurrencyScenarioArray.of(marketData.ScenarioCount, i => pv01CalibratedSum(trade, marketData.scenario(i).discountingProvider())));
 }
 /// <summary>
 /// Calculates present value sensitivity for a single set of market data.
 /// <para>
 /// This is the sensitivity of
 /// <seealso cref="#presentValue(ResolvedFixedCouponBondTrade, LegalEntityDiscountingMarketDataLookup, ScenarioMarketData) present value"/>
 /// to a one basis point shift in the market quotes used to calibrate the curves.
 /// The result is the sum of the sensitivities of all affected curves.
 ///
 /// </para>
 /// </summary>
 /// <param name="trade">  the trade </param>
 /// <param name="ratesProvider">  the market data </param>
 /// <returns> the present value sensitivity </returns>
 public virtual MultiCurrencyAmount pv01MarketQuoteSum(ResolvedFixedCouponBondTrade trade, LegalEntityDiscountingProvider ratesProvider)
 {
     return(calc.pv01MarketQuoteSum(trade, ratesProvider));
 }
        // calibrated bucketed PV01 for one scenario
        internal CurrencyParameterSensitivities pv01CalibratedBucketed(ResolvedFixedCouponBondTrade trade, LegalEntityDiscountingProvider discountingProvider)
        {
            PointSensitivities pointSensitivity = tradePricer.presentValueSensitivity(trade, discountingProvider);

            return(discountingProvider.parameterSensitivity(pointSensitivity).multipliedBy(ONE_BASIS_POINT));
        }
 //-------------------------------------------------------------------------
 /// <summary>
 /// Calculates present value sensitivity across one or more scenarios.
 /// <para>
 /// This is the sensitivity of
 /// <seealso cref="#presentValue(ResolvedFixedCouponBondTrade, LegalEntityDiscountingMarketDataLookup, ScenarioMarketData) present value"/>
 /// to a one basis point shift in the market quotes used to calibrate the curves.
 /// The result is provided for each affected curve and currency, bucketed by curve node.
 ///
 /// </para>
 /// </summary>
 /// <param name="trade">  the trade </param>
 /// <param name="lookup">  the lookup used to query the market data </param>
 /// <param name="marketData">  the market data </param>
 /// <returns> the present value sensitivity, one entry per scenario </returns>
 public virtual ScenarioArray <CurrencyParameterSensitivities> pv01MarketQuoteBucketed(ResolvedFixedCouponBondTrade trade, LegalEntityDiscountingMarketDataLookup lookup, ScenarioMarketData marketData)
 {
     return(calc.pv01MarketQuoteBucketed(trade, lookup.marketDataView(marketData)));
 }