QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
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 /*! \deprecated Renamed to MarketQuotedOptionPricer.
65 Deprecated in version 1.31.
66 */
67 [[deprecated("Renamed to MarketQuotedOptionPricer")]]
69
70 class GFunction {
71 public:
72 virtual ~GFunction() = default;
73 virtual Real operator()(Real x) = 0;
74 virtual Real firstDerivative(Real x) = 0;
75 virtual Real secondDerivative(Real x) = 0;
76 };
77
79 public:
84 };
85
86 GFunctionFactory() = delete;
87
88 static ext::shared_ptr<GFunction>
90 Real delta,
91 Size swapLength);
92 static ext::shared_ptr<GFunction>
93 newGFunctionExactYield(const CmsCoupon& coupon);
94 static ext::shared_ptr<GFunction>
96 const Handle<Quote>& meanReversion);
97 private:
99 public:
101 Real delta,
102 Size swapLength)
103 : q_(q), delta_(delta), swapLength_(swapLength) {}
104 Real operator()(Real x) override;
105 Real firstDerivative(Real x) override;
106 Real secondDerivative(Real x) override;
107
108 protected:
109 /* number of period per year */
110 const int q_;
111 /* fraction of a period between the swap start date and
112 the pay date */
114 /* length of swap*/
116 };
117
119 public:
120 GFunctionExactYield(const CmsCoupon& coupon);
121 Real operator()(Real x) override;
122 Real firstDerivative(Real x) override;
123 Real secondDerivative(Real x) override;
124
125 protected:
126 /* fraction of a period between the swap start date and
127 the pay date */
129 /* accruals fraction*/
130 std::vector<Time> accruals_;
131 };
132
134
136
138 std::vector<Time> shapedSwapPaymentTimes_;
139
140 std::vector<Time> accruals_;
141 std::vector<Real> swapPaymentDiscounts_;
143
146
147 Real calibratedShift_ = 0.03, tmpRs_ = 10000000.0;
148 const Real accuracy_ = 1.0e-14;
149
150 //* function describing the non-parallel shape of the curve shift*/
151 Real shapeOfShift(Real s) const;
152 //* calibration of shift*/
159
164 public:
165 virtual ~ObjectiveFunction() = default;
166 ObjectiveFunction(const GFunctionWithShifts& o, const Real Rs) : o_(o), Rs_(Rs) {}
167 virtual Real operator()(const Real& x) const;
168 Real derivative(const Real& x) const;
169 void setSwapRateValue(Real x);
170 const GFunctionWithShifts& gFunctionWithShifts() const { return o_; }
171 };
172
173 ext::shared_ptr<ObjectiveFunction> objectiveFunction_;
174 public:
175 GFunctionWithShifts(const CmsCoupon& coupon, Handle<Quote> meanReversion);
176 Real operator()(Real x) override;
177 Real firstDerivative(Real x) override;
178 Real secondDerivative(Real x) override;
179 };
180
181 };
182
183 inline std::ostream& operator<<(std::ostream& out,
185 switch (type) {
187 return out << "Standard";
189 return out << "ExactYield";
191 return out << "ParallelShifts";
193 return out << "NonParallelShifts";
194 default:
195 QL_FAIL("unknown option type");
196 }
197 }
198
199 //! CMS-coupon pricer
200 /*! Base class for the pricing of a CMS coupon via static replication
201 as in Hagan's "Conundrums..." article
202 */
204 public:
205 /* */
206 Real swapletPrice() const override = 0;
207 Rate swapletRate() const override;
208 Real capletPrice(Rate effectiveCap) const override;
209 Rate capletRate(Rate effectiveCap) const override;
210 Real floorletPrice(Rate effectiveFloor) const override;
211 Rate floorletRate(Rate effectiveFloor) const override;
212 /* */
213 Real meanReversion() const override;
218 update();
219 };
220
221 protected:
223 GFunctionFactory::YieldCurveModel modelOfYieldCurve,
225 void initialize(const FloatingRateCoupon& coupon) override;
226
227 virtual Real optionletPrice(Option::Type optionType,
228 Real strike) const = 0;
229
230 ext::shared_ptr<YieldTermStructure> rateCurve_;
232 ext::shared_ptr<GFunction> gFunction_;
244 ext::shared_ptr<VanillaOptionPricer> vanillaOptionPricer_;
245 };
246
247
248 //! CMS-coupon pricer
249 /*! Prices a cms coupon via static replication as in Hagan's
250 "Conundrums..." article via numerical integration based on
251 prices of vanilla swaptions
252 */
254 public:
256 const Handle<SwaptionVolatilityStructure>& swaptionVol,
257 GFunctionFactory::YieldCurveModel modelOfYieldCurve,
259 Rate lowerLimit = 0.0,
260 Rate upperLimit = 1.0,
261 Real precision = 1.0e-6,
262 Real hardUpperLimit = QL_MAX_REAL);
263
264 Real upperLimit() const { return upperLimit_; }
265 Real lowerLimit() const { return lowerLimit_; }
267
268 // private:
269 class Function {
270 public:
271 virtual ~Function() = default;
272 virtual Real operator()(Real x) const = 0;
273 };
274
276 friend class NumericHaganPricer;
277 public:
278 ConundrumIntegrand(ext::shared_ptr<VanillaOptionPricer> o,
279 const ext::shared_ptr<YieldTermStructure>& rateCurve,
280 ext::shared_ptr<GFunction> gFunction,
282 Date paymentDate,
284 Real forwardValue,
285 Real strike,
286 Option::Type optionType);
287 Real operator()(Real x) const override;
288
289 protected:
290 Real functionF(Real x) const;
293
294 Real strike() const;
295 Real annuity() const;
296 Date fixingDate() const;
297 void setStrike(Real strike);
298
299 const ext::shared_ptr<VanillaOptionPricer> vanillaOptionPricer_;
304 ext::shared_ptr<GFunction> gFunction_;
305 };
306
308 Real b,
309 const ConundrumIntegrand& Integrand) const;
310 Real optionletPrice(Option::Type optionType, Rate strike) const override;
311 Real swapletPrice() const override;
312 Real resetUpperLimit(Real stdDeviationsForUpperLimit) const;
313 Real resetLowerLimit(Real stdDeviationsForLowerLimit) const;
314 Real refineIntegration(Real integralValue, const ConundrumIntegrand& integrand) const;
315
320 };
321
322 //! CMS-coupon pricer
324 public:
326 const Handle<SwaptionVolatilityStructure>& swaptionVol,
327 GFunctionFactory::YieldCurveModel modelOfYieldCurve,
329 protected:
330 Real optionletPrice(Option::Type optionType, Real strike) const override;
331 Real swapletPrice() const override;
332 };
333
334}
335
336
337#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:245
std::pair< iterator, bool > registerWith(const ext::shared_ptr< Observable > &)
Definition: observable.hpp:228
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
ext::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:35
MarketQuotedOptionPricer BlackVanillaOptionPricer
std::ostream & operator<<(std::ostream &out, GFunctionFactory::YieldCurveModel type)
Payoffs for various options.
ext::shared_ptr< YieldTermStructure > q