24#include <ql/cashflows/cmscoupon.hpp>
25#include <ql/cashflows/fixedratecoupon.hpp>
26#include <ql/cashflows/iborcoupon.hpp>
27#include <ql/cashflows/lineartsrpricer.hpp>
28#include <ql/indexes/iborindex.hpp>
29#include <ql/instruments/vanillaswap.hpp>
30#include <ql/math/integrals/kronrodintegral.hpp>
31#include <ql/math/solvers1d/brent.hpp>
32#include <ql/pricingengines/blackformula.hpp>
33#include <ql/quotes/simplequote.hpp>
34#include <ql/termstructures/volatility/atmsmilesection.hpp>
35#include <ql/termstructures/yieldtermstructure.hpp>
36#include <ql/time/schedule.hpp>
41 class LinearTsrPricer::integrand_f {
42 const LinearTsrPricer* pricer;
44 explicit integrand_f(
const LinearTsrPricer* pricer) : pricer(pricer) {}
46 return pricer->integrand(x);
57 ext::shared_ptr<Integrator> integrator)
59 couponDiscountCurve_(
std::move(couponDiscountCurve)), settings_(settings),
60 volDayCounter_(swaptionVol->dayCounter()), integrator_(
std::move(integrator)) {
67 ext::make_shared<GaussKronrodNonAdaptive>(1E-10, 5000, 1E-10);
81 const Real strike)
const {
102 QL_REQUIRE(
coupon_,
"CMS coupon needed");
144 ext::shared_ptr<SmileSection> sectionTmp =
150 if(sectionTmp->volatilityType() ==
Normal) {
171 Real gx = 0.0, gy = 0.0;
172 for (
const auto& i :
swap_->fixedLeg()) {
173 ext::shared_ptr<Coupon> c = ext::dynamic_pointer_cast<Coupon>(i);
174 Real yf = c->accrualPeriod();
181 Real gamma = gx / gy;
182 Date lastd =
swap_->fixedLeg().back()->date();
196 Real referenceStrike)
const {
198 Real a, b, min, max, k;
201 min = referenceStrike;
210 max = referenceStrike;
218 k = solver.
solve(h, 1.0E-5, (a + b) / 2.0, a, b);
224 return std::min(std::max(k, min), max);
228 Real referenceStrike)
const {
230 Real a, b, min, max, k;
233 min = referenceStrike;
242 max = referenceStrike;
255 return std::min(std::max(k, min), max);
268 Real lower = strike, upper = strike;
308 Real lowerTmp, upperTmp;
310 upperTmp = (atm + shift) *
312 0.5 * atmVol * atmVol *
315 lowerTmp = (atm + shift) *
317 0.5 * atmVol * atmVol *
323 upperTmp = atm + tmp;
324 lowerTmp = atm - tmp;
341 if (tmpBound > lower) {
342 result += (*integrator_)(integrand_f(
this),
346 if (upper > tmpBound) {
347 result += (*integrator_)(integrand_f(
this),
371 const Rate Rs = std::max(
394 const Rate Rs = std::max(
428 atmCapletPrice - atmFloorletPrice) +
const ext::shared_ptr< SwapIndex > & swapIndex() const
base pricer for vanilla CMS coupons
Handle< SwaptionVolatilityStructure > swaptionVolatility() const
Date date() const override
Time accrualPeriod() const
accrual period as fraction of year
Time yearFraction(const Date &, const Date &, const Date &refPeriodStart=Date(), const Date &refPeriodEnd=Date()) const
Returns the period between two dates as a fraction of year.
base floating-rate coupon class
virtual Date fixingDate() const
fixing date
Real gearing() const
index gearing, i.e. multiplicative coefficient for the index
Spread spread() const
spread paid over the fixing of the underlying index
Shared handle to an observable.
const CmsCoupon * coupon_
Real couponDiscountRatio_
Real capletPrice(Rate effectiveCap) const override
Rate floorletRate(Rate effectiveFloor) const override
Handle< YieldTermStructure > discountCurve_
Real singularTerms(Option::Type type, Real strike) const
Real strikeFromPrice(Real price, Option::Type optionType, Real referenceStrike) const
Handle< Quote > meanReversion_
LinearTsrPricer(const Handle< SwaptionVolatilityStructure > &swaptionVol, Handle< Quote > meanReversion, Handle< YieldTermStructure > couponDiscountCurve=Handle< YieldTermStructure >(), const Settings &settings=Settings(), ext::shared_ptr< Integrator > integrator=ext::shared_ptr< Integrator >())
ext::shared_ptr< SmileSection > smileSection_
void initialize(const FloatingRateCoupon &coupon) override
ext::shared_ptr< VanillaSwap > swap_
ext::shared_ptr< Integrator > integrator_
DayCounter volDayCounter_
ext::shared_ptr< SwapIndex > swapIndex_
static const Real defaultLowerBound
Real integrand(Real strike) const
Real strikeFromVegaRatio(Real ratio, Option::Type optionType, Real referenceStrike) const
static const Real defaultUpperBound
Handle< YieldTermStructure > couponDiscountCurve_
Real GsrG(const Date &d) const
Rate swapletRate() const override
Real floorletPrice(Rate effectiveFloor) const override
Real meanReversion() const override
Handle< YieldTermStructure > forwardCurve_
Real swapletPrice() const override
Real optionletPrice(Option::Type optionType, Real strike) const
Rate capletRate(Rate effectiveCap) const override
template class providing a null value for a given type.
std::pair< iterator, bool > registerWith(const ext::shared_ptr< Observable > &)
static Settings & instance()
access to the unique instance
Real solve(const F &f, Real accuracy, Real guess, Real step) const