Skip to content

Commit 127314a

Browse files
pcaspersjenkins
authored andcommitted
QPR-12424 handle edge cases
1 parent f5d04e3 commit 127314a

1 file changed

Lines changed: 13 additions & 7 deletions

File tree

QuantExt/qle/pricingengines/numericalintegrationindexcdsoptionengine.cpp

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -223,13 +223,19 @@ void NumericalIntegrationIndexCdsOptionEngine::doCalc() const {
223223
};
224224

225225
Real fepAdjustedForwardSpread;
226-
Brent brent;
227-
brent.setLowerBound(1.0E-8);
228-
try {
229-
fepAdjustedForwardSpread = brent.solve(target, 1.0E-7, arguments_.swap->fairSpreadClean(), 0.0001);
230-
} catch (const std::exception& e) {
231-
QL_FAIL(
232-
"NumericalIntegrationIndexCdsOptionEngine::doCalc(): failed to calibrate forward spread: " << e.what());
226+
if (target(0.0) > 0.0) {
227+
// the target function might not have a zero, because of the continuous annuity approximation
228+
// in some extreme situations (e.g. survival prob = 1 everywhere)
229+
fepAdjustedForwardSpread = 0.0;
230+
} else {
231+
Brent brent;
232+
brent.setLowerBound(0.0);
233+
try {
234+
fepAdjustedForwardSpread = brent.solve(target, 1.0E-7, arguments_.swap->fairSpreadClean(), 0.0001);
235+
} catch (const std::exception& e) {
236+
QL_FAIL("NumericalIntegrationIndexCdsOptionEngine::doCalc(): failed to calibrate forward spread: "
237+
<< e.what());
238+
}
233239
}
234240
results_.additionalResults["fepAdjustedForwardSpread"] = fepAdjustedForwardSpread;
235241
results_.additionalResults["forwardSpread"] = arguments_.swap->fairSpreadClean();

0 commit comments

Comments
 (0)