예제 #1
0
        public virtual void present_value_sensitivity_payer_receiver_parity()
        {
            PointSensitivities             pvptLongPay  = PRICER_SWAPTION_BLACK.presentValueSensitivityRatesStickyStrike(SWAPTION_LONG_PAY, MULTI_USD, BLACK_VOLS_USD_STD).build();
            PointSensitivities             pvptShortRec = PRICER_SWAPTION_BLACK.presentValueSensitivityRatesStickyStrike(SWAPTION_SHORT_REC, MULTI_USD, BLACK_VOLS_USD_STD).build();
            PointSensitivities             pvptSwapRec  = PRICER_SWAP.presentValueSensitivity(RSWAP_PAY, MULTI_USD).build();
            CurrencyParameterSensitivities pvpsLongPay  = MULTI_USD.parameterSensitivity(pvptLongPay);
            CurrencyParameterSensitivities pvpsShortRec = MULTI_USD.parameterSensitivity(pvptShortRec);
            CurrencyParameterSensitivities pvpsSwapRec  = MULTI_USD.parameterSensitivity(pvptSwapRec);

            assertTrue(pvpsLongPay.combinedWith(pvpsShortRec).equalWithTolerance(pvpsSwapRec, TOLERANCE_PV_DELTA));
        }
예제 #2
0
        private void calibration_market_quote_sensitivity_check(System.Func <MarketData, RatesProvider> calibrator, double shift)
        {
            double                         notional = 100_000_000.0;
            double                         spread   = 0.0050;
            SwapTrade                      trade    = IborIborSwapConventions.USD_LIBOR_3M_LIBOR_6M.createTrade(VAL_DATE, Period.ofMonths(8), Tenor.TENOR_7Y, BuySell.BUY, notional, spread, REF_DATA);
            RatesProvider                  result   = calibrator(ALL_QUOTES);
            ResolvedSwap                   product  = trade.Product.resolve(REF_DATA);
            PointSensitivityBuilder        pts      = SWAP_PRICER.presentValueSensitivity(product, result);
            CurrencyParameterSensitivities ps       = result.parameterSensitivity(pts.build());
            CurrencyParameterSensitivities mqs      = MQC.sensitivity(ps, result);
            double                         pv0      = SWAP_PRICER.presentValue(product, result).getAmount(USD).Amount;

            double[] mqsDscComputed = mqs.getSensitivity(DSCON_CURVE_NAME, USD).Sensitivity.toArray();
            for (int i = 0; i < DSC_NB_NODES; i++)
            {
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: java.util.Map<com.opengamma.strata.data.MarketDataId<?>, Object> map = new java.util.HashMap<>(ALL_QUOTES.getValues());
                IDictionary <MarketDataId <object>, object> map = new Dictionary <MarketDataId <object>, object>(ALL_QUOTES.Values);
                map[QuoteId.of(StandardId.of(SCHEME, DSC_ID_VALUE[i]))] = DSC_MARKET_QUOTES[i] + shift;
                ImmutableMarketData marketData = ImmutableMarketData.of(VAL_DATE, map);
                RatesProvider       rpShifted  = calibrator(marketData);
                double pvS = SWAP_PRICER.presentValue(product, rpShifted).getAmount(USD).Amount;
                assertEquals(mqsDscComputed[i], (pvS - pv0) / shift, TOLERANCE_PV_DELTA, "DSC - node " + i);
            }
            double[] mqsFwd3Computed = mqs.getSensitivity(FWD3_CURVE_NAME, USD).Sensitivity.toArray();
            for (int i = 0; i < FWD3_NB_NODES; i++)
            {
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: java.util.Map<com.opengamma.strata.data.MarketDataId<?>, Object> map = new java.util.HashMap<>(ALL_QUOTES.getValues());
                IDictionary <MarketDataId <object>, object> map = new Dictionary <MarketDataId <object>, object>(ALL_QUOTES.Values);
                map[QuoteId.of(StandardId.of(SCHEME, FWD3_ID_VALUE[i]))] = FWD3_MARKET_QUOTES[i] + shift;
                ImmutableMarketData marketData = ImmutableMarketData.of(VAL_DATE, map);
                RatesProvider       rpShifted  = calibrator(marketData);
                double pvS = SWAP_PRICER.presentValue(product, rpShifted).getAmount(USD).Amount;
                assertEquals(mqsFwd3Computed[i], (pvS - pv0) / shift, TOLERANCE_PV_DELTA, "FWD3 - node " + i);
            }
            double[] mqsFwd6Computed = mqs.getSensitivity(FWD6_CURVE_NAME, USD).Sensitivity.toArray();
            for (int i = 0; i < FWD6_NB_NODES; i++)
            {
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: java.util.Map<com.opengamma.strata.data.MarketDataId<?>, Object> map = new java.util.HashMap<>(ALL_QUOTES.getValues());
                IDictionary <MarketDataId <object>, object> map = new Dictionary <MarketDataId <object>, object>(ALL_QUOTES.Values);
                map[QuoteId.of(StandardId.of(SCHEME, FWD6_ID_VALUE[i]))] = FWD6_MARKET_QUOTES[i] + shift;
                ImmutableMarketData marketData = ImmutableMarketData.of(VAL_DATE, map);
                RatesProvider       rpShifted  = calibrator(marketData);
                double pvS = SWAP_PRICER.presentValue(product, rpShifted).getAmount(USD).Amount;
                assertEquals(mqsFwd6Computed[i], (pvS - pv0) / shift, TOLERANCE_PV_DELTA, "FWD6 - node " + i);
            }
        }
예제 #3
0
        public virtual void test_presentValueSensitivity_parity()
        {
            CurrencyParameterSensitivities pvSensiRecLong  = RATE_PROVIDER.parameterSensitivity(PRICER.presentValueSensitivityRates(SWAPTION_REC_LONG, RATE_PROVIDER, HW_PROVIDER).build());
            CurrencyParameterSensitivities pvSensiRecShort = RATE_PROVIDER.parameterSensitivity(PRICER.presentValueSensitivityRates(SWAPTION_REC_SHORT, RATE_PROVIDER, HW_PROVIDER).build());
            CurrencyParameterSensitivities pvSensiPayLong  = RATE_PROVIDER.parameterSensitivity(PRICER.presentValueSensitivityRates(SWAPTION_PAY_LONG, RATE_PROVIDER, HW_PROVIDER).build());
            CurrencyParameterSensitivities pvSensiPayShort = RATE_PROVIDER.parameterSensitivity(PRICER.presentValueSensitivityRates(SWAPTION_PAY_SHORT, RATE_PROVIDER, HW_PROVIDER).build());

            assertTrue(pvSensiRecLong.equalWithTolerance(pvSensiRecShort.multipliedBy(-1d), NOTIONAL * TOL));
            assertTrue(pvSensiPayLong.equalWithTolerance(pvSensiPayShort.multipliedBy(-1d), NOTIONAL * TOL));
            PointSensitivities             expectedPoint = SWAP_PRICER.presentValueSensitivity(RSWAP_PAY, RATE_PROVIDER).build();
            CurrencyParameterSensitivities expected      = RATE_PROVIDER.parameterSensitivity(expectedPoint);

            assertTrue(expected.equalWithTolerance(pvSensiPayLong.combinedWith(pvSensiRecLong.multipliedBy(-1d)), NOTIONAL * TOL));
            assertTrue(expected.equalWithTolerance(pvSensiRecShort.combinedWith(pvSensiPayShort.multipliedBy(-1d)), NOTIONAL * TOL));
        }
예제 #4
0
        // test diagonal part against finite difference approximation computed from pv
        public virtual void swap_exampleTest()
        {
            LocalDate    start    = LocalDate.of(2014, 3, 10);
            LocalDate    end      = LocalDate.of(2021, 3, 10);
            double       notional = 1.0e6;
            ResolvedSwap swap     = FixedIborSwapConventions.USD_FIXED_6M_LIBOR_3M.toTrade(RatesProviderDataSets.VAL_DATE_2014_01_22, start, end, BuySell.BUY, notional, 0.005).Product.resolve(REF_DATA);
            DiscountingSwapProductPricer pricer = DiscountingSwapProductPricer.DEFAULT;

            System.Func <ImmutableRatesProvider, CurrencyAmount> pvFunction = p => pricer.presentValue(swap, USD, p);
            System.Func <ImmutableRatesProvider, CurrencyParameterSensitivities> sensiFunction = p =>
            {
                PointSensitivities sensi = pricer.presentValueSensitivity(swap, p).build();
                return(p.parameterSensitivity(sensi));
            };
            CurrencyParameterSensitivities expected = sensitivityDiagonal(RatesProviderDataSets.MULTI_CPI_USD, pvFunction);
            CurrencyParameterSensitivities computed = CENTRAL.calculateCrossGammaIntraCurve(RatesProviderDataSets.MULTI_CPI_USD, sensiFunction).diagonal();

            assertTrue(computed.equalWithTolerance(expected, Math.Sqrt(EPS) * notional));
            CurrencyParameterSensitivities computedFromCross = CENTRAL.calculateCrossGammaCrossCurve(RatesProviderDataSets.MULTI_CPI_USD, sensiFunction).diagonal();

            assertTrue(computed.equalWithTolerance(computedFromCross, TOL));
        }
        public virtual void test_presentValueSensitivity_parity()
        {
            CurrencyParameterSensitivities pvSensiRecLong  = RATE_PROVIDER.parameterSensitivity(SWAPTION_PRICER.presentValueSensitivityRatesStickyModel(SWAPTION_REC_LONG, RATE_PROVIDER, VOLS).build());
            CurrencyParameterSensitivities pvSensiRecShort = RATE_PROVIDER.parameterSensitivity(SWAPTION_PRICER.presentValueSensitivityRatesStickyModel(SWAPTION_REC_SHORT, RATE_PROVIDER, VOLS).build());
            CurrencyParameterSensitivities pvSensiPayLong  = RATE_PROVIDER.parameterSensitivity(SWAPTION_PRICER.presentValueSensitivityRatesStickyModel(SWAPTION_PAY_LONG, RATE_PROVIDER, VOLS).build());
            CurrencyParameterSensitivities pvSensiPayShort = RATE_PROVIDER.parameterSensitivity(SWAPTION_PRICER.presentValueSensitivityRatesStickyModel(SWAPTION_PAY_SHORT, RATE_PROVIDER, VOLS).build());

            assertTrue(pvSensiRecLong.equalWithTolerance(pvSensiRecShort.multipliedBy(-1d), NOTIONAL * TOL));
            assertTrue(pvSensiPayLong.equalWithTolerance(pvSensiPayShort.multipliedBy(-1d), NOTIONAL * TOL));

            CurrencyParameterSensitivities pvSensiSwap = RATE_PROVIDER.parameterSensitivity(SWAP_PRICER.presentValueSensitivity(RSWAP_PAY, RATE_PROVIDER).build());

            assertTrue(pvSensiSwap.equalWithTolerance(pvSensiPayLong.combinedWith(pvSensiRecLong.multipliedBy(-1d)), NOTIONAL * TOL));
            assertTrue(pvSensiSwap.equalWithTolerance(pvSensiRecShort.combinedWith(pvSensiPayShort.multipliedBy(-1d)), NOTIONAL * TOL));
        }