Пример #1
0
        public virtual double test_VanillaFixedVsLibor3mSwapWithFixing()
        {
            DiscountingSwapTradePricer pricer   = swapPricer();
            ResolvedSwapTrade          resolved = TRADE3.resolve(REF_DATA);
            CurrencyAmount             pv       = pricer.presentValue(resolved, USD, PROVIDER);

            return(pv.Amount);
        }
Пример #2
0
        public virtual double test_BasisCompoundedLibor1mVsLibor3mSwap()
        {
            DiscountingSwapTradePricer pricer   = swapPricer();
            ResolvedSwapTrade          resolved = TRADE5.resolve(REF_DATA);
            CurrencyAmount             pv       = pricer.presentValue(resolved, USD, PROVIDER);

            return(pv.Amount);
        }
        //-------------------------------------------------------------------------
        public virtual void test_OnAASpreadVsLibor3MSwap()
        {
            SwapLeg payLeg = RateCalculationSwapLeg.builder().payReceive(PAY).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2014, 9, 12)).endDate(LocalDate.of(2020, 9, 12)).frequency(P3M).businessDayAdjustment(BDA_MF).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(P3M).paymentDateOffset(DaysAdjustment.NONE).build()).notionalSchedule(NOTIONAL).calculation(IborRateCalculation.builder().index(USD_LIBOR_3M).fixingDateOffset(DaysAdjustment.ofBusinessDays(-2, CalendarUSD.NYC, BDA_P)).build()).build();

            SwapLeg receiveLeg = RateCalculationSwapLeg.builder().payReceive(RECEIVE).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2014, 9, 12)).endDate(LocalDate.of(2020, 9, 12)).frequency(P3M).businessDayAdjustment(BDA_MF).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(P3M).paymentDateOffset(DaysAdjustment.NONE).build()).notionalSchedule(NOTIONAL).calculation(OvernightRateCalculation.builder().dayCount(ACT_360).index(USD_FED_FUND).accrualMethod(OvernightAccrualMethod.AVERAGED).rateCutOffDays(0).spread(ValueSchedule.of(0.0025)).build()).build();

            ResolvedSwapTrade trade = SwapTrade.builder().info(TradeInfo.builder().tradeDate(LocalDate.of(2014, 1, 15)).build()).product(Swap.of(payLeg, receiveLeg)).build().resolve(REF_DATA);

            DiscountingSwapTradePricer pricer = swapPricer();
            CurrencyAmount             pv     = pricer.presentValue(trade, provider()).getAmount(USD);

            assertEquals(pv.Amount, -160663.8362, TOLERANCE_PV);
        }
        //-------------------------------------------------------------------------
        public virtual void test_InterpolatedStub4mFixed6mVsLibor6mSwap()
        {
            SwapLeg receiveLeg = fixedLeg(LocalDate.of(2014, 9, 12), LocalDate.of(2016, 7, 12), P6M, RECEIVE, NOTIONAL, 0.01, StubConvention.SHORT_INITIAL);

            SwapLeg payLeg = RateCalculationSwapLeg.builder().payReceive(PAY).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2014, 9, 12)).endDate(LocalDate.of(2016, 7, 12)).frequency(P6M).businessDayAdjustment(BDA_MF).stubConvention(StubConvention.SHORT_INITIAL).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(P6M).paymentDateOffset(DaysAdjustment.NONE).build()).notionalSchedule(NOTIONAL).calculation(IborRateCalculation.builder().index(USD_LIBOR_6M).fixingDateOffset(DaysAdjustment.ofBusinessDays(-2, CalendarUSD.NYC, BDA_P)).initialStub(IborRateStubCalculation.ofIborInterpolatedRate(USD_LIBOR_3M, USD_LIBOR_6M)).build()).build();

            ResolvedSwapTrade trade = SwapTrade.builder().info(TradeInfo.builder().tradeDate(LocalDate.of(2014, 9, 10)).build()).product(Swap.of(receiveLeg, payLeg)).build().resolve(REF_DATA);

            DiscountingSwapTradePricer pricer = swapPricer();
            CurrencyAmount             pv     = pricer.presentValue(trade, provider()).getAmount(USD);

            assertEquals(pv.Amount, 314215.2347116342, TOLERANCE_PV);
        }
        //-------------------------------------------------------------------------
        public virtual void test_CompoundingOisFixed2mVsFedFund12mSwapWithFixing()
        {
            SwapLeg payLeg = RateCalculationSwapLeg.builder().payReceive(PAY).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2014, 1, 17)).endDate(LocalDate.of(2014, 3, 17)).frequency(TERM).businessDayAdjustment(BDA_MF).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(TERM).paymentDateOffset(DaysAdjustment.ofBusinessDays(2, CalendarUSD.NYC)).build()).notionalSchedule(NOTIONAL).calculation(FixedRateCalculation.builder().dayCount(ACT_360).rate(ValueSchedule.of(0.00123)).build()).build();

            SwapLeg receiveLeg = RateCalculationSwapLeg.builder().payReceive(RECEIVE).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2014, 1, 17)).endDate(LocalDate.of(2014, 3, 17)).frequency(TERM).businessDayAdjustment(BDA_MF).stubConvention(StubConvention.SHORT_INITIAL).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(TERM).paymentDateOffset(DaysAdjustment.ofBusinessDays(2, CalendarUSD.NYC)).build()).notionalSchedule(NOTIONAL).calculation(OvernightRateCalculation.builder().dayCount(ACT_360).index(USD_FED_FUND).build()).build();

            ResolvedSwapTrade trade = SwapTrade.builder().info(TradeInfo.builder().tradeDate(LocalDate.of(2014, 1, 15)).build()).product(Swap.of(payLeg, receiveLeg)).build().resolve(REF_DATA);

            DiscountingSwapTradePricer pricer = swapPricer();
            CurrencyAmount             pv     = pricer.presentValue(trade, provider()).getAmount(USD);

            assertEquals(pv.Amount, -7352.973875972721, TOLERANCE_PV);
        }
        //-------------------------------------------------------------------------
        public virtual void test_ZeroCouponFixedVsLibor3mSwap()
        {
            SwapLeg payLeg = RateCalculationSwapLeg.builder().payReceive(PAY).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2014, 9, 12)).endDate(LocalDate.of(2021, 9, 12)).frequency(P12M).businessDayAdjustment(BDA_MF).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(TERM).paymentDateOffset(DaysAdjustment.NONE).compoundingMethod(CompoundingMethod.STRAIGHT).build()).notionalSchedule(NOTIONAL).calculation(FixedRateCalculation.builder().dayCount(THIRTY_U_360).rate(ValueSchedule.of(0.015)).build()).build();

            SwapLeg receiveLeg = RateCalculationSwapLeg.builder().payReceive(RECEIVE).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2014, 9, 12)).endDate(LocalDate.of(2021, 9, 12)).frequency(P3M).businessDayAdjustment(BDA_MF).stubConvention(StubConvention.SHORT_INITIAL).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(TERM).paymentDateOffset(DaysAdjustment.NONE).compoundingMethod(CompoundingMethod.STRAIGHT).build()).notionalSchedule(NOTIONAL).calculation(IborRateCalculation.builder().index(USD_LIBOR_3M).fixingDateOffset(DaysAdjustment.ofBusinessDays(-2, CalendarUSD.NYC, BDA_P)).build()).build();

            ResolvedSwapTrade trade = SwapTrade.builder().info(TradeInfo.builder().tradeDate(LocalDate.of(2014, 9, 10)).build()).product(Swap.of(payLeg, receiveLeg)).build().resolve(REF_DATA);

            DiscountingSwapTradePricer pricer = swapPricer();
            CurrencyAmount             pv     = pricer.presentValue(trade, provider()).getAmount(USD);

            assertEquals(pv.Amount, 7850279.042216873, TOLERANCE_PV);
        }
        //-------------------------------------------------------------------------
        public virtual void test_BasisCompoundedLibor1mVsLibor3mSwap()
        {
            SwapLeg receiveLeg = RateCalculationSwapLeg.builder().payReceive(RECEIVE).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2014, 8, 29)).endDate(LocalDate.of(2019, 8, 29)).frequency(P1M).businessDayAdjustment(BDA_MF).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(Frequency.P3M).paymentDateOffset(DaysAdjustment.NONE).compoundingMethod(CompoundingMethod.FLAT).build()).notionalSchedule(NOTIONAL).calculation(IborRateCalculation.builder().index(USD_LIBOR_1M).fixingDateOffset(DaysAdjustment.ofBusinessDays(-2, CalendarUSD.NYC, BDA_P)).build()).build();

            SwapLeg payLeg = RateCalculationSwapLeg.builder().payReceive(PAY).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2014, 8, 29)).endDate(LocalDate.of(2019, 8, 29)).frequency(P3M).businessDayAdjustment(BDA_MF).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(Frequency.P3M).paymentDateOffset(DaysAdjustment.NONE).build()).notionalSchedule(NOTIONAL).calculation(IborRateCalculation.builder().index(USD_LIBOR_3M).fixingDateOffset(DaysAdjustment.ofBusinessDays(-2, CalendarUSD.NYC, BDA_P)).build()).build();

            ResolvedSwapTrade trade = SwapTrade.builder().info(TradeInfo.builder().tradeDate(LocalDate.of(2014, 8, 27)).build()).product(Swap.of(receiveLeg, payLeg)).build().resolve(REF_DATA);

            DiscountingSwapTradePricer pricer = swapPricer();
            CurrencyAmount             pv     = pricer.presentValue(trade, provider()).getAmount(USD);

            assertEquals(pv.Amount, -342874.98367929866, TOLERANCE_PV);
        }
        //-------------------------------------------------------------------------
        public virtual void test_BasisLibor3mVsLibor6mSwapWithSpread()
        {
            SwapLeg payLeg = RateCalculationSwapLeg.builder().payReceive(PAY).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2014, 8, 29)).endDate(LocalDate.of(2024, 8, 29)).frequency(P6M).businessDayAdjustment(BDA_MF).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(Frequency.P6M).paymentDateOffset(DaysAdjustment.NONE).build()).notionalSchedule(NOTIONAL).calculation(IborRateCalculation.builder().index(USD_LIBOR_6M).fixingDateOffset(DaysAdjustment.ofBusinessDays(-2, CalendarUSD.NYC, BDA_P)).build()).build();

            SwapLeg receiveLeg = RateCalculationSwapLeg.builder().payReceive(RECEIVE).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2014, 8, 29)).endDate(LocalDate.of(2024, 8, 29)).frequency(P3M).businessDayAdjustment(BDA_MF).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(Frequency.P3M).paymentDateOffset(DaysAdjustment.NONE).build()).notionalSchedule(NOTIONAL).calculation(IborRateCalculation.builder().index(USD_LIBOR_3M).fixingDateOffset(DaysAdjustment.ofBusinessDays(-2, CalendarUSD.NYC, BDA_P)).spread(ValueSchedule.of(0.0010)).build()).build();

            ResolvedSwapTrade trade = SwapTrade.builder().info(TradeInfo.builder().tradeDate(LocalDate.of(2014, 8, 27)).build()).product(Swap.of(payLeg, receiveLeg)).build().resolve(REF_DATA);

            DiscountingSwapTradePricer pricer = swapPricer();
            CurrencyAmount             pv     = pricer.presentValue(trade, provider()).getAmount(USD);

            assertEquals(pv.Amount, -21875.376339152455, TOLERANCE_PV);
        }
        //-------------------------------------------------------------------------
        public virtual void test_VanillaFixedVsLibor3mSwapWithFixing()
        {
            SwapLeg payLeg = fixedLeg(LocalDate.of(2013, 9, 12), LocalDate.of(2020, 9, 12), P6M, PAY, NOTIONAL, 0.015, null);

            SwapLeg receiveLeg = RateCalculationSwapLeg.builder().payReceive(RECEIVE).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2013, 9, 12)).endDate(LocalDate.of(2020, 9, 12)).frequency(P3M).businessDayAdjustment(BDA_MF).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(P3M).paymentDateOffset(DaysAdjustment.NONE).build()).notionalSchedule(NOTIONAL).calculation(IborRateCalculation.builder().index(USD_LIBOR_3M).fixingDateOffset(DaysAdjustment.ofBusinessDays(-2, CalendarUSD.NYC, BDA_P)).build()).build();

            ResolvedSwapTrade trade = SwapTrade.builder().info(TradeInfo.builder().tradeDate(LocalDate.of(2013, 9, 10)).build()).product(Swap.of(payLeg, receiveLeg)).build().resolve(REF_DATA);

            DiscountingSwapTradePricer pricer = swapPricer();
            CurrencyAmount             pv     = pricer.presentValue(trade, provider()).getAmount(USD);

            assertEquals(pv.Amount, 3588376.471608199, TOLERANCE_PV);
        }
        //-----------------------------------------------------------------------
        // XCcy swap with exchange of notional
        public virtual void test_XCcyEur3MSpreadVsUSD3M()
        {
            SwapLeg payLeg = RateCalculationSwapLeg.builder().payReceive(PAY).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2014, 1, 24)).endDate(LocalDate.of(2016, 1, 24)).frequency(P3M).businessDayAdjustment(BDA_MF).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(P3M).paymentDateOffset(DaysAdjustment.NONE).build()).notionalSchedule(NotionalSchedule.builder().finalExchange(true).initialExchange(true).amount(ValueSchedule.of(NOTIONAL_EUR)).currency(EUR).build()).calculation(IborRateCalculation.builder().index(EUR_EURIBOR_3M).fixingDateOffset(DaysAdjustment.ofBusinessDays(-2, CalendarUSD.NYC, BDA_P)).spread(ValueSchedule.of(0.0020)).build()).build();

            SwapLeg receiveLeg = RateCalculationSwapLeg.builder().payReceive(RECEIVE).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2014, 1, 24)).endDate(LocalDate.of(2016, 1, 24)).frequency(P3M).businessDayAdjustment(BDA_MF).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(P3M).paymentDateOffset(DaysAdjustment.NONE).build()).notionalSchedule(NotionalSchedule.builder().finalExchange(true).initialExchange(true).amount(ValueSchedule.of(NOTIONAL_USD)).currency(USD).build()).calculation(IborRateCalculation.builder().index(USD_LIBOR_3M).fixingDateOffset(DaysAdjustment.ofBusinessDays(-2, CalendarUSD.NYC, BDA_P)).build()).build();

            ResolvedSwapTrade trade = SwapTrade.builder().info(TradeInfo.builder().tradeDate(LocalDate.of(2014, 9, 10)).build()).product(Swap.of(payLeg, receiveLeg)).build().resolve(REF_DATA);

            double pvUsdExpected = 431944.6868;
            double pvEurExpected = -731021.1778;

            DiscountingSwapTradePricer pricer = swapPricer();
            MultiCurrencyAmount        pv     = pricer.presentValue(trade, provider());

            assertEquals(pv.getAmount(USD).Amount, pvUsdExpected, TOLERANCE_PV);
            assertEquals(pv.getAmount(EUR).Amount, pvEurExpected, TOLERANCE_PV);
        }
        private void test_XCcyEurUSDFxReset(bool initialExchange, bool intermediateExchange, bool finalExchange)
        {
            ResolvedSwapTrade trade = getMtmTrade(initialExchange, intermediateExchange, finalExchange, null).resolve(REF_DATA);

            DiscountingSwapTradePricer pricer = swapPricer();
            MultiCurrencyAmount        pv     = pricer.presentValue(trade, provider());

            //Coupons are always included, so base is the total coupon pvs
            double pvUsdExpected            = 1447799.5318;
            double pvEurExpected            = -1020648.6461;
            int    usdExpectedPaymentEvents = 0;
            int    eurExpectedPaymentEvents = 0;

            //Add PV amounts of included exchanges to arrive at total expected pv
            if (initialExchange)
            {
                pvUsdExpected += -143998710.0091;
                pvEurExpected += 99999104.1730;
                ++usdExpectedPaymentEvents;
                ++eurExpectedPaymentEvents;
            }

            if (intermediateExchange)
            {
                pvUsdExpected            += -344525.1458;
                usdExpectedPaymentEvents += 14;
            }

            if (finalExchange)
            {
                pvUsdExpected += 143414059.1395;
                pvEurExpected += -99709476.7047;
                ++usdExpectedPaymentEvents;
                ++eurExpectedPaymentEvents;
            }

            assertEquals(pv.getAmount(USD).Amount, pvUsdExpected, TOLERANCE_PV);
            assertEquals(pv.getAmount(EUR).Amount, pvEurExpected, TOLERANCE_PV);

            //Assert the payment event (exchange) count on each leg
            IList <ExplainMap> legs = pricer.explainPresentValue(trade, provider()).get(ExplainKey.LEGS).get();

            assertThat(legs[0].get(ExplainKey.PAYMENT_EVENTS).orElse(ImmutableList.of())).hasSize(eurExpectedPaymentEvents);
            assertThat(legs[1].get(ExplainKey.PAYMENT_EVENTS).orElse(ImmutableList.of())).hasSize(usdExpectedPaymentEvents);
        }
        //-------------------------------------------------------------------------
        public virtual void test_AmortizingFixedVsLibor3mSwap()
        {
            ValueAdjustment   stepReduction = ValueAdjustment.ofDeltaAmount(-3_000_000);
            IList <ValueStep> steps         = new List <ValueStep>();

            for (int i = 1; i < 28; i++)
            {
                steps.Add(ValueStep.of(i, stepReduction));
            }
            ValueSchedule notionalSchedule = ValueSchedule.of(100_000_000, steps);
            SwapLeg       receiveLeg       = RateCalculationSwapLeg.builder().payReceive(RECEIVE).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2014, 9, 12)).endDate(LocalDate.of(2021, 9, 12)).frequency(P3M).businessDayAdjustment(BDA_MF).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(P3M).paymentDateOffset(DaysAdjustment.NONE).build()).notionalSchedule(NotionalSchedule.of(USD, notionalSchedule)).calculation(FixedRateCalculation.builder().dayCount(THIRTY_U_360).rate(ValueSchedule.of(0.016)).build()).build();

            SwapLeg payLeg = RateCalculationSwapLeg.builder().payReceive(PAY).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2014, 9, 12)).endDate(LocalDate.of(2021, 9, 12)).frequency(P3M).businessDayAdjustment(BDA_MF).stubConvention(StubConvention.SHORT_INITIAL).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(P3M).paymentDateOffset(DaysAdjustment.NONE).build()).notionalSchedule(NotionalSchedule.of(USD, notionalSchedule)).calculation(IborRateCalculation.builder().index(USD_LIBOR_3M).fixingDateOffset(DaysAdjustment.ofBusinessDays(-2, CalendarUSD.NYC, BDA_P)).build()).build();

            ResolvedSwapTrade trade = SwapTrade.builder().info(TradeInfo.builder().tradeDate(LocalDate.of(2014, 9, 10)).build()).product(Swap.of(receiveLeg, payLeg)).build().resolve(REF_DATA);

            DiscountingSwapTradePricer pricer = swapPricer();
            CurrencyAmount             pv     = pricer.presentValue(trade, provider()).getAmount(USD);

            assertEquals(pv.Amount, -1850080.2895532502, TOLERANCE_PV);
        }
        //-----------------------------------------------------------------------
        public virtual void test_VanillaFixedVsLibor3mSwap()
        {
            SwapLeg           payLeg     = fixedLeg(LocalDate.of(2014, 9, 12), LocalDate.of(2021, 9, 12), P6M, PAY, NOTIONAL, 0.015, null);
            SwapLeg           receiveLeg = iborLeg(LocalDate.of(2014, 9, 12), LocalDate.of(2021, 9, 12), USD_LIBOR_3M, RECEIVE, NOTIONAL, null);
            ResolvedSwapTrade trade      = SwapTrade.builder().info(TradeInfo.builder().tradeDate(LocalDate.of(2014, 9, 10)).build()).product(Swap.of(payLeg, receiveLeg)).build().resolve(REF_DATA);

            // test pv
            DiscountingSwapTradePricer pricer = swapPricer();
            CurrencyAmount             pv     = pricer.presentValue(trade, provider()).getAmount(USD);

            assertEquals(pv.Amount, 7170391.798257509, TOLERANCE_PV);
            // test par rate
            double parRate = PRICER_PRODUCT.parRate(trade.Product, provider());

            assertEquals(parRate, 0.02589471566819517, TOLERANCE_RATE);
            // test par rate vs pv
            ResolvedSwap   swapPV0 = Swap.of(fixedLeg(LocalDate.of(2014, 9, 12), LocalDate.of(2021, 9, 12), P6M, PAY, NOTIONAL, parRate, null), receiveLeg).resolve(REF_DATA);
            CurrencyAmount pv0     = PRICER_PRODUCT.presentValue(swapPV0, provider()).getAmount(USD);

            assertEquals(pv0.Amount, 0, TOLERANCE_PV);     // PV at par rate should be 0
        }
        // XCcy swap with exchange of notional and FX Reset on the USD leg
        public virtual void test_XCcyFixedInitialNotional()
        {
            DiscountingSwapTradePricer pricer = swapPricer();

            //Create an MTM swap with initial notional override
            double            notional = 1_000_000d;
            ResolvedSwapTrade fixedNotionalMtmTrade = getMtmTrade(true, true, true, notional).resolve(REF_DATA);
            ExplainMap        explainMap            = pricer.explainPresentValue(fixedNotionalMtmTrade, provider());

            CurrencyAmount fixedNotional       = CurrencyAmount.of(Currency.USD, notional);
            ExplainMap     fixedNotionalMtmLeg = explainMap.get(ExplainKey.LEGS).get().get(1);

            IList <ExplainMap> events = fixedNotionalMtmLeg.get(ExplainKey.PAYMENT_EVENTS).get();

            //First two payment events should use fixed initial notional
            ExplainMap firstPaymentEvent = events[0];

            assertFixedNotionalPaymentEvent(firstPaymentEvent, fixedNotional.negated());
            ExplainMap secondPaymentEvent = events[1];

            assertFixedNotionalPaymentEvent(secondPaymentEvent, fixedNotional);

            //First coupon also uses fixed notional
            ExplainMap firstCoupon = fixedNotionalMtmLeg.get(ExplainKey.PAYMENT_PERIODS).get().get(0);

            assertEquals(firstCoupon.get(ExplainKey.TRADE_NOTIONAL), fixedNotional);
            assertEquals(firstCoupon.get(ExplainKey.NOTIONAL), fixedNotional);

            //Sum of all pv amounts which are impacted by overriding the first period with a  fixed notional
            CurrencyAmount firstPaymentPv  = firstPaymentEvent.get(ExplainKey.PRESENT_VALUE).get();
            CurrencyAmount secondPaymentPv = secondPaymentEvent.get(ExplainKey.PRESENT_VALUE).get();
            CurrencyAmount firstCouponPv   = firstCoupon.get(ExplainKey.PRESENT_VALUE).get();
            CurrencyAmount fixedNotionalImpactedEventsPv = firstPaymentPv.plus(secondPaymentPv).plus(firstCouponPv);

            //----------------------------------------------------------------------------------------------------------

            //Build identical trade but with no fixed notional
            ResolvedSwapTrade noFixedNotionalMtmTrade = getMtmTrade(true, true, true, null).resolve(REF_DATA);
            ExplainMap        noFixedNotionalMtmLeg   = pricer.explainPresentValue(noFixedNotionalMtmTrade, provider()).get(ExplainKey.LEGS).get().get(1);

            //Sum the pvs for the same combination of payments and events that are impacted by fixed notional in first trade
//JAVA TO C# CONVERTER TODO TASK: Method reference arbitrary object instance method syntax is not converted by Java to C# Converter:
            CurrencyAmount noFixedNotionalEventsPv = noFixedNotionalMtmLeg.get(ExplainKey.PAYMENT_EVENTS).get().subList(0, 2).Select(payment => payment.get(ExplainKey.PRESENT_VALUE).get()).Aggregate(CurrencyAmount.zero(Currency.USD), CurrencyAmount::plus);

            CurrencyAmount noFixedNotionalCouponsPv = noFixedNotionalMtmLeg.get(ExplainKey.PAYMENT_PERIODS).get().get(0).get(ExplainKey.PRESENT_VALUE).get();

            CurrencyAmount noFixedNotionalImpactedEventsPv = noFixedNotionalCouponsPv.plus(noFixedNotionalEventsPv);

            //----------------------------------------------------------------------------------------------------------

            //PV difference of the events impacted by fixing notional
            CurrencyAmount paymentsPvDifference = fixedNotionalImpactedEventsPv.minus(noFixedNotionalImpactedEventsPv);

            //Calculate PV of the full trades
            MultiCurrencyAmount fixedNotionalLegPv   = pricer.presentValue(fixedNotionalMtmTrade, provider());
            MultiCurrencyAmount noFixedNotionalLegPv = pricer.presentValue(noFixedNotionalMtmTrade, provider());

            //EUR PV should not have changed
            assertEquals(fixedNotionalLegPv.getAmount(Currency.EUR).Amount, noFixedNotionalLegPv.getAmount(Currency.EUR).Amount, TOLERANCE_PV);

            //Difference in USD PV should be equal the difference in PV of the three events impacted by the initial notional
            //All else should remain equal
            CurrencyAmount tradePvDifference = fixedNotionalLegPv.getAmount(Currency.USD).minus(noFixedNotionalLegPv.getAmount(Currency.USD));

            assertEquals(tradePvDifference.Amount, paymentsPvDifference.Amount, TOLERANCE_PV);
        }
Пример #15
0
 /// <summary>
 /// Creates an instance.
 /// </summary>
 /// <param name="tradePricer">  the pricer for <seealso cref="ResolvedSwapTrade"/> </param>
 internal SwapMeasureCalculations(DiscountingSwapTradePricer tradePricer)
 {
     this.tradePricer = ArgChecker.notNull(tradePricer, "tradePricer");
 }