final double[] bumpedDownMarketSpreads = new double[marketSpreads.length];
// ----------------------------------------------------------------------------------------------------------------------------------------
// Create a CDS Swaption PV calculator
final PresentValueCreditDefaultSwapOption creditDefaultSwapOption = new PresentValueCreditDefaultSwapOption();
// Calculate the unbumped CDS Swaption PV
final double presentValue = creditDefaultSwapOption.getPresentValueCreditDefaultSwapOption(valuationDate, cdsSwaption, sigma, marketTenors, marketSpreads, yieldCurve, hazardRateCurve);
// ----------------------------------------------------------------------------------------------------------------------------------------
// Loop through each of the spreads at each tenor
for (int m = 0; m < marketTenors.length; m++) {
// Reset the bumpedMarketSpreads vector to the original marketSpreads
for (int n = 0; n < marketTenors.length; n++) {
bumpedUpMarketSpreads[n] = marketSpreads[n];
bumpedDownMarketSpreads[n] = marketSpreads[n];
}
// Bump the spread at tenor m
if (spreadBumpType == SpreadBumpType.ADDITIVE_BUCKETED || spreadBumpType == SpreadBumpType.ADDITIVE) {
bumpedUpMarketSpreads[m] = marketSpreads[m] + spreadBump;
bumpedDownMarketSpreads[m] = marketSpreads[m] - spreadBump;
} else if (spreadBumpType == SpreadBumpType.MULTIPLICATIVE_BUCKETED || spreadBumpType == SpreadBumpType.MULTIPLICATIVE) {
bumpedUpMarketSpreads[m] = marketSpreads[m] * (1 + spreadBump);
bumpedDownMarketSpreads[m] = marketSpreads[m] * (1 - spreadBump);
} else {
throw new IllegalArgumentException("Cannot handle bumps of type " + spreadBumpType);
}
// Calculate the bumped up CDS Swaption PV
final double bumpedUpPresentValue = creditDefaultSwapOption.getPresentValueCreditDefaultSwapOption(valuationDate, cdsSwaption, sigma, marketTenors, bumpedUpMarketSpreads, yieldCurve,
hazardRateCurve);
// Calculate the bumped down CDS Swaption PV
final double bumpedDownPresentValue = creditDefaultSwapOption.getPresentValueCreditDefaultSwapOption(valuationDate, cdsSwaption, sigma, marketTenors, bumpedDownMarketSpreads, yieldCurve,
hazardRateCurve);
// Compute the bucketed gamma for this tenor
bucketedGamma[m] = (bumpedUpPresentValue - 2 * presentValue + bumpedDownPresentValue) / (2 * spreadBump);
}