QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
couponpricer.hpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2007 Giorgio Facchinetti
5 Copyright (C) 2007 Cristina Duminuco
6 Copyright (C) 2011 Ferdinando Ametrano
7 Copyright (C) 2015 Peter Caspers
8
9 This file is part of QuantLib, a free-software/open-source library
10 for financial quantitative analysts and developers - http://quantlib.org/
11
12 QuantLib is free software: you can redistribute it and/or modify it
13 under the terms of the QuantLib license. You should have received a
14 copy of the license along with this program; if not, please email
15 <quantlib-dev@lists.sf.net>. The license is also available online at
16 <http://quantlib.org/license.shtml>.
17
18 This program is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
20 FOR A PARTICULAR PURPOSE. See the license for more details.
21*/
22
27#ifndef quantlib_coupon_pricer_hpp
28#define quantlib_coupon_pricer_hpp
29
30#include <ql/cashflow.hpp>
31#include <ql/indexes/iborindex.hpp>
32#include <ql/option.hpp>
33#include <ql/optional.hpp>
34#include <ql/quotes/simplequote.hpp>
35#include <ql/termstructures/volatility/optionlet/optionletvolatilitystructure.hpp>
36#include <ql/termstructures/volatility/swaption/swaptionvolstructure.hpp>
37#include <utility>
38
39namespace QuantLib {
40
41 class FloatingRateCoupon;
42 class IborCoupon;
43
45 class FloatingRateCouponPricer: public virtual Observer,
46 public virtual Observable {
47 public:
48 ~FloatingRateCouponPricer() override = default;
50
51 virtual Real swapletPrice() const = 0;
52 virtual Rate swapletRate() const = 0;
53 virtual Real capletPrice(Rate effectiveCap) const = 0;
54 virtual Rate capletRate(Rate effectiveCap) const = 0;
55 virtual Real floorletPrice(Rate effectiveFloor) const = 0;
56 virtual Rate floorletRate(Rate effectiveFloor) const = 0;
57 virtual void initialize(const FloatingRateCoupon& coupon) = 0;
59
61 void update() override { notifyObservers(); }
63 };
64
67 public:
68 explicit IborCouponPricer(
70 ext::optional<bool> useIndexedCoupon = ext::nullopt);
71
72 bool useIndexedCoupon() const { return useIndexedCoupon_; }
73
75 return capletVol_;
76 }
81 capletVol_ = v;
83 update();
84 }
85 void initialize(const FloatingRateCoupon& coupon) override;
86
87 void initializeCachedData(const IborCoupon& coupon) const;
88
89 protected:
90
92
93 ext::shared_ptr<IborIndex> index_;
98
101
104 };
105
112 public:
116 const TimingAdjustment timingAdjustment = Black76,
117 Handle<Quote> correlation = Handle<Quote>(ext::shared_ptr<Quote>(new SimpleQuote(1.0))),
118 const ext::optional<bool> useIndexedCoupon = ext::nullopt)
119 : IborCouponPricer(v, useIndexedCoupon), timingAdjustment_(timingAdjustment),
120 correlation_(std::move(correlation)) {
121 { // this additional scope seems required to avoid a misleading-indentation warning
123 "unknown timing adjustment (code " << timingAdjustment_ << ")");
124 }
126 };
127 void initialize(const FloatingRateCoupon& coupon) override;
128 Real swapletPrice() const override;
129 Rate swapletRate() const override;
130 Real capletPrice(Rate effectiveCap) const override;
131 Rate capletRate(Rate effectiveCap) const override;
132 Real floorletPrice(Rate effectiveFloor) const override;
133 Rate floorletRate(Rate effectiveFloor) const override;
134
135 protected:
136 Real optionletPrice(Option::Type optionType, Real effStrike) const;
137 Real optionletRate(Option::Type optionType, Real effStrike) const;
138
139 virtual Rate adjustedFixing(Rate fixing = Null<Rate>()) const;
140
142
143 private:
146 };
147
150 public:
153 : swaptionVol_(std::move(v)) {
155 }
156
158 return swaptionVol_;
159 }
164 swaptionVol_ = v;
166 update();
167 }
168 private:
170 };
171
175 public:
176 virtual Real meanReversion() const = 0;
177 virtual void setMeanReversion(const Handle<Quote>&) = 0;
178 virtual ~MeanRevertingPricer() = default;
179 };
180
181 void setCouponPricer(const Leg& leg,
182 const ext::shared_ptr<FloatingRateCouponPricer>&);
183
184 void setCouponPricers(
185 const Leg& leg,
186 const std::vector<ext::shared_ptr<FloatingRateCouponPricer> >&);
187
189 void setCouponPricers(
190 const Leg& leg,
191 const ext::shared_ptr<FloatingRateCouponPricer>&,
192 const ext::shared_ptr<FloatingRateCouponPricer>&);
193
194 void setCouponPricers(
195 const Leg& leg,
196 const ext::shared_ptr<FloatingRateCouponPricer>&,
197 const ext::shared_ptr<FloatingRateCouponPricer>&,
198 const ext::shared_ptr<FloatingRateCouponPricer>&);
199
200 void setCouponPricers(
201 const Leg& leg,
202 const ext::shared_ptr<FloatingRateCouponPricer>&,
203 const ext::shared_ptr<FloatingRateCouponPricer>&,
204 const ext::shared_ptr<FloatingRateCouponPricer>&,
205 const ext::shared_ptr<FloatingRateCouponPricer>&);
206
207 // inline
208
210 // past or future fixing is managed in InterestRateIndex::fixing()
211 QL_REQUIRE(discount_ != Null<Rate>(), "no forecast curve provided");
213 }
214
216 return gearing_ * adjustedFixing() + spread_;
217 }
218
219 inline Real BlackIborCouponPricer::capletPrice(Rate effectiveCap) const {
220 QL_REQUIRE(discount_ != Null<Rate>(), "no forecast curve provided");
221 return capletRate(effectiveCap) * accrualPeriod_ * discount_;
222 }
223
224 inline Rate BlackIborCouponPricer::capletRate(Rate effectiveCap) const {
225 return gearing_ * optionletRate(Option::Call, effectiveCap);
226 }
227
228 inline
230 QL_REQUIRE(discount_ != Null<Rate>(), "no forecast curve provided");
231 return floorletRate(effectiveFloor) * accrualPeriod_ * discount_;
232 }
233
234 inline
236 return gearing_ * optionletRate(Option::Put, effectiveFloor);
237 }
238
239}
240
241#endif
Real capletPrice(Rate effectiveCap) const override
Rate floorletRate(Rate effectiveFloor) const override
const Handle< Quote > correlation_
BlackIborCouponPricer(const Handle< OptionletVolatilityStructure > &v=Handle< OptionletVolatilityStructure >(), const TimingAdjustment timingAdjustment=Black76, Handle< Quote > correlation=Handle< Quote >(ext::shared_ptr< Quote >(new SimpleQuote(1.0))), const ext::optional< bool > useIndexedCoupon=ext::nullopt)
void initialize(const FloatingRateCoupon &coupon) override
virtual Rate adjustedFixing(Rate fixing=Null< Rate >()) const
Real optionletPrice(Option::Type optionType, Real effStrike) const
const TimingAdjustment timingAdjustment_
Real optionletRate(Option::Type optionType, Real effStrike) const
Rate swapletRate() const override
Real floorletPrice(Rate effectiveFloor) const override
Real swapletPrice() const override
Rate capletRate(Rate effectiveCap) const override
base pricer for vanilla CMS coupons
Handle< SwaptionVolatilityStructure > swaptionVol_
void setSwaptionVolatility(const Handle< SwaptionVolatilityStructure > &v=Handle< SwaptionVolatilityStructure >())
CmsCouponPricer(Handle< SwaptionVolatilityStructure > v=Handle< SwaptionVolatilityStructure >())
Handle< SwaptionVolatilityStructure > swaptionVolatility() const
Concrete date class.
Definition: date.hpp:125
base floating-rate coupon class
generic pricer for floating-rate coupons
virtual Real capletPrice(Rate effectiveCap) const =0
virtual Real floorletPrice(Rate effectiveFloor) const =0
virtual Rate capletRate(Rate effectiveCap) const =0
virtual Rate floorletRate(Rate effectiveFloor) const =0
virtual Real swapletPrice() const =0
virtual Rate swapletRate() const =0
virtual void initialize(const FloatingRateCoupon &coupon)=0
~FloatingRateCouponPricer() override=default
Shared handle to an observable.
Definition: handle.hpp:41
Coupon paying a Libor-type index
Definition: iborcoupon.hpp:41
base pricer for capped/floored Ibor coupons
void initializeCachedData(const IborCoupon &coupon) const
void initialize(const FloatingRateCoupon &coupon) override
Handle< OptionletVolatilityStructure > capletVolatility() const
Handle< OptionletVolatilityStructure > capletVol_
const IborCoupon * coupon_
void setCapletVolatility(const Handle< OptionletVolatilityStructure > &v=Handle< OptionletVolatilityStructure >())
ext::shared_ptr< IborIndex > index_
virtual void setMeanReversion(const Handle< Quote > &)=0
virtual ~MeanRevertingPricer()=default
virtual Real meanReversion() const =0
template class providing a null value for a given type.
Definition: null.hpp:76
Object that notifies its changes to a set of observers.
Definition: observable.hpp:62
Object that gets notified when a given observable changes.
Definition: observable.hpp:116
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
market element returning a stored value
Definition: simplequote.hpp:33
Real Time
continuous quantity with 1-year units
Definition: types.hpp:62
QL_REAL Real
real number
Definition: types.hpp:50
Real Spread
spreads on interest rates
Definition: types.hpp:74
Real Rate
interest rates
Definition: types.hpp:70
const boost::none_t & nullopt
Definition: optional.cpp:27
Definition: any.hpp:35
void setCouponPricers(const Leg &leg, const std::vector< ext::shared_ptr< FloatingRateCouponPricer > > &pricers)
void setCouponPricer(const Leg &leg, const ext::shared_ptr< FloatingRateCouponPricer > &pricer)
std::vector< ext::shared_ptr< CashFlow > > Leg
Sequence of cash-flows.
Definition: cashflow.hpp:78
STL namespace.