//-------------------------------------------------------------------------
        public virtual void test_presentValue()
        {
            CurrencyAmount    computed = LEG_PRICER.presentValue(COUPON_LEG, RATES_PROVIDER);
            double            expected = 0d;
            IList <CmsPeriod> cms      = COUPON_LEG.CmsPeriods;
            int size = cms.Count;

            for (int i = 0; i < size; ++i)
            {
                expected += PERIOD_PRICER.presentValue(cms[i], RATES_PROVIDER).Amount;
            }
            assertEquals(computed.Currency, EUR);
            assertEquals(computed.Amount, expected, TOLERANCE_PV);
        }
Example #2
0
        public virtual void test_presentValue()
        {
            MultiCurrencyAmount pv1   = PRODUCT_PRICER.presentValue(CMS_ONE_LEG, RATES_PROVIDER);
            MultiCurrencyAmount pv2   = PRODUCT_PRICER.presentValue(CMS_TWO_LEGS, RATES_PROVIDER);
            CurrencyAmount      pvCms = CMS_LEG_PRICER.presentValue(CMS_LEG, RATES_PROVIDER);
            CurrencyAmount      pvPay = SWAP_LEG_PRICER.presentValue(PAY_LEG, RATES_PROVIDER);

            assertEquals(pv1, MultiCurrencyAmount.of(pvCms));
            assertEquals(pv2, MultiCurrencyAmount.of(pvCms).plus(pvPay));
        }
        //-------------------------------------------------------------------------
        /// <summary>
        /// Calculates the present value of the CMS product by simple forward estimation.
        /// </summary>
        /// <param name="cms">  the CMS product </param>
        /// <param name="ratesProvider">  the rates provider </param>
        /// <returns> the present value </returns>
        public virtual MultiCurrencyAmount presentValue(ResolvedCms cms, RatesProvider ratesProvider)
        {
            CurrencyAmount pvCmsLeg = cmsLegPricer.presentValue(cms.CmsLeg, ratesProvider);

            if (!cms.PayLeg.Present)
            {
                return(MultiCurrencyAmount.of(pvCmsLeg));
            }
            CurrencyAmount pvPayLeg = swapPricer.LegPricer.presentValue(cms.PayLeg.get(), ratesProvider);

            return(MultiCurrencyAmount.of(pvCmsLeg).plus(pvPayLeg));
        }