// ----------------------------------------------------------------------------------------------------------------------------------------
// Create a CDS whose maturity and spreads we will vary to be that of the calibration instruments
LegacyVanillaCreditDefaultSwapDefinition calibrationCDS = cds;
// This vector will store the bootstrapped hazard rates that will be used to construct the calibrated hazard rate term structure object
double[] calibratedHazardRateCurve = new double[marketTenors.length];
// The tenorsAsDoubles vector includes time zero (valuationDate)
final double[] tenorsAsDoubles = new double[marketTenors.length + 1];
tenorsAsDoubles[0] = 0.0;
for (int m = 1; m <= marketTenors.length; m++) {
tenorsAsDoubles[m] = ACT_365.getDayCountFraction(valuationDate, marketTenors[m - 1]);
}
// ----------------------------------------------------------------------------------------------------------------------------------------
// Loop over each of the calibration instruments
for (int i = 0; i < marketTenors.length; i++) {
// Remember that the input spreads are in bps, therefore need dividing by 10,000
final double guess = (marketSpreads[i] / 10000.0) / (1 - cds.getRecoveryRate());
// Modify the input CDS to have the maturity of the current calibration instrument
calibrationCDS = calibrationCDS.withMaturityDate(marketTenors[i]);
// Modify the input CDS to have the par spread of the current calibration instrument
calibrationCDS = calibrationCDS.withSpread(marketSpreads[i]);
// Now need to build a HazardRateCurve object from the first i calibrated points
double[] runningTenorsAsDoubles = new double[i + 1];
double[] runningHazardRates = new double[i + 1];