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);
        }
Beispiel #2
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));
        }