34 std::vector<ext::shared_ptr<BlackCalibrationHelper>>
36 const ext::shared_ptr<Exercise>& exercise,
37 const ext::shared_ptr<SwapIndex>& standardSwapBase,
38 const ext::shared_ptr<SwaptionVolatilityStructure>& swaptionVolatility,
42 !standardSwapBase->forwardingTermStructure().empty(),
43 "standard swap base forwarding term structure must not be empty.");
45 !standardSwapBase->exogenousDiscount() ||
46 !standardSwapBase->discountingTermStructure().empty(),
47 "standard swap base discounting term structure must not be empty.");
49 std::vector<ext::shared_ptr<BlackCalibrationHelper> > result;
52 Size minIdxAlive =
static_cast<Size>(
53 std::upper_bound(exercise->dates().begin(), exercise->dates().end(),
55 exercise->dates().begin());
57 ext::shared_ptr<RebatedExercise> rebEx =
58 ext::dynamic_pointer_cast<RebatedExercise>(exercise);
60 for (
Size i = minIdxAlive; i < exercise->dates().size(); i++) {
62 Date expiry = exercise->date(i);
64 Date rebateDate = expiry;
65 if (rebEx !=
nullptr) {
66 rebate = rebEx->rebate(i);
67 rebateDate = rebEx->rebatePaymentDate(i);
70 ext::shared_ptr<SwaptionHelper> helper;
75 Real swapLength = swaptionVolatility->dayCounter().yearFraction(
77 ext::shared_ptr<SmileSection> sec =
78 swaptionVolatility->smileSection(
80 static_cast<Size>(std::lround(swapLength * 12.0)) *
Months,
82 Real atmStrike = sec->atmLevel();
85 atmVol = sec->volatility(0.03);
87 atmVol = sec->volatility(atmStrike);
88 Real shift = sec->shift();
90 helper = ext::make_shared<SwaptionHelper>(
93 standardSwapBase->iborIndex(),
94 standardSwapBase->fixedLegTenor(),
95 standardSwapBase->dayCounter(),
96 standardSwapBase->iborIndex()->dayCounter(),
97 standardSwapBase->exogenousDiscount()
98 ? standardSwapBase->discountingTermStructure()
99 : standardSwapBase->forwardingTermStructure(),
101 swaptionVolatility->volatilityType() ,shift);
111 const Real h = 0.0001;
115 : exp(-
oas_->value() *
118 .yearFraction(expiry, rebateDate));
135 Real delta = (npvp - npvm) / (2.0 * h);
136 Real gamma = (npvp - 2.0 * npv + npvm) / (h * h);
138 QL_REQUIRE(npv * npv + delta * delta + gamma * gamma > 0.0,
139 "(npv,delta,gamma) must have a positive norm");
159 swaptionVolatility->dayCounter().yearFraction(
162 ext::shared_ptr<MatchHelper> matchHelper_;
163 matchHelper_ = ext::make_shared<MatchHelper>(
165 standardSwapBase, expiry, maxMaturity, h);
170 "initial guess must have size 3 (but is "
171 << initial.
size() <<
")");
179 Problem p(*matchHelper_, constraint, initial);
186 "optimizer returns error (" << ret <<
")");
189 Real maturity = fabs(solution[1]);
203 ext::shared_ptr<SmileSection> sec =
204 swaptionVolatility->smileSection(expiry, matPeriod,
true);
205 Real shift = sec->shift();
209 solution[2] = std::max(
210 solution[2], 0.00001 - shift);
214 std::max(solution[0], 0.000001);
216 Real vol = sec->volatility(solution[2]);
218 helper = ext::make_shared<SwaptionHelper>(
222 standardSwapBase->iborIndex(),
223 standardSwapBase->fixedLegTenor(),
224 standardSwapBase->dayCounter(),
225 standardSwapBase->iborIndex()->dayCounter(),
226 standardSwapBase->exogenousDiscount()
227 ? standardSwapBase->discountingTermStructure()
228 : standardSwapBase->forwardingTermStructure(),
230 fabs(solution[0]), swaptionVolatility->volatilityType(), shift);
235 QL_FAIL(
"Calibration basket type not known (" << basketType
239 result.push_back(helper);
base class for pricing engines capable of generating a calibration basket
1-D array used in linear algebra.
Size size() const
dimension of the array
const Handle< YieldTermStructure > discountCurve_
virtual Real underlyingNpv(const Date &expiry, Real y) const =0
std::vector< ext::shared_ptr< BlackCalibrationHelper > > calibrationBasket(const ext::shared_ptr< Exercise > &exercise, const ext::shared_ptr< SwapIndex > &standardSwapBase, const ext::shared_ptr< SwaptionVolatilityStructure > &swaptionVolatility, CalibrationBasketType basketType=MaturityStrikeByDeltaGamma) const
const Handle< Quote > oas_
virtual const Date underlyingLastDate() const =0
virtual const Array initialGuess(const Date &expiry) const =0
const Handle< Gaussian1dModel > onefactormodel_
@ MaturityStrikeByDeltaGamma
virtual Swap::Type underlyingType() const =0
static Date maxDate()
latest allowed date
Criteria to end optimization process:
Shared handle to an observable.
Levenberg-Marquardt optimization method.
EndCriteria::Type minimize(Problem &P, const EndCriteria &endCriteria) override
minimize the optimization problem P
template class providing a null value for a given type.
Constrained optimization problem.
const Array & currentValue() const
current value of the local minimum
DateProxy & evaluationDate()
the date at which pricing is to be performed.
static Settings & instance()
access to the unique instance
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
#define QL_FAIL(message)
throw an error (possibly with file and line information)
std::size_t Size
size of a container
Levenberg-Marquardt optimization method.
Real months(const Period &p)
Real years(const Period &p)
Option exercise with rebate payments.
Simplex optimization method.
Swaption calibration helper.
Swaption volatility cube.