public virtual void test_explainPresentValue_paymentDateInPast() { SimpleRatesProvider prov = createProvider(NOTIONAL_EXCHANGE_REC_GBP); prov.ValuationDate = VAL_DATE.plusYears(1); DiscountingNotionalExchangePricer test = DiscountingNotionalExchangePricer.DEFAULT; ExplainMapBuilder builder = ExplainMap.builder(); test.explainPresentValue(NOTIONAL_EXCHANGE_REC_GBP, prov, builder); ExplainMap explain = builder.build(); Currency currency = NOTIONAL_EXCHANGE_REC_GBP.Currency; CurrencyAmount notional = NOTIONAL_EXCHANGE_REC_GBP.PaymentAmount; assertEquals(explain.get(ExplainKey.ENTRY_TYPE).get(), "NotionalExchange"); assertEquals(explain.get(ExplainKey.PAYMENT_DATE).get(), NOTIONAL_EXCHANGE_REC_GBP.PaymentDate); assertEquals(explain.get(ExplainKey.PAYMENT_CURRENCY).get(), currency); assertEquals(explain.get(ExplainKey.TRADE_NOTIONAL).get().Currency, currency); assertEquals(explain.get(ExplainKey.TRADE_NOTIONAL).get().Amount, notional.Amount, TOLERANCE); assertEquals(explain.get(ExplainKey.FORECAST_VALUE).get().Currency, currency); assertEquals(explain.get(ExplainKey.FORECAST_VALUE).get().Amount, 0d, TOLERANCE); assertEquals(explain.get(ExplainKey.PRESENT_VALUE).get().Currency, currency); assertEquals(explain.get(ExplainKey.PRESENT_VALUE).get().Amount, 0d * DISCOUNT_FACTOR, TOLERANCE); }
public virtual void test_explainPresentValue_paymentDateInPast() { SimpleRatesProvider prov = createProvider(FX_RESET_NOTIONAL_EXCHANGE_REC_USD); prov.ValuationDate = VAL_DATE.plusYears(1); DiscountingFxResetNotionalExchangePricer test = new DiscountingFxResetNotionalExchangePricer(); ExplainMapBuilder builder = ExplainMap.builder(); test.explainPresentValue(FX_RESET_NOTIONAL_EXCHANGE_REC_USD, prov, builder); ExplainMap explain = builder.build(); Currency paymentCurrency = FX_RESET_NOTIONAL_EXCHANGE_REC_USD.Currency; Currency notionalCurrency = FX_RESET_NOTIONAL_EXCHANGE_REC_USD.ReferenceCurrency; double notional = FX_RESET_NOTIONAL_EXCHANGE_REC_USD.Notional; assertEquals(explain.get(ExplainKey.ENTRY_TYPE).get(), "FxResetNotionalExchange"); assertEquals(explain.get(ExplainKey.PAYMENT_DATE).get(), FX_RESET_NOTIONAL_EXCHANGE_REC_USD.PaymentDate); assertEquals(explain.get(ExplainKey.PAYMENT_CURRENCY).get(), paymentCurrency); assertEquals(explain.get(ExplainKey.TRADE_NOTIONAL).get().Currency, notionalCurrency); assertEquals(explain.get(ExplainKey.TRADE_NOTIONAL).get().Amount, notional, TOLERANCE); assertEquals(explain.get(ExplainKey.FORECAST_VALUE).get().Currency, paymentCurrency); assertEquals(explain.get(ExplainKey.FORECAST_VALUE).get().Amount, 0d, TOLERANCE); assertEquals(explain.get(ExplainKey.PRESENT_VALUE).get().Currency, paymentCurrency); assertEquals(explain.get(ExplainKey.PRESENT_VALUE).get().Amount, 0d * DISCOUNT_FACTOR, TOLERANCE); }
/// <summary> /// Explain present value for a swap leg. /// </summary> /// <param name="leg"> the swap log </param> /// <param name="provider"> the rates provider </param> /// <returns> the explain PV map </returns> public virtual ExplainMap explainPresentValue(ResolvedSwapLeg leg, RatesProvider provider) { ExplainMapBuilder builder = ExplainMap.builder(); explainPresentValueInternal(leg, provider, builder); return(builder.build()); }
//------------------------------------------------------------------------- /// <summary> /// Explains the present value of the swap product. /// <para> /// This returns explanatory information about the calculation. /// /// </para> /// </summary> /// <param name="swap"> the product </param> /// <param name="provider"> the rates provider </param> /// <returns> the explanatory information </returns> public virtual ExplainMap explainPresentValue(ResolvedSwap swap, RatesProvider provider) { ExplainMapBuilder builder = ExplainMap.builder(); builder.put(ExplainKey.ENTRY_TYPE, "Swap"); foreach (ResolvedSwapLeg leg in swap.Legs) { builder.addListEntryWithIndex(ExplainKey.LEGS, child => legPricer.explainPresentValueInternal(leg, provider, child)); } return(builder.build()); }
//------------------------------------------------------------------------- public virtual void test_explainRate_FixedRateComputation() { FixedRateComputation ro = FixedRateComputation.of(0.0123d); DispatchingRateComputationFn test = DispatchingRateComputationFn.DEFAULT; ExplainMapBuilder builder = ExplainMap.builder(); assertEquals(test.explainRate(ro, ACCRUAL_START_DATE, ACCRUAL_END_DATE, MOCK_PROV, builder), 0.0123d, 0d); ExplainMap built = builder.build(); assertEquals(built.get(ExplainKey.FIXED_RATE), 0.0123d); assertEquals(built.get(ExplainKey.COMBINED_RATE), 0.0123d); }
public virtual void test_rate() { LocalDate fixingDate = OBSERVATIONS[0].FixingDate; LocalDateDoubleTimeSeries timeSeries = LocalDateDoubleTimeSeries.of(fixingDate, FIXING_VALUES[0]); LocalDateDoubleTimeSeries rates = LocalDateDoubleTimeSeries.builder().put(OBSERVATIONS[1].FixingDate, FIXING_VALUES[1]).put(OBSERVATIONS[2].FixingDate, FIXING_VALUES[2]).put(OBSERVATIONS[3].FixingDate, FIXING_VALUES[3]).build(); IborIndexRates mockIbor = new TestingIborIndexRates(GBP_LIBOR_3M, fixingDate, rates, timeSeries); SimpleRatesProvider prov = new SimpleRatesProvider(fixingDate); prov.IborRates = mockIbor; IList <IborAveragedFixing> fixings = new List <IborAveragedFixing>(); double totalWeightedRate = 0.0d; double totalWeight = 0.0d; for (int i = 0; i < OBSERVATIONS.Length; i++) { IborIndexObservation obs = OBSERVATIONS[i]; IborAveragedFixing fixing = IborAveragedFixing.builder().observation(obs).weight(WEIGHTS[i]).build(); fixings.Add(fixing); totalWeightedRate += FIXING_VALUES[i] * WEIGHTS[i]; totalWeight += WEIGHTS[i]; } double rateExpected = totalWeightedRate / totalWeight; IborAveragedRateComputation ro = IborAveragedRateComputation.of(fixings); ForwardIborAveragedRateComputationFn obsFn = ForwardIborAveragedRateComputationFn.DEFAULT; double rateComputed = obsFn.rate(ro, ACCRUAL_START_DATE, ACCRUAL_END_DATE, prov); assertEquals(rateComputed, rateExpected, TOLERANCE_RATE); // explain ExplainMapBuilder builder = ExplainMap.builder(); assertEquals(obsFn.explainRate(ro, ACCRUAL_START_DATE, ACCRUAL_END_DATE, prov, builder), rateExpected, TOLERANCE_RATE); ExplainMap built = builder.build(); assertEquals(built.get(ExplainKey.OBSERVATIONS).Present, true); assertEquals(built.get(ExplainKey.OBSERVATIONS).get().size(), OBSERVATIONS.Length); for (int i = 0; i < 4; i++) { ExplainMap childMap = built.get(ExplainKey.OBSERVATIONS).get().get(i); assertEquals(childMap.get(ExplainKey.FIXING_DATE), (OBSERVATIONS[i].FixingDate)); assertEquals(childMap.get(ExplainKey.INDEX), GBP_LIBOR_3M); assertEquals(childMap.get(ExplainKey.INDEX_VALUE), FIXING_VALUES[i]); assertEquals(childMap.get(ExplainKey.WEIGHT), WEIGHTS[i]); assertEquals(childMap.get(ExplainKey.FROM_FIXING_SERIES), i == 0 ? true : null); } assertEquals(built.get(ExplainKey.COMBINED_RATE), rateExpected); }
//------------------------------------------------------------------------- /// <summary> /// Explains the present value of the CMS product. /// <para> /// This returns explanatory information about the calculation. /// /// </para> /// </summary> /// <param name="cms"> the CMS product </param> /// <param name="ratesProvider"> the rates provider </param> /// <param name="swaptionVolatilities"> the swaption volatilities </param> /// <returns> the explain PV map </returns> public virtual ExplainMap explainPresentValue(ResolvedCms cms, RatesProvider ratesProvider, SabrSwaptionVolatilities swaptionVolatilities) { ExplainMapBuilder builder = ExplainMap.builder(); builder.put(ExplainKey.ENTRY_TYPE, "CmsSwap"); IList <ExplainMap> legsExplain = new List <ExplainMap>(); legsExplain.Add(cmsLegPricer.explainPresentValue(cms.CmsLeg, ratesProvider, swaptionVolatilities)); if (cms.PayLeg.Present) { legsExplain.Add(payLegPricer.explainPresentValue(cms.PayLeg.get(), ratesProvider)); } builder.put(ExplainKey.LEGS, legsExplain); return(builder.build()); }
//------------------------------------------------------------------------- /// <summary> /// Test for the case where publication lag=1, effective offset=0 (USD conventions) and no cutoff period. </summary> public virtual void rateFedFundNoCutOff() { OvernightIndexRates mockRates = mock(typeof(OvernightIndexRates)); when(mockRates.Index).thenReturn(USD_FED_FUND); SimpleRatesProvider simpleProv = new SimpleRatesProvider(mockRates); for (int i = 0; i < USD_OBS.Length; i++) { when(mockRates.rate(USD_OBS[i])).thenReturn(FIXING_RATES[i]); } OvernightAveragedRateComputation ro = OvernightAveragedRateComputation.of(USD_FED_FUND, START_DATE, END_DATE, 0, REF_DATA); // Accrual dates = fixing dates ForwardOvernightAveragedRateComputationFn obsFn = ForwardOvernightAveragedRateComputationFn.DEFAULT; double accrualFactorTotal = 0.0d; double accruedRate = 0.0d; int indexLast = 5; // Fixing in the observation period are from 1 to 5 (inclusive) for (int i = 1; i <= indexLast; i++) { LocalDate endDate = USD_OBS[i].MaturityDate; double af = USD_FED_FUND.DayCount.yearFraction(FIXING_DATES[i], endDate); accrualFactorTotal += af; accruedRate += FIXING_RATES[i] * af; } double rateExpected = accruedRate / accrualFactorTotal; double rateComputed = obsFn.rate(ro, DUMMY_ACCRUAL_START_DATE, DUMMY_ACCRUAL_END_DATE, simpleProv); assertEquals(rateExpected, rateComputed, TOLERANCE_RATE); // explain ExplainMapBuilder builder = ExplainMap.builder(); double explainedRate = obsFn.explainRate(ro, DUMMY_ACCRUAL_START_DATE, DUMMY_ACCRUAL_END_DATE, simpleProv, builder); assertEquals(explainedRate, rateExpected, TOLERANCE_RATE); ExplainMap built = builder.build(); assertEquals(built.get(ExplainKey.OBSERVATIONS).Present, false); assertEquals(built.get(ExplainKey.COMBINED_RATE).Value.doubleValue(), rateExpected, TOLERANCE_RATE); }