public virtual void test_trade_noMarketData() { CdsIndexIsdaCreditCurveNode node = CdsIndexIsdaCreditCurveNode.ofParSpread(TEMPLATE, QUOTE_ID, INDEX_ID, LEGAL_ENTITIES); MarketData marketData = MarketData.empty(VAL_DATE); assertThrows(() => node.trade(1d, marketData, REF_DATA), typeof(MarketDataNotFoundException)); }
//------------------------------------------------------------------------- public virtual void test_trade() { CdsIndexIsdaCreditCurveNode node = CdsIndexIsdaCreditCurveNode.ofQuotedSpread(TEMPLATE, QUOTE_ID, INDEX_ID, LEGAL_ENTITIES, 0.01); double rate = 0.0125; double quantity = -1234.56; MarketData marketData = ImmutableMarketData.builder(VAL_DATE).addValue(QUOTE_ID, rate).build(); CdsIndexCalibrationTrade trade = node.trade(quantity, marketData, REF_DATA); CdsTrade cdsTrade = TEMPLATE.createTrade(INDEX_ID, VAL_DATE, SELL, -quantity, 0.01, REF_DATA); CdsIndex cdsIndex = CdsIndex.of(SELL, INDEX_ID, LEGAL_ENTITIES, TEMPLATE.Convention.Currency, -quantity, date(2015, 6, 20), date(2025, 6, 20), Frequency.P3M, TEMPLATE.Convention.SettlementDateOffset.Calendar, 0.01); CdsIndex cdsIndexMod = cdsIndex.toBuilder().paymentSchedule(cdsIndex.PaymentSchedule.toBuilder().rollConvention(RollConventions.DAY_20).startDateBusinessDayAdjustment(cdsIndex.PaymentSchedule.BusinessDayAdjustment).build()).build(); CdsIndexTrade expected = CdsIndexTrade.builder().product(cdsIndexMod).info(cdsTrade.Info).build(); assertEquals(trade.UnderlyingTrade, expected); assertEquals(trade.Quote, CdsQuote.of(CdsQuoteConvention.QUOTED_SPREAD, rate)); CdsIndexIsdaCreditCurveNode node1 = CdsIndexIsdaCreditCurveNode.ofParSpread(TEMPLATE, QUOTE_ID, INDEX_ID, LEGAL_ENTITIES); CdsTrade cdsTrade1 = TEMPLATE.createTrade(INDEX_ID, VAL_DATE, SELL, -quantity, rate, REF_DATA); CdsIndexCalibrationTrade trade1 = node1.trade(quantity, marketData, REF_DATA); CdsIndex cdsIndex1 = CdsIndex.of(SELL, INDEX_ID, LEGAL_ENTITIES, TEMPLATE.Convention.Currency, -quantity, date(2015, 6, 20), date(2025, 6, 20), Frequency.P3M, TEMPLATE.Convention.SettlementDateOffset.Calendar, rate); CdsIndex cdsIndexMod1 = cdsIndex1.toBuilder().paymentSchedule(cdsIndex.PaymentSchedule.toBuilder().rollConvention(RollConventions.DAY_20).startDateBusinessDayAdjustment(cdsIndex1.PaymentSchedule.BusinessDayAdjustment).build()).build(); CdsIndexTrade expected1 = CdsIndexTrade.builder().product(cdsIndexMod1).info(cdsTrade1.Info).build(); assertEquals(trade1.UnderlyingTrade, expected1); assertEquals(trade1.Quote, CdsQuote.of(CdsQuoteConvention.PAR_SPREAD, rate)); }