final double[] tenorsAsDoubles = SCHEDULE_GENERATOR.convertTenorsToDoubles(marketTenors, valuationDate, DayCountFactory.INSTANCE.getDayCount("ACT/365"));
// ----------------------------------------------------------------------------------------------------------------------------------------
// Create a calibration CDS object from the input CDS (maturity and contractual spread of this CDS will vary as we bootstrap up the hazard rate term structure)
LegacyCreditDefaultSwapDefinition calibrationCDS = cds;
// ----------------------------------------------------------------------------------------------------------------------------------------
// Loop through each of the input tenors
for (int m = 0; m < marketTenors.length; m++) {
// Construct a temporary vector of the first m tenors (note size of array)
final ZonedDateTime[] runningTenors = new ZonedDateTime[m + 1];
final double[] runningTenorsAsDoubles = new double[m + 1];
// Construct a temporary vector of the hazard rates corresponding to the first m tenors (note size of array)
final double[] runningHazardRates = new double[m + 1];
// Populate these vector with the first m tenors (needed to construct the survival curve using these tenors)
for (int i = 0; i <= m; i++) {
runningTenors[i] = marketTenors[i];
runningTenorsAsDoubles[i] = tenorsAsDoubles[i];
runningHazardRates[i] = hazardRates[i];
}
// Modify the calibration CDS to have a maturity of tenor[m]
calibrationCDS = (LegacyCreditDefaultSwapDefinition) calibrationCDS.withMaturityDate(marketTenors[m]);
// Modify the calibration CDS to have a contractual spread of marketSpread[m]
calibrationCDS = calibrationCDS.withSpread(marketSpreads[m]);
// Compute the calibrated hazard rate for tenor[m] (using the calibrated hazard rates for tenors 1, ..., m - 1)
hazardRates[m] = calibrateHazardRate(valuationDate, calibrationCDS, yieldCurve, runningTenors, runningTenorsAsDoubles, runningHazardRates, priceType);
}