Esempio n. 1
0
        //-------------------------------------------------------------------------
        public virtual void test_priceSensitivity()
        {
            PointSensitivities             point    = FUTURE_PRICER.priceSensitivity(FUTURE_PRODUCT, PROVIDER);
            CurrencyParameterSensitivities computed = PROVIDER.parameterSensitivity(point);
            CurrencyParameterSensitivities expected = FD_CAL.sensitivity(PROVIDER, (p) => CurrencyAmount.of(USD, FUTURE_PRICER.price(FUTURE_PRODUCT, (p))));

            assertTrue(computed.equalWithTolerance(expected, EPS * 10.0));
        }
Esempio n. 2
0
        public virtual void priceSensitivity()
        {
            // March
            PointSensitivities             pointMar = PRODUCT_PRICER.priceSensitivity(FUTURE_PRODUCT_MAR, LED_PROVIDER).multipliedBy(HUNDRED * ONE_BASIS_POINT);
            CurrencyParameterSensitivities sensiMar = LED_PROVIDER.parameterSensitivity(pointMar);

            double[] sensiIssuerMar = new double[] { -4.795692708445902E-6, -2.0781215861310126E-5, -7.730767169573405E-5, -1.6071777740512183E-4, -2.3044416935116369E-4, -3.333307694739688E-4, -4.263036155523118E-4, -5.685365085703306E-4, -0.10407934097674876, -0.0, -0.0, -0.0, -0.0, -0.0, -0.0, -0.0 };
            double[] sensiRepoMar   = new double[] { 0.0, 0.0, 0.0, 0.0, 0.001370140084809201, 3.3554451056551886E-4, 0.0, 0.0 };
            assertTrue(DoubleArrayMath.fuzzyEquals(sensiMar.getSensitivity(ISSUER_CURVE_NAME, JPY).Sensitivity.toArray(), sensiIssuerMar, TOL));
            assertTrue(DoubleArrayMath.fuzzyEquals(sensiMar.getSensitivity(REPO_CURVE_NAME, JPY).Sensitivity.toArray(), sensiRepoMar, TOL));
            // June
            PointSensitivities             pointJun = PRODUCT_PRICER.priceSensitivity(FUTURE_PRODUCT_JUN, LED_PROVIDER).multipliedBy(HUNDRED * ONE_BASIS_POINT);
            CurrencyParameterSensitivities sensiJun = LED_PROVIDER.parameterSensitivity(pointJun);

            double[] sensiIssuerJun = new double[] { -1.1453989553600325E-5, -2.348926498286566E-5, -1.0106640809190963E-4, -1.9509367993719023E-4, -3.132622179286758E-4, -4.395002117284386E-4, -5.572262990208806E-4, -7.858225833901946E-4, -0.07087170775675304, -0.03539736978075175, -0.0, -0.0, -0.0, -0.0, -0.0, -0.0 };
            double[] sensiRepoJun   = new double[] { 0.0, 0.0, 0.0, 0.0, 0.0, 0.003012223890022257, 0.0024215917547237764, 0.0 };
            assertTrue(DoubleArrayMath.fuzzyEquals(sensiJun.getSensitivity(ISSUER_CURVE_NAME, JPY).Sensitivity.toArray(), sensiIssuerJun, TOL));
            assertTrue(DoubleArrayMath.fuzzyEquals(sensiJun.getSensitivity(REPO_CURVE_NAME, JPY).Sensitivity.toArray(), sensiRepoJun, TOL));
            // September
            PointSensitivities             pointSep = PRODUCT_PRICER.priceSensitivity(FUTURE_PRODUCT_SEP, LED_PROVIDER).multipliedBy(HUNDRED * ONE_BASIS_POINT);
            CurrencyParameterSensitivities sensiSep = LED_PROVIDER.parameterSensitivity(pointSep);

            double[] sensiIssuerSep = new double[] { -6.287268294968501E-6, -2.7244672992830814E-5, -1.0135221390528455E-4, -2.1070486533414349E-4, -3.021178394458564E-4, -4.370046427203812E-4, -5.588942763935072E-4, -7.453650144370277E-4, -0.03687605192905092, -0.07313888023068209, -0.0, -0.0, -0.0, -0.0, -0.0, -0.0 };
            double[] sensiRepoSep   = new double[] { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.007209056180693214, 0.0020653493968426154 };
            assertTrue(DoubleArrayMath.fuzzyEquals(sensiSep.getSensitivity(ISSUER_CURVE_NAME, JPY).Sensitivity.toArray(), sensiIssuerSep, TOL));
            assertTrue(DoubleArrayMath.fuzzyEquals(sensiSep.getSensitivity(REPO_CURVE_NAME, JPY).Sensitivity.toArray(), sensiRepoSep, TOL));
        }
Esempio n. 3
0
        //-------------------------------------------------------------------------
        public virtual void presentValueSensitivity()
        {
            PointSensitivities sensiComputed = PRICER.presentValueSensitivity(BILL, PROVIDER);
            PointSensitivities sensiExpected = IssuerCurveDiscountFactors.of(DSC_FACTORS_ISSUER, GROUP_ISSUER).zeroRatePointSensitivity(MATURITY_DATE).multipliedBy(NOTIONAL.Amount).build();

            assertTrue(sensiComputed.equalWithTolerance(sensiExpected, TOLERANCE_PV));
            CurrencyParameterSensitivities paramSensiComputed = PROVIDER.parameterSensitivity(sensiComputed);
            CurrencyParameterSensitivities paramSensiExpected = FD_CALC.sensitivity(PROVIDER, p => PRICER.presentValue(BILL, p));

            assertTrue(paramSensiComputed.equalWithTolerance(paramSensiExpected, EPS * NOTIONAL_AMOUNT));
        }
        //-------------------------------------------------------------------------
        public virtual void test_presentValueSensitivity()
        {
            PointSensitivityBuilder        point    = PRICER.presentValueSensitivity(PRODUCT, PROVIDER);
            CurrencyParameterSensitivities computed = PROVIDER.parameterSensitivity(point.build());
            CurrencyParameterSensitivities expected = FD_CAL.sensitivity(PROVIDER, p => PRICER.presentValue(PRODUCT, p));

            assertTrue(computed.equalWithTolerance(expected, 30d * NOTIONAL * EPS));
        }
Esempio n. 5
0
        public virtual void test_presentValueSensitivity_afterFix()
        {
            PointSensitivityBuilder        pointInterp      = PRICER.presentValueSensitivity(PERIOD_INTERP, IRP_AFTER_FIX, ICDF_AFTER_FIX);
            CurrencyParameterSensitivities computedInterp1  = LEDP_AFTER_FIX.parameterSensitivity(pointInterp.build());
            CurrencyParameterSensitivities computedInterp2  = IRP_AFTER_FIX.parameterSensitivity(pointInterp.build());
            PointSensitivityBuilder        pointMonthly     = PRICER.presentValueSensitivity(PERIOD_MONTHLY, IRP_AFTER_FIX, ICDF_AFTER_FIX);
            CurrencyParameterSensitivities computedMonthly1 = LEDP_AFTER_FIX.parameterSensitivity(pointMonthly.build());
            CurrencyParameterSensitivities computedMonthly2 = IRP_AFTER_FIX.parameterSensitivity(pointMonthly.build());
            CurrencyParameterSensitivities expectedInterp   = fdSensitivity(PERIOD_INTERP, IRP_AFTER_FIX, LEDP_AFTER_FIX);
            CurrencyParameterSensitivities expectedMonthly  = fdSensitivity(PERIOD_MONTHLY, IRP_AFTER_FIX, LEDP_AFTER_FIX);

            assertTrue(computedInterp1.combinedWith(computedInterp2).equalWithTolerance(expectedInterp, NOTIONAL * FD_EPS));
            assertTrue(computedMonthly1.combinedWith(computedMonthly2).equalWithTolerance(expectedMonthly, NOTIONAL * FD_EPS));
        }
        public virtual void test_presentValueSensitivity()
        {
            PointSensitivities             point    = TRADE_PRICER.presentValueSensitivity(FUTURE_TRADE, PROVIDER);
            CurrencyParameterSensitivities computed = PROVIDER.parameterSensitivity(point);
            CurrencyParameterSensitivities expected = FD_CAL.sensitivity(PROVIDER, (p) => TRADE_PRICER.presentValue(FUTURE_TRADE, (p), SETTLE_PRICE));

            assertTrue(computed.equalWithTolerance(expected, 10.0 * EPS * NOTIONAL * QUANTITY));
        }
        //-------------------------------------------------------------------------
        public virtual void test_presentValueSensitivity()
        {
            PointSensitivities             point    = OPTION_TRADE_PRICER.presentValueSensitivityRates(OPTION_TRADE, RATE_PROVIDER, VOLS);
            CurrencyParameterSensitivities computed = RATE_PROVIDER.parameterSensitivity(point);
            double futurePrice    = FUTURE_PRICER.price(OPTION_PRODUCT.UnderlyingFuture, RATE_PROVIDER);
            double strike         = OPTION_PRODUCT.StrikePrice;
            double expiryTime     = ACT_365F.relativeYearFraction(VAL_DATE, OPTION_PRODUCT.ExpiryDate);
            double logMoneyness   = Math.Log(strike / futurePrice);
            double logMoneynessUp = Math.Log(strike / (futurePrice + EPS));
            double logMoneynessDw = Math.Log(strike / (futurePrice - EPS));
            double vol            = SURFACE.zValue(expiryTime, logMoneyness);
            double volUp          = SURFACE.zValue(expiryTime, logMoneynessUp);
            double volDw          = SURFACE.zValue(expiryTime, logMoneynessDw);
            double volSensi       = 0.5 * (volUp - volDw) / EPS;
            double vega           = BlackFormulaRepository.vega(futurePrice, strike, expiryTime, vol);
            CurrencyParameterSensitivities sensiVol = RATE_PROVIDER.parameterSensitivity(FUTURE_PRICER.priceSensitivity(OPTION_PRODUCT.UnderlyingFuture, RATE_PROVIDER)).multipliedBy(-vega * volSensi * NOTIONAL * QUANTITY);
            CurrencyParameterSensitivities expected = FD_CAL.sensitivity(RATE_PROVIDER, (p) => OPTION_TRADE_PRICER.presentValue(OPTION_TRADE, (p), VOLS, REFERENCE_PRICE));

            assertTrue(computed.equalWithTolerance(expected.combinedWith(sensiVol), 30d * EPS * NOTIONAL * QUANTITY));
        }
        public virtual void test_pv01_quote()
        {
            BillTradeCalculationFunction <BillTrade> function = BillTradeCalculationFunction.TRADE;
            ScenarioMarketData             md                      = marketData();
            LegalEntityDiscountingProvider provider                = LOOKUP.marketDataView(md.scenario(0)).discountingProvider();
            DiscountingBillTradePricer     pricer                  = DiscountingBillTradePricer.DEFAULT;
            PointSensitivities             pvPointSens             = pricer.presentValueSensitivity(RTRADE, provider);
            CurrencyParameterSensitivities pvParamSens             = provider.parameterSensitivity(pvPointSens);
            CurrencyParameterSensitivities expectedPv01CalBucketed = MQ_CALC.sensitivity(pvParamSens, provider).multipliedBy(1e-4);
            MultiCurrencyAmount            expectedPv01Cal         = expectedPv01CalBucketed.total();

            ISet <Measure> measures = ImmutableSet.of(Measures.PV01_MARKET_QUOTE_SUM, Measures.PV01_MARKET_QUOTE_BUCKETED);

            assertThat(function.calculate(TRADE, measures, PARAMS, md, REF_DATA)).containsEntry(Measures.PV01_MARKET_QUOTE_SUM, Result.success(MultiCurrencyScenarioArray.of(ImmutableList.of(expectedPv01Cal)))).containsEntry(Measures.PV01_MARKET_QUOTE_BUCKETED, Result.success(ScenarioArray.of(ImmutableList.of(expectedPv01CalBucketed))));
        }
Esempio n. 9
0
        public virtual void test_pv01()
        {
            BondFutureOptionTradeCalculationFunction <BondFutureOptionTrade> function = BondFutureOptionTradeCalculationFunction.TRADE;
            ScenarioMarketData                       md                      = marketData();
            LegalEntityDiscountingProvider           provider                = LED_LOOKUP.marketDataView(md.scenario(0)).discountingProvider();
            BlackBondFutureOptionMarginedTradePricer pricer                  = BlackBondFutureOptionMarginedTradePricer.DEFAULT;
            PointSensitivities                       pvPointSens             = pricer.presentValueSensitivityRates(RTRADE, provider, VOLS);
            CurrencyParameterSensitivities           pvParamSens             = provider.parameterSensitivity(pvPointSens);
            MultiCurrencyAmount                      expectedPv01Cal         = pvParamSens.total().multipliedBy(1e-4);
            CurrencyParameterSensitivities           expectedPv01CalBucketed = pvParamSens.multipliedBy(1e-4);

            ISet <Measure> measures = ImmutableSet.of(Measures.PV01_CALIBRATED_SUM, Measures.PV01_CALIBRATED_BUCKETED);

            assertThat(function.calculate(TRADE, measures, PARAMS, md, REF_DATA)).containsEntry(Measures.PV01_CALIBRATED_SUM, Result.success(MultiCurrencyScenarioArray.of(ImmutableList.of(expectedPv01Cal)))).containsEntry(Measures.PV01_CALIBRATED_BUCKETED, Result.success(ScenarioArray.of(ImmutableList.of(expectedPv01CalBucketed))));
        }
Esempio n. 10
0
        //-------------------------------------------------------------------------
        public virtual void test_pvsensi_settle_before_val()
        {
            PointSensitivities pvsensiComputed = PRICER_TRADE.presentValueSensitivity(BILL_TRADE_SETTLE_BEFORE_VAL, PROVIDER);
            PointSensitivities pvsensiExpected = PRICER_PRODUCT.presentValueSensitivity(BILL_PRODUCT.resolve(REF_DATA), PROVIDER).multipliedBy(QUANTITY);

            assertTrue(pvsensiComputed.equalWithTolerance(pvsensiExpected, TOLERANCE_PVSENSI));
            CurrencyParameterSensitivities paramSensiComputed = PROVIDER.parameterSensitivity(pvsensiComputed);
            CurrencyParameterSensitivities paramSensiExpected = FD_CALC.sensitivity(PROVIDER, p => PRICER_TRADE.presentValue(BILL_TRADE_SETTLE_BEFORE_VAL, p));

            assertTrue(paramSensiComputed.equalWithTolerance(paramSensiExpected, EPS * NOTIONAL_AMOUNT * QUANTITY));
        }
Esempio n. 11
0
        public virtual void test_pv01_quote()
        {
            FixedCouponBondTradeCalculationFunction <FixedCouponBondTrade> function = FixedCouponBondTradeCalculationFunction.TRADE;
            ScenarioMarketData                    md                      = marketData();
            LegalEntityDiscountingProvider        provider                = LOOKUP.marketDataView(md.scenario(0)).discountingProvider();
            DiscountingFixedCouponBondTradePricer pricer                  = DiscountingFixedCouponBondTradePricer.DEFAULT;
            PointSensitivities                    pvPointSens             = pricer.presentValueSensitivity(RTRADE, provider);
            CurrencyParameterSensitivities        pvParamSens             = provider.parameterSensitivity(pvPointSens);
            CurrencyParameterSensitivities        expectedPv01CalBucketed = MQ_CALC.sensitivity(pvParamSens, provider).multipliedBy(1e-4);
            MultiCurrencyAmount                   expectedPv01Cal         = expectedPv01CalBucketed.total();

            ISet <Measure> measures = ImmutableSet.of(Measures.PV01_MARKET_QUOTE_SUM, Measures.PV01_MARKET_QUOTE_BUCKETED);
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: java.util.Map<com.opengamma.strata.calc.Measure, com.opengamma.strata.collect.result.Result<?>> computed = function.calculate(TRADE, measures, PARAMS, md, REF_DATA);
            IDictionary <Measure, Result <object> > computed = function.calculate(TRADE, measures, PARAMS, md, REF_DATA);
            MultiCurrencyScenarioArray sumComputed           = (MultiCurrencyScenarioArray)computed[Measures.PV01_MARKET_QUOTE_SUM].Value;
            ScenarioArray <CurrencyParameterSensitivities> bucketedComputed = (ScenarioArray <CurrencyParameterSensitivities>)computed[Measures.PV01_MARKET_QUOTE_BUCKETED].Value;

            assertEquals(sumComputed.ScenarioCount, 1);
            assertEquals(sumComputed.get(0).Currencies, ImmutableSet.of(GBP));
            assertTrue(DoubleMath.fuzzyEquals(sumComputed.get(0).getAmount(GBP).Amount, expectedPv01Cal.getAmount(GBP).Amount, 1.0e-10));
            assertEquals(bucketedComputed.ScenarioCount, 1);
            assertTrue(bucketedComputed.get(0).equalWithTolerance(expectedPv01CalBucketed, 1.0e-10));
        }
Esempio n. 12
0
        //-------------------------------------------------------------------------
        public virtual void test_presentValueSensitivityFromCleanPrice_standard()
        {
            PointSensitivities             point    = PRICER.presentValueSensitivityFromCleanPrice(TRADE_STANDARD, RATES_PROVIDER, ISSUER_RATES_PROVIDER, REF_DATA, TRADE_PRICE);
            CurrencyParameterSensitivities computed = ISSUER_RATES_PROVIDER.parameterSensitivity(point).combinedWith(RATES_PROVIDER.parameterSensitivity(point));
            CurrencyParameterSensitivities expected = FD_CAL.sensitivity(RATES_PROVIDER, p => PRICER.presentValueFromCleanPrice(TRADE_STANDARD, p, ISSUER_RATES_PROVIDER, REF_DATA, TRADE_PRICE)).combinedWith(FD_CAL.sensitivity(ISSUER_RATES_PROVIDER, p => PRICER.presentValueFromCleanPrice(TRADE_STANDARD, RATES_PROVIDER, p, REF_DATA, TRADE_PRICE)));

            assertTrue(computed.equalWithTolerance(expected, NOTIONAL * QUANTITY * EPS));
        }