29 "cash settled (ParYieldCurve) swaptions not priced with "
30 "Gaussian1dSwaptionEngine");
33 "non-constant nominals are not supported yet");
35 Date settlement =
model_->termStructure()->referenceDate();
44 int idx =
static_cast<int>(
arguments_.exercise->dates().size()) - 1;
45 int minIdxAlive =
static_cast<int>(
46 std::upper_bound(
arguments_.exercise->dates().begin(),
47 arguments_.exercise->dates().end(), settlement) -
54 const Schedule& floatSchedule =
swap->floatingSchedule();
62 std::vector<Array> npvp0, npvp1;
64 for (
int i = 0; i < idx - minIdxAlive + 2; ++i) {
67 npvp0.push_back(npvTmp0);
68 npvp1.push_back(npvTmp1);
78 if (idx == minIdxAlive - 1)
83 expiry0Time = std::max(
84 model_->termStructure()->timeFromReference(expiry0), 0.0);
87 std::upper_bound(fixedSchedule.
dates().begin(),
88 fixedSchedule.
dates().end(), expiry0 - 1) -
89 fixedSchedule.
dates().begin();
91 std::upper_bound(floatSchedule.
dates().begin(),
92 floatSchedule.
dates().end(), expiry0 - 1) -
93 floatSchedule.
dates().begin();
105 if (expiry0 > settlement) {
121#pragma omp parallel for default(shared) firstprivate(p) if(expiry0>settlement)
122 for (
long k = 0; k < (expiry0 > settlement ? (long)npv0.size() : 1);
128 expiry1Time, expiry0Time,
129 expiry0 > settlement ? z[k] : 0.0);
135 for (
Size i = 0; i < yg.
size(); i++) {
136 p[i] = payoff0(yg[i],
true);
143 for (
Size i = 0; i < z.
size() - 1; i++) {
153 0.0, 0.0, 0.0, 0.0, p[z.
size() - 2],
154 z[z.
size() - 2], z[z.
size() - 1], 100.0);
156 0.0, 0.0, 0.0, 0.0, p[0], z[0], -100.0, z[0]);
166 z[z.
size() - 1], 100.0);
182 for (
Size m = 0; m < npvp0.size(); m++) {
187 expiry0Time, expiry0 > settlement ? z[k] : 0.0);
189 z.
begin(), z.
end(), npvp1[m].begin(),
193 for (
Size i = 0; i < yg.
size(); i++) {
194 p[i] = payoff0(yg[i],
true);
201 for (
Size i = 0; i < z.
size() - 1; i++) {
216 z[z.
size() - 1], 100.0);
219 0.0, 0.0, 0.0, 0.0, p[0],
234 z[z.
size() - 1], 100.0);
245 p[0], z[0], -100.0, z[0]);
255 if (expiry0 > settlement) {
256 Real floatingLegNpv = 0.0;
269 Real fixedLegNpv = 0.0;
278 (floatingLegNpv - fixedLegNpv) /
283 if (idx ==
static_cast<int>(
291 : 1.0 / (
model_->zerobond(expiry0Time, 0.0,
294 model_->numeraire(expiry0, z[k],
296 if (exerciseValue >= npv0[k]) {
297 npvp0[idx - minIdxAlive][k] =
301 (
model_->zerobond(expiry0Time, 0.0,
304 model_->numeraire(expiry0Time, z[k],
306 for (
Size ii = idx - minIdxAlive + 1;
307 ii < npvp0.size(); ii++)
313 npv0[k] = std::max(npv0[k], exerciseValue);
321 for (
Size i = 0; i < npvp0.size(); i++)
322 npvp1[i].
swap(npvp0[i]);
327 expiry1Time = expiry0Time;
329 }
while (--idx >= minIdxAlive - 1);
335 std::vector<Real> prob(npvp0.size());
336 for (
Size i = 0; i < npvp0.size(); i++) {
337 prob[i] = npvp1[i][0] *
342 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_
void calculate() const override
const int integrationPoints_
const Probabilities probabilities_
Handle< Gaussian1dModel > model_
template class providing a null value for a given type.
const std::vector< Date > & dates() const
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