22#include <ql/cashflows/cmscoupon.hpp>
23#include <ql/cashflows/fixedratecoupon.hpp>
24#include <ql/cashflows/iborcoupon.hpp>
25#include <ql/cashflows/lineartsrpricer.hpp>
26#include <ql/indexes/iborindex.hpp>
27#include <ql/instruments/vanillaswap.hpp>
28#include <ql/math/integrals/kronrodintegral.hpp>
29#include <ql/math/solvers1d/brent.hpp>
30#include <ql/pricingengines/blackformula.hpp>
31#include <ql/quotes/simplequote.hpp>
32#include <ql/termstructures/volatility/atmsmilesection.hpp>
33#include <ql/time/schedule.hpp>
38 const Handle<SwaptionVolatilityStructure>& swaptionVol,
39 const QuantLib::ext::shared_ptr<AnnuityMappingBuilder>& annuityMappingBuilder,
const Real lowerIntegrationBound,
40 const Real upperIntegrationBound,
const QuantLib::ext::shared_ptr<Integrator>& integrator)
41 :
CmsCouponPricer(swaptionVol), annuityMappingBuilder_(annuityMappingBuilder),
42 lowerIntegrationBound_(lowerIntegrationBound), upperIntegrationBound_(upperIntegrationBound),
43 integrator_(integrator) {
45 integrator_ = ext::make_shared<GaussKronrodNonAdaptive>(1E-10, 5000, 1E-10);
51 QL_FAIL(
"DurationAdjustedCmsCouponTsrPricer::swapletPrice() is not implemented");
55 QL_FAIL(
"DurationAdjustedCmsCouponTsrPricer::swapletPrice() is not implemented");
59 QL_FAIL(
"DurationAdjustedCmsCouponTsrPricer::swapletPrice() is not implemented");
86 QL_REQUIRE(
coupon_,
"DurationAdjustedCmsCoupon needed");
87 today_ = QuantLib::Settings::instance().evaluationDate();
91 Handle<YieldTermStructure> discountCurve;
117 if (swaptionVolatility()->volatilityType() == ShiftedLognormal) {
118 effectiveLowerIntegrationBound = std::max(
124 if (optionType == Option::Call)
125 effectiveLowerIntegrationBound = std::max(effectiveLowerIntegrationBound, strike);
127 effectiveUpperIntegrationBound = std::min(effectiveUpperIntegrationBound, strike);
130 Real omega = optionType == Option::Call ? 1.0 : -1.0;
134 if (effectiveLowerIntegrationBound < effectiveUpperIntegrationBound &&
135 !
close_enough(effectiveLowerIntegrationBound, effectiveUpperIntegrationBound)) {
137 auto f = [
this, strike, omega](
const Real S) -> Real {
141 auto fp = [
this, strike, omega](
const Real S) -> Real {
143 return omega * (omega * S > omega * strike ? 1.0 : 0.0);
147 dp -=
static_cast<Real
>(i + 1) / std::pow(1.0 + this->
swapRate_, i + 2);
150 dp * std::max(omega * (S - strike), 0.0);
154 auto fpp = [
this, strike, omega](
const Real S) -> Real {
158 Real dp1 = 0.0, dp2 = 0.0;
160 dp1 -=
static_cast<Real
>(i + 1) / std::pow(1.0 + this->
swapRate_, i + 2);
161 dp2 +=
static_cast<Real
>(i + 1) *
static_cast<Real
>(i + 2) / std::pow(1.0 + this->
swapRate_, i + 3);
163 return dp1 * omega * (omega * S > omega * strike ? 1.0 : 0.0) +
164 dp2 * std::max(omega * (S - strike), 0.0);
168 auto integrand = [
this, &f, &fp, &fpp](
const Real S) -> Real {
182 tmpBound = std::min(effectiveUpperIntegrationBound,
swapRate_);
183 if (tmpBound > effectiveLowerIntegrationBound)
184 integral += (*integrator_)(integrand, effectiveLowerIntegrationBound, tmpBound);
185 tmpBound = std::max(effectiveLowerIntegrationBound,
swapRate_);
186 if (effectiveUpperIntegrationBound > tmpBound)
187 integral += (*integrator_)(integrand, tmpBound, effectiveUpperIntegrationBound);
189 integral = (*integrator_)(integrand, effectiveLowerIntegrationBound, effectiveUpperIntegrationBound);
Real durationAdjustment() const
const QuantLib::ext::shared_ptr< SwapIndex > & swapIndex() const
Real capletPrice(Rate effectiveCap) const override
Rate floorletRate(Rate effectiveFloor) const override
QuantLib::ext::shared_ptr< SmileSection > smileSection_
Real optionletRate(Option::Type type, Real effectiveStrike) const
const DurationAdjustedCmsCoupon * coupon_
void initialize(const FloatingRateCoupon &coupon) override
Real lowerIntegrationBound_
QuantLib::ext::shared_ptr< AnnuityMappingBuilder > annuityMappingBuilder_
DurationAdjustedCmsCouponTsrPricer(const Handle< SwaptionVolatilityStructure > &swaptionVol, const QuantLib::ext::shared_ptr< AnnuityMappingBuilder > &annuityMappingBuilder, const Real lowerIntegrationBound=-0.3, const Real upperIntegrationBound=0.3, const QuantLib::ext::shared_ptr< Integrator > &integrator=QuantLib::ext::shared_ptr< Integrator >())
QuantLib::ext::shared_ptr< Integrator > integrator_
Rate swapletRate() const override
Real upperIntegrationBound_
Real floorletPrice(Rate effectiveFloor) const override
Real swapletPrice() const override
Rate capletRate(Rate effectiveCap) const override
QuantLib::ext::shared_ptr< AnnuityMapping > annuityMapping_
cms coupon scaled by a duration number
tsr coupon pricer for duration adjusted cms coupon
Real integral(const CrossAssetModel &model, const E &e, const Real a, const Real b)
Filter close_enough(const RandomVariable &x, const RandomVariable &y)