Skip to content

Commit 5889741

Browse files
pcaspersjenkins
authored andcommitted
QPR-12325 handle too few market points, fixes
1 parent d28da25 commit 5889741

2 files changed

Lines changed: 17 additions & 5 deletions

File tree

QuantExt/qle/termstructures/sabrparametricvolatility.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,13 +258,26 @@ std::tuple<std::vector<Real>, Real, Size>
258258
SabrParametricVolatility::calibrateModelParameters(const MarketSmile& marketSmile,
259259
const std::vector<std::pair<Real, bool>>& params) const {
260260

261-
// check the number of free parameters vs. the number of given market points
261+
// determine the number of free parameters
262262

263263
Size noFreeParams = 0;
264264
for (auto const& p : params)
265265
if (!p.second)
266266
++noFreeParams;
267267

268+
// if there are no free parameters, we just pass back the fixed parameters as the result
269+
270+
if(noFreeParams == 0) {
271+
std::vector<Real> resultParams;
272+
for(auto const& p : params)
273+
resultParams.push_back(p.first);
274+
return std::make_tuple(resultParams, 0.0, 0);
275+
}
276+
277+
// if we have less data points than free parameters -> exit early
278+
279+
QL_REQUIRE(noFreeParams <= marketSmile.strikes.size(), "internal: less data points than free parameters");
280+
268281
// define the target function
269282

270283
struct TargetFunction : public QuantLib::CostFunction {

QuantExt/qle/termstructures/sabrparametricvolatility.hpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,15 @@ class SabrParametricVolatility final : public ParametricVolatility {
6161
const std::vector<Real>& underlyingLenghts() const;
6262
// calibrated or interpolated model parameters (rows = underlying lenghts, cols = option expiries)
6363
const QuantLib::Matrix& alpha() const { return alpha_; }
64-
const QuantLib::Matrix& beta() const { return beta_; }
64+
const QuantLib::Matrix& beta() const { return beta_; }
6565
const QuantLib::Matrix& nu() const { return nu_; }
6666
const QuantLib::Matrix& rho() const { return rho_; }
6767
const QuantLib::Matrix& lognormalShift() const { return lognormalShift_; }
6868
const QuantLib::Matrix& numberOfCalibrationAttempts() const { return numberOfCalibrationAttempts_; }
6969
// calibration error
70-
const QuantLib::Matrix& calibrationError() const;
70+
const QuantLib::Matrix& calibrationError() const { return calibrationError_; }
7171
// indicator whether smile params were interpolated (1) or calibrated (0)
72-
const QuantLib::Matrix& isInterpolated() const;
73-
72+
const QuantLib::Matrix& isInterpolated() const { return isInterpolated_; }
7473

7574
private:
7675
static constexpr double eps1 = .0000001;

0 commit comments

Comments
 (0)