QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
lineartsrpricer.hpp
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
24#ifndef quantlib_lineartsr_pricer_hpp
25#define quantlib_lineartsr_pricer_hpp
26
27#include <ql/termstructures/volatility/smilesection.hpp>
28#include <ql/cashflows/couponpricer.hpp>
29#include <ql/instruments/payoffs.hpp>
30#include <ql/indexes/swapindex.hpp>
31#include <ql/math/integrals/integral.hpp>
32
33namespace QuantLib {
34
35 class CmsCoupon;
36 class YieldTermStructure;
37
39
64
65 private:
66 static const Real defaultLowerBound,
68
69 public:
70
71 struct Settings {
72
74
76 const Real upperRateBound = defaultUpperBound) {
78 lowerRateBound_ = lowerRateBound;
79 upperRateBound_ = upperRateBound;
80 defaultBounds_ = false;
81 return *this;
82 }
83
84 Settings &withVegaRatio(const Real vegaRatio = 0.01) {
86 vegaRatio_ = vegaRatio;
89 defaultBounds_ = true;
90 return *this;
91 }
92
93 Settings &withVegaRatio(const Real vegaRatio,
94 const Real lowerRateBound,
95 const Real upperRateBound) {
97 vegaRatio_ = vegaRatio;
98 lowerRateBound_ = lowerRateBound;
99 upperRateBound_ = upperRateBound;
100 defaultBounds_ = false;
101 return *this;
102 }
103
104 Settings &withPriceThreshold(const Real priceThreshold = 1.0E-8) {
106 priceThreshold_ = priceThreshold;
109 defaultBounds_ = true;
110 return *this;
111 }
112
113 Settings &withPriceThreshold(const Real priceThreshold,
114 const Real lowerRateBound,
115 const Real upperRateBound) {
117 priceThreshold_ = priceThreshold;
118 lowerRateBound_ = lowerRateBound;
119 upperRateBound_ = upperRateBound;
120 defaultBounds_ = false;
121 return *this;
122 }
123
124 Settings &withBSStdDevs(const Real stdDevs = 3.0) {
126 stdDevs_ = stdDevs;
129 defaultBounds_ = true;
130 return *this;
131 }
132
134 const Real lowerRateBound,
135 const Real upperRateBound) {
137 stdDevs_ = stdDevs;
138 lowerRateBound_ = lowerRateBound;
139 upperRateBound_ = upperRateBound;
140 defaultBounds_ = false;
141 return *this;
142 }
143
144 enum Strategy {
149 };
150
156 bool defaultBounds_ = true;
157 };
158
159
161 const Handle<SwaptionVolatilityStructure>& swaptionVol,
164 const Settings& settings = Settings(),
165 ext::shared_ptr<Integrator> integrator = ext::shared_ptr<Integrator>());
166
167 /* */
168 Real swapletPrice() const override;
169 Rate swapletRate() const override;
170 Real capletPrice(Rate effectiveCap) const override;
171 Rate capletRate(Rate effectiveCap) const override;
172 Real floorletPrice(Rate effectiveFloor) const override;
173 Rate floorletRate(Rate effectiveFloor) const override;
174 /* */
175 Real meanReversion() const override;
180 update();
181 }
182
183
184 private:
185
186 Real GsrG(const Date &d) const;
187 Real singularTerms(Option::Type type, Real strike) const;
188 Real integrand(Real strike) const;
190
191 class integrand_f;
192
194 public:
195 VegaRatioHelper(const SmileSection *section, const Real targetVega)
196 : section_(section), targetVega_(targetVega) {}
197 Real operator()(Real strike) const {
198 return section_->vega(strike) - targetVega_;
199 };
202 };
203
205 public:
206 PriceHelper(const SmileSection *section, const Option::Type type,
207 const Real targetPrice)
208 : section_(section), targetPrice_(targetPrice), type_(type) {}
209 Real operator()(Real strike) const {
210 return section_->optionPrice(strike, type_) - targetPrice_;
211 };
215 };
216
217 void initialize(const FloatingRateCoupon& coupon) override;
218 Real optionletPrice(Option::Type optionType, Real strike) const;
219 Real strikeFromVegaRatio(Real ratio, Option::Type optionType,
220 Real referenceStrike) const;
221 Real strikeFromPrice(Real price, Option::Type optionType,
222 Real referenceStrike) const;
223
225
228
230
232
234
237
238 ext::shared_ptr<SwapIndex> swapIndex_;
239 ext::shared_ptr<VanillaSwap> swap_;
240 ext::shared_ptr<SmileSection> smileSection_;
241
244 ext::shared_ptr<Integrator> integrator_;
245
247 };
248}
249
250#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< VanillaSwap > swap_
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
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
QL_REAL Real
real number
Definition: types.hpp:50
Real Rate
interest rates
Definition: types.hpp:70
Definition: any.hpp:35
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)