final Tenor[] tenors = CreditFunctionUtils.getTenors(spreadCurve.getXData());
final Double[] marketSpreadObjects = CreditFunctionUtils.getSpreads(spreadCurve.getYData());
ParallelArrayBinarySort.parallelBinarySort(tenors, marketSpreadObjects);
final int n = tenors.length;
// assume new style IMM maturities
final CDSAnalyticFactory analyticFactory = new CDSAnalyticFactory(cds.getRecoveryRate(), cds.getCouponFrequency().getPeriod())
.with(cds.getBusinessDayAdjustmentConvention())
.with(calendar).with(cds.getStubType())
.withAccualDCC(cds.getDayCountFractionConvention());
final CDSAnalytic pricingCDS = analyticFactory.makeCDS(valuationTime.toLocalDate(), cds.getEffectiveDate().toLocalDate(), cds.getMaturityDate().toLocalDate());
double spread = 0;
final ZonedDateTime[] times = new ZonedDateTime[n];
final CDSAnalytic[] creditAnalytics = new CDSAnalytic[n];
final double[] marketSpreads = new double[n];
for (int i = 0; i < n; i++) {
ZonedDateTime nextIMM = IMMDateGenerator.getNextIMMDate(valuationTime, tenors[i]).withHour(0).withMinute(0).withSecond(0).withNano(0);
creditAnalytics[i] = analyticFactory.makeCDS(valuationTime.toLocalDate(), cds.getEffectiveDate().toLocalDate(), nextIMM.toLocalDate());
marketSpreads[i] = marketSpreadObjects[i] * 1e-4;
if (!nextIMM.isAfter(cds.getMaturityDate().withHour(0).withMinute(0).withSecond(0).withNano(0))) {
spread = marketSpreads[i];
}
}