示例#1
0
        public virtual void test_legInitialNotional()
        {
            ResolvedSwapLeg   firstLeg           = SWAP_TRADE.Product.Legs.get(0);
            ResolvedSwapLeg   secondLeg          = SWAP_TRADE.Product.Legs.get(1);
            Currency          ccy                = firstLeg.Currency;
            RatePaymentPeriod firstPaymentPeriod = (RatePaymentPeriod)firstLeg.PaymentPeriods.get(0);
            double            notional           = firstPaymentPeriod.Notional;

            LegAmounts expected = LegAmounts.of(SwapLegAmount.of(firstLeg, CurrencyAmount.of(ccy, notional)), SwapLegAmount.of(secondLeg, CurrencyAmount.of(ccy, notional)));

            assertEquals(SwapMeasureCalculations.DEFAULT.legInitialNotional(SWAP_TRADE), expected);
        }
        public virtual void test_cashFlowEquivalentAndSensitivity_compounding()
        {
            RatePaymentPeriod iborCmp    = RatePaymentPeriod.builder().paymentDate(PAYMENT2).accrualPeriods(IBOR1, IBOR2).dayCount(ACT_365F).currency(GBP).notional(-NOTIONAL).build();
            ResolvedSwapLeg   iborLegCmp = ResolvedSwapLeg.builder().type(IBOR).payReceive(PAY).paymentPeriods(iborCmp).build();
            ResolvedSwap      swap1      = ResolvedSwap.of(iborLegCmp, FIXED_LEG);

            assertThrowsIllegalArg(() => CashFlowEquivalentCalculator.cashFlowEquivalentAndSensitivitySwap(swap1, PROVIDER));
            RatePaymentPeriod fixedCmp    = RatePaymentPeriod.builder().paymentDate(PAYMENT2).accrualPeriods(FIXED1, FIXED2).dayCount(ACT_365F).currency(GBP).notional(NOTIONAL).build();
            ResolvedSwapLeg   fixedLegCmp = ResolvedSwapLeg.builder().type(FIXED).payReceive(RECEIVE).paymentPeriods(fixedCmp).build();
            ResolvedSwap      swap2       = ResolvedSwap.of(IBOR_LEG, fixedLegCmp);

            assertThrowsIllegalArg(() => CashFlowEquivalentCalculator.cashFlowEquivalentAndSensitivitySwap(swap2, PROVIDER));
        }
        public virtual void currency_exposure_USD()
        {
            LocalDate               startDate     = LocalDate.of(2016, 8, 2);
            LocalDate               fixingDate    = LocalDate.of(2016, 11, 2);
            LocalDate               endDate       = LocalDate.of(2016, 11, 4);
            double                  yearFraction  = 0.25;
            double                  rate          = 0.10;
            RateAccrualPeriod       accrual       = RateAccrualPeriod.builder().startDate(startDate).endDate(endDate).yearFraction(yearFraction).rateComputation(FixedRateComputation.of(rate)).build();
            double                  notional      = 1000000;
            RatePaymentPeriod       fixedFx       = RatePaymentPeriod.builder().accrualPeriods(accrual).fxReset(FxReset.of(FxIndexObservation.of(FxIndices.GBP_USD_WM, fixingDate, REF_DATA), USD)).notional(notional).paymentDate(endDate).dayCount(DayCounts.ONE_ONE).currency(GBP).build(); // 1_000_000 USD paid in GBP at maturity
            PointSensitivityBuilder pts           = PERIOD_PRICER.presentValueSensitivity(fixedFx, PROVIDER);
            MultiCurrencyAmount     ceComputed    = PERIOD_PRICER.currencyExposure(fixedFx, PROVIDER);
            double                  dfUsd         = PROVIDER.discountFactor(USD, endDate);
            double                  ceUsdExpected = notional * yearFraction * rate * dfUsd;

            assertEquals(ceComputed.getAmount(USD).Amount, ceUsdExpected, 1.0E-6);
            MultiCurrencyAmount ceWithoutPvComputed = PROVIDER.currencyExposure(pts.build().convertedTo(USD, PROVIDER));
            CurrencyAmount      pvComputed          = CurrencyAmount.of(GBP, PERIOD_PRICER.presentValue(fixedFx, PROVIDER));
            MultiCurrencyAmount ceComputed2         = ceWithoutPvComputed.plus(pvComputed);

            assertEquals(ceComputed2.getAmount(USD).Amount, ceUsdExpected, TOLERANCE);
            assertEquals(ceComputed2.getAmount(GBP).Amount, 0.0, TOLERANCE);
        }