/// <summary> /// Calibrate a single curve to 4 points. Use the resulting calibrated curves as starting point of the computation /// of a Jacobian. Compare the direct Jacobian and the one reconstructed from trades. /// </summary> public virtual void direct_one_curve() { /* Create trades */ IList <ResolvedTrade> trades = new List <ResolvedTrade>(); IList <LocalDate> nodeDates = new List <LocalDate>(); for (int looptenor = 0; looptenor < TENORS_STD_1.Length; looptenor++) { ResolvedSwapTrade t0 = EUR_FIXED_1Y_EURIBOR_6M.createTrade(VALUATION_DATE, TENORS_STD_1[looptenor], BuySell.BUY, 1.0, 0.0, REF_DATA).resolve(REF_DATA); double rate = MARKET_QUOTE.value(t0, MULTICURVE_EUR_SINGLE_CALIBRATED); ResolvedSwapTrade t = EUR_FIXED_1Y_EURIBOR_6M.createTrade(VALUATION_DATE, TENORS_STD_1[looptenor], BuySell.BUY, 1.0, rate, REF_DATA).resolve(REF_DATA); nodeDates.Add(t.Product.EndDate); trades.Add(t); } /* Par rate sensitivity */ System.Func <ResolvedTrade, CurrencyParameterSensitivities> sensitivityFunction = (t) => MULTICURVE_EUR_SINGLE_CALIBRATED.parameterSensitivity(PRICER_SWAP_PRODUCT.parRateSensitivity(((ResolvedSwapTrade)t).Product, MULTICURVE_EUR_SINGLE_CALIBRATED).build()); DoubleMatrix jiComputed = CurveSensitivityUtils.jacobianFromMarketQuoteSensitivities(LIST_CURVE_NAMES_1, trades, sensitivityFunction); DoubleMatrix jiExpected = MULTICURVE_EUR_SINGLE_CALIBRATED.findData(EUR_SINGLE_NAME).get().Metadata.findInfo(CurveInfoType.JACOBIAN).get().JacobianMatrix; /* Comparison */ assertEquals(jiComputed.rowCount(), jiExpected.rowCount()); assertEquals(jiComputed.columnCount(), jiExpected.columnCount()); for (int i = 0; i < jiComputed.rowCount(); i++) { for (int j = 0; j < jiComputed.columnCount(); j++) { assertEquals(jiComputed.get(i, j), jiExpected.get(i, j), TOLERANCE_JAC); } } }
// market quote bucketed PV01 for one scenario internal CurrencyParameterSensitivities pv01MarketQuoteBucketed(ResolvedSwapTrade trade, RatesProvider ratesProvider) { PointSensitivities pointSensitivity = tradePricer.presentValueSensitivity(trade, ratesProvider); CurrencyParameterSensitivities parameterSensitivity = ratesProvider.parameterSensitivity(pointSensitivity); return(MARKET_QUOTE_SENS.sensitivity(parameterSensitivity, ratesProvider).multipliedBy(ONE_BASIS_POINT)); }
public virtual double test_BasisCompoundedLibor1mVsLibor3mSwap() { DiscountingSwapTradePricer pricer = swapPricer(); ResolvedSwapTrade resolved = TRADE5.resolve(REF_DATA); CurrencyAmount pv = pricer.presentValue(resolved, USD, PROVIDER); return(pv.Amount); }
private void checkSwapPvIsZero(FixedIborSwapCurveNode node, RatesProvider ratesProvider, MarketData marketDataMap) { ResolvedSwapTrade trade = node.resolvedTrade(1d, marketDataMap, REF_DATA); MultiCurrencyAmount amount = DiscountingSwapTradePricer.DEFAULT.presentValue(trade, ratesProvider); double pv = amount.getAmount(Currency.USD).Amount; assertThat(pv).isCloseTo(0, offset(PV_TOLERANCE)); }
public virtual double test_VanillaFixedVsLibor3mSwapWithFixing() { DiscountingSwapTradePricer pricer = swapPricer(); ResolvedSwapTrade resolved = TRADE3.resolve(REF_DATA); CurrencyAmount pv = pricer.presentValue(resolved, USD, PROVIDER); return(pv.Amount); }
// calculates the sensitivity private CurrencyParameterSensitivity calculateCurveSensitivity(ResolvedSwapTrade trade, RatesMarketData marketData, CurveId curveId, Curve bumpedCurve) { MarketData bumpedMarketData = marketData.MarketData.withValue(curveId, bumpedCurve); RatesProvider bumpedRatesProvider = marketData.withMarketData(bumpedMarketData).ratesProvider(); PointSensitivities pointSensitivities = tradePricer.presentValueSensitivity(trade, bumpedRatesProvider); CurrencyParameterSensitivities paramSensitivities = bumpedRatesProvider.parameterSensitivity(pointSensitivities); return(Iterables.getOnlyElement(paramSensitivities.Sensitivities)); }
// calculate one measure //JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET: //ORIGINAL LINE: private com.opengamma.strata.collect.result.Result<?> calculate(com.opengamma.strata.calc.Measure measure, com.opengamma.strata.product.swap.ResolvedSwapTrade trade, com.opengamma.strata.measure.rate.RatesScenarioMarketData marketData) private Result <object> calculate(Measure measure, ResolvedSwapTrade trade, RatesScenarioMarketData marketData) { SingleMeasureCalculation calculator = CALCULATORS.get(measure); if (calculator == null) { return(Result.failure(FailureReason.UNSUPPORTED, "Unsupported measure for SwapTrade: {}", measure)); } return(Result.of(() => calculator(trade, marketData))); }
// leg initial notional, which is the same for all scenarios // package-scoped for testing internal LegAmounts legInitialNotional(ResolvedSwapTrade trade) { IList <Pair <ResolvedSwapLeg, CurrencyAmount> > notionals = trade.Product.Legs.Select(leg => Pair.of(leg, buildLegNotional(leg))).ToList(); CurrencyAmount firstNotional = notionals.Where(pair => pair.Second != NOT_FOUND).Select(pair => pair.Second).First().orElseThrow(() => new System.ArgumentException("No notional found on any swap leg")); notionals = notionals.Select(pair => pair.Second != NOT_FOUND ? pair : Pair.of(pair.First, firstNotional)).ToList(); //JAVA TO C# CONVERTER TODO TASK: Most Java stream collectors are not converted by Java to C# Converter: ImmutableList <LegAmount> legAmounts = notionals.Select(pair => SwapLegAmount.of(pair.First, pair.Second)).collect(toImmutableList()); return(LegAmounts.of(legAmounts)); }
//------------------------------------------------------------------------- public virtual void test_OnAASpreadVsLibor3MSwap() { SwapLeg payLeg = RateCalculationSwapLeg.builder().payReceive(PAY).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2014, 9, 12)).endDate(LocalDate.of(2020, 9, 12)).frequency(P3M).businessDayAdjustment(BDA_MF).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(P3M).paymentDateOffset(DaysAdjustment.NONE).build()).notionalSchedule(NOTIONAL).calculation(IborRateCalculation.builder().index(USD_LIBOR_3M).fixingDateOffset(DaysAdjustment.ofBusinessDays(-2, CalendarUSD.NYC, BDA_P)).build()).build(); SwapLeg receiveLeg = RateCalculationSwapLeg.builder().payReceive(RECEIVE).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2014, 9, 12)).endDate(LocalDate.of(2020, 9, 12)).frequency(P3M).businessDayAdjustment(BDA_MF).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(P3M).paymentDateOffset(DaysAdjustment.NONE).build()).notionalSchedule(NOTIONAL).calculation(OvernightRateCalculation.builder().dayCount(ACT_360).index(USD_FED_FUND).accrualMethod(OvernightAccrualMethod.AVERAGED).rateCutOffDays(0).spread(ValueSchedule.of(0.0025)).build()).build(); ResolvedSwapTrade trade = SwapTrade.builder().info(TradeInfo.builder().tradeDate(LocalDate.of(2014, 1, 15)).build()).product(Swap.of(payLeg, receiveLeg)).build().resolve(REF_DATA); DiscountingSwapTradePricer pricer = swapPricer(); CurrencyAmount pv = pricer.presentValue(trade, provider()).getAmount(USD); assertEquals(pv.Amount, -160663.8362, TOLERANCE_PV); }
//------------------------------------------------------------------------- public virtual void test_CompoundingOisFixed2mVsFedFund12mSwapWithFixing() { SwapLeg payLeg = RateCalculationSwapLeg.builder().payReceive(PAY).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2014, 1, 17)).endDate(LocalDate.of(2014, 3, 17)).frequency(TERM).businessDayAdjustment(BDA_MF).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(TERM).paymentDateOffset(DaysAdjustment.ofBusinessDays(2, CalendarUSD.NYC)).build()).notionalSchedule(NOTIONAL).calculation(FixedRateCalculation.builder().dayCount(ACT_360).rate(ValueSchedule.of(0.00123)).build()).build(); SwapLeg receiveLeg = RateCalculationSwapLeg.builder().payReceive(RECEIVE).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2014, 1, 17)).endDate(LocalDate.of(2014, 3, 17)).frequency(TERM).businessDayAdjustment(BDA_MF).stubConvention(StubConvention.SHORT_INITIAL).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(TERM).paymentDateOffset(DaysAdjustment.ofBusinessDays(2, CalendarUSD.NYC)).build()).notionalSchedule(NOTIONAL).calculation(OvernightRateCalculation.builder().dayCount(ACT_360).index(USD_FED_FUND).build()).build(); ResolvedSwapTrade trade = SwapTrade.builder().info(TradeInfo.builder().tradeDate(LocalDate.of(2014, 1, 15)).build()).product(Swap.of(payLeg, receiveLeg)).build().resolve(REF_DATA); DiscountingSwapTradePricer pricer = swapPricer(); CurrencyAmount pv = pricer.presentValue(trade, provider()).getAmount(USD); assertEquals(pv.Amount, -7352.973875972721, TOLERANCE_PV); }
//------------------------------------------------------------------------- public virtual void test_ZeroCouponFixedVsLibor3mSwap() { SwapLeg payLeg = RateCalculationSwapLeg.builder().payReceive(PAY).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2014, 9, 12)).endDate(LocalDate.of(2021, 9, 12)).frequency(P12M).businessDayAdjustment(BDA_MF).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(TERM).paymentDateOffset(DaysAdjustment.NONE).compoundingMethod(CompoundingMethod.STRAIGHT).build()).notionalSchedule(NOTIONAL).calculation(FixedRateCalculation.builder().dayCount(THIRTY_U_360).rate(ValueSchedule.of(0.015)).build()).build(); SwapLeg receiveLeg = RateCalculationSwapLeg.builder().payReceive(RECEIVE).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2014, 9, 12)).endDate(LocalDate.of(2021, 9, 12)).frequency(P3M).businessDayAdjustment(BDA_MF).stubConvention(StubConvention.SHORT_INITIAL).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(TERM).paymentDateOffset(DaysAdjustment.NONE).compoundingMethod(CompoundingMethod.STRAIGHT).build()).notionalSchedule(NOTIONAL).calculation(IborRateCalculation.builder().index(USD_LIBOR_3M).fixingDateOffset(DaysAdjustment.ofBusinessDays(-2, CalendarUSD.NYC, BDA_P)).build()).build(); ResolvedSwapTrade trade = SwapTrade.builder().info(TradeInfo.builder().tradeDate(LocalDate.of(2014, 9, 10)).build()).product(Swap.of(payLeg, receiveLeg)).build().resolve(REF_DATA); DiscountingSwapTradePricer pricer = swapPricer(); CurrencyAmount pv = pricer.presentValue(trade, provider()).getAmount(USD); assertEquals(pv.Amount, 7850279.042216873, TOLERANCE_PV); }
//------------------------------------------------------------------------- public virtual void test_InterpolatedStub4mFixed6mVsLibor6mSwap() { SwapLeg receiveLeg = fixedLeg(LocalDate.of(2014, 9, 12), LocalDate.of(2016, 7, 12), P6M, RECEIVE, NOTIONAL, 0.01, StubConvention.SHORT_INITIAL); SwapLeg payLeg = RateCalculationSwapLeg.builder().payReceive(PAY).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2014, 9, 12)).endDate(LocalDate.of(2016, 7, 12)).frequency(P6M).businessDayAdjustment(BDA_MF).stubConvention(StubConvention.SHORT_INITIAL).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(P6M).paymentDateOffset(DaysAdjustment.NONE).build()).notionalSchedule(NOTIONAL).calculation(IborRateCalculation.builder().index(USD_LIBOR_6M).fixingDateOffset(DaysAdjustment.ofBusinessDays(-2, CalendarUSD.NYC, BDA_P)).initialStub(IborRateStubCalculation.ofIborInterpolatedRate(USD_LIBOR_3M, USD_LIBOR_6M)).build()).build(); ResolvedSwapTrade trade = SwapTrade.builder().info(TradeInfo.builder().tradeDate(LocalDate.of(2014, 9, 10)).build()).product(Swap.of(receiveLeg, payLeg)).build().resolve(REF_DATA); DiscountingSwapTradePricer pricer = swapPricer(); CurrencyAmount pv = pricer.presentValue(trade, provider()).getAmount(USD); assertEquals(pv.Amount, 314215.2347116342, TOLERANCE_PV); }
//------------------------------------------------------------------------- public virtual void test_BasisCompoundedLibor1mVsLibor3mSwap() { SwapLeg receiveLeg = RateCalculationSwapLeg.builder().payReceive(RECEIVE).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2014, 8, 29)).endDate(LocalDate.of(2019, 8, 29)).frequency(P1M).businessDayAdjustment(BDA_MF).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(Frequency.P3M).paymentDateOffset(DaysAdjustment.NONE).compoundingMethod(CompoundingMethod.FLAT).build()).notionalSchedule(NOTIONAL).calculation(IborRateCalculation.builder().index(USD_LIBOR_1M).fixingDateOffset(DaysAdjustment.ofBusinessDays(-2, CalendarUSD.NYC, BDA_P)).build()).build(); SwapLeg payLeg = RateCalculationSwapLeg.builder().payReceive(PAY).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2014, 8, 29)).endDate(LocalDate.of(2019, 8, 29)).frequency(P3M).businessDayAdjustment(BDA_MF).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(Frequency.P3M).paymentDateOffset(DaysAdjustment.NONE).build()).notionalSchedule(NOTIONAL).calculation(IborRateCalculation.builder().index(USD_LIBOR_3M).fixingDateOffset(DaysAdjustment.ofBusinessDays(-2, CalendarUSD.NYC, BDA_P)).build()).build(); ResolvedSwapTrade trade = SwapTrade.builder().info(TradeInfo.builder().tradeDate(LocalDate.of(2014, 8, 27)).build()).product(Swap.of(receiveLeg, payLeg)).build().resolve(REF_DATA); DiscountingSwapTradePricer pricer = swapPricer(); CurrencyAmount pv = pricer.presentValue(trade, provider()).getAmount(USD); assertEquals(pv.Amount, -342874.98367929866, TOLERANCE_PV); }
//------------------------------------------------------------------------- public virtual void test_BasisLibor3mVsLibor6mSwapWithSpread() { SwapLeg payLeg = RateCalculationSwapLeg.builder().payReceive(PAY).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2014, 8, 29)).endDate(LocalDate.of(2024, 8, 29)).frequency(P6M).businessDayAdjustment(BDA_MF).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(Frequency.P6M).paymentDateOffset(DaysAdjustment.NONE).build()).notionalSchedule(NOTIONAL).calculation(IborRateCalculation.builder().index(USD_LIBOR_6M).fixingDateOffset(DaysAdjustment.ofBusinessDays(-2, CalendarUSD.NYC, BDA_P)).build()).build(); SwapLeg receiveLeg = RateCalculationSwapLeg.builder().payReceive(RECEIVE).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2014, 8, 29)).endDate(LocalDate.of(2024, 8, 29)).frequency(P3M).businessDayAdjustment(BDA_MF).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(Frequency.P3M).paymentDateOffset(DaysAdjustment.NONE).build()).notionalSchedule(NOTIONAL).calculation(IborRateCalculation.builder().index(USD_LIBOR_3M).fixingDateOffset(DaysAdjustment.ofBusinessDays(-2, CalendarUSD.NYC, BDA_P)).spread(ValueSchedule.of(0.0010)).build()).build(); ResolvedSwapTrade trade = SwapTrade.builder().info(TradeInfo.builder().tradeDate(LocalDate.of(2014, 8, 27)).build()).product(Swap.of(payLeg, receiveLeg)).build().resolve(REF_DATA); DiscountingSwapTradePricer pricer = swapPricer(); CurrencyAmount pv = pricer.presentValue(trade, provider()).getAmount(USD); assertEquals(pv.Amount, -21875.376339152455, TOLERANCE_PV); }
//------------------------------------------------------------------------- public virtual void test_VanillaFixedVsLibor3mSwapWithFixing() { SwapLeg payLeg = fixedLeg(LocalDate.of(2013, 9, 12), LocalDate.of(2020, 9, 12), P6M, PAY, NOTIONAL, 0.015, null); SwapLeg receiveLeg = RateCalculationSwapLeg.builder().payReceive(RECEIVE).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2013, 9, 12)).endDate(LocalDate.of(2020, 9, 12)).frequency(P3M).businessDayAdjustment(BDA_MF).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(P3M).paymentDateOffset(DaysAdjustment.NONE).build()).notionalSchedule(NOTIONAL).calculation(IborRateCalculation.builder().index(USD_LIBOR_3M).fixingDateOffset(DaysAdjustment.ofBusinessDays(-2, CalendarUSD.NYC, BDA_P)).build()).build(); ResolvedSwapTrade trade = SwapTrade.builder().info(TradeInfo.builder().tradeDate(LocalDate.of(2013, 9, 10)).build()).product(Swap.of(payLeg, receiveLeg)).build().resolve(REF_DATA); DiscountingSwapTradePricer pricer = swapPricer(); CurrencyAmount pv = pricer.presentValue(trade, provider()).getAmount(USD); assertEquals(pv.Amount, 3588376.471608199, TOLERANCE_PV); }
public virtual void check_equivalent_notional() { ImmutableRatesProvider multicurve = CALIBRATOR.calibrate(GROUP_DEFINITION_PV_SENSI, MARKET_QUOTES, REF_DATA); // Create notional equivalent for a basis trade ResolvedSwapTrade trade = ThreeLegBasisSwapConventions.EUR_FIXED_1Y_EURIBOR_3M_EURIBOR_6M.createTrade(VALUATION_DATE, Period.ofMonths(7), Tenor.TENOR_6Y, BuySell.SELL, 1_000_000, 0.03, REF_DATA).resolve(REF_DATA); PointSensitivities pts = PRICER_SWAP_TRADE.presentValueSensitivity(trade, multicurve); CurrencyParameterSensitivities ps = multicurve.parameterSensitivity(pts); CurrencyParameterSensitivities mqs = MQSC.sensitivity(ps, multicurve); CurrencyParameterSensitivities notionalEquivalent = NEC.notionalEquivalent(mqs, multicurve); // Check metadata are same as market quote sensitivities. foreach (CurrencyParameterSensitivity sensi in mqs.Sensitivities) { assertEquals(notionalEquivalent.getSensitivity(sensi.MarketDataName, sensi.Currency).ParameterMetadata, sensi.ParameterMetadata); } // Check sensitivity: trade sensitivity = sum(notional equivalent sensitivities) int totalNbParameters = 0; IDictionary <CurveName, IList <ResolvedTrade> > equivalentTrades = new Dictionary <CurveName, IList <ResolvedTrade> >(); ImmutableList <CurveDefinition> curveGroups = GROUP_DEFINITION.CurveDefinitions; ImmutableList.Builder <CurveParameterSize> builder = ImmutableList.builder(); foreach (CurveDefinition entry in curveGroups) { totalNbParameters += entry.ParameterCount; DoubleArray notionalCurve = notionalEquivalent.getSensitivity(entry.Name, Currency.EUR).Sensitivity; ImmutableList <CurveNode> nodes = entry.Nodes; IList <ResolvedTrade> resolvedTradesCurve = new List <ResolvedTrade>(); for (int i = 0; i < nodes.size(); i++) { resolvedTradesCurve.Add(nodes.get(i).resolvedTrade(notionalCurve.get(i), MARKET_QUOTES, REF_DATA)); } equivalentTrades[entry.Name] = resolvedTradesCurve; builder.add(entry.toCurveParameterSize()); } ImmutableList <CurveParameterSize> order = builder.build(); // order of the curves DoubleArray totalSensitivity = DoubleArray.filled(totalNbParameters); foreach (KeyValuePair <CurveName, IList <ResolvedTrade> > entry in equivalentTrades.SetOfKeyValuePairs()) { foreach (ResolvedTrade t in entry.Value) { totalSensitivity = totalSensitivity.plus(PV_MEASURES.derivative(t, multicurve, order)); } } DoubleArray instrumentSensi = PV_MEASURES.derivative(trade, multicurve, order); assertTrue(totalSensitivity.equalWithTolerance(instrumentSensi, TOLERANCE_PV_DELTA)); }
//----------------------------------------------------------------------- // XCcy swap with exchange of notional public virtual void test_XCcyEur3MSpreadVsUSD3M() { SwapLeg payLeg = RateCalculationSwapLeg.builder().payReceive(PAY).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2014, 1, 24)).endDate(LocalDate.of(2016, 1, 24)).frequency(P3M).businessDayAdjustment(BDA_MF).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(P3M).paymentDateOffset(DaysAdjustment.NONE).build()).notionalSchedule(NotionalSchedule.builder().finalExchange(true).initialExchange(true).amount(ValueSchedule.of(NOTIONAL_EUR)).currency(EUR).build()).calculation(IborRateCalculation.builder().index(EUR_EURIBOR_3M).fixingDateOffset(DaysAdjustment.ofBusinessDays(-2, CalendarUSD.NYC, BDA_P)).spread(ValueSchedule.of(0.0020)).build()).build(); SwapLeg receiveLeg = RateCalculationSwapLeg.builder().payReceive(RECEIVE).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2014, 1, 24)).endDate(LocalDate.of(2016, 1, 24)).frequency(P3M).businessDayAdjustment(BDA_MF).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(P3M).paymentDateOffset(DaysAdjustment.NONE).build()).notionalSchedule(NotionalSchedule.builder().finalExchange(true).initialExchange(true).amount(ValueSchedule.of(NOTIONAL_USD)).currency(USD).build()).calculation(IborRateCalculation.builder().index(USD_LIBOR_3M).fixingDateOffset(DaysAdjustment.ofBusinessDays(-2, CalendarUSD.NYC, BDA_P)).build()).build(); ResolvedSwapTrade trade = SwapTrade.builder().info(TradeInfo.builder().tradeDate(LocalDate.of(2014, 9, 10)).build()).product(Swap.of(payLeg, receiveLeg)).build().resolve(REF_DATA); double pvUsdExpected = 431944.6868; double pvEurExpected = -731021.1778; DiscountingSwapTradePricer pricer = swapPricer(); MultiCurrencyAmount pv = pricer.presentValue(trade, provider()); assertEquals(pv.getAmount(USD).Amount, pvUsdExpected, TOLERANCE_PV); assertEquals(pv.getAmount(EUR).Amount, pvEurExpected, TOLERANCE_PV); }
private void test_XCcyEurUSDFxReset(bool initialExchange, bool intermediateExchange, bool finalExchange) { ResolvedSwapTrade trade = getMtmTrade(initialExchange, intermediateExchange, finalExchange, null).resolve(REF_DATA); DiscountingSwapTradePricer pricer = swapPricer(); MultiCurrencyAmount pv = pricer.presentValue(trade, provider()); //Coupons are always included, so base is the total coupon pvs double pvUsdExpected = 1447799.5318; double pvEurExpected = -1020648.6461; int usdExpectedPaymentEvents = 0; int eurExpectedPaymentEvents = 0; //Add PV amounts of included exchanges to arrive at total expected pv if (initialExchange) { pvUsdExpected += -143998710.0091; pvEurExpected += 99999104.1730; ++usdExpectedPaymentEvents; ++eurExpectedPaymentEvents; } if (intermediateExchange) { pvUsdExpected += -344525.1458; usdExpectedPaymentEvents += 14; } if (finalExchange) { pvUsdExpected += 143414059.1395; pvEurExpected += -99709476.7047; ++usdExpectedPaymentEvents; ++eurExpectedPaymentEvents; } assertEquals(pv.getAmount(USD).Amount, pvUsdExpected, TOLERANCE_PV); assertEquals(pv.getAmount(EUR).Amount, pvEurExpected, TOLERANCE_PV); //Assert the payment event (exchange) count on each leg IList <ExplainMap> legs = pricer.explainPresentValue(trade, provider()).get(ExplainKey.LEGS).get(); assertThat(legs[0].get(ExplainKey.PAYMENT_EVENTS).orElse(ImmutableList.of())).hasSize(eurExpectedPaymentEvents); assertThat(legs[1].get(ExplainKey.PAYMENT_EVENTS).orElse(ImmutableList.of())).hasSize(usdExpectedPaymentEvents); }
/// <summary> /// Start from a generic zero-coupon curve. Compute the (inverse) Jacobian matrix using linear projection to a small /// number of points and the Jacobian utility. Compare the direct Jacobian obtained by calibrating a curve /// based on the trades with market quotes computed from the zero-coupon curve. /// </summary> public virtual void with_rebucketing_one_curve() { /* Create trades */ IList <ResolvedTrade> trades = new List <ResolvedTrade>(); IList <LocalDate> nodeDates = new List <LocalDate>(); double[] marketQuotes = new double[TENORS_STD_1.Length]; for (int looptenor = 0; looptenor < TENORS_STD_1.Length; looptenor++) { ResolvedSwapTrade t0 = EUR_FIXED_1Y_EURIBOR_6M.createTrade(VALUATION_DATE, TENORS_STD_1[looptenor], BuySell.BUY, 1.0, 0.0, REF_DATA).resolve(REF_DATA); marketQuotes[looptenor] = MARKET_QUOTE.value(t0, MULTICURVE_EUR_SINGLE_INPUT); ResolvedSwapTrade t = EUR_FIXED_1Y_EURIBOR_6M.createTrade(VALUATION_DATE, TENORS_STD_1[looptenor], BuySell.BUY, 1.0, marketQuotes[looptenor], REF_DATA).resolve(REF_DATA); nodeDates.Add(t.Product.EndDate); trades.Add(t); } System.Func <ResolvedTrade, CurrencyParameterSensitivities> sensitivityFunction = (t) => CurveSensitivityUtils.linearRebucketing(MULTICURVE_EUR_SINGLE_INPUT.parameterSensitivity(PRICER_SWAP_PRODUCT.parRateSensitivity(((ResolvedSwapTrade)t).Product, MULTICURVE_EUR_SINGLE_INPUT).build()), nodeDates, VALUATION_DATE); /* Market quotes for comparison */ IDictionary <QuoteId, double> mqCmp = new Dictionary <QuoteId, double>(); for (int looptenor = 0; looptenor < TENORS_STD_1.Length; looptenor++) { mqCmp[QuoteId.of(StandardId.of(OG_TICKER, TICKERS_STD_1[looptenor]))] = marketQuotes[looptenor]; } ImmutableMarketData marketQuotesObject = ImmutableMarketData.of(VALUATION_DATE, mqCmp); RatesProvider multicurveCmp = CALIBRATOR.calibrate(GROUPS_IN_1, marketQuotesObject, REF_DATA); /* Comparison */ DoubleMatrix jiComputed = CurveSensitivityUtils.jacobianFromMarketQuoteSensitivities(LIST_CURVE_NAMES_1, trades, sensitivityFunction); DoubleMatrix jiExpected = multicurveCmp.findData(EUR_SINGLE_NAME).get().Metadata.findInfo(CurveInfoType.JACOBIAN).get().JacobianMatrix; assertEquals(jiComputed.rowCount(), jiExpected.rowCount()); assertEquals(jiComputed.columnCount(), jiExpected.columnCount()); for (int i = 0; i < jiComputed.rowCount(); i++) { for (int j = 0; j < jiComputed.columnCount(); j++) { assertEquals(jiComputed.get(i, j), jiExpected.get(i, j), TOLERANCE_JAC_APPROX); // The comparison is not perfect due to the incoherences introduced by the re-bucketing } } }
// semi-parallel gamma PV01 for one scenario private CurrencyParameterSensitivities pv01SemiParallelGammaBucketed(ResolvedSwapTrade trade, RatesMarketData marketData) { // find the curve identifiers and resolve to a single curve ResolvedSwap product = trade.Product; if (product.CrossCurrency) { throw new System.ArgumentException("Implementation only supports a single curve, but swap is cross-currency"); } Currency currency = product.Legs.get(0).Currency; ISet <Index> indices = product.allIndices(); //JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET: //ORIGINAL LINE: com.google.common.collect.ImmutableSet<com.opengamma.strata.data.MarketDataId<?>> discountIds = marketData.getLookup().getDiscountMarketDataIds(currency); ImmutableSet <MarketDataId <object> > discountIds = marketData.Lookup.getDiscountMarketDataIds(currency); //JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET: //ORIGINAL LINE: com.google.common.collect.ImmutableSet<com.opengamma.strata.data.MarketDataId<?>> forwardIds = indices.stream().flatMap(idx -> marketData.getLookup().getForwardMarketDataIds(idx).stream()).collect(toImmutableSet()); ImmutableSet <MarketDataId <object> > forwardIds = indices.stream().flatMap(idx => marketData.Lookup.getForwardMarketDataIds(idx).stream()).collect(toImmutableSet()); //JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET: //ORIGINAL LINE: java.util.Set<com.opengamma.strata.data.MarketDataId<?>> allIds = com.google.common.collect.Sets.union(discountIds, forwardIds); ISet <MarketDataId <object> > allIds = Sets.union(discountIds, forwardIds); if (allIds.Count != 1) { throw new System.ArgumentException(Messages.format("Implementation only supports a single curve, but lookup refers to more than one: {}", allIds)); } //JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET: //ORIGINAL LINE: com.opengamma.strata.data.MarketDataId<?> singleId = allIds.iterator().next(); MarketDataId <object> singleId = allIds.GetEnumerator().next(); if (!(singleId is CurveId)) { //JAVA TO C# CONVERTER WARNING: The .NET Type.FullName property will not always yield results identical to the Java Class.getName method: throw new System.ArgumentException(Messages.format("Implementation only supports a single curve, but lookup does not refer to a curve: {} {}", singleId.GetType().FullName, singleId)); } CurveId curveId = (CurveId)singleId; Curve curve = marketData.MarketData.getValue(curveId); // calculate gamma CurrencyParameterSensitivity gamma = CurveGammaCalculator.DEFAULT.calculateSemiParallelGamma(curve, currency, c => calculateCurveSensitivity(trade, marketData, curveId, c)); return(CurrencyParameterSensitivities.of(gamma).multipliedBy(ONE_BASIS_POINT * ONE_BASIS_POINT)); }
//------------------------------------------------------------------------- //JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET: //ORIGINAL LINE: @Override public java.util.Map<com.opengamma.strata.calc.Measure, com.opengamma.strata.collect.result.Result<?>> calculate(com.opengamma.strata.product.swap.SwapTrade trade, java.util.Set<com.opengamma.strata.calc.Measure> measures, com.opengamma.strata.calc.runner.CalculationParameters parameters, com.opengamma.strata.data.scenario.ScenarioMarketData scenarioMarketData, com.opengamma.strata.basics.ReferenceData refData) public virtual IDictionary <Measure, Result <object> > calculate(SwapTrade trade, ISet <Measure> measures, CalculationParameters parameters, ScenarioMarketData scenarioMarketData, ReferenceData refData) { // resolve the trade once for all measures and all scenarios ResolvedSwapTrade resolved = trade.resolve(refData); // use lookup to query market data RatesMarketDataLookup ratesLookup = parameters.getParameter(typeof(RatesMarketDataLookup)); RatesScenarioMarketData marketData = ratesLookup.marketDataView(scenarioMarketData); // loop around measures, calculating all scenarios for one measure //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<?>> results = new java.util.HashMap<>(); IDictionary <Measure, Result <object> > results = new Dictionary <Measure, Result <object> >(); foreach (Measure measure in measures) { results[measure] = calculate(measure, resolved, marketData); } return(results); }
//----------------------------------------------------------------------- public virtual void test_VanillaFixedVsLibor3mSwap() { SwapLeg payLeg = fixedLeg(LocalDate.of(2014, 9, 12), LocalDate.of(2021, 9, 12), P6M, PAY, NOTIONAL, 0.015, null); SwapLeg receiveLeg = iborLeg(LocalDate.of(2014, 9, 12), LocalDate.of(2021, 9, 12), USD_LIBOR_3M, RECEIVE, NOTIONAL, null); ResolvedSwapTrade trade = SwapTrade.builder().info(TradeInfo.builder().tradeDate(LocalDate.of(2014, 9, 10)).build()).product(Swap.of(payLeg, receiveLeg)).build().resolve(REF_DATA); // test pv DiscountingSwapTradePricer pricer = swapPricer(); CurrencyAmount pv = pricer.presentValue(trade, provider()).getAmount(USD); assertEquals(pv.Amount, 7170391.798257509, TOLERANCE_PV); // test par rate double parRate = PRICER_PRODUCT.parRate(trade.Product, provider()); assertEquals(parRate, 0.02589471566819517, TOLERANCE_RATE); // test par rate vs pv ResolvedSwap swapPV0 = Swap.of(fixedLeg(LocalDate.of(2014, 9, 12), LocalDate.of(2021, 9, 12), P6M, PAY, NOTIONAL, parRate, null), receiveLeg).resolve(REF_DATA); CurrencyAmount pv0 = PRICER_PRODUCT.presentValue(swapPV0, provider()).getAmount(USD); assertEquals(pv0.Amount, 0, TOLERANCE_PV); // PV at par rate should be 0 }
//------------------------------------------------------------------------- public virtual void test_AmortizingFixedVsLibor3mSwap() { ValueAdjustment stepReduction = ValueAdjustment.ofDeltaAmount(-3_000_000); IList <ValueStep> steps = new List <ValueStep>(); for (int i = 1; i < 28; i++) { steps.Add(ValueStep.of(i, stepReduction)); } ValueSchedule notionalSchedule = ValueSchedule.of(100_000_000, steps); SwapLeg receiveLeg = RateCalculationSwapLeg.builder().payReceive(RECEIVE).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2014, 9, 12)).endDate(LocalDate.of(2021, 9, 12)).frequency(P3M).businessDayAdjustment(BDA_MF).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(P3M).paymentDateOffset(DaysAdjustment.NONE).build()).notionalSchedule(NotionalSchedule.of(USD, notionalSchedule)).calculation(FixedRateCalculation.builder().dayCount(THIRTY_U_360).rate(ValueSchedule.of(0.016)).build()).build(); SwapLeg payLeg = RateCalculationSwapLeg.builder().payReceive(PAY).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2014, 9, 12)).endDate(LocalDate.of(2021, 9, 12)).frequency(P3M).businessDayAdjustment(BDA_MF).stubConvention(StubConvention.SHORT_INITIAL).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(P3M).paymentDateOffset(DaysAdjustment.NONE).build()).notionalSchedule(NotionalSchedule.of(USD, notionalSchedule)).calculation(IborRateCalculation.builder().index(USD_LIBOR_3M).fixingDateOffset(DaysAdjustment.ofBusinessDays(-2, CalendarUSD.NYC, BDA_P)).build()).build(); ResolvedSwapTrade trade = SwapTrade.builder().info(TradeInfo.builder().tradeDate(LocalDate.of(2014, 9, 10)).build()).product(Swap.of(receiveLeg, payLeg)).build().resolve(REF_DATA); DiscountingSwapTradePricer pricer = swapPricer(); CurrencyAmount pv = pricer.presentValue(trade, provider()).getAmount(USD); assertEquals(pv.Amount, -1850080.2895532502, TOLERANCE_PV); }
public static void Main(string[] arg) { int nbRrpWarm = 2; int nbRunPerf = 2; /* Load the curve configurations from csv files */ IDictionary <CurveGroupName, RatesCurveGroupDefinition> configs = RatesCalibrationCsvLoader.load(GROUP_RESOURCE, SETTINGS_RESOURCE, NODES_RESOURCE); /* Construct a swaps */ ResolvedSwapTrade[] swaps = new ResolvedSwapTrade[NB_COUPONS * NB_TENORS]; for (int loopswap = 0; loopswap < NB_COUPONS; loopswap++) { for (int looptenor = 0; looptenor < NB_TENORS; looptenor++) { double coupon = SWAP_COUPON + loopswap * SWAP_COUPON_RANGE / NB_COUPONS; swaps[looptenor * NB_COUPONS + loopswap] = GBP_FIXED_6M_LIBOR_6M.createTrade(VALUATION_DATE, SWAP_PERIOD_TO_START, Tenor.of(Period.ofYears(TENOR_START + looptenor)), BuySell.BUY, SWAP_NOTIONAL, coupon, REF_DATA).resolve(REF_DATA); } } /* Warm-up */ Pair <MultiCurrencyAmount[], CurrencyParameterSensitivities[]> r = Pair.of(new MultiCurrencyAmount[0], new CurrencyParameterSensitivities[0]); for (int i = 0; i < nbRrpWarm; i++) { r = computation(configs, swaps); } long start, end; start = DateTimeHelper.CurrentUnixTimeMillis(); for (int i = 0; i < nbRunPerf; i++) { r = computation(configs, swaps); } end = DateTimeHelper.CurrentUnixTimeMillis(); Console.WriteLine("Computation time: " + (end - start) + " ms"); Console.WriteLine("Performance estimate for curve calibration, " + (NB_COUPONS * NB_TENORS) + " trades and " + nbRunPerf + " repetitions.\n" + Arrays.ToString(r.First) + Arrays.ToString(r.Second)); }
private const double BP1 = 1.0E-4; // Scaling by 1 bp. public static void Main(string[] arg) { /* Load the curve configurations from csv files */ IList <IDictionary <CurveGroupName, RatesCurveGroupDefinition> > configs = new List <IDictionary <CurveGroupName, RatesCurveGroupDefinition> >(); for (int loopconfig = 0; loopconfig < NB_SETTINGS; loopconfig++) { configs.Add(RatesCalibrationCsvLoader.load(GROUP_RESOURCE, SETTINGS_RESOURCE[loopconfig], NODES_RESOURCE)); } /* Construct a swap */ ResolvedSwapTrade swap = GBP_FIXED_6M_LIBOR_6M.createTrade(VALUATION_DATE, SWAP_PERIOD_TO_START, Tenor.of(SWAP_TENOR), BuySell.BUY, SWAP_NOTIONAL, SWAP_COUPON, REF_DATA).resolve(REF_DATA); /* Calibrate curves */ ImmutableRatesProvider[] multicurve = new ImmutableRatesProvider[3]; for (int loopconfig = 0; loopconfig < NB_SETTINGS; loopconfig++) { multicurve[loopconfig] = CALIBRATOR.calibrate(configs[loopconfig][CONFIG_NAME], MARKET_QUOTES, REF_DATA); } /* Computes PV and bucketed PV01 */ MultiCurrencyAmount[] pv = new MultiCurrencyAmount[NB_SETTINGS]; CurrencyParameterSensitivities[] mqs = new CurrencyParameterSensitivities[NB_SETTINGS]; for (int loopconfig = 0; loopconfig < NB_SETTINGS; loopconfig++) { pv[loopconfig] = PRICER_SWAP.presentValue(swap, multicurve[loopconfig]); PointSensitivities pts = PRICER_SWAP.presentValueSensitivity(swap, multicurve[loopconfig]); CurrencyParameterSensitivities ps = multicurve[loopconfig].parameterSensitivity(pts); mqs[loopconfig] = MQC.sensitivity(ps, multicurve[loopconfig]); } /* Export to csv files. */ for (int loopconfig = 0; loopconfig < NB_SETTINGS; loopconfig++) { ExportUtils.export(mqs[loopconfig], BP1, PATH_RESULTS + CONFIG_STR + SETTINGS_SUFFIX[loopconfig] + "-mqs" + SUFFIX_CSV); ExportUtils.export(pv[loopconfig], PATH_RESULTS + CONFIG_STR + SETTINGS_SUFFIX[loopconfig] + "-pv" + SUFFIX_CSV); } Console.WriteLine("Calibration and export finished: " + CONFIG_STR); }
private const double BP1 = 1.0E-4; // Scaling by 1 bp. public static void Main(string[] arg) { /* Load the curve configurations from csv files */ IDictionary <CurveGroupName, RatesCurveGroupDefinition> configs = RatesCalibrationCsvLoader.load(GROUP_RESOURCE, SETTINGS_RESOURCE, NODES_RESOURCE); /* Calibrate curves */ ImmutableRatesProvider multicurve = CALIBRATOR.calibrate(configs[CONFIG_NAME], MARKET_QUOTES, REF_DATA); /* Construct a swap */ ResolvedSwapTrade swap = GBP_FIXED_6M_LIBOR_6M.createTrade(VALUATION_DATE, SWAP_PERIOD_TO_START, Tenor.of(SWAP_TENOR), BuySell.BUY, SWAP_NOTIONAL, SWAP_COUPON, REF_DATA).resolve(REF_DATA); /* Computes PV and bucketed PV01 */ MultiCurrencyAmount pv = PRICER_SWAP.presentValue(swap, multicurve); PointSensitivities pts = PRICER_SWAP.presentValueSensitivity(swap, multicurve); CurrencyParameterSensitivities ps = multicurve.parameterSensitivity(pts); CurrencyParameterSensitivities mqs = MQC.sensitivity(ps, multicurve); /* Export to csv files. */ ExportUtils.export(mqs, BP1, PATH_RESULTS + CONFIG_STR + "-delta" + SUFFIX_CSV); ExportUtils.export(pv, PATH_RESULTS + CONFIG_STR + "-pv" + SUFFIX_CSV); Console.WriteLine("Calibration and export finished: " + CONFIG_STR); }
/// <summary> /// Calibrate a single curve to 4 points. Use the resulting calibrated curves as starting point of the computation /// of a Jacobian. Compare the direct Jacobian and the one reconstructed from trades. /// </summary> public virtual void direct_two_curves() { JacobianCalibrationMatrix jiObject = MULTICURVE_EUR_2_CALIBRATED.findData(EUR_DSCON_OIS).get().Metadata.findInfo(CurveInfoType.JACOBIAN).get(); ImmutableList <CurveParameterSize> order = jiObject.Order; // To obtain the order of the curves in the jacobian /* Create trades */ IList <ResolvedTrade> tradesDsc = new List <ResolvedTrade>(); for (int looptenor = 0; looptenor < TENORS_STD_2_OIS.Length; looptenor++) { ResolvedSwapTrade t0 = EUR_FIXED_1Y_EONIA_OIS.createTrade(VALUATION_DATE, TENORS_STD_2_OIS[looptenor], BuySell.BUY, 1.0, 0.0, REF_DATA).resolve(REF_DATA); double rate = MARKET_QUOTE.value(t0, MULTICURVE_EUR_2_CALIBRATED); ResolvedSwapTrade t = EUR_FIXED_1Y_EONIA_OIS.createTrade(VALUATION_DATE, TENORS_STD_2_OIS[looptenor], BuySell.BUY, 1.0, rate, REF_DATA).resolve(REF_DATA); tradesDsc.Add(t); } IList <ResolvedTrade> tradesE3 = new List <ResolvedTrade>(); // Fixing IborFixingDepositConvention c = IborFixingDepositConvention.of(EUR_EURIBOR_6M); ResolvedIborFixingDepositTrade fix0 = c.createTrade(VALUATION_DATE, EUR_EURIBOR_6M.Tenor.Period, BuySell.BUY, 1.0, 0.0, REF_DATA).resolve(REF_DATA); double rateFixing = MARKET_QUOTE.value(fix0, MULTICURVE_EUR_2_CALIBRATED); ResolvedIborFixingDepositTrade fix = c.createTrade(VALUATION_DATE, EUR_EURIBOR_6M.Tenor.Period, BuySell.BUY, 1.0, rateFixing, REF_DATA).resolve(REF_DATA); tradesE3.Add(fix); // IRS for (int looptenor = 0; looptenor < TENORS_STD_2_IRS.Length; looptenor++) { ResolvedSwapTrade t0 = EUR_FIXED_1Y_EURIBOR_6M.createTrade(VALUATION_DATE, TENORS_STD_2_IRS[looptenor], BuySell.BUY, 1.0, 0.0, REF_DATA).resolve(REF_DATA); double rate = MARKET_QUOTE.value(t0, MULTICURVE_EUR_2_CALIBRATED); ResolvedSwapTrade t = EUR_FIXED_1Y_EURIBOR_6M.createTrade(VALUATION_DATE, TENORS_STD_2_IRS[looptenor], BuySell.BUY, 1.0, rate, REF_DATA).resolve(REF_DATA); tradesE3.Add(t); } IList <ResolvedTrade> trades = new List <ResolvedTrade>(); if (order.get(0).Name.Equals(EUR_DSCON_OIS)) { ((IList <ResolvedTrade>)trades).AddRange(tradesDsc); ((IList <ResolvedTrade>)trades).AddRange(tradesE3); } else { ((IList <ResolvedTrade>)trades).AddRange(tradesE3); ((IList <ResolvedTrade>)trades).AddRange(tradesDsc); } /* Par rate sensitivity */ System.Func <ResolvedTrade, CurrencyParameterSensitivities> sensitivityFunction = (t) => MULTICURVE_EUR_2_CALIBRATED.parameterSensitivity((t is ResolvedSwapTrade) ? PRICER_SWAP_PRODUCT.parRateSensitivity(((ResolvedSwapTrade)t).Product, MULTICURVE_EUR_2_CALIBRATED).build() : PRICER_IBORFIX_PRODUCT.parRateSensitivity(((ResolvedIborFixingDepositTrade)t).Product, MULTICURVE_EUR_2_CALIBRATED)); DoubleMatrix jiComputed = CurveSensitivityUtils.jacobianFromMarketQuoteSensitivities(order, trades, sensitivityFunction); DoubleMatrix jiExpectedDsc = MULTICURVE_EUR_2_CALIBRATED.findData(EUR_DSCON_OIS).get().Metadata.getInfo(CurveInfoType.JACOBIAN).JacobianMatrix; DoubleMatrix jiExpectedE3 = MULTICURVE_EUR_2_CALIBRATED.findData(EUR_EURIBOR6M_IRS).get().Metadata.getInfo(CurveInfoType.JACOBIAN).JacobianMatrix; /* Comparison */ assertEquals(jiComputed.rowCount(), jiExpectedDsc.rowCount() + jiExpectedE3.rowCount()); assertEquals(jiComputed.columnCount(), jiExpectedDsc.columnCount()); assertEquals(jiComputed.columnCount(), jiExpectedE3.columnCount()); int shiftDsc = order.get(0).Name.Equals(EUR_DSCON_OIS) ? 0 : jiExpectedE3.rowCount(); for (int i = 0; i < jiExpectedDsc.rowCount(); i++) { for (int j = 0; j < jiExpectedDsc.columnCount(); j++) { assertEquals(jiComputed.get(i + shiftDsc, j), jiExpectedDsc.get(i, j), TOLERANCE_JAC); } } int shiftE3 = order.get(0).Name.Equals(EUR_DSCON_OIS) ? jiExpectedDsc.rowCount() : 0; for (int i = 0; i < jiExpectedE3.rowCount(); i++) { for (int j = 0; j < jiExpectedDsc.columnCount(); j++) { assertEquals(jiComputed.get(i + shiftE3, j), jiExpectedE3.get(i, j), TOLERANCE_JAC); } } }
// current cash for one scenario internal MultiCurrencyAmount currentCash(ResolvedSwapTrade trade, RatesProvider ratesProvider) { return(tradePricer.currentCash(trade, ratesProvider)); }
//------------------------------------------------------------------------- // calculates present value for all scenarios internal MultiCurrencyScenarioArray presentValue(ResolvedSwapTrade trade, RatesScenarioMarketData marketData) { return(MultiCurrencyScenarioArray.of(marketData.ScenarioCount, i => presentValue(trade, marketData.scenario(i).ratesProvider()))); }
// XCcy swap with exchange of notional and FX Reset on the USD leg public virtual void test_XCcyFixedInitialNotional() { DiscountingSwapTradePricer pricer = swapPricer(); //Create an MTM swap with initial notional override double notional = 1_000_000d; ResolvedSwapTrade fixedNotionalMtmTrade = getMtmTrade(true, true, true, notional).resolve(REF_DATA); ExplainMap explainMap = pricer.explainPresentValue(fixedNotionalMtmTrade, provider()); CurrencyAmount fixedNotional = CurrencyAmount.of(Currency.USD, notional); ExplainMap fixedNotionalMtmLeg = explainMap.get(ExplainKey.LEGS).get().get(1); IList <ExplainMap> events = fixedNotionalMtmLeg.get(ExplainKey.PAYMENT_EVENTS).get(); //First two payment events should use fixed initial notional ExplainMap firstPaymentEvent = events[0]; assertFixedNotionalPaymentEvent(firstPaymentEvent, fixedNotional.negated()); ExplainMap secondPaymentEvent = events[1]; assertFixedNotionalPaymentEvent(secondPaymentEvent, fixedNotional); //First coupon also uses fixed notional ExplainMap firstCoupon = fixedNotionalMtmLeg.get(ExplainKey.PAYMENT_PERIODS).get().get(0); assertEquals(firstCoupon.get(ExplainKey.TRADE_NOTIONAL), fixedNotional); assertEquals(firstCoupon.get(ExplainKey.NOTIONAL), fixedNotional); //Sum of all pv amounts which are impacted by overriding the first period with a fixed notional CurrencyAmount firstPaymentPv = firstPaymentEvent.get(ExplainKey.PRESENT_VALUE).get(); CurrencyAmount secondPaymentPv = secondPaymentEvent.get(ExplainKey.PRESENT_VALUE).get(); CurrencyAmount firstCouponPv = firstCoupon.get(ExplainKey.PRESENT_VALUE).get(); CurrencyAmount fixedNotionalImpactedEventsPv = firstPaymentPv.plus(secondPaymentPv).plus(firstCouponPv); //---------------------------------------------------------------------------------------------------------- //Build identical trade but with no fixed notional ResolvedSwapTrade noFixedNotionalMtmTrade = getMtmTrade(true, true, true, null).resolve(REF_DATA); ExplainMap noFixedNotionalMtmLeg = pricer.explainPresentValue(noFixedNotionalMtmTrade, provider()).get(ExplainKey.LEGS).get().get(1); //Sum the pvs for the same combination of payments and events that are impacted by fixed notional in first trade //JAVA TO C# CONVERTER TODO TASK: Method reference arbitrary object instance method syntax is not converted by Java to C# Converter: CurrencyAmount noFixedNotionalEventsPv = noFixedNotionalMtmLeg.get(ExplainKey.PAYMENT_EVENTS).get().subList(0, 2).Select(payment => payment.get(ExplainKey.PRESENT_VALUE).get()).Aggregate(CurrencyAmount.zero(Currency.USD), CurrencyAmount::plus); CurrencyAmount noFixedNotionalCouponsPv = noFixedNotionalMtmLeg.get(ExplainKey.PAYMENT_PERIODS).get().get(0).get(ExplainKey.PRESENT_VALUE).get(); CurrencyAmount noFixedNotionalImpactedEventsPv = noFixedNotionalCouponsPv.plus(noFixedNotionalEventsPv); //---------------------------------------------------------------------------------------------------------- //PV difference of the events impacted by fixing notional CurrencyAmount paymentsPvDifference = fixedNotionalImpactedEventsPv.minus(noFixedNotionalImpactedEventsPv); //Calculate PV of the full trades MultiCurrencyAmount fixedNotionalLegPv = pricer.presentValue(fixedNotionalMtmTrade, provider()); MultiCurrencyAmount noFixedNotionalLegPv = pricer.presentValue(noFixedNotionalMtmTrade, provider()); //EUR PV should not have changed assertEquals(fixedNotionalLegPv.getAmount(Currency.EUR).Amount, noFixedNotionalLegPv.getAmount(Currency.EUR).Amount, TOLERANCE_PV); //Difference in USD PV should be equal the difference in PV of the three events impacted by the initial notional //All else should remain equal CurrencyAmount tradePvDifference = fixedNotionalLegPv.getAmount(Currency.USD).minus(noFixedNotionalLegPv.getAmount(Currency.USD)); assertEquals(tradePvDifference.Amount, paymentsPvDifference.Amount, TOLERANCE_PV); }