예제 #1
0
        public virtual void test_withCurrency()
        {
            PointSensitivityBuilder @base = PointSensitivityBuilder.none();

            assertSame(@base.withCurrency(GBP), @base);     // no effect
            assertSame(@base.withCurrency(USD), @base);     // no effect
        }
예제 #2
0
        /// <summary>
        /// Calculates the present value sensitivity of the swap product converted in a given currency.
        /// <para>
        /// The present value sensitivity of the product is the sensitivity of the present value to
        /// the underlying curves.
        ///
        /// </para>
        /// </summary>
        /// <param name="swap">  the product </param>
        /// <param name="currency">  the currency to convert to </param>
        /// <param name="provider">  the rates provider </param>
        /// <returns> the present value curve sensitivity of the swap product converted in the given currency </returns>
        public virtual PointSensitivityBuilder presentValueSensitivity(ResolvedSwap swap, Currency currency, RatesProvider provider)
        {
            PointSensitivityBuilder builder = PointSensitivityBuilder.none();

            foreach (ResolvedSwapLeg leg in swap.Legs)
            {
                PointSensitivityBuilder ls          = legPricer.presentValueSensitivity(leg, provider);
                PointSensitivityBuilder lsConverted = ls.withCurrency(currency).multipliedBy(provider.fxRate(leg.Currency, currency));
                builder = builder.combinedWith(lsConverted);
            }
            return(builder);
        }
예제 #3
0
        /// <summary>
        /// Calculates the par rate curve sensitivity for a swap with a fixed leg.
        /// <para>
        /// The par rate is the common rate on all payments of the fixed leg for which the total swap present value is 0.
        /// </para>
        /// <para>
        /// At least one leg must be a fixed leg. The par rate will be computed with respect to the first fixed leg.
        /// All the payments in that leg should be fixed payments with a unique accrual period (no compounding) and no FX reset.
        ///
        /// </para>
        /// </summary>
        /// <param name="swap">  the product </param>
        /// <param name="provider">  the rates provider </param>
        /// <returns> the par rate curve sensitivity of the swap product </returns>
        public virtual PointSensitivityBuilder parRateSensitivity(ResolvedSwap swap, RatesProvider provider)
        {
            ResolvedSwapLeg fixedLeg    = this.fixedLeg(swap);
            Currency        ccyFixedLeg = fixedLeg.Currency;
            // other payments (not fixed leg coupons) converted in fixed leg currency
            double otherLegsConvertedPv = 0.0;

            foreach (ResolvedSwapLeg leg in swap.Legs)
            {
                if (leg != fixedLeg)
                {
                    double pvLocal = legPricer.presentValueInternal(leg, provider);
                    otherLegsConvertedPv += (pvLocal * provider.fxRate(leg.Currency, ccyFixedLeg));
                }
            }
            double fixedLegEventsPv = legPricer.presentValueEventsInternal(fixedLeg, provider);
            double pvbpFixedLeg     = legPricer.pvbp(fixedLeg, provider);
            // Backward sweep
            double otherLegsConvertedPvBar                 = -1.0d / pvbpFixedLeg;
            double fixedLegEventsPvBar                     = -1.0d / pvbpFixedLeg;
            double pvbpFixedLegBar                         = (otherLegsConvertedPv + fixedLegEventsPv) / (pvbpFixedLeg * pvbpFixedLeg);
            PointSensitivityBuilder pvbpFixedLegDr         = legPricer.pvbpSensitivity(fixedLeg, provider);
            PointSensitivityBuilder fixedLegEventsPvDr     = legPricer.presentValueSensitivityEventsInternal(fixedLeg, provider);
            PointSensitivityBuilder otherLegsConvertedPvDr = PointSensitivityBuilder.none();

            foreach (ResolvedSwapLeg leg in swap.Legs)
            {
                if (leg != fixedLeg)
                {
                    PointSensitivityBuilder pvLegDr = legPricer.presentValueSensitivity(leg, provider).multipliedBy(provider.fxRate(leg.Currency, ccyFixedLeg));
                    otherLegsConvertedPvDr = otherLegsConvertedPvDr.combinedWith(pvLegDr);
                }
            }
            otherLegsConvertedPvDr = otherLegsConvertedPvDr.withCurrency(ccyFixedLeg);
            return(pvbpFixedLegDr.multipliedBy(pvbpFixedLegBar).combinedWith(fixedLegEventsPvDr.multipliedBy(fixedLegEventsPvBar)).combinedWith(otherLegsConvertedPvDr.multipliedBy(otherLegsConvertedPvBar)));
        }