QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
lineartsrpricer.hpp
Go to the documentation of this file.
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2014, 2016 Peter Caspers
5
6 This file is part of QuantLib, a free-software/open-source library
7 for financial quantitative analysts and developers - http://quantlib.org/
8
9 QuantLib is free software: you can redistribute it and/or modify it
10 under the terms of the QuantLib license. You should have received a
11 copy of the license along with this program; if not, please email
12 <quantlib-dev@lists.sf.net>. The license is also available online at
13 <http://quantlib.org/license.shtml>.
14
15
16 This program is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
18 or FITNESS FOR A PARTICULAR PURPOSE. See the license for more details. */
19
20/*! \file lineartsrpricer.hpp
21 \brief linear terminal swap rate model for cms coupon pricing
22*/
23
24#ifndef quantlib_lineartsr_pricer_hpp
25#define quantlib_lineartsr_pricer_hpp
26
33
34namespace QuantLib {
35
36 class CmsCoupon;
37 class YieldTermStructure;
38
39 //! CMS-coupon pricer
40 /*! Prices a cms coupon using a linear terminal swap rate model
41 The slope parameter is linked to a gaussian short rate model.
42 Reference: Andersen, Piterbarg, Interest Rate Modeling, 16.3.2
43
44 The cut off point for integration can be set
45 - by explicitly specifying the lower and upper bound
46 - by defining the lower and upper bound to be the strike where
47 a vanilla swaption has 1% or less vega of the atm swaption
48 - by defining the lower and upper bound to be the strike where
49 undeflated (!) payer resp. receiver prices are below a given
50 threshold
51 - by specificying a number of standard deviations to cover
52 using a Black Scholes process with an atm volatility as
53 a benchmark
54 In every case the lower and upper bound are applied though.
55 In case the smile section is shifted lognormal, the specified
56 lower and upper bound are applied to strike + shift so that
57 e.g. a zero lower bound always refers to the lower bound of
58 the rates in the shifted lognormal model.
59 Note that for normal volatility input the lower rate bound
60 is adjusted to min(-upperBound, lowerBound), except the bounds
61 are set explicitly.
62 */
63
65
66 private:
67 static const Real defaultLowerBound,
69
70 public:
71
72 struct Settings {
73
75
77 const Real upperRateBound = defaultUpperBound) {
79 lowerRateBound_ = lowerRateBound;
80 upperRateBound_ = upperRateBound;
81 defaultBounds_ = false;
82 return *this;
83 }
84
85 Settings &withVegaRatio(const Real vegaRatio = 0.01) {
87 vegaRatio_ = vegaRatio;
90 defaultBounds_ = true;
91 return *this;
92 }
93
94 Settings &withVegaRatio(const Real vegaRatio,
95 const Real lowerRateBound,
96 const Real upperRateBound) {
98 vegaRatio_ = vegaRatio;
99 lowerRateBound_ = lowerRateBound;
100 upperRateBound_ = upperRateBound;
101 defaultBounds_ = false;
102 return *this;
103 }
104
105 Settings &withPriceThreshold(const Real priceThreshold = 1.0E-8) {
107 priceThreshold_ = priceThreshold;
110 defaultBounds_ = true;
111 return *this;
112 }
113
114 Settings &withPriceThreshold(const Real priceThreshold,
115 const Real lowerRateBound,
116 const Real upperRateBound) {
118 priceThreshold_ = priceThreshold;
119 lowerRateBound_ = lowerRateBound;
120 upperRateBound_ = upperRateBound;
121 defaultBounds_ = false;
122 return *this;
123 }
124
125 Settings &withBSStdDevs(const Real stdDevs = 3.0) {
127 stdDevs_ = stdDevs;
130 defaultBounds_ = true;
131 return *this;
132 }
133
135 const Real lowerRateBound,
136 const Real upperRateBound) {
138 stdDevs_ = stdDevs;
139 lowerRateBound_ = lowerRateBound;
140 upperRateBound_ = upperRateBound;
141 defaultBounds_ = false;
142 return *this;
143 }
144
145 enum Strategy {
150 };
151
157 bool defaultBounds_ = true;
158 };
159
160
162 const Handle<SwaptionVolatilityStructure>& swaptionVol,
165 const Settings& settings = Settings(),
166 ext::shared_ptr<Integrator> integrator = ext::shared_ptr<Integrator>());
167
168 /* */
169 Real swapletPrice() const override;
170 Rate swapletRate() const override;
171 Real capletPrice(Rate effectiveCap) const override;
172 Rate capletRate(Rate effectiveCap) const override;
173 Real floorletPrice(Rate effectiveFloor) const override;
174 Rate floorletRate(Rate effectiveFloor) const override;
175 /* */
176 Real meanReversion() const override;
181 update();
182 }
183
184
185 private:
186
187 Real GsrG(const Date &d) const;
188 Real singularTerms(Option::Type type, Real strike) const;
189 Real integrand(Real strike) const;
191
192 class integrand_f;
193
195 public:
196 VegaRatioHelper(const SmileSection *section, const Real targetVega)
197 : section_(section), targetVega_(targetVega) {}
198 Real operator()(Real strike) const {
199 return section_->vega(strike) - targetVega_;
200 };
203 };
204
206 public:
207 PriceHelper(const SmileSection *section, const Option::Type type,
208 const Real targetPrice)
209 : section_(section), targetPrice_(targetPrice), type_(type) {}
210 Real operator()(Real strike) const {
211 return section_->optionPrice(strike, type_) - targetPrice_;
212 };
216 };
217
218 void initialize(const FloatingRateCoupon& coupon) override;
219 Real optionletPrice(Option::Type optionType, Real strike) const;
220 Real strikeFromVegaRatio(Real ratio, Option::Type optionType,
221 Real referenceStrike) const;
222 Real strikeFromPrice(Real price, Option::Type optionType,
223 Real referenceStrike) const;
224
226
229
231
233
235
239
240 ext::shared_ptr<SwapIndex> swapIndex_;
241 ext::shared_ptr<FixedVsFloatingSwap> swap_;
242 ext::shared_ptr<SmileSection> smileSection_;
243
246 ext::shared_ptr<Integrator> integrator_;
247
249 };
250}
251
252#endif
CMS coupon class.
Definition: cmscoupon.hpp:39
base pricer for vanilla CMS coupons
Concrete date class.
Definition: date.hpp:125
day counter class
Definition: daycounter.hpp:44
base floating-rate coupon class
Shared handle to an observable.
Definition: handle.hpp:41
PriceHelper(const SmileSection *section, const Option::Type type, const Real targetPrice)
VegaRatioHelper(const SmileSection *section, const Real targetVega)
void setMeanReversion(const Handle< Quote > &meanReversion) override
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
ext::shared_ptr< SmileSection > smileSection_
void initialize(const FloatingRateCoupon &coupon) override
ext::shared_ptr< Integrator > integrator_
ext::shared_ptr< SwapIndex > swapIndex_
static const Real defaultLowerBound
Real strikeFromVegaRatio(Real ratio, Option::Type optionType, Real referenceStrike) const
static const Real defaultUpperBound
ext::shared_ptr< FixedVsFloatingSwap > swap_
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
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
interest rate volatility smile section
virtual Real vega(Rate strike, Real discount=1.0) const
virtual Real optionPrice(Rate strike, Option::Type type=Option::Call, Real discount=1.0) const
Coupon pricers.
Date d
Fixed-rate vs floating-rate swap.
QL_REAL Real
real number
Definition: types.hpp:50
Real Rate
interest rates
Definition: types.hpp:70
Integrators base class definition.
Definition: any.hpp:35
Payoffs for various options.
Smile section base class.
Settings & withVegaRatio(const Real vegaRatio=0.01)
Settings & withPriceThreshold(const Real priceThreshold=1.0E-8)
Settings & withBSStdDevs(const Real stdDevs=3.0)
Settings & withPriceThreshold(const Real priceThreshold, const Real lowerRateBound, const Real upperRateBound)
Settings & withRateBound(const Real lowerRateBound=defaultLowerBound, const Real upperRateBound=defaultUpperBound)
Settings & withVegaRatio(const Real vegaRatio, const Real lowerRateBound, const Real upperRateBound)
Settings & withBSStdDevs(const Real stdDevs, const Real lowerRateBound, const Real upperRateBound)
swap-rate indexes