Exemplo n.º 1
0
        //-------------------------------------------------------------------------
        public virtual void test_price()
        {
            double computed   = FUTURE_PRICER.price(FUTURE_PRODUCT, PROVIDER);
            double dirtyPrice = BOND_PRICER.dirtyPriceFromCurves(BOND, PROVIDER, FUTURE_PRODUCT.LastDeliveryDate);
            double expected   = BOND_PRICER.cleanPriceFromDirtyPrice(BOND, FUTURE_PRODUCT.LastDeliveryDate, dirtyPrice) / CONVERSION_FACTOR[0];

            assertEquals(computed, expected, TOL);
        }
        //-------------------------------------------------------------------------
        /// <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_dirtyPriceFromCleanPrice_cleanPriceFromDirtyPrice()
        {
            double    dirtyPrice      = PRICER.dirtyPriceFromCurves(PRODUCT, PROVIDER, REF_DATA);
            LocalDate settlement      = DATE_OFFSET.adjust(VAL_DATE, REF_DATA);
            double    cleanPrice      = PRICER.cleanPriceFromDirtyPrice(PRODUCT, settlement, dirtyPrice);
            double    accruedInterest = PRICER.accruedInterest(PRODUCT, settlement);

            assertEquals(cleanPrice, dirtyPrice - accruedInterest / NOTIONAL, NOTIONAL * TOL);
            double dirtyPriceRe = PRICER.dirtyPriceFromCleanPrice(PRODUCT, settlement, cleanPrice);

            assertEquals(dirtyPriceRe, dirtyPrice, TOL);
        }