39 std::upper_bound(
arguments_.fixedResetDates.begin(),
40 arguments_.fixedResetDates.end(), expiry - 1) -
43 std::upper_bound(
arguments_.floatingResetDates.begin(),
44 arguments_.floatingResetDates.end(), expiry - 1) -
52 for (
Size i = fixedIdx; i <
arguments_.fixedResetDates.size(); i++) {
59 : exp(-
oas_->value() *
60 model_->termStructure()->dayCounter().yearFraction(
64 for (
Size i = floatingIdx; i <
arguments_.floatingResetDates.size();
82 : exp(-
oas_->value() *
83 model_->termStructure()->dayCounter().yearFraction(
103 std::upper_bound(
arguments_.fixedResetDates.begin(),
104 arguments_.fixedResetDates.end(), expiry - 1) -
108 Real nominalSum = 0.0, weightedRate = 0.0, ind = 0.0;
109 for (
Size i = fixedIdx; i <
arguments_.fixedResetDates.size(); i++) {
112 if (
close(rate, 0.0))
114 weightedRate +=
arguments_.fixedNominal[i] * rate;
118 Real nominalAvg = nominalSum / ind;
121 "sum of nominals on fixed leg must be positive ("
122 << nominalSum <<
")");
124 weightedRate /= nominalSum;
125 initial[0] = nominalAvg;
128 model_->termStructure()->timeFromReference(expiry);
129 initial[2] = weightedRate;
137 "cash settled (ParYieldCurve) swaptions not priced with "
138 "Gaussian1dNonstandardSwaptionEngine");
140 Date settlement =
model_->termStructure()->referenceDate();
149 ext::shared_ptr<RebatedExercise> rebatedExercise =
150 ext::dynamic_pointer_cast<RebatedExercise>(
arguments_.exercise);
152 int idx =
arguments_.exercise->dates().size() - 1;
153 int minIdxAlive =
static_cast<int>(
154 std::upper_bound(
arguments_.exercise->dates().begin(),
155 arguments_.exercise->dates().end(), settlement) -
168 std::vector<Array> npvp0, npvp1;
170 for (
int i = 0; i < idx - minIdxAlive + 2; ++i) {
173 npvp0.push_back(npvTmp0);
174 npvp1.push_back(npvTmp1);
184 if (idx == minIdxAlive - 1)
185 expiry0 = settlement;
189 expiry0Time = std::max(
190 model_->termStructure()->timeFromReference(expiry0), 0.0);
193 std::upper_bound(
arguments_.fixedResetDates.begin(),
194 arguments_.fixedResetDates.end(), expiry0 - 1) -
197 std::upper_bound(
arguments_.floatingResetDates.begin(),
198 arguments_.floatingResetDates.end(), expiry0 - 1) -
203 for (
Size k = 0; k < (expiry0 > settlement ? npv0.size() : 1);
210 : std::exp(-
oas_->value() *
211 (expiry1Time - expiry0Time));
213 expiry1Time, expiry0Time,
214 expiry0 > settlement ? z[k] : 0.0);
220 for (
Size i = 0; i < yg.
size(); i++) {
221 p[i] = payoff0(yg[i],
true);
228 for (
Size i = 0; i < z.
size() - 1; i++) {
240 0.0, 0.0, 0.0, 0.0, p[z.
size() - 2],
241 z[z.
size() - 2], z[z.
size() - 1], 100.0) *
244 0.0, 0.0, 0.0, 0.0, p[0], z[0], -100.0,
256 z[z.
size() - 1], 100.0) *
274 for (
Size m = 0; m < npvp0.size(); m++) {
280 : std::exp(-
oas_->value() *
281 (expiry1Time - expiry0Time));
284 expiry0Time, expiry0 > settlement ? z[k] : 0.0);
286 z.
begin(), z.
end(), npvp1[m].begin(),
290 for (
Size i = 0; i < yg.
size(); i++) {
291 p[i] = payoff0(yg[i],
true);
298 for (
Size i = 0; i < z.
size() - 1; i++) {
314 z[z.
size() - 1], 100.0) *
318 0.0, 0.0, 0.0, 0.0, p[0],
319 z[0], -100.0, z[0]) *
334 z[z.
size() - 1], 100.0) *
358 if (expiry0 > settlement) {
359 Real floatingLegNpv = 0.0;
372 .floatingPayDates[l])));
391 Real fixedLegNpv = 0.0;
410 Real zSpreadDf = 1.0;
411 Date rebateDate = expiry0;
412 if (rebatedExercise !=
nullptr) {
413 rebate = rebatedExercise->rebate(idx);
414 rebateDate = rebatedExercise->rebatePaymentDate(idx);
422 .yearFraction(expiry0, rebateDate)));
426 (floatingLegNpv - fixedLegNpv) +
427 rebate *
model_->zerobond(rebateDate, expiry0, z[k],
434 if (idx ==
static_cast<int>(
442 : 1.0 / (
model_->zerobond(expiry0Time, 0.0,
445 model_->numeraire(expiry0, z[k],
447 if (exerciseValue >= npv0[k]) {
448 npvp0[idx - minIdxAlive][k] =
452 (
model_->zerobond(expiry0Time, 0.0,
455 model_->numeraire(expiry0Time, z[k],
457 for (
Size ii = idx - minIdxAlive + 1;
458 ii < npvp0.size(); ii++)
464 npv0[k] = std::max(npv0[k], exerciseValue);
472 for (
Size i = 0; i < npvp0.size(); i++)
473 npvp1[i].
swap(npvp0[i]);
478 expiry1Time = expiry0Time;
480 }
while (--idx >= minIdxAlive - 1);
486 std::vector<Real> prob(npvp0.size());
487 for (
Size i = 0; i < npvp0.size(); i++) {
488 prob[i] = npvp1[i][0] *
493 results_.additionalResults[
"probabilities"] = prob;
1-D array used in linear algebra.
void swap(Array &) noexcept
const_iterator end() const
Size size() const
dimension of the array
const_iterator begin() const
Cubic interpolation between discrete points.
const std::vector< Real > & cCoefficients() const
const std::vector< Real > & bCoefficients() const
const std::vector< Real > & aCoefficients() const
static Real gaussianShiftedPolynomialIntegral(Real a, Real b, Real c, Real d, Real e, Real h, Real x0, Real x1)
const bool extrapolatePayoff_
const Handle< YieldTermStructure > discountCurve_
const bool flatPayoffExtrapolation_
const Array initialGuess(const Date &expiry) const override
void calculate() const override
const int integrationPoints_
const Handle< Quote > oas_
const Date underlyingLastDate() const override
Real underlyingNpv(const Date &expiry, Real y) const override
Swap::Type underlyingType() const override
const Probabilities probabilities_
Handle< Gaussian1dModel > model_
template class providing a null value for a given type.
cubic interpolation between discrete points
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
Real Time
continuous quantity with 1-year units
std::size_t Size
size of a container
void swap(Array &v, Array &w) noexcept
bool close(const Quantity &m1, const Quantity &m2, Size n)
Option exercise with rebate payments.