/** * Restricted copy constructor. * @param beanToCopy the bean to copy from, not null */ private Builder(CdsIndexIsdaCreditCurveNode beanToCopy) { this.template = beanToCopy.getTemplate(); this.label = beanToCopy.getLabel(); this.observableId = beanToCopy.getObservableId(); this.cdsIndexId = beanToCopy.getCdsIndexId(); this.legalEntityIds = beanToCopy.getLegalEntityIds(); this.quoteConvention = beanToCopy.getQuoteConvention(); this.fixedRate = beanToCopy.fixedRate; }
private CdsIsdaCreditCurveNode toCdsNode(CdsIndexIsdaCreditCurveNode index) { return CdsIsdaCreditCurveNode.builder() .label(index.getLabel()) .legalEntityId(index.getCdsIndexId()) .observableId(index.getObservableId()) .quoteConvention(index.getQuoteConvention()) .template(index.getTemplate()) .fixedRate(index.getFixedRate().isPresent() ? index.getFixedRate().getAsDouble() : null) .build(); }
public void test_of_pardSpread() { CdsIndexIsdaCreditCurveNode test = CdsIndexIsdaCreditCurveNode.ofParSpread(TEMPLATE_NS, QUOTE_ID, INDEX_ID, LEGAL_ENTITIES); assertEquals(test.getLabel(), END_DATE.toString()); assertEquals(test.getCdsIndexId(), INDEX_ID); assertEquals(test.getLegalEntityIds(), LEGAL_ENTITIES); assertEquals(test.getObservableId(), QUOTE_ID); assertEquals(test.getTemplate(), TEMPLATE_NS); assertEquals(test.date(VAL_DATE, REF_DATA), END_DATE); }
public void test_of_pointsUpfront() { CdsIndexIsdaCreditCurveNode test = CdsIndexIsdaCreditCurveNode.ofPointsUpfront(TEMPLATE, QUOTE_ID, INDEX_ID, LEGAL_ENTITIES, 0.01); assertEquals(test.getLabel(), LABEL_AUTO); assertEquals(test.getCdsIndexId(), INDEX_ID); assertEquals(test.getLegalEntityIds(), LEGAL_ENTITIES); assertEquals(test.getObservableId(), QUOTE_ID); assertEquals(test.getTemplate(), TEMPLATE); assertEquals(test.date(VAL_DATE, REF_DATA), date(2025, 6, 20)); }
public void test_of_quotedSpread() { CdsIndexIsdaCreditCurveNode test = CdsIndexIsdaCreditCurveNode.ofQuotedSpread(TEMPLATE, QUOTE_ID, INDEX_ID, LEGAL_ENTITIES, 0.01); assertEquals(test.getLabel(), LABEL_AUTO); assertEquals(test.getCdsIndexId(), INDEX_ID); assertEquals(test.getLegalEntityIds(), LEGAL_ENTITIES); assertEquals(test.getObservableId(), QUOTE_ID); assertEquals(test.getTemplate(), TEMPLATE); assertEquals(test.date(VAL_DATE, REF_DATA), date(2025, 6, 20)); }
public void test_builder() { CdsIndexIsdaCreditCurveNode test = CdsIndexIsdaCreditCurveNode.builder() .label(LABEL) .template(TEMPLATE) .observableId(QUOTE_ID) .quoteConvention(CdsQuoteConvention.PAR_SPREAD) .cdsIndexId(INDEX_ID) .legalEntityIds(LEGAL_ENTITIES) .build(); assertEquals(test.getLabel(), LABEL); assertEquals(test.getCdsIndexId(), INDEX_ID); assertEquals(test.getLegalEntityIds(), LEGAL_ENTITIES); assertEquals(test.getObservableId(), QUOTE_ID); assertEquals(test.getTemplate(), TEMPLATE); assertEquals(test.date(VAL_DATE, REF_DATA), date(2025, 6, 20)); }
public void test_consistency_singleName() { IsdaCreditCurveDefinition curveDefinition = IsdaCreditCurveDefinition.of( CURVE_NAME, EUR, VALUATION_DATE, ACT_365F, CURVE_NODES_PS, true, true); LegalEntitySurvivalProbabilities creditCurveComputed = CALIBRATOR.calibrate( curveDefinition, MARKET_DATA_PS, RATES_PROVIDER, REF_DATA); NodalCurve curveComputed = (NodalCurve) creditCurveComputed.getSurvivalProbabilities().findData(CURVE_NAME).get(); double computedIndex = curveComputed.getMetadata().getInfo(CurveInfoType.CDS_INDEX_FACTOR); assertEquals(computedIndex, 93.0 / 97.0, TOL); IsdaCompliantCreditCurveCalibrator cdsCalibrator = FastCreditCurveCalibrator.standard(); List<CdsIsdaCreditCurveNode> cdsNodes = new ArrayList<>(); for (int i = 0; i < CURVE_NODES_PS.size(); ++i) { cdsNodes.add(CdsIsdaCreditCurveNode.ofParSpread( CURVE_NODES_PS.get(i).getTemplate(), CURVE_NODES_PS.get(i).getObservableId(), CURVE_NODES_PS.get(i).getCdsIndexId())); ParameterMetadata metadata = curveComputed.getParameterMetadata(i); assertTrue(metadata instanceof ResolvedTradeParameterMetadata); ResolvedTradeParameterMetadata tradeMetadata = (ResolvedTradeParameterMetadata) metadata; assertTrue(tradeMetadata.getTrade() instanceof ResolvedCdsIndexTrade); } IsdaCreditCurveDefinition cdsCurveDefinition = IsdaCreditCurveDefinition.of( CURVE_NAME, EUR, VALUATION_DATE, ACT_365F, cdsNodes, true, false); LegalEntitySurvivalProbabilities creditCurveExpected = cdsCalibrator.calibrate( cdsCurveDefinition, MARKET_DATA_PS, RATES_PROVIDER, REF_DATA); NodalCurve curveExpected = (NodalCurve) creditCurveExpected.getSurvivalProbabilities().findData(CURVE_NAME).get(); assertTrue(DoubleArrayMath.fuzzyEquals(curveComputed.getXValues().toArray(), curveExpected.getXValues().toArray(), TOL)); assertTrue(DoubleArrayMath.fuzzyEquals(curveComputed.getYValues().toArray(), curveExpected.getYValues().toArray(), TOL)); assertEquals(curveComputed.getMetadata().getInfo(CurveInfoType.JACOBIAN), curveExpected.getMetadata().getInfo(CurveInfoType.JACOBIAN)); }
private double computeIndexFactor(CdsIndexIsdaCreditCurveNode node, MarketData marketData) { double numDefaulted = node.getLegalEntityIds().stream() .map(s -> marketData.getValue(LegalEntityInformationId.of(s))) .map(casting(LegalEntityInformation.class)) .filter(LegalEntityInformation::isDefaulted) .collect(Collectors.toList()) .size(); double numTotal = node.getLegalEntityIds().size(); return (numTotal - numDefaulted) / numTotal; }
ImmutableMarketDataBuilder builderCreditDw = MARKET_DATA.toBuilder(); for (int j = 0; j < nNode; ++j) { builderCreditUp.addValue(nodes.get(j).getObservableId(), quotesUp[j]); builderCreditDw.addValue(nodes.get(j).getObservableId(), quotesDw[j]);
public 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( assertEquals(trade.getQuote(), 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.getConvention().getCurrency(), -quantity, date(2015, 6, 20),
/** * Returns a curve node with par spread convention. * * @param template the template * @param observableId the observable ID * @param cdsIndexId the CDS index ID * @param legalEntityIds the legal entity IDs * @return the curve node */ public static CdsIndexIsdaCreditCurveNode ofParSpread( CdsTemplate template, ObservableId observableId, StandardId cdsIndexId, List<StandardId> legalEntityIds) { return builder() .template(template) .observableId(observableId) .cdsIndexId(cdsIndexId) .legalEntityIds(legalEntityIds) .quoteConvention(CdsQuoteConvention.PAR_SPREAD) .build(); }
public 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), MarketDataNotFoundException.class); }
cdsTrade = template.createTrade(cdsIndexId, valuationDate, buySell, notional, quoteValue, refData); } else { double coupon = getFixedRate().getAsDouble(); // always success cdsTrade = template.createTrade(cdsIndexId, valuationDate, buySell, notional, coupon, refData);
/** * Returns a curve node with quoted spread convention. * * @param template the template * @param observableId the observable ID * @param cdsIndexId the CDS index ID * @param legalEntityIds the legal entity IDs * @param fixedRate the fixed rate * @return the curve node */ public static CdsIndexIsdaCreditCurveNode ofQuotedSpread( CdsTemplate template, ObservableId observableId, StandardId cdsIndexId, List<StandardId> legalEntityIds, Double fixedRate) { return builder() .template(template) .observableId(observableId) .cdsIndexId(cdsIndexId) .legalEntityIds(legalEntityIds) .quoteConvention(CdsQuoteConvention.QUOTED_SPREAD) .fixedRate(fixedRate) .build(); }
@Override protected Object propertyGet(Bean bean, String propertyName, boolean quiet) { switch (propertyName.hashCode()) { case -1321546630: // template return ((CdsIndexIsdaCreditCurveNode) bean).getTemplate(); case 102727412: // label return ((CdsIndexIsdaCreditCurveNode) bean).getLabel(); case -518800962: // observableId return ((CdsIndexIsdaCreditCurveNode) bean).getObservableId(); case -464117509: // cdsIndexId return ((CdsIndexIsdaCreditCurveNode) bean).getCdsIndexId(); case 1085098268: // legalEntityIds return ((CdsIndexIsdaCreditCurveNode) bean).getLegalEntityIds(); case 2049149709: // quoteConvention return ((CdsIndexIsdaCreditCurveNode) bean).getQuoteConvention(); case 747425396: // fixedRate return ((CdsIndexIsdaCreditCurveNode) bean).fixedRate; } return super.propertyGet(bean, propertyName, quiet); }
/** * Returns a curve node with points upfront convention. * * @param template the template * @param observableId the observable ID * @param cdsIndexId the CDS index ID * @param legalEntityIds the legal entity IDs * @param fixedRate the fixed rate * @return the curve node */ public static CdsIndexIsdaCreditCurveNode ofPointsUpfront( CdsTemplate template, ObservableId observableId, StandardId cdsIndexId, List<StandardId> legalEntityIds, Double fixedRate) { return builder() .template(template) .observableId(observableId) .cdsIndexId(cdsIndexId) .legalEntityIds(legalEntityIds) .quoteConvention(CdsQuoteConvention.POINTS_UPFRONT) .fixedRate(fixedRate) .build(); }
public void test_build_fail_noRate() { assertThrows( () -> CdsIndexIsdaCreditCurveNode.builder().template(TEMPLATE).observableId(QUOTE_ID).cdsIndexId(INDEX_ID) .legalEntityIds(LEGAL_ENTITIES).quoteConvention(CdsQuoteConvention.QUOTED_SPREAD).build(), IllegalArgumentException.class); }