public virtual void test_rateSensitivity() { RatesProvider mockProv = mock(typeof(RatesProvider)); IborIndexRates mockRates3M = mock(typeof(IborIndexRates)); IborIndexRates mockRates6M = mock(typeof(IborIndexRates)); when(mockProv.iborIndexRates(GBP_LIBOR_3M)).thenReturn(mockRates3M); when(mockProv.iborIndexRates(GBP_LIBOR_6M)).thenReturn(mockRates6M); when(mockRates3M.ratePointSensitivity(GBP_LIBOR_3M_OBS)).thenReturn(SENSITIVITY3); when(mockRates6M.ratePointSensitivity(GBP_LIBOR_6M_OBS)).thenReturn(SENSITIVITY6); IborInterpolatedRateComputation ro = IborInterpolatedRateComputation.of(GBP_LIBOR_3M, GBP_LIBOR_6M, FIXING_DATE, REF_DATA); ForwardIborInterpolatedRateComputationFn obsFn = ForwardIborInterpolatedRateComputationFn.DEFAULT; LocalDate fixingEndDate3M = GBP_LIBOR_3M_OBS.MaturityDate; LocalDate fixingEndDate6M = GBP_LIBOR_6M_OBS.MaturityDate; double days3M = fixingEndDate3M.toEpochDay() - FIXING_DATE.toEpochDay(); //nb days in 3M fixing period double days6M = fixingEndDate6M.toEpochDay() - FIXING_DATE.toEpochDay(); //nb days in 6M fixing period double daysCpn = ACCRUAL_END_DATE.toEpochDay() - FIXING_DATE.toEpochDay(); double weight3M = (days6M - daysCpn) / (days6M - days3M); double weight6M = (daysCpn - days3M) / (days6M - days3M); IborRateSensitivity sens3 = IborRateSensitivity.of(GBP_LIBOR_3M_OBS, weight3M); IborRateSensitivity sens6 = IborRateSensitivity.of(GBP_LIBOR_6M_OBS, weight6M); PointSensitivities expected = PointSensitivities.of(ImmutableList.of(sens3, sens6)); PointSensitivityBuilder test = obsFn.rateSensitivity(ro, ACCRUAL_START_DATE, ACCRUAL_END_DATE, mockProv); assertEquals(test.build(), expected); }
/// <summary> /// Calculates the price sensitivity of the Ibor future product. /// <para> /// The price sensitivity of the product is the sensitivity of the price to the underlying curves. /// /// </para> /// </summary> /// <param name="future"> the future </param> /// <param name="ratesProvider"> the rates provider </param> /// <returns> the price curve sensitivity of the product </returns> public virtual PointSensitivities priceSensitivity(ResolvedIborFuture future, RatesProvider ratesProvider) { IborRateSensitivity sensi = IborRateSensitivity.of(future.IborRate.Observation, -1d); // The sensitivity should be to no currency or currency XXX. To avoid useless conversion, the dimension-less // price sensitivity is reported in the future currency. return(PointSensitivities.of(sensi)); }
//------------------------------------------------------------------------- public virtual void test_marginIndexSensitivity() { double notional = FUTURE.Notional; double accrualFactor = FUTURE.AccrualFactor; PointSensitivities sensiExpected = PointSensitivities.of(IborRateSensitivity.of(FUTURE.IborRate.Observation, -notional * accrualFactor)); PointSensitivities priceSensitivity = PRICER.priceSensitivity(FUTURE, new MockRatesProvider()); PointSensitivities sensiComputed = PRICER.marginIndexSensitivity(FUTURE, priceSensitivity).normalized(); assertTrue(sensiComputed.equalWithTolerance(sensiExpected, 1e-5)); }
/// <summary> /// Calculates the price sensitivity of the Ibor future product. /// <para> /// The price sensitivity of the product is the sensitivity of the price to the underlying curves. /// /// </para> /// </summary> /// <param name="future"> the future </param> /// <param name="ratesProvider"> the rates provider </param> /// <param name="hwProvider"> the Hull-White model parameter provider </param> /// <returns> the price curve sensitivity of the product </returns> public virtual PointSensitivities priceSensitivityRates(ResolvedIborFuture future, RatesProvider ratesProvider, HullWhiteOneFactorPiecewiseConstantParametersProvider hwProvider) { IborIndexObservation obs = future.IborRate.Observation; LocalDate fixingStartDate = obs.EffectiveDate; LocalDate fixingEndDate = obs.MaturityDate; double convexity = hwProvider.futuresConvexityFactor(future.LastTradeDate, fixingStartDate, fixingEndDate); IborRateSensitivity sensi = IborRateSensitivity.of(obs, -convexity); // The sensitivity should be to no currency or currency XXX. To avoid useless conversion, the dimension-less // price sensitivity is reported in the future currency. return(PointSensitivities.of(sensi)); }
//------------------------------------------------------------------------- public virtual void test_priceSensitivity() { IborIndexRates mockIbor = mock(typeof(IborIndexRates)); SimpleRatesProvider prov = new SimpleRatesProvider(); prov.IborRates = mockIbor; PointSensitivities sensiExpected = PointSensitivities.of(IborRateSensitivity.of(FUTURE.IborRate.Observation, -1d)); PointSensitivities sensiComputed = PRICER.priceSensitivity(FUTURE, prov); assertTrue(sensiComputed.equalWithTolerance(sensiExpected, TOLERANCE_PRICE_DELTA)); }
static DiscountingFraTradePricerTest() { DiscountFactors mockDf = mock(typeof(DiscountFactors)); IborIndexRates mockIbor = mock(typeof(IborIndexRates)); RATES_PROVIDER = new SimpleRatesProvider(VAL_DATE, mockDf); RATES_PROVIDER.IborRates = mockIbor; IborIndexObservation obs = ((IborRateComputation)RFRA.FloatingRate).Observation; IborRateSensitivity sens = IborRateSensitivity.of(obs, 1d); when(mockIbor.ratePointSensitivity(obs)).thenReturn(sens); when(mockIbor.rate(obs)).thenReturn(FORWARD_RATE); when(mockDf.discountFactor(RFRA.PaymentDate)).thenReturn(DISCOUNT_FACTOR); }
//------------------------------------------------------------------------- public virtual void test_compareKey() { ZeroRateSensitivity a1 = ZeroRateSensitivity.of(GBP, YEARFRAC, 32d); ZeroRateSensitivity a2 = ZeroRateSensitivity.of(GBP, YEARFRAC, 32d); ZeroRateSensitivity b = ZeroRateSensitivity.of(USD, YEARFRAC, 32d); ZeroRateSensitivity c = ZeroRateSensitivity.of(GBP, YEARFRAC2, 32d); IborRateSensitivity other = IborRateSensitivity.of(IborIndexObservation.of(GBP_LIBOR_3M, date(2014, 6, 30), REF_DATA), 32d); assertEquals(a1.compareKey(a2), 0); assertEquals(a1.compareKey(b) < 0, true); assertEquals(b.compareKey(a1) > 0, true); assertEquals(a1.compareKey(c) < 0, true); assertEquals(c.compareKey(a1) > 0, true); assertEquals(a1.compareKey(other) > 0, true); assertEquals(other.compareKey(a1) < 0, true); }
//------------------------------------------------------------------------- public virtual void test_compareKey() { CreditCurveZeroRateSensitivity a1 = CreditCurveZeroRateSensitivity.of(LEGAL_ENTITY, GBP, YEAR_FRACTION, 32d); CreditCurveZeroRateSensitivity a2 = CreditCurveZeroRateSensitivity.of(LEGAL_ENTITY, GBP, YEAR_FRACTION, 32d); CreditCurveZeroRateSensitivity b = CreditCurveZeroRateSensitivity.of(LEGAL_ENTITY, GBP, 10d, 32d); CreditCurveZeroRateSensitivity c = CreditCurveZeroRateSensitivity.of(LEGAL_ENTITY, USD, YEAR_FRACTION, 32d); CreditCurveZeroRateSensitivity d = CreditCurveZeroRateSensitivity.of(LEGAL_ENTITY, USD, YEAR_FRACTION, GBP, 32d); IborRateSensitivity other = IborRateSensitivity.of(IborIndexObservation.of(GBP_LIBOR_3M, date(2014, 6, 30), REF_DATA), 32d); assertEquals(a1.compareKey(a2), 0); assertEquals(a1.compareKey(b) < 0, true); assertEquals(b.compareKey(a1) > 0, true); assertEquals(a1.compareKey(c) < 0, true); assertEquals(a1.compareKey(d) < 0, true); assertEquals(c.compareKey(a1) > 0, true); assertEquals(a1.compareKey(other) < 0, true); assertEquals(other.compareKey(a1) > 0, true); }
public virtual void test_compareKey() { IssuerCurveZeroRateSensitivity a1 = IssuerCurveZeroRateSensitivity.of(CURRENCY, YEARFRAC, GROUP, VALUE); IssuerCurveZeroRateSensitivity a2 = IssuerCurveZeroRateSensitivity.of(CURRENCY, YEARFRAC, GROUP, VALUE); IssuerCurveZeroRateSensitivity b = IssuerCurveZeroRateSensitivity.of(GBP, YEARFRAC, GROUP, VALUE); IssuerCurveZeroRateSensitivity c = IssuerCurveZeroRateSensitivity.of(CURRENCY, YEARFRAC2, GROUP, VALUE); IssuerCurveZeroRateSensitivity d = IssuerCurveZeroRateSensitivity.of(CURRENCY, YEARFRAC, LegalEntityGroup.of("ISSUER2"), VALUE); IborRateSensitivity other = IborRateSensitivity.of(IborIndexObservation.of(GBP_LIBOR_3M, date(2015, 8, 27), REF_DATA), 32d); assertEquals(a1.compareKey(a2), 0); assertEquals(a1.compareKey(b) > 0, true); assertEquals(b.compareKey(a1) < 0, true); assertEquals(a1.compareKey(c) < 0, true); assertEquals(c.compareKey(a1) > 0, true); assertEquals(a1.compareKey(d) < 0, true); assertEquals(d.compareKey(a1) > 0, true); assertEquals(a1.compareKey(other) > 0, true); assertEquals(other.compareKey(a1) < 0, true); }
public virtual void test_compareKey() { RepoCurveZeroRateSensitivity a1 = RepoCurveZeroRateSensitivity.of(CURRENCY, YEARFRAC, GROUP, VALUE); RepoCurveZeroRateSensitivity a2 = RepoCurveZeroRateSensitivity.of(CURRENCY, YEARFRAC, GROUP, VALUE); RepoCurveZeroRateSensitivity b = RepoCurveZeroRateSensitivity.of(GBP, YEARFRAC, GROUP, VALUE); RepoCurveZeroRateSensitivity c = RepoCurveZeroRateSensitivity.of(CURRENCY, YEARFRAC2, GROUP, VALUE); RepoCurveZeroRateSensitivity d = RepoCurveZeroRateSensitivity.of(CURRENCY, YEARFRAC, RepoGroup.of("ISSUER1 BND 3Y"), VALUE); IborRateSensitivity other = IborRateSensitivity.of(IborIndexObservation.of(GBP_LIBOR_3M, date(2014, 6, 30), REF_DATA), 32d); assertEquals(a1.compareKey(a2), 0); assertEquals(a1.compareKey(b) > 0, true); assertEquals(b.compareKey(a1) < 0, true); assertEquals(a1.compareKey(c) < 0, true); assertEquals(c.compareKey(a1) > 0, true); assertEquals(a1.compareKey(d) < 0, true); assertEquals(d.compareKey(a1) > 0, true); assertEquals(a1.compareKey(other) > 0, true); assertEquals(other.compareKey(a1) < 0, true); }