public virtual void test_mergedWith_map_mergeAndAdd() { CurveSensitivities base1 = sut(); CurveSensitivities base2 = sut2(); CurveSensitivities test = base1.mergedWith(base2.TypedSensitivities); assertEquals(test.Info, base1.Info); assertEquals(test.TypedSensitivities.Keys, ImmutableSet.of(ZERO_RATE_DELTA, ZERO_RATE_GAMMA)); assertEquals(test.TypedSensitivities.get(ZERO_RATE_DELTA), SENSI1.multipliedBy(2)); assertEquals(test.TypedSensitivities.get(ZERO_RATE_GAMMA), SENSI2); }
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)); }
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)); }
public virtual void present_value_sensitivity_long_short_parity() { PointSensitivities pvptLong = PRICER_SWAPTION_BLACK.presentValueSensitivityRatesStickyStrike(SWAPTION_LONG_REC, MULTI_USD, BLACK_VOLS_USD_STD).build(); PointSensitivities pvptShort = PRICER_SWAPTION_BLACK.presentValueSensitivityRatesStickyStrike(SWAPTION_SHORT_REC, MULTI_USD, BLACK_VOLS_USD_STD).build(); CurrencyParameterSensitivities pvpsLong = MULTI_USD.parameterSensitivity(pvptLong); CurrencyParameterSensitivities pvpsShort = MULTI_USD.parameterSensitivity(pvptShort); assertTrue(pvpsLong.equalWithTolerance(pvpsShort.multipliedBy(-1.0), TOLERANCE_PV_DELTA)); }
public virtual void test_presentValueSensitivityRatesStickyStrike_parity() { CurrencyParameterSensitivities pvSensiRecLong = RATE_PROVIDER.parameterSensitivity(PRICER_SWAPTION.presentValueSensitivityRatesStickyStrike(SWAPTION_REC_LONG, RATE_PROVIDER, VOLS).build()); CurrencyParameterSensitivities pvSensiRecShort = RATE_PROVIDER.parameterSensitivity(PRICER_SWAPTION.presentValueSensitivityRatesStickyStrike(SWAPTION_REC_SHORT, RATE_PROVIDER, VOLS).build()); CurrencyParameterSensitivities pvSensiPayLong = RATE_PROVIDER.parameterSensitivity(PRICER_SWAPTION.presentValueSensitivityRatesStickyStrike(SWAPTION_PAY_LONG, RATE_PROVIDER, VOLS).build()); CurrencyParameterSensitivities pvSensiPayShort = RATE_PROVIDER.parameterSensitivity(PRICER_SWAPTION.presentValueSensitivityRatesStickyStrike(SWAPTION_PAY_SHORT, RATE_PROVIDER, VOLS).build()); assertTrue(pvSensiRecLong.equalWithTolerance(pvSensiRecShort.multipliedBy(-1d), NOTIONAL * TOL)); assertTrue(pvSensiPayLong.equalWithTolerance(pvSensiPayShort.multipliedBy(-1d), NOTIONAL * TOL)); double forward = PRICER_SWAP.parRate(RSWAP_REC, RATE_PROVIDER); PointSensitivityBuilder forwardSensi = PRICER_SWAP.parRateSensitivity(RSWAP_REC, RATE_PROVIDER); double annuityCash = PRICER_SWAP.LegPricer.annuityCash(RSWAP_REC.getLegs(SwapLegType.FIXED).get(0), forward); double annuityCashDeriv = PRICER_SWAP.LegPricer.annuityCashDerivative(RSWAP_REC.getLegs(SwapLegType.FIXED).get(0), forward).getDerivative(0); double discount = RATE_PROVIDER.discountFactor(USD, SETTLE_DATE); PointSensitivityBuilder discountSensi = RATE_PROVIDER.discountFactors(USD).zeroRatePointSensitivity(SETTLE_DATE); PointSensitivities expecedPoint = discountSensi.multipliedBy(annuityCash * (forward - STRIKE)).combinedWith(forwardSensi.multipliedBy(discount * annuityCash + discount * annuityCashDeriv * (forward - STRIKE))).build(); CurrencyParameterSensitivities expected = RATE_PROVIDER.parameterSensitivity(expecedPoint); assertTrue(expected.equalWithTolerance(pvSensiPayLong.combinedWith(pvSensiRecLong.multipliedBy(-1d)), NOTIONAL * TOL)); assertTrue(expected.equalWithTolerance(pvSensiRecShort.combinedWith(pvSensiPayShort.multipliedBy(-1d)), NOTIONAL * TOL)); }
public virtual void test_pv01() { FxVanillaOptionTradeCalculationFunction function = new FxVanillaOptionTradeCalculationFunction(); ScenarioMarketData md = marketData(); RatesProvider provider = RATES_LOOKUP.ratesProvider(md.scenario(0)); BlackFxVanillaOptionTradePricer pricer = BlackFxVanillaOptionTradePricer.DEFAULT; PointSensitivities pvPointSens = pricer.presentValueSensitivityRatesStickyStrike(RTRADE, provider, VOLS); CurrencyParameterSensitivities pvParamSens = provider.parameterSensitivity(pvPointSens); MultiCurrencyAmount expectedPv01 = pvParamSens.total().multipliedBy(1e-4); CurrencyParameterSensitivities expectedBucketedPv01 = 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(expectedPv01)))).containsEntry(Measures.PV01_CALIBRATED_BUCKETED, Result.success(ScenarioArray.of(ImmutableList.of(expectedBucketedPv01)))); }
public virtual void test_pv01_calibrated() { 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); 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)))); }
public virtual void test_pv01() { TermDepositTradeCalculationFunction function = new TermDepositTradeCalculationFunction(); ScenarioMarketData md = marketData(); RatesProvider provider = RATES_LOOKUP.ratesProvider(md.scenario(0)); DiscountingTermDepositProductPricer pricer = DiscountingTermDepositProductPricer.DEFAULT; ResolvedTermDeposit resolved = TRADE.Product.resolve(REF_DATA); PointSensitivities pvPointSens = pricer.presentValueSensitivity(resolved, provider); CurrencyParameterSensitivities pvParamSens = provider.parameterSensitivity(pvPointSens); MultiCurrencyAmount expectedPv01 = pvParamSens.total().multipliedBy(1e-4); CurrencyParameterSensitivities expectedBucketedPv01 = 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(expectedPv01)))).containsEntry(Measures.PV01_CALIBRATED_BUCKETED, Result.success(ScenarioArray.of(ImmutableList.of(expectedBucketedPv01)))); }
public virtual void test_curveSensitivityMeasures() { double oneBp = 1e-4; PointSensitivities pvPointSens = PRICER.presentValueSensitivity(RTRADE, RATES_PROVIDER, CreditDataSet.REF_DATA); CurrencyParameterSensitivities pvParamSens = RATES_PROVIDER.parameterSensitivity(pvPointSens); MultiCurrencyAmount expectedPv01Cal = pvParamSens.total().multipliedBy(oneBp); CurrencyParameterSensitivities expectedPv01CalBucketed = pvParamSens.multipliedBy(oneBp); CurrencyParameterSensitivity expectedCs01Bucketed = CS01_CALC.bucketedCs01(RTRADE, RATES_PROVIDER, CreditDataSet.REF_DATA); CurrencyAmount expectedCs01Parallel = CS01_CALC.parallelCs01(RTRADE, RATES_PROVIDER, CreditDataSet.REF_DATA); PointSensitivities pvPointSensOnSettle = PRICER.presentValueOnSettleSensitivity(RTRADE, RATES_PROVIDER, CreditDataSet.REF_DATA); CurrencyParameterSensitivity ir01 = RATES_PROVIDER.singleDiscountCurveParameterSensitivity(pvPointSensOnSettle, USD); CurrencyAmount expectedIr01Cal = ir01.total().multipliedBy(oneBp); CurrencyParameterSensitivity expectedIr01CalBucketed = ir01.multipliedBy(oneBp); ISet <Measure> measures = ImmutableSet.of(Measures.PV01_CALIBRATED_SUM, Measures.PV01_CALIBRATED_BUCKETED, CreditMeasures.CS01_PARALLEL, CreditMeasures.CS01_BUCKETED, CreditMeasures.IR01_CALIBRATED_PARALLEL, CreditMeasures.IR01_CALIBRATED_BUCKETED); assertThat(FUNCTION.calculate(TRADE, measures, CreditDataSet.CDS_PARAMS, CreditDataSet.MARKET_DATA, CreditDataSet.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)))).containsEntry(CreditMeasures.CS01_PARALLEL, Result.success(CurrencyScenarioArray.of(ImmutableList.of(expectedCs01Parallel)))).containsEntry(CreditMeasures.CS01_BUCKETED, Result.success(ScenarioArray.of(ImmutableList.of(expectedCs01Bucketed)))).containsEntry(CreditMeasures.IR01_CALIBRATED_PARALLEL, Result.success(CurrencyScenarioArray.of(ImmutableList.of(expectedIr01Cal)))).containsEntry(CreditMeasures.IR01_CALIBRATED_BUCKETED, Result.success(ScenarioArray.of(ImmutableList.of(expectedIr01CalBucketed)))); }
public virtual void test_pv01_quote() { BondFutureTradeCalculationFunction <BondFutureTrade> function = BondFutureTradeCalculationFunction.TRADE; ScenarioMarketData md = marketData(); LegalEntityDiscountingProvider provider = LOOKUP.marketDataView(md.scenario(0)).discountingProvider(); DiscountingBondFutureTradePricer pricer = DiscountingBondFutureTradePricer.DEFAULT; PointSensitivities pvPointSens = pricer.presentValueSensitivity(RTRADE, provider); CurrencyParameterSensitivities pvParamSens = provider.parameterSensitivity(pvPointSens); CurrencyParameterSensitivities expectedPv01CalBucketed = MQ_CALC.sensitivity(pvParamSens.multipliedBy(1e-4), provider); 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(USD)); assertTrue(DoubleMath.fuzzyEquals(sumComputed.get(0).getAmount(USD).Amount, expectedPv01Cal.getAmount(USD).Amount, 1.0e-10)); assertEquals(bucketedComputed.ScenarioCount, 1); assertTrue(bucketedComputed.get(0).equalWithTolerance(expectedPv01CalBucketed, 1.0e-10)); }