Ejemplo n.º 1
0
        //-------------------------------------------------------------------------
        /// <summary>
        /// Calculates the present value sensitivity of the deliverable swap futures trade.
        /// <para>
        /// The present value sensitivity of the trade 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 </param>
        /// <returns> the present value curve sensitivity of the trade </returns>
        public virtual PointSensitivities presentValueSensitivity(ResolvedDsfTrade trade, RatesProvider ratesProvider)
        {
            ResolvedDsf        product          = trade.Product;
            PointSensitivities priceSensi       = productPricer.priceSensitivity(product, ratesProvider);
            PointSensitivities marginIndexSensi = productPricer.marginIndexSensitivity(product, priceSensi);

            return(marginIndexSensi.multipliedBy(trade.Quantity));
        }
        //-------------------------------------------------------------------------
        /// <summary>
        /// Calculates the price of the deliverable swap futures product.
        /// <para>
        /// The price of the product is the price on the valuation date.
        ///
        /// </para>
        /// </summary>
        /// <param name="future">  the future </param>
        /// <param name="ratesProvider">  the rates provider </param>
        /// <returns> the price of the product, in decimal form </returns>
        public double price(ResolvedDsf future, RatesProvider ratesProvider)
        {
            ResolvedSwap   swap     = future.UnderlyingSwap;
            Currency       currency = future.Currency;
            CurrencyAmount pvSwap   = swapPricer.presentValue(swap, currency, ratesProvider);
            double         df       = ratesProvider.discountFactor(currency, future.DeliveryDate);

            return(1d + pvSwap.Amount / df);
        }
Ejemplo n.º 3
0
        //-------------------------------------------------------------------------
        /// <summary>
        /// Calculates the present value of the deliverable swap futures trade from the current price.
        /// <para>
        /// The present value of the product is the value on the valuation date.
        /// The current price is specified, not calculated.
        /// </para>
        /// <para>
        /// The calculation is performed against a reference price. The reference price
        /// must be the last settlement price used for margining, except on the trade date,
        /// when it must be the trade price.
        ///
        /// </para>
        /// </summary>
        /// <param name="trade">  the trade </param>
        /// <param name="currentPrice">  the current price, in decimal form </param>
        /// <param name="referencePrice">  the reference price to margin against, typically the last settlement price, in decimal form </param>
        /// <returns> the present value </returns>
        private CurrencyAmount presentValue(ResolvedDsfTrade trade, double currentPrice, double referencePrice)
        {
            ResolvedDsf future         = trade.Product;
            double      priceIndex     = productPricer.marginIndex(future, currentPrice);
            double      referenceIndex = productPricer.marginIndex(future, referencePrice);
            double      pv             = (priceIndex - referenceIndex) * trade.Quantity;

            return(CurrencyAmount.of(future.Currency, pv));
        }
        //-------------------------------------------------------------------------
        /// <summary>
        /// Calculates the price sensitivity of the deliverable swap futures product.
        /// <para>
        /// The price sensitivity of the product is the sensitivity of the price to the underlying curves.
        ///
        /// </para>
        /// </summary>
        /// <param name="future">  the future </param>
        /// <param name="ratesProvider">  the rates provider </param>
        /// <returns> the price curve sensitivity of the product </returns>
        public PointSensitivities priceSensitivity(ResolvedDsf future, RatesProvider ratesProvider)
        {
            ResolvedSwap            swap        = future.UnderlyingSwap;
            Currency                currency    = future.Currency;
            double                  pvSwap      = swapPricer.presentValue(swap, currency, ratesProvider).Amount;
            double                  dfInv       = 1d / ratesProvider.discountFactor(currency, future.DeliveryDate);
            PointSensitivityBuilder sensiSwapPv = swapPricer.presentValueSensitivity(swap, ratesProvider).multipliedBy(dfInv);
            PointSensitivityBuilder sensiDf     = ratesProvider.discountFactors(currency).zeroRatePointSensitivity(future.DeliveryDate).multipliedBy(-pvSwap * dfInv * dfInv);

            return(sensiSwapPv.combinedWith(sensiDf).build());
        }
 /// <summary>
 /// Calculates the margin index sensitivity of the deliverable swap futures product.
 /// <para>
 /// The margin index sensitivity is the sensitivity of the margin index to the underlying curves.
 /// For two consecutive settlement prices C1 and C2, the daily margin is computed as
 ///    {@code (marginIndex(future, C2) - marginIndex(future, C1))}.
 ///
 /// </para>
 /// </summary>
 /// <param name="future">  the future </param>
 /// <param name="priceSensitivity">  the price sensitivity of the product </param>
 /// <returns> the index sensitivity </returns>
 internal PointSensitivities marginIndexSensitivity(ResolvedDsf future, PointSensitivities priceSensitivity)
 {
     return(priceSensitivity.multipliedBy(future.Notional));
 }
 //-------------------------------------------------------------------------
 /// <summary>
 /// Calculates the number related to deliverable swap futures product on which the daily margin is computed.
 /// <para>
 /// For two consecutive settlement prices C1 and C2, the daily margin is computed as
 ///    {@code (marginIndex(future, C2) - marginIndex(future, C1))}.
 ///
 /// </para>
 /// </summary>
 /// <param name="future">  the future </param>
 /// <param name="price">  the price of the product, in decimal form </param>
 /// <returns> the index </returns>
 internal double marginIndex(ResolvedDsf future, double price)
 {
     return(price * future.Notional);
 }