QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.38
Loading...
Searching...
No Matches
conundrumpricer.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2006 Giorgio Facchinetti
3 Copyright (C) 2006 Mario Pucci
4 Copyright (C) 2023 Andre Miemiec
5
6
7 This file is part of QuantLib, a free-software/open-source library
8 for financial quantitative analysts and developers - http://quantlib.org/
9
10 QuantLib is free software: you can redistribute it and/or modify it
11 under the terms of the QuantLib license. You should have received a
12 copy of the license along with this program; if not, please email
13 <quantlib-dev@lists.sf.net>. The license is also available online at
14 <http://quantlib.org/license.shtml>.
15
16
17 This program is distributed in the hope that it will be useful, but
18 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19 or FITNESS FOR A PARTICULAR PURPOSE. See the license for more details. */
20
21/*! \file conundrumpricer.hpp
22 \brief CMS-coupon pricer
23*/
24
25#ifndef quantlib_conundrum_pricer_hpp
26#define quantlib_conundrum_pricer_hpp
27
30
31namespace QuantLib {
32
33 class CmsCoupon;
34 class YieldTermStructure;
35 class Quote;
36
38 public:
39 virtual ~VanillaOptionPricer() = default;
40 virtual Real operator()(Real strike,
41 Option::Type optionType,
42 Real deflator) const = 0;
43 };
44
46 public:
48 Rate forwardValue,
49 Date expiryDate,
50 const Period& swapTenor,
51 const ext::shared_ptr<SwaptionVolatilityStructure>&
52 volatilityStructure);
53
54 Real operator()(Real strike, Option::Type optionType, Real deflator) const override;
55
56 private:
60 ext::shared_ptr<SwaptionVolatilityStructure> volatilityStructure_;
61 ext::shared_ptr<SmileSection> smile_;
62 };
63
64 class GFunction {
65 public:
66 virtual ~GFunction() = default;
67 virtual Real operator()(Real x) = 0;
68 virtual Real firstDerivative(Real x) = 0;
69 virtual Real secondDerivative(Real x) = 0;
70 };
71
73 public:
78 };
79
80 GFunctionFactory() = delete;
81
82 static ext::shared_ptr<GFunction>
84 Real delta,
85 Size swapLength);
86 static ext::shared_ptr<GFunction>
87 newGFunctionExactYield(const CmsCoupon& coupon);
88 static ext::shared_ptr<GFunction>
90 const Handle<Quote>& meanReversion);
91 private:
93 public:
95 Real delta,
96 Size swapLength)
97 : q_(q), delta_(delta), swapLength_(swapLength) {}
98 Real operator()(Real x) override;
99 Real firstDerivative(Real x) override;
100 Real secondDerivative(Real x) override;
101
102 protected:
103 /* number of period per year */
104 const int q_;
105 /* fraction of a period between the swap start date and
106 the pay date */
108 /* length of swap*/
110 };
111
113 public:
114 GFunctionExactYield(const CmsCoupon& coupon);
115 Real operator()(Real x) override;
116 Real firstDerivative(Real x) override;
117 Real secondDerivative(Real x) override;
118
119 protected:
120 /* fraction of a period between the swap start date and
121 the pay date */
123 /* accruals fraction*/
124 std::vector<Time> accruals_;
125 };
126
128
130
132 std::vector<Time> shapedSwapPaymentTimes_;
133
134 std::vector<Time> accruals_;
135 std::vector<Real> swapPaymentDiscounts_;
137
140
141 Real calibratedShift_ = 0.03, tmpRs_ = 10000000.0;
142 const Real accuracy_ = 1.0e-14;
143
144 //* function describing the non-parallel shape of the curve shift*/
145 Real shapeOfShift(Real s) const;
146 //* calibration of shift*/
153
158 public:
159 virtual ~ObjectiveFunction() = default;
160 ObjectiveFunction(const GFunctionWithShifts& o, const Real Rs) : o_(o), Rs_(Rs) {}
161 virtual Real operator()(const Real& x) const;
162 Real derivative(const Real& x) const;
163 void setSwapRateValue(Real x);
164 const GFunctionWithShifts& gFunctionWithShifts() const { return o_; }
165 };
166
167 ext::shared_ptr<ObjectiveFunction> objectiveFunction_;
168 public:
169 GFunctionWithShifts(const CmsCoupon& coupon, Handle<Quote> meanReversion);
170 Real operator()(Real x) override;
171 Real firstDerivative(Real x) override;
172 Real secondDerivative(Real x) override;
173 };
174
175 };
176
177 inline std::ostream& operator<<(std::ostream& out,
179 switch (type) {
181 return out << "Standard";
183 return out << "ExactYield";
185 return out << "ParallelShifts";
187 return out << "NonParallelShifts";
188 default:
189 QL_FAIL("unknown option type");
190 }
191 }
192
193 //! CMS-coupon pricer
194 /*! Base class for the pricing of a CMS coupon via static replication
195 as in Hagan's "Conundrums..." article
196 */
198 public:
199 /* */
200 Real swapletPrice() const override = 0;
201 Rate swapletRate() const override;
202 Real capletPrice(Rate effectiveCap) const override;
203 Rate capletRate(Rate effectiveCap) const override;
204 Real floorletPrice(Rate effectiveFloor) const override;
205 Rate floorletRate(Rate effectiveFloor) const override;
206 /* */
207 Real meanReversion() const override;
212 update();
213 };
214
215 protected:
217 GFunctionFactory::YieldCurveModel modelOfYieldCurve,
219 void initialize(const FloatingRateCoupon& coupon) override;
220
221 virtual Real optionletPrice(Option::Type optionType,
222 Real strike) const = 0;
223
224 ext::shared_ptr<YieldTermStructure> rateCurve_;
226 ext::shared_ptr<GFunction> gFunction_;
238 ext::shared_ptr<VanillaOptionPricer> vanillaOptionPricer_;
239 };
240
241
242 //! CMS-coupon pricer
243 /*! Prices a cms coupon via static replication as in Hagan's
244 "Conundrums..." article via numerical integration based on
245 prices of vanilla swaptions
246 */
248 public:
250 const Handle<SwaptionVolatilityStructure>& swaptionVol,
251 GFunctionFactory::YieldCurveModel modelOfYieldCurve,
253 Rate lowerLimit = 0.0,
254 Rate upperLimit = 1.0,
255 Real precision = 1.0e-6,
256 Real hardUpperLimit = QL_MAX_REAL);
257
258 Real upperLimit() const { return upperLimit_; }
259 Real lowerLimit() const { return lowerLimit_; }
261
262 // private:
263 class Function {
264 public:
265 virtual ~Function() = default;
266 virtual Real operator()(Real x) const = 0;
267 };
268
270 friend class NumericHaganPricer;
271 public:
272 ConundrumIntegrand(ext::shared_ptr<VanillaOptionPricer> o,
273 const ext::shared_ptr<YieldTermStructure>& rateCurve,
274 ext::shared_ptr<GFunction> gFunction,
276 Date paymentDate,
278 Real forwardValue,
279 Real strike,
280 Option::Type optionType);
281 Real operator()(Real x) const override;
282
283 protected:
284 Real functionF(Real x) const;
287
288 Real strike() const;
289 Real annuity() const;
290 Date fixingDate() const;
291 void setStrike(Real strike);
292
293 const ext::shared_ptr<VanillaOptionPricer> vanillaOptionPricer_;
298 ext::shared_ptr<GFunction> gFunction_;
299 };
300
302 Real b,
303 const ConundrumIntegrand& Integrand) const;
304 Real optionletPrice(Option::Type optionType, Rate strike) const override;
305 Real swapletPrice() const override;
306 Real resetUpperLimit(Real stdDeviationsForUpperLimit) const;
307 Real resetLowerLimit(Real stdDeviationsForLowerLimit) const;
308 Real refineIntegration(Real integralValue, const ConundrumIntegrand& integrand) const;
309
314 };
315
316 //! CMS-coupon pricer
318 public:
320 const Handle<SwaptionVolatilityStructure>& swaptionVol,
321 GFunctionFactory::YieldCurveModel modelOfYieldCurve,
323 protected:
324 Real optionletPrice(Option::Type optionType, Real strike) const override;
325 Real swapletPrice() const override;
326 };
327
328}
329
330
331#endif
Real optionletPrice(Option::Type optionType, Real strike) const override
Real swapletPrice() const override
CMS coupon class.
Definition: cmscoupon.hpp:39
base pricer for vanilla CMS coupons
Concrete date class.
Definition: date.hpp:125
base floating-rate coupon class
GFunctionStandard(Size q, Real delta, Size swapLength)
ObjectiveFunction(const GFunctionWithShifts &o, const Real Rs)
ext::shared_ptr< ObjectiveFunction > objectiveFunction_
static ext::shared_ptr< GFunction > newGFunctionExactYield(const CmsCoupon &coupon)
static ext::shared_ptr< GFunction > newGFunctionStandard(Size q, Real delta, Size swapLength)
static ext::shared_ptr< GFunction > newGFunctionWithShifts(const CmsCoupon &coupon, const Handle< Quote > &meanReversion)
virtual ~GFunction()=default
virtual Real operator()(Real x)=0
virtual Real secondDerivative(Real x)=0
virtual Real firstDerivative(Real x)=0
CMS-coupon pricer.
ext::shared_ptr< GFunction > gFunction_
const CmsCoupon * coupon_
void setMeanReversion(const Handle< Quote > &meanReversion) override
Real capletPrice(Rate effectiveCap) const override
Rate floorletRate(Rate effectiveFloor) const override
Handle< Quote > meanReversion_
void initialize(const FloatingRateCoupon &coupon) override
virtual Real optionletPrice(Option::Type optionType, Real strike) const =0
ext::shared_ptr< VanillaOptionPricer > vanillaOptionPricer_
GFunctionFactory::YieldCurveModel modelOfYieldCurve_
ext::shared_ptr< YieldTermStructure > rateCurve_
Real swapletPrice() const override=0
Rate swapletRate() const override
Real floorletPrice(Rate effectiveFloor) const override
Real meanReversion() const override
Rate capletRate(Rate effectiveCap) const override
Shared handle to an observable.
Definition: handle.hpp:41
ext::shared_ptr< SwaptionVolatilityStructure > volatilityStructure_
ext::shared_ptr< SmileSection > smile_
Real operator()(Real strike, Option::Type optionType, Real deflator) const override
const ext::shared_ptr< VanillaOptionPricer > vanillaOptionPricer_
virtual Real operator()(Real x) const =0
Real optionletPrice(Option::Type optionType, Rate strike) const override
Real resetLowerLimit(Real stdDeviationsForLowerLimit) const
Real resetUpperLimit(Real stdDeviationsForUpperLimit) const
Real integrate(Real a, Real b, const ConundrumIntegrand &Integrand) const
Real swapletPrice() const override
Real refineIntegration(Real integralValue, const ConundrumIntegrand &integrand) const
Size unregisterWith(const ext::shared_ptr< Observable > &)
Definition: observable.hpp:243
std::pair< iterator, bool > registerWith(const ext::shared_ptr< Observable > &)
Definition: observable.hpp:226
virtual ~VanillaOptionPricer()=default
virtual Real operator()(Real strike, Option::Type optionType, Real deflator) const =0
Coupon pricers.
#define QL_FAIL(message)
throw an error (possibly with file and line information)
Definition: errors.hpp:92
std::function< Real(Real)> b
#define QL_MAX_REAL
Definition: qldefines.hpp:176
Real Time
continuous quantity with 1-year units
Definition: types.hpp:62
QL_REAL Real
real number
Definition: types.hpp:50
Real DiscountFactor
discount factor between dates
Definition: types.hpp:66
Real Spread
spreads on interest rates
Definition: types.hpp:74
Real Rate
interest rates
Definition: types.hpp:70
std::size_t Size
size of a container
Definition: types.hpp:58
Definition: any.hpp:37
std::ostream & operator<<(std::ostream &out, GFunctionFactory::YieldCurveModel type)
Payoffs for various options.
ext::shared_ptr< YieldTermStructure > q