QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
conundrumpricer.hpp
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
25#ifndef quantlib_conundrum_pricer_hpp
26#define quantlib_conundrum_pricer_hpp
27
28#include <ql/cashflows/couponpricer.hpp>
29#include <ql/instruments/payoffs.hpp>
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
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
200
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
249
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:
274 QL_DEPRECATED
276
280 QL_DEPRECATED
282 virtual ~Function() = default;
283 virtual Real operator()(Real x) const = 0;
284 };
285
287 friend class NumericHaganPricer;
288 public:
289 ConundrumIntegrand(ext::shared_ptr<VanillaOptionPricer> o,
290 const ext::shared_ptr<YieldTermStructure>& rateCurve,
291 ext::shared_ptr<GFunction> gFunction,
293 Date paymentDate,
295 Real forwardValue,
296 Real strike,
297 Option::Type optionType);
298 Real operator()(Real x) const override;
299
300 protected:
301 Real functionF(Real x) const;
304
305 Real strike() const;
306 Real annuity() const;
307 Date fixingDate() const;
308 void setStrike(Real strike);
309
310 const ext::shared_ptr<VanillaOptionPricer> vanillaOptionPricer_;
315 ext::shared_ptr<GFunction> gFunction_;
316 };
317
319 Real b,
320 const ConundrumIntegrand& Integrand) const;
321 Real optionletPrice(Option::Type optionType, Rate strike) const override;
322 Real swapletPrice() const override;
323 Real resetUpperLimit(Real stdDeviationsForUpperLimit) const;
324 Real resetLowerLimit(Real stdDeviationsForLowerLimit) const;
325 Real refineIntegration(Real integralValue, const ConundrumIntegrand& integrand) const;
326
331 };
332
335 public:
337 const Handle<SwaptionVolatilityStructure>& swaptionVol,
338 GFunctionFactory::YieldCurveModel modelOfYieldCurve,
340 protected:
341 Real optionletPrice(Option::Type optionType, Real strike) const override;
342 Real swapletPrice() const override;
343 };
344
345}
346
347
348#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
QL_DEPRECATED typedef Real argument_type
QL_DEPRECATED typedef Real result_type
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
#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)