//------------------------------------------------------------------------- public virtual void coverage() { SwapIsdaCreditCurveNode test1 = SwapIsdaCreditCurveNode.of(OBS_ID, ADJ_3D, BUS_ADJ, TENOR, THIRTY_U_360, FREQUENCY); coverImmutableBean(test1); SwapIsdaCreditCurveNode test2 = SwapIsdaCreditCurveNode.builder().observableId(QuoteId.of(StandardId.of("OG", "foo"))).spotDateOffset(DaysAdjustment.NONE).businessDayAdjustment(BusinessDayAdjustment.NONE).tenor(Tenor.TENOR_15Y).dayCount(DayCounts.ACT_365F).paymentFrequency(Frequency.P3M).label("test2").build(); coverBeanEquals(test1, test2); }
public virtual void test_of() { SwapIsdaCreditCurveNode test = SwapIsdaCreditCurveNode.of(OBS_ID, ADJ_3D, BUS_ADJ, TENOR, THIRTY_U_360, FREQUENCY); assertEquals(test.BusinessDayAdjustment, BUS_ADJ); assertEquals(test.DayCount, THIRTY_U_360); assertEquals(test.Label, TENOR.ToString()); assertEquals(test.ObservableId, OBS_ID); assertEquals(test.PaymentFrequency, FREQUENCY); assertEquals(test.SpotDateOffset, ADJ_3D); assertEquals(test.Tenor, TENOR); assertEquals(test.date(TRADE_DATE, REF_DATA), LocalDate.of(2026, 10, 5)); assertEquals(test.metadata(LocalDate.of(2026, 10, 5)), TenorDateParameterMetadata.of(LocalDate.of(2026, 10, 5), TENOR)); }
//------------------------------------------------------------------------- /// <summary> /// Calibrates the ISDA compliant discount curve to the market data. /// <para> /// This creates the single discount curve for a specified currency. /// The curve nodes in {@code IsdaCreditCurveDefinition} should be term deposit or fixed-for-Ibor swap, /// and the number of nodes should be greater than 1. /// /// </para> /// </summary> /// <param name="curveDefinition"> the curve definition </param> /// <param name="marketData"> the market data </param> /// <param name="refData"> the reference data </param> /// <returns> the ISDA compliant discount curve </returns> public IsdaCreditDiscountFactors calibrate(IsdaCreditCurveDefinition curveDefinition, MarketData marketData, ReferenceData refData) { //JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET: //ORIGINAL LINE: java.util.List<? extends com.opengamma.strata.market.curve.IsdaCreditCurveNode> curveNodes = curveDefinition.getCurveNodes(); IList <IsdaCreditCurveNode> curveNodes = curveDefinition.CurveNodes; int nNodes = curveNodes.Count; ArgChecker.isTrue(nNodes > 1, "the number of curve nodes must be greater than 1"); LocalDate curveSnapDate = marketData.ValuationDate; LocalDate curveValuationDate = curveDefinition.CurveValuationDate; DayCount curveDayCount = curveDefinition.DayCount; BasicFixedLeg[] swapLeg = new BasicFixedLeg[nNodes]; double[] termDepositYearFraction = new double[nNodes]; double[] curveNodeTime = new double[nNodes]; double[] rates = new double[nNodes]; ImmutableList.Builder <ParameterMetadata> paramMetadata = ImmutableList.builder(); int nTermDeposit = 0; LocalDate curveSpotDate = null; for (int i = 0; i < nNodes; i++) { LocalDate cvDateTmp; IsdaCreditCurveNode node = curveNodes[i]; rates[i] = marketData.getValue(node.ObservableId); LocalDate adjMatDate = node.date(curveSnapDate, refData); paramMetadata.add(node.metadata(adjMatDate)); if (node is DepositIsdaCreditCurveNode) { DepositIsdaCreditCurveNode termDeposit = (DepositIsdaCreditCurveNode)node; cvDateTmp = termDeposit.SpotDateOffset.adjust(curveSnapDate, refData); curveNodeTime[i] = curveDayCount.relativeYearFraction(cvDateTmp, adjMatDate); termDepositYearFraction[i] = termDeposit.DayCount.relativeYearFraction(cvDateTmp, adjMatDate); ArgChecker.isTrue(nTermDeposit == i, "TermDepositCurveNode should not be after FixedIborSwapCurveNode"); ++nTermDeposit; } else if (node is SwapIsdaCreditCurveNode) { SwapIsdaCreditCurveNode swap = (SwapIsdaCreditCurveNode)node; cvDateTmp = swap.SpotDateOffset.adjust(curveSnapDate, refData); curveNodeTime[i] = curveDayCount.relativeYearFraction(cvDateTmp, adjMatDate); BusinessDayAdjustment busAdj = swap.BusinessDayAdjustment; swapLeg[i] = new BasicFixedLeg(this, cvDateTmp, cvDateTmp.plus(swap.Tenor), swap.PaymentFrequency.Period, swap.DayCount, curveDayCount, busAdj, refData); } else { throw new System.ArgumentException("unsupported cuve node type"); } if (i > 0) { ArgChecker.isTrue(curveNodeTime[i] - curveNodeTime[i - 1] > 0, "curve nodes should be ascending in terms of tenor"); ArgChecker.isTrue(cvDateTmp.Equals(curveSpotDate), "spot lag should be common for all of the curve nodes"); } else { ArgChecker.isTrue(curveNodeTime[i] >= 0d, "the first node should be after curve spot date"); curveSpotDate = cvDateTmp; } } ImmutableList <ParameterMetadata> parameterMetadata = paramMetadata.build(); double[] ratesMod = Arrays.copyOf(rates, nNodes); for (int i = 0; i < nTermDeposit; ++i) { double dfInv = 1d + ratesMod[i] * termDepositYearFraction[i]; ratesMod[i] = Math.Log(dfInv) / curveNodeTime[i]; } InterpolatedNodalCurve curve = curveDefinition.curve(DoubleArray.ofUnsafe(curveNodeTime), DoubleArray.ofUnsafe(ratesMod)); for (int i = nTermDeposit; i < nNodes; ++i) { curve = fitSwap(i, swapLeg[i], curve, rates[i]); } Currency currency = curveDefinition.Currency; DoubleMatrix sensi = quoteValueSensitivity(nTermDeposit, termDepositYearFraction, swapLeg, ratesMod, curve, curveDefinition.ComputeJacobian); if (curveValuationDate.isEqual(curveSpotDate)) { if (curveDefinition.ComputeJacobian) { JacobianCalibrationMatrix jacobian = JacobianCalibrationMatrix.of(ImmutableList.of(CurveParameterSize.of(curveDefinition.Name, nNodes)), MATRIX_ALGEBRA.getInverse(sensi)); NodalCurve curveWithParamMetadata = curve.withMetadata(curve.Metadata.withInfo(CurveInfoType.JACOBIAN, jacobian).withParameterMetadata(parameterMetadata)); return(IsdaCreditDiscountFactors.of(currency, curveValuationDate, curveWithParamMetadata)); } NodalCurve curveWithParamMetadata = curve.withMetadata(curve.Metadata.withParameterMetadata(parameterMetadata)); return(IsdaCreditDiscountFactors.of(currency, curveValuationDate, curveWithParamMetadata)); } double offset = curveDayCount.relativeYearFraction(curveSpotDate, curveValuationDate); return(IsdaCreditDiscountFactors.of(currency, curveValuationDate, withShift(curve, parameterMetadata, sensi, curveDefinition.ComputeJacobian, offset))); }
public virtual void test_serialization() { SwapIsdaCreditCurveNode test = SwapIsdaCreditCurveNode.of(OBS_ID, ADJ_3D, BUS_ADJ, TENOR, THIRTY_U_360, FREQUENCY); assertSerialization(test); }
static IsdaCompliantCreditCurveCalibratorBase() { ImmutableList.Builder <IsdaCreditCurveNode> dscNodeBuilder = ImmutableList.builder(); for (int i = 0; i < NUM_MM; i++) { Tenor tenor = Tenor.ofMonths(MM_MONTHS[i]); dscNodeBuilder.add(DepositIsdaCreditCurveNode.of(QuoteId.of(StandardId.of("OG", ID_VALUES[i])), ADJ_3D, BUS_ADJ, tenor, ACT_360)); } for (int i = NUM_MM; i < NUM_INSTRUMENTS; i++) { Tenor tenor = Tenor.ofYears(SWAP_YEARS[i - NUM_MM]); dscNodeBuilder.add(SwapIsdaCreditCurveNode.of(QuoteId.of(StandardId.of("OG", ID_VALUES[i])), ADJ_3D, BUS_ADJ, tenor, THIRTY_U_360, Frequency.P12M)); } DSC_NODES = dscNodeBuilder.build(); EXP_NODE_CDS = new ResolvedCdsTrade[NUM_TESTS][]; NODE_CDS = new CdsIsdaCreditCurveNode[NUM_TESTS][]; CDS_MARKET_DATA = new ImmutableMarketData[NUM_TESTS]; SPREADS = new double[NUM_TESTS][]; YIELD_CURVES = new ImmutableCreditRatesProvider[NUM_TESTS]; // case0 LocalDate tradeDate0 = LocalDate.of(2011, 6, 19); LocalDate startDate0 = LocalDate.of(2011, 3, 21); YIELD_CURVES[0] = createRatesProvider(tradeDate0, tradeDate0, 1d, 0.4); Period[] tenors = new Period[] { Period.ofMonths(6), Period.ofYears(1), Period.ofYears(3), Period.ofYears(5), Period.ofYears(7), Period.ofYears(10) }; int nTenors = tenors.Length; EXP_NODE_CDS[0] = new ResolvedCdsTrade[nTenors]; NODE_CDS[0] = new CdsIsdaCreditCurveNode[nTenors]; ImmutableMarketDataBuilder builderCredit0 = ImmutableMarketData.builder(tradeDate0); SPREADS[0] = new double[] { 0.00886315689995649, 0.00886315689995649, 0.0133044689825873, 0.0171490070952563, 0.0183903639181293, 0.0194721890639724 }; for (int i = 0; i < nTenors; ++i) { Cds product = Cds.of(BUY, LEGAL_ENTITY, EUR, 1d, startDate0, LocalDate.of(2011, 6, 20).plus(tenors[i]), Frequency.P3M, DEFAULT_CALENDAR, SPREADS[0][i]); EXP_NODE_CDS[0][i] = CdsTrade.builder().info(TradeInfo.builder().settlementDate(product.SettlementDateOffset.adjust(tradeDate0, REF_DATA)).build()).product(product).build().resolve(REF_DATA); CdsConvention conv = ImmutableCdsConvention.of("conv", EUR, ACT_360, Frequency.P3M, BUS_ADJ, CDS_SETTLE_STD); CdsTemplate temp = DatesCdsTemplate.of(startDate0, LocalDate.of(2011, 6, 20).plus(tenors[i]), conv); QuoteId id = QuoteId.of(StandardId.of("OG", tenors[i].ToString())); NODE_CDS[0][i] = CdsIsdaCreditCurveNode.ofParSpread(temp, id, LEGAL_ENTITY); builderCredit0.addValue(id, SPREADS[0][i]); } CDS_MARKET_DATA[0] = builderCredit0.build(); // case1 LocalDate tradeDate1 = LocalDate.of(2011, 3, 21); LocalDate snapDate1 = LocalDate.of(2011, 3, 18); LocalDate effDate1 = LocalDate.of(2011, 3, 20); //note this is a Sunday - for a standard CDS this would roll to the Monday. YIELD_CURVES[1] = createRatesProvider(tradeDate1, snapDate1, 1d, 0.4); tenors = new Period[] { Period.ofMonths(6), Period.ofYears(1), Period.ofYears(3), Period.ofYears(5), Period.ofYears(7), Period.ofYears(10) }; nTenors = tenors.Length; NODE_CDS[1] = new CdsIsdaCreditCurveNode[nTenors]; ImmutableMarketDataBuilder builderCredit1 = ImmutableMarketData.builder(tradeDate1); EXP_NODE_CDS[1] = new ResolvedCdsTrade[nTenors]; SPREADS[1] = new double[] { 0.027, 0.018, 0.012, 0.009, 0.007, 0.006 }; for (int i = 0; i < nTenors; ++i) { Cds product = Cds.of(BUY, LEGAL_ENTITY, EUR, 1d, effDate1, LocalDate.of(2011, 6, 20).plus(tenors[i]), P3M, DEFAULT_CALENDAR, SPREADS[1][i]); EXP_NODE_CDS[1][i] = CdsTrade.builder().info(TradeInfo.builder().settlementDate(product.SettlementDateOffset.adjust(tradeDate1, REF_DATA)).build()).product(product).build().resolve(REF_DATA); CdsConvention conv = ImmutableCdsConvention.builder().name("conv").currency(EUR).dayCount(ACT_360).paymentFrequency(P3M).startDateBusinessDayAdjustment(BusinessDayAdjustment.NONE).businessDayAdjustment(BUS_ADJ).settlementDateOffset(CDS_SETTLE_STD).build(); CdsTemplate temp = DatesCdsTemplate.of(effDate1, LocalDate.of(2011, 6, 20).plus(tenors[i]), conv); QuoteId id = QuoteId.of(StandardId.of("OG", tenors[i].ToString())); NODE_CDS[1][i] = CdsIsdaCreditCurveNode.ofParSpread(temp, id, LEGAL_ENTITY); builderCredit1.addValue(id, SPREADS[1][i]); } CDS_MARKET_DATA[1] = builderCredit1.build(); // case2 LocalDate tradeDate2 = LocalDate.of(2011, 5, 30); LocalDate snapDate2 = LocalDate.of(2011, 5, 29); YIELD_CURVES[2] = createRatesProvider(tradeDate2, snapDate2, 1d, 0.25); LocalDate[] matDates2 = new LocalDate[] { LocalDate.of(2011, 6, 20), LocalDate.of(2012, 5, 30), LocalDate.of(2014, 6, 20), LocalDate.of(2016, 6, 20), LocalDate.of(2018, 6, 20) }; int nMatDates2 = matDates2.Length; NODE_CDS[2] = new CdsIsdaCreditCurveNode[nMatDates2]; ImmutableMarketDataBuilder builderCredit2 = ImmutableMarketData.builder(tradeDate2); EXP_NODE_CDS[2] = new ResolvedCdsTrade[nMatDates2]; SPREADS[2] = new double[] { 0.05, 0.05, 0.05, 0.05, 0.05 }; for (int i = 0; i < nMatDates2; ++i) { Cds product = Cds.of(BUY, LEGAL_ENTITY, EUR, 1d, tradeDate2.plusDays(1), matDates2[i], P3M, DEFAULT_CALENDAR, SPREADS[2][i]).toBuilder().dayCount(THIRTY_U_360).build(); EXP_NODE_CDS[2][i] = CdsTrade.builder().info(TradeInfo.builder().settlementDate(product.SettlementDateOffset.adjust(tradeDate2, REF_DATA)).build()).product(product).build().resolve(REF_DATA); CdsConvention conv = ImmutableCdsConvention.builder().name("conv").currency(EUR).dayCount(THIRTY_U_360).paymentFrequency(P3M).rollConvention(RollConventions.NONE).businessDayAdjustment(BUS_ADJ).settlementDateOffset(CDS_SETTLE_STD).build(); CdsTemplate temp = DatesCdsTemplate.of(tradeDate2.plusDays(1), matDates2[i], conv); QuoteId id = QuoteId.of(StandardId.of("OG", matDates2[i].ToString())); NODE_CDS[2][i] = CdsIsdaCreditCurveNode.ofParSpread(temp, id, LEGAL_ENTITY); builderCredit2.addValue(id, SPREADS[2][i]); } CDS_MARKET_DATA[2] = builderCredit2.build(); // case3 LocalDate tradeDate3 = LocalDate.of(2011, 5, 30); LocalDate snapDate3 = LocalDate.of(2011, 5, 29); LocalDate effDate3 = LocalDate.of(2011, 7, 31); YIELD_CURVES[3] = createRatesProvider(tradeDate3, snapDate3, 1d, 0.25); LocalDate[] matDates3 = new LocalDate[] { LocalDate.of(2011, 11, 30), LocalDate.of(2012, 5, 30), LocalDate.of(2014, 5, 30), LocalDate.of(2016, 5, 30), LocalDate.of(2018, 5, 30), LocalDate.of(2021, 5, 30) }; int nMatDates3 = matDates3.Length; NODE_CDS[3] = new CdsIsdaCreditCurveNode[nMatDates3]; ImmutableMarketDataBuilder builderCredit3 = ImmutableMarketData.builder(tradeDate3); EXP_NODE_CDS[3] = new ResolvedCdsTrade[nMatDates3]; SPREADS[3] = new double[] { 0.07, 0.06, 0.05, 0.055, 0.06, 0.065 }; for (int i = 0; i < nMatDates3; ++i) { Cds product = Cds.builder().buySell(BUY).legalEntityId(LEGAL_ENTITY).currency(EUR).dayCount(ACT_365F).fixedRate(SPREADS[3][i]).notional(1d).paymentSchedule(PeriodicSchedule.builder().businessDayAdjustment(BusinessDayAdjustment.of(FOLLOWING, DEFAULT_CALENDAR)).startDate(effDate3).endDate(matDates3[i]).startDateBusinessDayAdjustment(BusinessDayAdjustment.NONE).endDateBusinessDayAdjustment(BusinessDayAdjustment.NONE).frequency(Frequency.P6M).rollConvention(RollConventions.NONE).stubConvention(StubConvention.LONG_INITIAL).build()).paymentOnDefault(PaymentOnDefault.ACCRUED_PREMIUM).protectionStart(ProtectionStartOfDay.BEGINNING).stepinDateOffset(DaysAdjustment.ofCalendarDays(1)).settlementDateOffset(CDS_SETTLE_STD).build(); EXP_NODE_CDS[3][i] = CdsTrade.builder().info(TradeInfo.builder().settlementDate(product.SettlementDateOffset.adjust(tradeDate3, REF_DATA)).build()).product(product).build().resolve(REF_DATA); CdsConvention conv = ImmutableCdsConvention.builder().name("conv").currency(EUR).dayCount(ACT_365F).paymentFrequency(Frequency.P6M).rollConvention(RollConventions.NONE).stubConvention(StubConvention.LONG_INITIAL).startDateBusinessDayAdjustment(BusinessDayAdjustment.NONE).businessDayAdjustment(BusinessDayAdjustment.of(FOLLOWING, DEFAULT_CALENDAR)).settlementDateOffset(CDS_SETTLE_STD).build(); CdsTemplate temp = DatesCdsTemplate.of(effDate3, matDates3[i], conv); QuoteId id = QuoteId.of(StandardId.of("OG", matDates3[i].ToString())); NODE_CDS[3][i] = CdsIsdaCreditCurveNode.ofParSpread(temp, id, LEGAL_ENTITY); builderCredit3.addValue(id, SPREADS[3][i]); } CDS_MARKET_DATA[3] = builderCredit3.build(); // case4: designed to trip the low rates/low spreads branch LocalDate tradeDate4 = LocalDate.of(2014, 1, 14); LocalDate snapDate4 = LocalDate.of(2014, 1, 13); YIELD_CURVES[4] = createRatesProvider(tradeDate4, snapDate4, 1d / 1000d, 0.4); int nSpreads4 = 6; NODE_CDS[4] = new CdsIsdaCreditCurveNode[nSpreads4]; ImmutableMarketDataBuilder builderCredit4 = ImmutableMarketData.builder(tradeDate4); SPREADS[4] = new double[nSpreads4]; Arrays.fill(SPREADS[4], 1.0e-4); EXP_NODE_CDS[4] = new ResolvedCdsTrade[nSpreads4]; for (int i = 0; i < nSpreads4; ++i) { Cds product = Cds.of(BUY, LEGAL_ENTITY, EUR, 1d, LocalDate.of(2013, 12, 20), LocalDate.of(2014, 3, 20).plus(tenors[i]), P3M, DEFAULT_CALENDAR, SPREADS[4][i]); EXP_NODE_CDS[4][i] = CdsTrade.builder().info(TradeInfo.builder().settlementDate(product.SettlementDateOffset.adjust(tradeDate4, REF_DATA)).build()).product(product).build().resolve(REF_DATA); CdsConvention conv = ImmutableCdsConvention.of("conv", EUR, ACT_360, P3M, BUS_ADJ, CDS_SETTLE_STD); CdsTemplate temp = DatesCdsTemplate.of(LocalDate.of(2013, 12, 20), LocalDate.of(2014, 3, 20).plus(tenors[i]), conv); QuoteId id = QuoteId.of(StandardId.of("OG", tenors[i].ToString())); NODE_CDS[4][i] = CdsIsdaCreditCurveNode.ofParSpread(temp, id, LEGAL_ENTITY); builderCredit4.addValue(id, SPREADS[4][i]); } CDS_MARKET_DATA[4] = builderCredit4.build(); }