25#include <ql/cashflows/coupon.hpp>
45Real GsrG(
const Real yf,
const Real reversion) {
46 if (std::fabs(reversion) < 1.0E-4)
49 return (1.0 - std::exp(-reversion * yf)) / reversion;
54 const Date& paymentDate,
55 const VanillaSwap& underlying,
56 const Handle<YieldTermStructure>& discountCurve) {
60 if (optionDate <= valuationDate)
61 return QuantLib::ext::make_shared<LinearAnnuityMapping>(0.0, 0.0);
65 if (
a_ != Null<Real>() &&
b_ != Null<Real>()) {
66 return QuantLib::ext::make_shared<LinearAnnuityMapping>(
a_,
b_);
68 Real atmForward = underlying.fairRate();
69 Real gx = 0.0, gy = 0.0;
70 for (Size i = 0; i < underlying.fixedLeg().size(); i++) {
71 QuantLib::ext::shared_ptr<Coupon> c = QuantLib::ext::dynamic_pointer_cast<Coupon>(underlying.fixedLeg()[i]);
72 Real yf = c->accrualPeriod();
73 Real pv = yf * discountCurve->discount(c->date());
74 gx += pv * GsrG(discountCurve->dayCounter().yearFraction(optionDate, c->date()),
reversion_->value());
78 Date lastd = underlying.fixedLeg().back()->date();
80 discountCurve->discount(paymentDate) *
81 (gamma - GsrG(discountCurve->dayCounter().yearFraction(optionDate, paymentDate),
reversion_->value())) /
82 (discountCurve->discount(lastd) *
83 GsrG(discountCurve->dayCounter().yearFraction(optionDate, lastd),
reversion_->value()) +
84 atmForward * gy * gamma);
85 Real b = discountCurve->discount(paymentDate) / gy - a * atmForward;
86 return QuantLib::ext::make_shared<LinearAnnuityMapping>(a, b);
88 QL_FAIL(
"LinearAnnuityMapping::build(): failed, because neither a, b nor a reversion is given");
QuantLib::ext::shared_ptr< AnnuityMapping > build(const Date &valuationDate, const Date &optionDate, const Date &paymentDate, const VanillaSwap &underlying, const Handle< YieldTermStructure > &discountCurve) override
Handle< Quote > reversion_
LinearAnnuityMappingBuilder(const Real a, const Real b)
Real map(const Real S) const override
LinearAnnuityMapping(const Real a, const Real b)
bool mapPrime2IsZero() const override
Real mapPrime(const Real S) const override
Real mapPrime2(const Real S) const override
linear annuity mapping function f(S) = a*S+b