30 "cash settled (ParYieldCurve) swaptions not priced with "
31 "Gaussian1dFloatFloatSwaptionEngine");
33 Date settlement =
model_->termStructure()->referenceDate();
45 ext::dynamic_pointer_cast<RebatedExercise>(
arguments_.exercise);
47 std::pair<Real, Real> result =
51 results_.additionalResults[
"underlyingValue"] = result.second;
57 return npvs(expiry,
y,
true).second;
68 return l2 >= l1 ? l2 : l1;
75 std::upper_bound(
arguments_.leg1ResetDates.begin(),
82 Real nominalSum1 = 0.0;
86 Real nominalAvg1 = nominalSum1 /
88 Real weightedMaturity1 = 0.0;
93 weightedMaturity1 /= nominalAvg1;
103 std::pair<Real, Real>
106 const bool includeExerciseOnExpiry,
107 const bool considerProbabilities)
const {
116 std::vector<Date> events;
117 events.insert(events.end(),
arguments_.exercise->dates().begin(),
119 events.insert(events.end(),
arguments_.leg1FixingDates.begin(),
121 events.insert(events.end(),
arguments_.leg2FixingDates.begin(),
123 std::sort(events.begin(), events.end());
125 auto it = std::unique(events.begin(), events.end());
126 events.resize(std::distance(events.begin(), it));
131 auto filit = std::upper_bound(events.begin(), events.end(),
132 expiry - (includeExerciseOnExpiry ? 1 : 0));
133 events.erase(events.begin(), filit);
135 int idx = events.size() - 1;
151 std::vector<Array> npvp0, npvp1;
154 (std::upper_bound(
arguments_.exercise->dates().begin(),
156 expiry - (includeExerciseOnExpiry ? 1 : 0)) -
160 for (
Size i = 0; i < noEx+1 ; ++i) {
163 npvp0.push_back(npvTmp0);
164 npvp1.push_back(npvTmp1);
172 ext::shared_ptr<IborIndex> ibor1 =
173 ext::dynamic_pointer_cast<IborIndex>(
arguments_.index1);
174 ext::shared_ptr<SwapIndex> cms1 =
175 ext::dynamic_pointer_cast<SwapIndex>(
arguments_.index1);
176 ext::shared_ptr<SwapSpreadIndex> cmsspread1 =
177 ext::dynamic_pointer_cast<SwapSpreadIndex>(
arguments_.index1);
178 ext::shared_ptr<IborIndex> ibor2 =
179 ext::dynamic_pointer_cast<IborIndex>(
arguments_.index2);
180 ext::shared_ptr<SwapIndex> cms2 =
181 ext::dynamic_pointer_cast<SwapIndex>(
arguments_.index2);
182 ext::shared_ptr<SwapSpreadIndex> cmsspread2 =
183 ext::dynamic_pointer_cast<SwapSpreadIndex>(
arguments_.index2);
185 QL_REQUIRE(ibor1 !=
nullptr || cms1 !=
nullptr || cmsspread1 !=
nullptr,
186 "index1 must be ibor or swap or swap spread index");
187 QL_REQUIRE(ibor2 !=
nullptr || cms2 !=
nullptr || cmsspread2 !=
nullptr,
188 "index2 must be ibor or swap or swap spread index");
195 bool isEventDate =
true;
200 event0 = events[idx];
201 if (event0 == expiry)
208 event0) !=
arguments_.exercise->dates().end();
218 event0Time = std::max(
219 model_->termStructure()->timeFromReference(event0), 0.0);
223 for (
Size k = 0; k < (event0 > expiry ? npv0.size() : 1); k++) {
227 Real price = 0.0, pricea = 0.0;
231 : std::exp(-
oas_->value() *
232 (event1Time - event0Time));
235 event0Time, event0 > expiry ? z[k] :
y);
246 for (
Size i = 0; i < yg.
size(); i++) {
247 p[i] = payoff0(yg[i],
true);
248 pa[i] = payoff0a(yg[i],
true);
260 for (
Size i = 0; i < z.
size() - 1; i++) {
278 0.0, 0.0, 0.0, 0.0, p[z.
size() - 2],
279 z[z.
size() - 2], z[z.
size() - 1], 100.0) *
282 0.0, 0.0, 0.0, 0.0, p[0], z[0], -100.0,
287 0.0, 0.0, 0.0, 0.0, pa[z.
size() - 2],
288 z[z.
size() - 2], z[z.
size() - 1], 100.0) *
291 0.0, 0.0, 0.0, 0.0, pa[0], z[0],
303 z[z.
size() - 1], 100.0) *
321 z[z.
size() - 1], 100.0) *
329 z[0], -100.0, z[0]) *
340 for (
Size m = 0; m < npvp0.size(); m++) {
346 : std::exp(-
oas_->value() *
347 (event1Time - event0Time));
350 event0Time, event0 > expiry ? z[k] : 0.0);
352 z.
begin(), z.
end(), npvp1[m].begin(),
356 for (
Size i = 0; i < yg.
size(); i++) {
357 p[i] = payoff0(yg[i],
true);
364 for (
Size i = 0; i < z.
size() - 1; i++) {
380 z[z.
size() - 1], 100.0) *
384 0.0, 0.0, 0.0, 0.0, p[0],
385 z[0], -100.0, z[0]) *
400 z[z.
size() - 1], 100.0) *
428 Real zk = event0 > expiry ? z[k] :
y;
454 Real estFixing = 0.0;
455 if (ibor1 !=
nullptr) {
456 estFixing =
model_->forwardRate(
460 if (cms1 !=
nullptr) {
461 estFixing =
model_->swapRate(
463 cms1->tenor(), event0, zk, cms1);
465 if (cmsspread1 !=
nullptr)
467 cmsspread1->gearing1() *
470 cmsspread1->swapIndex1()
473 cmsspread1->swapIndex1()) +
474 cmsspread1->gearing2() *
477 cmsspread1->swapIndex2()
480 cmsspread1->swapIndex2());
500 model_->numeraire(event0Time, zk,
504 if (j <
arguments_.leg1FixingDates.size() - 1) {
538 Real estFixing = 0.0;
539 if (ibor2 !=
nullptr)
540 estFixing =
model_->forwardRate(
arguments_.leg2FixingDates[j],event0,zk,ibor2);
542 estFixing =
model_->swapRate(
arguments_.leg2FixingDates[j],cms2->tenor(),event0,zk,cms2);
543 if (cmsspread2 !=
nullptr)
545 cmsspread2->gearing1() *
548 cmsspread2->swapIndex1()
551 cmsspread2->swapIndex1()) +
552 cmsspread2->gearing2() *
555 cmsspread2->swapIndex2()
558 cmsspread2->swapIndex2());
578 model_->numeraire(event0Time, zk,
581 if (j <
arguments_.leg2FixingDates.size() - 1) {
597 Real zSpreadDf = 1.0;
598 Date rebateDate = event0;
605 : std::exp(-
oas_->value() *
608 .yearFraction(event0,
613 rebate *
model_->zerobond(rebateDate, event0) *
614 zSpreadDf /
model_->numeraire(event0Time, zk,
625 : 1.0 / (
model_->zerobond(
626 event0Time, 0.0, 0.0,
632 if (exerciseValue >= npv0[k]) {
636 : 1.0 / (
model_->zerobond(
637 event0Time, 0.0, 0.0,
642 for (
Size ii = exIdx; ii < noEx+1; ++ii)
648 npv0[k] = std::max(npv0[k], exerciseValue);
661 for(
Size i=0;i<npvp0.size();++i) {
662 npvp1[i].swap(npvp0[i]);
668 event1Time = event0Time;
670 }
while (--idx >= -1);
672 std::pair<Real, Real> res(
679 std::vector<Real> prob(noEx+1);
680 for (
Size i = 0; i < noEx+1; i++) {
681 prob[i] = npvp1[i][0] *
686 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
const bool extrapolatePayoff_
std::pair< Real, Real > npvs(const Date &expiry, Real y, bool includeExerciseOnxpiry, bool considerProbabilities=false) const
const Handle< YieldTermStructure > discountCurve_
const bool flatPayoffExtrapolation_
const Array initialGuess(const Date &expiry) const override
ext::shared_ptr< RebatedExercise > rebatedExercise_
void calculate() const override
const int integrationPoints_
const Handle< Quote > oas_
const bool includeTodaysExercise_
const Date underlyingLastDate() const override
Real underlyingNpv(const Date &expiry, Real y) const override
Swap::Type underlyingType() const override
const Probabilities probabilities_
static Real gaussianShiftedPolynomialIntegral(Real a, Real b, Real c, Real d, Real e, Real h, Real x0, Real x1)
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
float float swaption engine for one factor interest rate models
Real Time
continuous quantity with 1-year units
std::size_t Size
size of a container
void swap(Array &v, Array &w) noexcept