// ------------------------------------------------------------------------- public void test_build() { BondFutureOptionSensitivity base = BondFutureOptionSensitivity.of( NAME, OPTION_EXPIRY, FUTURE_EXPIRY, STRIKE_PRICE, FUTURE_PRICE, GBP, SENSITIVITY); PointSensitivities test = base.build(); assertEquals(test.getSensitivities(), ImmutableList.of(base)); }
/** * Test for the case where publication lag=0, effective offset=0 (GBP conventions) and no cutoff * period. The arithmetic average coupons are used mainly in USD. This test is more for * completeness than a real case. */ public void rateGbpNoCutOffSensitivity() { OvernightIndexRates mockRates = mock(OvernightIndexRates.class); when(mockRates.getIndex()).thenReturn(GBP_SONIA); SimpleRatesProvider simpleProv = new SimpleRatesProvider(mockRates); for (int i = 0; i < FIXING_DATES.length; i++) { when(mockRates.rate(FIXING_DATES[i])).thenReturn(FIXING_RATES[i]); LocalDate fixingStartDate = GBP_SONIA.calculateEffectiveFromFixing(FIXING_DATES[i]); LocalDate fixingEndDate = GBP_SONIA.calculateMaturityFromEffective(fixingStartDate); OvernightRateSensitivity sensitivity = OvernightRateSensitivity.of( GBP_SONIA, FIXING_DATES[i], fixingEndDate, GBP_SONIA.getCurrency(), 1d); when(mockRates.ratePointSensitivity(FIXING_DATES[i])).thenReturn(sensitivity); } OvernightAveragedRateObservation ro = OvernightAveragedRateObservation.of(GBP_SONIA, FIXING_START_DATE, FIXING_END_DATE, 0); ForwardOvernightAveragedRateObservationFn obsFn = ForwardOvernightAveragedRateObservationFn.DEFAULT; PointSensitivityBuilder sensitivityBuilderComputed = obsFn.rateSensitivity(ro, DUMMY_ACCRUAL_START_DATE, DUMMY_ACCRUAL_END_DATE, simpleProv); PointSensitivities sensitivityComputed = sensitivityBuilderComputed.build().normalized(); Double[] sensitivityExpected = computedSensitivityFD(ro, GBP_SONIA); assertEquals(sensitivityComputed.getSensitivities().size(), sensitivityExpected.length); for (int i = 0; i < sensitivityExpected.length; ++i) { assertEquals( sensitivityComputed.getSensitivities().get(i).getSensitivity(), sensitivityExpected[i], EPS_FD); } }
public void test_marginIndexSensitivity() { PointSensitivities point = OPTION_PRICER.priceSensitivityStickyStrike( FUTURE_OPTION_PRODUCT, RATE_PROVIDER, VOL_PROVIDER); PointSensitivities computed = OPTION_PRICER.marginIndexSensitivity(FUTURE_OPTION_PRODUCT, point); assertEquals(computed, point.multipliedBy(FUTURE_OPTION_PRODUCT.getUnderlying().getNotional())); }
public void test_presentValueSensitivity() { PointSensitivities pvSensiTrade = PRICER_TRADE.presentValueSensitivityRates(OPTION_TRADE, RATES_PROVIDER, VOLS); PointSensitivities pvSensiProduct = PRICER_PRODUCT.presentValueSensitivityRates(OPTION_PRODUCT, RATES_PROVIDER, VOLS); PointSensitivities pvSensiPremium = PRICER_PAYMENT.presentValueSensitivity(PREMIUM, RATES_PROVIDER).build(); assertEquals(pvSensiTrade, pvSensiProduct.combinedWith(pvSensiPremium)); }
/** Test forecast value sensitivity for AFMA FRA discounting method. */ public void test_forecastValueSensitivity_AFMA() { ExpandedFra fraExp = FRA_AFMA.expand(); SimpleRatesProvider prov = createProvider(fraExp); DiscountingFraProductPricer test = DiscountingFraProductPricer.DEFAULT; PointSensitivities sensitivity = test.forecastValueSensitivity(fraExp, prov); double eps = 1.e-7; double fdSense = forecastValueFwdSensitivity(FRA_AFMA, FORWARD_RATE, eps); ImmutableList<PointSensitivity> sensitivities = sensitivity.getSensitivities(); assertEquals(sensitivities.size(), 1); IborRateSensitivity sensitivity0 = (IborRateSensitivity) sensitivities.get(0); assertEquals(sensitivity0.getIndex(), FRA_AFMA.getIndex()); assertEquals(sensitivity0.getFixingDate(), FRA_AFMA.getStartDate()); assertEquals(sensitivity0.getSensitivity(), fdSense, FRA_AFMA.getNotional() * eps); }
/** Test present value sensitivity for ISDA */ public void test_presentValueSensitivity_ISDA() { RateObservationFn<RateObservation> mockObs = mock(RateObservationFn.class); DiscountFactors mockDf = mock(DiscountFactors.class); SimpleRatesProvider simpleProv = new SimpleRatesProvider(VAL_DATE, mockDf); ExpandedFra fraExp = FRA.expand(); double forwardRate = 0.05; double discountRate = 0.015; double paymentTime = 0.3; double discountFactor = Math.exp(-discountRate * paymentTime); LocalDate fixingDate = FRA.getStartDate(); PointSensitivityBuilder sens = IborRateSensitivity.of(FRA.getIndex(), fixingDate, 1d); when(mockDf.discountFactor(fraExp.getPaymentDate())).thenReturn(discountFactor); when(mockDf.zeroRatePointSensitivity(fraExp.getPaymentDate())) .thenReturn( ZeroRateSensitivity.of( fraExp.getCurrency(), fraExp.getPaymentDate(), -discountFactor * paymentTime)); when(mockObs.rateSensitivity( fraExp.getFloatingRate(), fraExp.getStartDate(), fraExp.getEndDate(), simpleProv)) .thenReturn(sens); when(mockObs.rate(fraExp.getFloatingRate(), FRA.getStartDate(), FRA.getEndDate(), simpleProv)) .thenReturn(forwardRate); DiscountingFraProductPricer test = new DiscountingFraProductPricer(mockObs); PointSensitivities sensitivity = test.presentValueSensitivity(fraExp, simpleProv); double eps = 1.e-7; double fdDscSense = dscSensitivity(FRA, forwardRate, discountFactor, paymentTime, eps); double fdSense = presentValueFwdSensitivity(FRA, forwardRate, discountFactor, eps); ImmutableList<PointSensitivity> sensitivities = sensitivity.getSensitivities(); assertEquals(sensitivities.size(), 2); IborRateSensitivity sensitivity0 = (IborRateSensitivity) sensitivities.get(0); assertEquals(sensitivity0.getIndex(), FRA.getIndex()); assertEquals(sensitivity0.getFixingDate(), fixingDate); assertEquals(sensitivity0.getSensitivity(), fdSense, FRA.getNotional() * eps); ZeroRateSensitivity sensitivity1 = (ZeroRateSensitivity) sensitivities.get(1); assertEquals(sensitivity1.getCurrency(), FRA.getCurrency()); assertEquals(sensitivity1.getDate(), fraExp.getPaymentDate()); assertEquals(sensitivity1.getSensitivity(), fdDscSense, FRA.getNotional() * eps); // test via FraTrade DiscountingFraTradePricer testTrade = new DiscountingFraTradePricer(test); assertEquals( testTrade.presentValueSensitivity(FRA_TRADE, simpleProv), test.presentValueSensitivity(fraExp, simpleProv)); }
@Override public CurrencyParameterSensitivities parameterSensitivity( PointSensitivities pointSensitivities) { CurrencyParameterSensitivities sens = CurrencyParameterSensitivities.empty(); for (PointSensitivity point : pointSensitivities.getSensitivities()) { if (point instanceof IborFutureOptionSensitivity) { IborFutureOptionSensitivity pt = (IborFutureOptionSensitivity) point; if (pt.getVolatilitiesName().equals(getName())) { sens = sens.combinedWith(parameterSensitivity(pt)); } } } return sens; }